Capistrano: run Grunt locally and upload files

I’ve modified this to be a bit cleaner and more Ruby/Cap idiomatic. The one major difference is ideally you should modify your Grunt production task to output the files you want to some separate dir like dist/ then you can just upload that whole file instead of individually listing files. It’s just easier not to duplicate some logic from Grunt in here.

Note: I haven’t actually tested this.

set :theme_path, Pathname.new('web/app/themes/mytheme')
set :local_app_path, Pathname.new('/Applications/MAMP/htdocs/mysite')
set :local_theme_path, fetch(:local_app_path).join(fetch(:theme_path))

namespace :deploy do
  task :compile_assets do
    run_locally do
      within fetch(:local_theme_path) do
        execute :grunt, :build
      end
    end
  end

  task :copy_assets do
    invoke 'deploy:compile_assets'

    on roles(:web) do
      upload! fetch(:local_theme_path).join('dist'), release_path.join(fetch(:theme_path)), recursive: true
    end
  end
end
1 Like