From 162889e0c18ecefc4d9c6a5e7cc7254143c87aed Mon Sep 17 00:00:00 2001 From: DavidWei Date: Mon, 4 Apr 2016 22:00:27 +0800 Subject: [PATCH 1/3] indent code --- lib/capistrano/tasks/faster_assets.rake | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/capistrano/tasks/faster_assets.rake b/lib/capistrano/tasks/faster_assets.rake index 30e3f8f..cf48de8 100644 --- a/lib/capistrano/tasks/faster_assets.rake +++ b/lib/capistrano/tasks/faster_assets.rake @@ -17,7 +17,7 @@ namespace :deploy do within release_path do with rails_env: fetch(:rails_env) do begin - # find the most recent release + # find the most recent release latest_release = capture(:ls, '-xr', releases_path).split[1] # precompile if this is the first deploy @@ -29,12 +29,12 @@ namespace :deploy do execute(:ls, latest_release_path.join('assets_manifest_backup')) rescue raise(PrecompileRequired) fetch(:assets_dependencies).each do |dep| - release = release_path.join(dep) - latest = latest_release_path.join(dep) - - # skip if both directories/files do not exist - next if [release, latest].map{|d| test "[ -e #{d} ]"}.uniq == [false] - + release = release_path.join(dep) + latest = latest_release_path.join(dep) + + # skip if both directories/files do not exist + next if [release, latest].map{|d| test "[ -e #{d} ]"}.uniq == [false] + # execute raises if there is a diff execute(:diff, '-Nqr', release, latest) rescue raise(PrecompileRequired) end From 9fa49eee4cabce3b180ea589352c870afd97d61e Mon Sep 17 00:00:00 2001 From: DavidWei Date: Mon, 4 Apr 2016 23:27:40 +0800 Subject: [PATCH 2/3] REF: https://github.com/capistrano-plugins/capistrano-faster-assets/pull/20 --- lib/capistrano/tasks/faster_assets.rake | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/capistrano/tasks/faster_assets.rake b/lib/capistrano/tasks/faster_assets.rake index cf48de8..98baa4b 100644 --- a/lib/capistrano/tasks/faster_assets.rake +++ b/lib/capistrano/tasks/faster_assets.rake @@ -41,8 +41,17 @@ namespace :deploy do info("Skipping asset precompile, no asset diff found") - # copy over all of the assets from the last release - execute(:cp, '-r', latest_release_path.join('public', fetch(:assets_prefix)), release_path.join('public', fetch(:assets_prefix))) + release_asset_path = release_path.join('public', fetch(:assets_prefix)) + # skip if assets directory is symlink + begin + execute(:test, '-L', release_asset_path.to_s) + rescue + # copy over all of the assets from the last release + execute(:cp, '-r', latest_release_path.join('public', fetch(:assets_prefix)), release_asset_path.parent) + end + + # copy assets if manifest file is not exist (this is first deploy after using symlink) + execute(:ls, release_asset_path.join('manifest*')) rescue raise(PrecompileRequired) rescue PrecompileRequired execute(:rake, "assets:precompile") end From 93b2bf66f7a9572d6e7e53a908ac48bc28fa75ba Mon Sep 17 00:00:00 2001 From: DavidWei Date: Tue, 5 Apr 2016 09:00:01 +0800 Subject: [PATCH 3/3] Add assets_env variable to make the environment variable work --- README.md | 6 ++++++ lib/capistrano/tasks/faster_assets.rake | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 93f06e1..1666cc2 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,12 @@ And then: Add this line to `Capfile`, after `require 'capistrano/rails/assets'` require 'capistrano/faster_assets' + +If U want to add some environment variable when compile assets, add `assets_env` in your stage file. + +```ruby +set :assets_env, { doit: false } +``` ### Warning diff --git a/lib/capistrano/tasks/faster_assets.rake b/lib/capistrano/tasks/faster_assets.rake index 98baa4b..08d3090 100644 --- a/lib/capistrano/tasks/faster_assets.rake +++ b/lib/capistrano/tasks/faster_assets.rake @@ -15,7 +15,9 @@ namespace :deploy do task :precompile do on roles(fetch(:assets_roles)) do within release_path do - with rails_env: fetch(:rails_env) do + # assets_env should be a hash, ie: assets_env: { skip_it: false } + _assets_env = fetch(:assets_env, {}).merge(rails_env: fetch(:rails_env)) + with _assets_env do begin # find the most recent release latest_release = capture(:ls, '-xr', releases_path).split[1]