Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds rake task to cleanup compiled assets #1355

Merged
merged 3 commits into from May 30, 2011
Merged

Adds rake task to cleanup compiled assets #1355

merged 3 commits into from May 30, 2011

Conversation

gnufied
Copy link
Contributor

@gnufied gnufied commented May 27, 2011

updated with requiring fileutils before attempting to use it.

@gnufied
Copy link
Contributor Author

gnufied commented May 27, 2011

/cc @josevalim

@josevalim
Copy link
Contributor

/cc @dhh and /cc @josh

@rhulse
Copy link

rhulse commented May 27, 2011

Shouldn't the globbed filespec match that which spockets uses?

i.e. Line 54 in Sprockets::StaticCompilation

pattern = /^#{Regexp.escape(asset_pathname.basename_without_extensions.to_s)}
-([0-9a-f]{7,40})
#{Regexp.escape(asset_pathname.extensions.join)}$/x

rm_ing everything might not be what some people expect.

@josh
Copy link
Contributor

josh commented May 27, 2011

Cool, but I'd suggest following rake conventions here. Call it assets:clean and make use of Rake::FileList instead of dir globbing.

@vishnuatrai
Copy link
Contributor

done! /cc @josh

assets = Rails.application.config.assets
public_asset_path = Rails.public_path + assets.prefix
file_list = FileList.new("#{public_asset_path}/*.js", "#{public_asset_path}/*.css")
file_list.each{ |list| FileUtils.rm list }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use FileUtils directly. Just do rm, its a helper built on to rake.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only *.js and *.css? I think image assets should be cleaned up as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why *.js and *.css only? Also why all of them?
If the rake task tries to be smart by deleting only the "asset" files, then deleting all js/css doesn't make sense.
On the other hand, why not then just delete the whole assets directory thus making sure that all assets are cleared properly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a proposed solution here: #1776, but I like @dnagir's suggestion to remove everything inside the assets directory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just change the glob to "#{public_asset_path}/**/*

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the pull request as per this suggestion. Thanks, @josh

@vishnuatrai
Copy link
Contributor

refectored!! /cc @josh

josh added a commit that referenced this pull request May 30, 2011
Adds rake task to cleanup compiled assets
@josh josh merged commit 8623905 into rails:master May 30, 2011
@josevalim
Copy link
Contributor

We need tests for this. Could someone please provide some tests? Otherwise I will have to revert it.

@vishnuatrai
Copy link
Contributor

@josevalim I will provide test case and other refactoring soon. /cc @josevalim

@jamesarosen
Copy link
Contributor

@vatrai how were you thinking of testing it? I had considered moving the cleanup into a method on Rails.application.assets (which is actually a Sprockets::Environment object), but that means monkey-patching Sprockets from within Rails.

@josevalim
Copy link
Contributor

Tests can be added here:

https://github.com/rails/rails/blob/master/railties/test/application/assets_test.rb

There are examples of invoking the rake tasks in the same test case.

@jamesarosen
Copy link
Contributor

Thanks, @josevalim! I'll get that done this morning and submit another pull request.

@jamesarosen
Copy link
Contributor

I added some tests on my pull request.

@vishnuatrai
Copy link
Contributor

thanks!! @jamesarosen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants