public
Created

Quick rake task to check if assets need to pre-compiled before deployment (since I don't like precompiling during deployment)

  • Download Gist
asset.rake
Ruby
1 2 3 4 5 6 7 8 9 10 11
namespace :assets do
task :check do
root_dir = File.join(File.dirname(__FILE__),"..","..")
assets_last_modified_at = Dir["#{root_dir}/app/assets/**/**"].map { |p| File.mtime(p) }.sort.last
assets_last_compiled_at = Dir["#{root_dir}/public/assets/**/**"].map { |p| File.mtime(p) }.sort.last
 
if assets_last_modified_at > assets_last_compiled_at
fail "Assets need to precompiled; last asset modified at #{assets_last_modified_at}"
end
end
end

I have a deployment rake task that runs this task as a prerequisite.

rails 4 does that

nick@nite:~/workspace/wonderpus$ time rake assets:precompile
I, [2013-03-03T16:57:10.293490 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime-webfont-39959c4d0ed4708ff007bd7379330491.eot
I, [2013-03-03T16:57:10.296108 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime-webfont-f69c2eb8befb4ed4bc39c5bdf3311ccd.svg
I, [2013-03-03T16:57:10.297458 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime-webfont-f1c3e0cf69e5e8ce9cd2959e3033644d.ttf
I, [2013-03-03T16:57:10.298700 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime-webfont-01e816614d7c45cbb1fc98b299c1f189.woff
I, [2013-03-03T16:57:10.300021 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime_bold-webfont-23302a809cbc3542abc09c0d4ef1473f.eot
I, [2013-03-03T16:57:10.301515 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime_bold-webfont-33cf08ac0cb187607b37823b0c0b6eb5.svg
I, [2013-03-03T16:57:10.303106 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime_bold-webfont-bc9f68a16809d5db5342933c5946d2bf.ttf
I, [2013-03-03T16:57:10.304689 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime_bold-webfont-7acd8104cd020334bb29c851e4e5a826.woff
I, [2013-03-03T16:57:10.306326 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime_bold_italic-webfont-50cfd79f41d379691fac4d174930d04b.eot
I, [2013-03-03T16:57:10.308152 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime_bold_italic-webfont-0a03730837e03c4284132971faaf3bf1.svg
I, [2013-03-03T16:57:10.309982 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime_bold_italic-webfont-ca9962fa097c4ac85080a669ca6c9980.ttf
I, [2013-03-03T16:57:10.311916 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime_bold_italic-webfont-9584c5af94b0f0efbb083ea1354f3ba2.woff
I, [2013-03-03T16:57:10.331749 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime_italic-webfont-e813dd45df6a1ebc0960b2746f700ba7.eot
I, [2013-03-03T16:57:10.334221 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime_italic-webfont-1a14d271dd822cffe8bd5523fd719561.svg
I, [2013-03-03T16:57:10.336500 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime_italic-webfont-271cd743b2d50b4bcc3b2c2f494882a6.ttf
I, [2013-03-03T16:57:10.338699 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/courier_prime_italic-webfont-5988867e78bda65d587a9a7c8ec24b8b.woff
I, [2013-03-03T16:57:10.340861 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/expand-8d599749eb38dd928a372ec1f4143cdc.png
I, [2013-03-03T16:57:10.343103 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/wonderpus-15edbc27efa5baf5144e38977d1ce86b.jpg
I, [2013-03-03T16:57:10.929282 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/application-608aa8887b6f3de74057c10d55edb1b7.js
I, [2013-03-03T16:57:11.379582 #6262]  INFO -- : Writing /home/nick/workspace/wonderpus/public/assets/application-6ad214b6b7bba7324f714ae79fa01cf1.css

real    0m2.948s
user    0m2.724s
sys 0m0.176s
nick@nite:~/workspace/wonderpus$ time rake assets:precompile

real    0m1.757s
user    0m1.652s
sys 0m0.092s

I'd love to see this integrated into Capistrano. If no assets modified, use the previous version if it exists.

Be aware the task doesn't check if assets inside gems have been updated, which may be a problem for some.

thanks guys! Nick looks like this is a solved problem, thanks!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.