Permalink
Browse files

Manifest now discovers requires and sc_resource directives and genera…

…tes entries for combined JavaScript and Stylesheets
  • Loading branch information...
1 parent 920adf9 commit 86b2d925e1f7a9cad05d52e3bfffbd8a53cfea2d Charles Jolley committed Jan 16, 2009
Showing with 972 additions and 126 deletions.
  1. +6 −2 Buildfile
  2. +3 −2 buildtasks/entry.rake
  3. +100 −101 buildtasks/manifest.rake
  4. +198 −0 lib/sproutcore/buildfile/string_ext.rb
  5. +6 −0 lib/sproutcore/buildfile/task.rb
  6. +66 −0 lib/sproutcore/models/manifest.rb
  7. +46 −0 lib/sproutcore/models/manifest_entry.rb
  8. +446 −21 spec/buildtasks/manifest_spec.rb
  9. 0 spec/fixtures/real_world/frameworks/sproutcore/debug/debug-resource.html
  10. 0 spec/fixtures/real_world/frameworks/sproutcore/english.lproj/demo.css
  11. 0 spec/fixtures/real_world/frameworks/sproutcore/english.lproj/demo2.sass
  12. +4 −0 spec/fixtures/real_world/frameworks/sproutcore/english.lproj/has_require.css
  13. +1 −0 spec/fixtures/real_world/frameworks/sproutcore/english.lproj/no_require.css
  14. +6 −0 spec/fixtures/real_world/frameworks/sproutcore/english.lproj/sc_resource.css
  15. 0 spec/fixtures/real_world/frameworks/sproutcore/english.lproj/tests/sample-loc.js
  16. +1 −0 spec/fixtures/real_world/frameworks/sproutcore/fixtures/sample-json-fixture.json
  17. 0 spec/fixtures/real_world/frameworks/sproutcore/french.lproj/french-resource.js
  18. 0 spec/fixtures/real_world/frameworks/sproutcore/german.lproj/german-resource.js
  19. 0 spec/fixtures/real_world/frameworks/sproutcore/german.lproj/strings.js
  20. +4 −0 spec/fixtures/real_world/frameworks/sproutcore/has_require.js
  21. +1 −0 spec/fixtures/real_world/frameworks/sproutcore/no_require.js
  22. +6 −0 spec/fixtures/real_world/frameworks/sproutcore/sc_resource.js
  23. 0 spec/fixtures/real_world/frameworks/sproutcore/tests/sample.js
  24. +1 −0 spec/fixtures/real_world/frameworks/sproutcore/tests/sample.rhtml
  25. +77 −0 spec/lib/models/manifest/add_transform_spec.rb
View
@@ -32,7 +32,10 @@ mode :all do
:load_fixtures => false,
# Do not include debug directory in built project
- :load_debug => false
+ :load_debug => false,
+
+ # Do not build tests.
+ :load_tests => false
end
@@ -41,6 +44,7 @@ mode :debug do
# in debug mode, load fixtures and debug code
:load_fixtures => true,
- :load_debug => true
+ :load_debug => true,
+ :load_tests => true
end
View
@@ -21,9 +21,10 @@ namespace :entry do
# contain the staging_path from the source_entries. The source_path
# is simply the first source_paths.
if ENTRY.composite?
- ENTRY.source_entries ||= []
+ ENTRY.source_entries ||= [ENTRY.source_entry].compact
ENTRY.source_paths ||= ENTRY.source_entries.map { |e| e.staging_path }
ENTRY.source_path ||= ENTRY.source_paths.first
+ ENTRY.source_entry ||= ENTRY.source_entries.first
# Otherwise, the source_path is where we will pull from and source_paths
# is simply the source_path in an array.
@@ -47,7 +48,7 @@ namespace :entry do
if ENTRY.build_task.to_s == 'build:copy'
ENTRY.staging_path ||= ENTRY.source_path
else
- ENTRY.staging_path ||= File.join(MANIFEST.staging_root, filename)
+ ENTRY.staging_path ||= MANIFEST.unique_staging_path(File.join(MANIFEST.staging_root, filename))
end
end
View
@@ -35,8 +35,7 @@ namespace :manifest do
end
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}"
+ task :build => %w(catalog localize prepare_build_tasks:all) do
end
desc "first step in building a manifest, this adds a simple copy file entry for every file in the source"
@@ -46,30 +45,32 @@ namespace :manifest do
next if !File.exist?(path) || File.directory?(path)
next if TARGET.target_directory?(path)
filename = path.sub /^#{Regexp.escape source_root}\//, ''
- MANIFEST.add_entry filename # entry:prepare will fill in the rest
+ MANIFEST.add_entry filename, :original => true # entry:prepare will fill in the rest
end
end
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
+ # these directories are to be excluded unless CONFIG.load_"dirname" = true
+ dirnames = %w(debug tests fixtures).reject { |k| CONFIG["load_#{k}"] }
+
+ # loop through entries and hide those that do not below...
MANIFEST.entries.each do |entry|
- # 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
+
+ # if in /dirname or /foo.lproj/dirname -- hide it!
+ dirnames.each do |dirname|
+ if entry.filename =~ /^(([^\/]+)\.lproj\/)?#{dirname}\/.+$/
+ entry.hide!
+ next
+ end
end
# otherwise, allow if inside lproj
next if entry.localized? || entry.filename =~ /^.+\.lproj\/.+$/
+ # allow if in tests, fixtures or debug as well...
+ next if entry.filename =~ /^(tests|fixtures|debug)\/.+$/
+
# or skip if ext not js
entry.hide! if entry.ext != 'js'
end
@@ -118,108 +119,106 @@ namespace :manifest do
end
end
end
-
- 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
+
+ namespace :prepare_build_tasks do
+
+ desc "main entrypoint for preparing all build tasks. This should invoke all needed tasks"
+ task :all => %w(tests javascript css html images sass)
+
+ desc "executes prerequisites needed before one of the subtasks can be invoked. All subtasks that have this as a prereq"
+ task :setup => %w(manifest:catalog manifest:hide_buildfiles manifest:localize)
+
+ desc "create builder tasks for all unit tests based on file extension."
+ task :tests => :setup do
- # Compute entry type, possibly swapping entry for a transformed entry
- entry.entry_type = case entry.filename
- when /^tests\/.+/
- :test
- when /\.(rhtml|haml|html\.erb)$/
- :html
- when /\.(css|sass)$/
- :stylesheet
- when /\.js$/
- :javascript
- when /\.(jpg|png|gif)$/
- :image
- else
- :resource
+ # Generate test entries
+ test_entries = []
+ MANIFEST.entries.each do |entry|
+ next unless entry.filename =~ /^tests\//
+ test_entries << MANIFEST.add_transform(entry,
+ :build_task => "build:test:#{entry.ext}",
+ :entry_type => :test,
+ :ext => :html)
end
+
+ # Add summary entry
+ MANIFEST.add_entry 'tests/-index.json',
+ :composite => true,
+ :source_entries => test_entries,
+ :build_task => 'build:test:index.json',
+ :entry_type => :resource
end
- end
-
- # Build compiled entries for each :javascript entry. Look inside the
- # entry for an sc_resource('foo') call. This will determine the resource
- # name. If none is supplied, use 'javascript.js'.
- task :prepare_javascripts => %w(manifest:assign_types) do
- entries = MANIFEST.entries.reject { |e| e.entry_type != :javascript }
-
- # sort entries by resource name
- sorted = {}
- entries.each do |entry|
- resource_name = 'javascript'
- File.readlines(entry.stage!.staging_path).each do |line|
- if line =~ /^\s*sc_resource\((["'])(.+)(\1)\)\s*\;/
- resource_name = $2
- break
- end
+ task :javascript => :tests # IMPORTANT! to avoid JS including unit tests.
+ task :html => :tests # IMPORTANT! to avoid HTML including tests
+
+ desc "scans for javascript files, annotates them and prepares combined entries for each output target"
+ task :javascript => :setup do
+ # select all entries relevant entries
+ entries = MANIFEST.entries.select do |e|
+ (e.entry_type == :javascript) || (e.entry_type.nil? && e.ext == 'js')
+ end
+
+ # tag entry with build directives and sort by resource
+ entries_by_resource = {}
+ entries.each do |entry|
+ entry.resource = 'javascript'
+ entry.discover_build_directives!
+ (entries_by_resource[entry.resource] ||= []) << entry
+ end
+
+ # Now, build combined entry for each resource
+ entries_by_resource.each do |resource_name, entries|
+ MANIFEST.add_composite resource_name.ext('js'),
+ :build_task => 'build:javascript',
+ :source_entries => entries
end
- (sorted[resource_name] ||= []) << entry
end
- # now generate composite javascript resources for each
- sorted.each do |resource_name, entries|
- MANIFEST.add_composite "#{resource_name}.js",
- :source_entries => entries, :build_task => 'build:javascript'
- end
- end
+ desc "scans for css files, annotates them and prepares combined entries for each output target"
+ task :css => :setup do
+ # select all entries with an entry_type of :css or with ext of css
+ entries = MANIFEST.entries.select do |e|
+ (e.entry_type == :css) || (e.entry_type.nil? && e.ext == 'css')
+ end
- # Build compiled entries for each :stylesheet entry. Look inside the
- # entry for an sc_resource('foo') call. This will determine the resource
- # name. If none is supplied, use 'stylesheet.css'.
- task :prepare_stylesheets => %w(manifest:prepare_javascripts) do
- entries = MANIFEST.entries.reject { |e| e.entry_type != :stylesheet }
-
- # sort entries by resource name
- sorted = {}
- entries.each do |entry|
- resource_name = 'stylesheet'
- File.readlines(entry.stage!.staging_path).each do |line|
- if line =~ /^\s*\/\*\s*sc_resource\((["'])(.+)(\1)\)\s*\/\*/
- resource_name = $2
- break
- end
+ # tag entry with build directives and sort by resource
+ entries_by_resource = {}
+ entries.each do |entry|
+ entry.resource = 'stylesheet'
+ entry.discover_build_directives!
+ (entries_by_resource[entry.resource] ||= []) << entry
+ end
+
+ # Now, build combined entry for each resource
+ entries_by_resource.each do |resource_name, entries|
+ MANIFEST.add_composite resource_name.ext('css'),
+ :build_task => 'build:css',
+ :source_entries => entries
end
- (sorted[resource_name] ||= []) << entry
end
- # now generate composite javascript resources for each
- sorted.each do |resource_name, entries|
- MANIFEST.add_composite "#{resource_name}.css",
- :source_entries => entries, :build_task => 'build:stylesheet'
+ desc "create a builder task for all sass files to create css files"
+ task :sass => :setup do
+ MANIFEST.entries.each do |entry|
+ next unless entry.ext == "sass"
+ MANIFEST.add_transform(entry,
+ :build_task => 'build:sass',
+ :entry_type => :css,
+ :ext => 'css')
+ end
end
- end
-
- # Build compiled entry for index.html. Look inside the
- # entry for an sc_resource('foo') call. This will determine the resource
- # name. If none is supplied, use 'stylesheet.css'.
- task :prepare_stylesheets => %w(manifest:prepare_javascripts) do
- entries = MANIFEST.entries.reject { |e| e.entry_type != :stylesheet }
+ task :css => :sass # IMPORTANT! to ensure sass files are rolled into css
- # sort entries by resource name
- sorted = {}
- entries.each do |entry|
- resource_name = 'stylesheet'
- File.readlines(entry.stage!.staging_path).each do |line|
- if line =~ /^\s*\/\*\s*sc_resource\((["'])(.+)(\1)\)\s*\/\*/
- resource_name = $2
- break
- end
- end
- (sorted[resource_name] ||= []) << entry
+ desc "..."
+ task :html => :setup do
end
- # now generate composite javascript resources for each
- sorted.each do |resource_name, entries|
- MANIFEST.add_composite "#{resource_name}.css",
- :source_entries => entries, :build_task => 'build:stylesheet'
+ desc "..."
+ task :image => :setup do
end
- end
+
+ end
end
Oops, something went wrong.

0 comments on commit 86b2d92

Please sign in to comment.