Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically call asset:publish --bench="vendor/package" during development in Laravel 4

I'm working on a an package and I really need to be able to fire the

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

command automatically during development.

It's very time consuming to write that command every time I do changes to my JavaScript or CSS files in my packages.

I've tried to call Artisan in 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 designed to be called via the web? Does anybody have some advice?

like image 657
Arni Gudjonsson Avatar asked Feb 01 '13 10:02

Arni Gudjonsson


2 Answers

You can use Guard for tasks like this. For example, here is a portion from my Guardfile to automatically publish assets from a package whenever they are changed:

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

You can also have it automatically compile Sass, setup livereload, etc. Take a look at Jeffrey Way's screencast to get started.

like image 118
Jamie Schembri Avatar answered Sep 21 '22 19:09

Jamie Schembri


You can achieve this using Grunt with a shell watch command, e.g:

$ npm install grunt-shell

In 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']);

Then start the watch:

$ grunt watch

This can naturally work after other grunt commands such as less or uglify has compiled your assets into public, thus changing them and triggering the publish.

like image 39
scipilot Avatar answered Sep 22 '22 19:09

scipilot