Automatically invoke a resource: publish --bench = "provider / package" during development in Laravel 4

I am working on a package and I really need to be able to run

php artisan asset:publish --bench="vendor/package"

automatically during development.

It takes a lot of time to write this command every time I make changes to my JavaScript or CSS files in my packages.

I tried to call Artisan with my service provider

public function boot()
{       
    Artisan::call('asset:publish', array('--bench' => 'arni-gudjonsson/webber'));
    ...
}

I got

ErrorException: Runtime Notice: Non-static method Illuminate\Foundation\Artisan::call() should not be called statically, assuming $this from incompatible context

Is Artisan not intended to be called over the Internet? Does anyone have any advice?

+5
source share
7 answers

You can use Guard for such tasks. For example, here is a part of my Guardfile to automatically publish assets from a package when they change:

guard :shell do
    watch(%r{^workbench/vendor/package/public/.+\..+$}) {
        `php artisan asset:publish --bench="vendor/package"`
    }
end

Sass, .. Jeffrey Way screencast, .

+4

, Grunt watch watch, :

$ npm install grunt-shell

vendor/yourname/yourpackage/Gruntfile.js:

    shell: {                           
        assets: {                      
            options: {                 
                stdout: true
            },
            command: 'cd ../../..; php artisan asset:publish yourname/yourpackage'
        },
        views: {                      
            options: {                
                stdout: true
            },
            command: 'cd ../../..; php artisan view:publish yourname/yourpackage;'
        }
    },
    watch: {
        assets: {
            files: ['./public/**/*.js', './public/**/*.css'],
            tasks: ['shell:assets']
        },
        views: {
            files: ['./src/views/**/*.php', './src/views/**/*.md'],
            tasks: ['shell:views']                          
        }
    }

...

grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask('default', ['watch']);

:

$ grunt watch

, , , grunt, less uglify, , .

+3

, :

<?php namespace Vendor\Package;

use \App;
use Illuminate\Filesystem\Filesystem;

class DecoyServiceProvider extends ServiceProvider {
    public function boot() {
        $this->package('bkwld/decoy');

        // Auto-publish the assets when developing locally
        if (App::environment() == 'local' && !App::runningInConsole()) {
            $workbench = realpath(base_path().'/workbench');
            if (strpos(__FILE__, $workbench) === false) App::make('asset.publisher')->publishPackage('vendor/package');
            else App::make('asset.publisher')->publishPackage('vendor/package', $workbench);
        }
    }   
}

, , , .

0

/Workbench/yourappspace/yourapp/AppServiceProvider.php

<?php namespace YourAppSpace\YourApp;

use Illuminate\Support\ServiceProvider;
use Artisan;

boot()

public function boot()
{
$this->package('yourappspace/yourapp');
$app = $this->app;
include __DIR__.'/../../routes.php';

Artisan::call('asset:publish', array('--bench' => 'yourappspace/yourapp'));
}

, , Artisan.

0

. , :

"post-install-cmd": [
    "php artisan clear-compiled",
    "php artisan optimize",
    "php artisan asset:publish vendor-name/package-name"
],
0

5.1 :

\Artisan::call('vendor:publish', [ '--tag' => ['public'], '--provider' => 'Some\Your\ServiceProvider', '--force' => true ]);

0

css js

{app_root}///{}/{CSS | JS}

, , . , , , . -

:: Run ( ( 'task_name'));

.

-1

All Articles