Permalink
Browse files

manifest:hide_buildfiles now hides debug and fixture files unless con…

…fig options are turned on. (the options are on in debug mode)
  • Loading branch information...
1 parent ea0d481 commit 920adf9079e0f983b47603c8b36a084e11cdfc17 Charles Jolley committed Jan 15, 2009
View
@@ -1,26 +1,46 @@
# Import all build tasks
import *Dir.glob(File.join(File.dirname(__FILE__), 'buildtasks', '**', '*.rake'))
-config :all,
+mode :all do
+ config :all,
- # REQUIRED CONFIGS
- # You will not usually need to override these configs, but the code assumes
- # they will be present, so you must support them.
- :build_prefix => 'tmp/build',
- :staging_prefix => 'tmp/staging',
- :url_prefix => 'static',
+ # REQUIRED CONFIGS
+ # You will not usually need to override these configs, but the code
+ # assumes they will be present, so you must support them.
+ :build_prefix => 'tmp/build',
+ :staging_prefix => 'tmp/staging',
+ :url_prefix => 'static',
- # Defines the directories that may contain targets, and maps them to a
- # target type. When a project tries to find all of the targets in a
- # project, it will use this map to find them.
- :target_types => {
- :apps => :app,
- :clients => :app,
- :frameworks => :framework,
- },
+ # Defines the directories that may contain targets, and maps them to a
+ # target type. When a project tries to find all of the targets in a
+ # project, it will use this map to find them.
+ :target_types => {
+ :apps => :app,
+ :clients => :app,
+ :frameworks => :framework,
+ },
- # Allows the target to have other targets nested inside of it. Override
- # this in your target Buildfile to disable nesting.
- :allow_nested_targets => true,
+ # Allows the target to have other targets nested inside of it. Override
+ # this in your target Buildfile to disable nesting.
+ :allow_nested_targets => true,
+
+ # The default preferred language. Assets will be pulled from this
+ # language unless otherwise specified.
+ :preferred_language => :en,
+
+ # Do not include fixtures in built project.
+ :load_fixtures => false,
+
+ # Do not include debug directory in built project
+ :load_debug => false
+end
+
+
+mode :debug do
+ config :all,
- :preferred_language => :en
+ # in debug mode, load fixtures and debug code
+ :load_fixtures => true,
+ :load_debug => true
+end
+
View
@@ -33,12 +33,10 @@ namespace :manifest do
# source_root
MANIFEST.source_root = TARGET.source_root
end
-
- # Invoked to actually build a manifest. This will invoke several other
- # tasks on the same manifest. In a Buildfile you may choose to extend or
- # override this task to provide your own manifest generation.
- task :build => %w(manifest:prepare_stylesheets) do
- puts "BUILDING MANIFEST!"
+
+ desc "Actually builds a manifest. This will catalog all entries and then filter them"
+ task :build => %w(manifest:catalog manifest:localize) do
+ puts "BUILDING MANIFEST! - #{SC.build_mode} - load_debug = #{CONFIG.load_debug} - load_fixtures = #{CONFIG.load_fixtures}"
end
desc "first step in building a manifest, this adds a simple copy file entry for every file in the source"
@@ -52,19 +50,33 @@ namespace :manifest do
end
end
- desc "hides structural files that do not belong in build"
- task :hide_buildfiles => 'manifest:catalog' do
+ desc "hides structural files that do not belong in build include Buildfiles and debug or fixtures if turned off"
+ task :hide_buildfiles => :catalog do
+ load_debug = CONFIG.load_debug
+ load_fixtures = CONFIG.load_fixtures
MANIFEST.entries.each do |entry|
- # allow if inside lproj
+ # if in /debug or /foo.lproj/debug - hide...
+ if !load_debug && entry.filename =~ /^(([^\/]+)\.lproj\/)?debug\/.+$/
+ entry.hide!
+ next
+ end
+
+ # if in /fixtures or /foo.lproj/fixtures - hide...
+ if !load_fixtures && entry.filename =~ /^(([^\/]+)\.lproj\/)?fixtures\/.+$/
+ entry.hide!
+ next
+ end
+
+ # otherwise, allow if inside lproj
next if entry.localized? || entry.filename =~ /^.+\.lproj\/.+$/
- # otherwise, skip if ext not js
+ # or skip if ext not js
entry.hide! if entry.ext != 'js'
end
end
desc "localizes files. reject any files from other languages"
- task :localize => %w(manifest:hide_buildfiles) do
+ task :localize => [:catalog, :hide_buildfiles] do
seen = {} # already seen entries...
preferred_language = TARGET.config.preferred_language || :en
@@ -107,31 +119,8 @@ namespace :manifest do
end
end
- desc "Removes fixtures from the list of entries unless config.load_fixtures is true"
- task :hide_fixtures => %w(manifest:localize) do
- unless CONFIG.load_fixtures
- MANIFEST.entries.each do |entry|
- entry.hide! if entry.filename =~ /^fixtures\/.+$/
- end
- end
- end
-
- desc "Removes any debug assets unless config.load_debug is true"
- task :hide_debug => %w(manifest:hide_fixtures) do
- unless CONFIG.load_debug
- MANIFEST.entries.each do |entry|
- entry.hide! if entry.filename =~ /^debug\/.+$/
- end
- end
- end
-
- # Assign a normalized type to each entry. Normalized types are used by
- # later tasks to sort the entries into groups for post-processing. The
- # default implementation assigns each item a type of :html, :javascript,
- # :stylesheet, :test, :image, or :resource. You can extend this to assign
- # different entry_types to an entry to do your own processing later.
- #
- task :assign_types => %w(manifest:hide_debug) do
+ desc "assigns a normalized type to each entry. These types will be used to control all the future filters"
+ task :assign_types => :localize do
MANIFEST.entries.each do |entry|
next if entry.entry_type
@@ -131,15 +131,15 @@ def invoke(*args)
# Same as invoke, but explicitly pass a call chain to detect
# circular dependencies.
def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
- return if invocation_chain.already_invoked?(self)
- new_chain = InvocationChain.append(self, invocation_chain)
- @lock.synchronize do
- SC.logger.debug "** Invoke #{name} #{format_trace_flags}"
- new_chain = invoke_prerequisites(task_args, new_chain)
- execute(task_args) if needed?
+ unless invocation_chain.already_invoked?(self)
+ invocation_chain = InvocationChain.append(self, invocation_chain)
+ @lock.synchronize do
+ SC.logger.debug "** Invoke #{name} #{format_trace_flags}"
+ invocation_chain = invoke_prerequisites(task_args, invocation_chain)
+ execute(task_args) if needed?
+ end
end
-
- return new_chain
+ return invocation_chain
end
protected :invoke_with_call_chain
@@ -104,20 +104,62 @@ def run_task
super('manifest:hide_buildfiles')
end
+ def entry_for(filename)
+ @manifest.entry_for filename, :hidden => true
+ end
+
it "should hide any Buildfile, sc-config, or sc-config.rb" do
run_task
- @manifest.entry_for('Buildfile', :hidden => true).hidden?.should be_true
+ entry_for('Buildfile').hidden?.should be_true
end
it "should hide any non .js file outside of .lproj dirs" do
run_task
- @manifest.entry_for('README', :hidden => true).hidden?.should be_true
- @manifest.entry_for('lib/index.html', :hidden => true).hidden?.should be_true
+ entry_for('README').hidden?.should be_true
+ entry_for('lib/index.html').hidden?.should be_true
end
it "should NOT hide non-js files inslide lproj dirs" do
run_task
- entry = @manifest.entry_for('english.lproj/demo.html', :hidden => true)
+ entry = entry_for('english.lproj/demo.html')
+ entry.hidden?.should be_false
+ end
+
+ # CONFIG.load_fixtures
+ it "should hide files in /fixtures and /*.lproj/fixtures if CONFIG.load_fixtures is false" do
+ @target.config.load_fixtures = false
+ run_task
+ entry = entry_for('fixtures/sample_fixtures.js')
+ entry.hidden?.should be_true
+ entry = entry_for('english.lproj/fixtures/sample_fixtures-loc.js')
+ entry.hidden?.should be_true
+ end
+
+ it "should NOT hide files in /fixtures and /*.lproj/fixtures if CONFIG.load_fixtures is true" do
+ @target.config.load_fixtures = true
+ run_task
+ entry = entry_for('fixtures/sample_fixtures.js')
+ entry.hidden?.should be_false
+ entry = entry_for('english.lproj/fixtures/sample_fixtures-loc.js')
+ entry.hidden?.should be_false
+ end
+
+ # CONFIG.load_debug
+ it "should hide files in /debug and /*.lproj/debug if CONFIG.load_debug is false" do
+ @target.config.load_debug = false
+ run_task
+ entry = entry_for('debug/sample_debug.js')
+ entry.hidden?.should be_true
+ entry = entry_for('english.lproj/debug/sample_debug-loc.js')
+ entry.hidden?.should be_true
+ end
+
+ it "should NOT hide files in /debug and /*.lproj/debug if CONFIG.load_fixtures is true" do
+ @target.config.load_debug = true
+ run_task
+ entry = entry_for('debug/sample_debug.js')
+ entry.hidden?.should be_false
+ entry = entry_for('english.lproj/debug/sample_debug-loc.js')
entry.hidden?.should be_false
end

0 comments on commit 920adf9

Please sign in to comment.