Add a new command to clean up generated files
This commit is contained in:
parent
2be7567bb2
commit
39df74c55a
@ -145,6 +145,7 @@ Feature: Command Line
|
|||||||
Scenario: Basic help
|
Scenario: Basic help
|
||||||
When I run: compass help
|
When I run: compass help
|
||||||
Then I should see the following "primary" commands:
|
Then I should see the following "primary" commands:
|
||||||
|
| clean |
|
||||||
| compile |
|
| compile |
|
||||||
| create |
|
| create |
|
||||||
| init |
|
| init |
|
||||||
@ -179,6 +180,27 @@ Feature: Command Line
|
|||||||
And I run: compass compile
|
And I run: compass compile
|
||||||
And a css file tmp/layout.css is reported overwritten
|
And a css file tmp/layout.css is reported overwritten
|
||||||
|
|
||||||
|
Scenario: Cleaning a project
|
||||||
|
Given I am using the existing project in test/fixtures/stylesheets/compass
|
||||||
|
When I run: compass compile
|
||||||
|
And I run: compass clean
|
||||||
|
Then the following files are reported removed:
|
||||||
|
| .sass-cache/ |
|
||||||
|
| tmp/border_radius.css |
|
||||||
|
| tmp/box.css |
|
||||||
|
| tmp/box_shadow.css |
|
||||||
|
| tmp/columns.css |
|
||||||
|
| tmp/fonts.css |
|
||||||
|
| images/flag-s03c3b29b35.png |
|
||||||
|
And the following files are removed:
|
||||||
|
| .sass-cache/ |
|
||||||
|
| tmp/border_radius.css |
|
||||||
|
| tmp/box.css |
|
||||||
|
| tmp/box_shadow.css |
|
||||||
|
| tmp/columns.css |
|
||||||
|
| tmp/fonts.css |
|
||||||
|
| images/flag-s03c3b29b35.png |
|
||||||
|
|
||||||
Scenario: Watching a project for changes
|
Scenario: Watching a project for changes
|
||||||
Given ruby supports fork
|
Given ruby supports fork
|
||||||
Given I am using the existing project in test/fixtures/stylesheets/compass
|
Given I am using the existing project in test/fixtures/stylesheets/compass
|
||||||
@ -218,7 +240,6 @@ Feature: Command Line
|
|||||||
| sass_dir | sass |
|
| sass_dir | sass |
|
||||||
| css_dir | assets/css |
|
| css_dir | assets/css |
|
||||||
|
|
||||||
@now
|
|
||||||
Scenario Outline: Print out a configuration value
|
Scenario Outline: Print out a configuration value
|
||||||
Given I am using the existing project in test/fixtures/stylesheets/compass
|
Given I am using the existing project in test/fixtures/stylesheets/compass
|
||||||
When I run: compass config -p <property>
|
When I run: compass config -p <property>
|
||||||
|
@ -116,10 +116,30 @@ Then /^a directory ([^ ]+) is (not )?created$/ do |directory, negated|
|
|||||||
File.directory?(directory).should == !negated
|
File.directory?(directory).should == !negated
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Then /an? \w+ file ([^ ]+) is (not )?removed/ do |filename, negated|
|
||||||
|
File.exists?(filename).should == !!negated
|
||||||
|
end
|
||||||
|
|
||||||
Then /an? \w+ file ([^ ]+) is (not )?created/ do |filename, negated|
|
Then /an? \w+ file ([^ ]+) is (not )?created/ do |filename, negated|
|
||||||
File.exists?(filename).should == !negated
|
File.exists?(filename).should == !negated
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Then "the following files are reported removed:" do |table|
|
||||||
|
table.rows.each do |css_file|
|
||||||
|
Then %Q{a css file #{css_file.first} is reported removed}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Then "the following files are removed:" do |table|
|
||||||
|
table.rows.each do |css_file|
|
||||||
|
Then %Q{a css file #{css_file.first} is removed}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Then /an? \w+ file ([^ ]+) is reported removed/ do |filename|
|
||||||
|
@last_result.should =~ /remove.*#{Regexp.escape(filename)}/
|
||||||
|
end
|
||||||
|
|
||||||
Then /an? \w+ file ([^ ]+) is reported created/ do |filename|
|
Then /an? \w+ file ([^ ]+) is reported created/ do |filename|
|
||||||
@last_result.should =~ /create.*#{Regexp.escape(filename)}/
|
@last_result.should =~ /create.*#{Regexp.escape(filename)}/
|
||||||
end
|
end
|
||||||
|
@ -4,7 +4,7 @@ end
|
|||||||
require 'compass/commands/registry'
|
require 'compass/commands/registry'
|
||||||
|
|
||||||
%w(base generate_grid_background default help list_frameworks project_base
|
%w(base generate_grid_background default help list_frameworks project_base
|
||||||
update_project watch_project create_project imports installer_command
|
update_project watch_project create_project clean_project imports installer_command
|
||||||
print_version project_stats stamp_pattern sprite validate_project
|
print_version project_stats stamp_pattern sprite validate_project
|
||||||
write_configuration interactive unpack_extension).each do |lib|
|
write_configuration interactive unpack_extension).each do |lib|
|
||||||
require "compass/commands/#{lib}"
|
require "compass/commands/#{lib}"
|
||||||
|
79
lib/compass/commands/clean_project.rb
Normal file
79
lib/compass/commands/clean_project.rb
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
require 'compass/commands/project_base'
|
||||||
|
require 'compass/compiler'
|
||||||
|
|
||||||
|
module Compass
|
||||||
|
module Commands
|
||||||
|
module CleanProjectOptionsParser
|
||||||
|
def set_options(opts)
|
||||||
|
opts.banner = %Q{
|
||||||
|
Usage: compass clean [path/to/project] [options]
|
||||||
|
|
||||||
|
Description:
|
||||||
|
Remove generated files and the sass cache.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
}.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n")
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class CleanProject < UpdateProject
|
||||||
|
|
||||||
|
register :clean
|
||||||
|
|
||||||
|
def initialize(working_path, options)
|
||||||
|
super
|
||||||
|
assert_project_directory_exists!
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform
|
||||||
|
compiler = new_compiler_instance
|
||||||
|
compiler.clean!
|
||||||
|
Compass::SpriteImporter.find_all_sprite_map_files(Compass.configuration.images_path).each do |sprite|
|
||||||
|
remove sprite
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def determine_cache_location
|
||||||
|
Compass.configuration.cache_path || Sass::Plugin.options[:cache_location] || File.join(working_path, ".sass-cache")
|
||||||
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def option_parser(arguments)
|
||||||
|
parser = Compass::Exec::CommandOptionParser.new(arguments)
|
||||||
|
parser.extend(Compass::Exec::GlobalOptionsParser)
|
||||||
|
parser.extend(Compass::Exec::ProjectOptionsParser)
|
||||||
|
parser.extend(CleanProjectOptionsParser)
|
||||||
|
end
|
||||||
|
|
||||||
|
def usage
|
||||||
|
option_parser([]).to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def primary; true; end
|
||||||
|
|
||||||
|
def description(command)
|
||||||
|
"Remove generated files and the sass cache"
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse!(arguments)
|
||||||
|
parser = option_parser(arguments)
|
||||||
|
parser.parse!
|
||||||
|
parse_arguments!(parser, arguments)
|
||||||
|
parser.options
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_arguments!(parser, arguments)
|
||||||
|
if arguments.size > 0
|
||||||
|
parser.options[:project_name] = arguments.shift if File.directory?(arguments.first)
|
||||||
|
unless arguments.empty?
|
||||||
|
parser.options[:sass_files] = arguments.dup
|
||||||
|
parser.options[:force] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -4,7 +4,14 @@ module Compass
|
|||||||
VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/
|
VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/
|
||||||
SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.png}
|
SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.png}
|
||||||
VALID_EXTENSIONS = ['.png']
|
VALID_EXTENSIONS = ['.png']
|
||||||
|
|
||||||
|
# finds all sprite files
|
||||||
|
def self.find_all_sprite_map_files(path)
|
||||||
|
hex = "[0-9a-f]"
|
||||||
|
glob = "*-{,s}#{hex*10}{#{VALID_EXTENSIONS.join(",")}}"
|
||||||
|
Dir.glob(File.join(path, "**", glob))
|
||||||
|
end
|
||||||
|
|
||||||
def self.load(uri, options)
|
def self.load(uri, options)
|
||||||
klass = Compass::SpriteImporter.new
|
klass = Compass::SpriteImporter.new
|
||||||
klass.uri, klass.options = uri, options
|
klass.uri, klass.options = uri, options
|
||||||
|
Loading…
Reference in New Issue
Block a user