Permalink
Browse files

Added stubs for remaining rake tasks. Updated sc-manifest and sc-buil…

…d so that they work now
  • Loading branch information...
1 parent d795320 commit 12ac78d6aaa610f571eedd25f6a0a380c53bf4cb Charles Jolley committed Jan 17, 2009
View
@@ -39,7 +39,10 @@ mode :all do
# Generate a combined javascript and stylesheet
:combine_javascript => true,
- :combine_stylesheet => true
+ :combine_stylesheet => true,
+
+ # by default all targets autobuild
+ :autobuild => true
end
View
@@ -2,6 +2,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib sproutcore]))
-SC::Toolss::Build.invoke
+SC::Tools.invoke 'build'
# EOF
View
@@ -7,11 +7,39 @@
# in your buildfiles.
namespace :build do
- # copies the files
+ desc "copies a single resource"
build_task :copy do
require 'fileutils'
FileUtils.mkdir_p(File.dirname(DST_PATH))
FileUtils.cp_r(SRC_PATH, DST_PATH)
end
+
+ desc "builds a single css files"
+ build_task :css do
+ end
+
+ desc "builds a single sass file"
+ build_task :sass do
+ end
+
+ desc "builds a single javascript file"
+ build_task :javascript do
+ end
+
+ desc "builds an html file, possibly executing render tasks"
+ build_task :html do
+ end
+
+ namespace :combine do
+
+ desc "combines several css files into a single css file"
+ build_task :css do
+ end
+
+ desc "combines several javascript files into a single javascript file"
+ build_task :javascript do
+ end
+
+ end
end
View
@@ -35,9 +35,8 @@ namespace :manifest do
end
desc "Actually builds a manifest. This will catalog all entries and then filter them"
- task :build => %w(catalog localize prepare_build_tasks:all) do
- end
-
+ task :build => %w(catalog hide_buildfiles localize) # prepare_build_tasks:all
+
desc "first step in building a manifest, this adds a simple copy file entry for every file in the source"
task :catalog do |t|
source_root = TARGET.source_root
View
@@ -0,0 +1,19 @@
+# ===========================================================================
+# SC::Target Buildtasks
+# copyright 2008, Sprout Systems, Inc. and Apple, Inc. all rights reserved
+# ===========================================================================
+
+# Tasks invoked to actually render a single HTML file. Works much like a
+# build task but also expects a CONTEXT variable that contains the html
+# context.
+namespace :render do
+
+ desc "renders erubis including .rhtml and .html.erb files"
+ build_task :erubis do
+ end
+
+ desc "renders haml files"
+ build_task :haml do
+ end
+
+end
@@ -93,6 +93,8 @@ def to_hash(opts={})
ret = filtered
end
+ # always add target name. needed to reload
+ ret[:target_name] = target.target_name
return ret
end
View
@@ -117,15 +117,36 @@ def requires_project!
# Find one or more targets with the passed target names
def find_targets(*targets)
requires_project!
- targets.map do |target_name|
- ret = project.target_for(target_name)
- if ret.nil?
- fatal! "No target named #{target_name} could be found in project"
- else
- debug "Found target '#{target_name}' at PROJECT:#{ret.source_root.sub(/^#{project.project_root}\//,'')}"
+
+ # If targets are specified, find the targets project or parents...
+ if targets.size > 0
+ targets = targets.map do |target_name|
+ ret = project.target_for(target_name)
+ if ret.nil?
+ fatal! "No target named #{target_name} could be found in project"
+ else
+ debug "Found target '#{target_name}' at PROJECT:#{ret.source_root.sub(/^#{project.project_root}\//,'')}"
+ end
+ ret
+ end
+
+ # IF no targets are specified, then just get all targets in project.
+ # If --all option was specified, include those that do not autobuild
+ else
+ targets = project.targets.values
+ unless options.all?
+ targets.reject! { |t| !t.config.autobuild? }
end
- ret
+ end
+
+ # If include required was specified, merge in all required bundles as
+ # well.
+ if options['include-required']
+ targets.each { |target| targets += target.expand_required_targets }
+ targets = targets.flatten.uniq.compact
end
+
+ return targets
end
# Wraps around find_targets but raises an exception if no target is
@@ -138,15 +159,55 @@ def requires_targets!(*targets)
targets
end
- # Finds one target. This is just a convenience method wrapped around
- # find_targets()
- def find_target(target); find_targets(target); end
-
# Requires exactly one target.
def requires_target!(*targets)
requires_targets!(*targets).first
end
+ # Discovers the languages requested by the user for a build. Uses the
+ # --languages command line option or disovers in targets.
+ def find_languages(*targets)
+ # Use passed languages. If none are specified, merge installed
+ # languages for all app targets.
+ if (languages = options.languages).nil?
+ languages = targets.map { |t| t.installed_languages }
+ else
+ languages = languages.split(':').map { |l| l.to_sym }
+ end
+ languages.flatten.uniq.compact
+ end
+
+ # Core method to process command line options and then build a manifest.
+ # Shared by sc-manifest and sc-build commands.
+ def build_manifests(*targets)
+
+ requires_project! # get project
+ targets = find_targets(*targets) # get targets
+ languages = find_languages(*targets) # get languages
+
+ # log output
+ SC.logger.info "Building targets: #{targets.map { |t| t.target_name } * ","}"
+ SC.logger.info "Building languages: #{ languages * "," }"
+
+ # Now fetch the manifests to build. One per target/language
+ manifests = targets.map do |target|
+ languages.map { |l| target.manifest_for :language => l }
+ end
+ manifests.flatten!
+
+ # Build'em
+ manifests.each do |manifest|
+ SC.logger.info "Building manifest for: #{manifest.target.target_name}:#{manifest.language}"
+ manifest.build!
+ end
+
+ return manifests
+ end
+
+ ################################################
+ ## MAIN ENTRYPOINT
+ ##
+
# Fix start so that it treats command-name like command_name
def self.start(args = ARGV)
# manually check for verbose in case we don't get far enough in regular
@@ -1,8 +1,62 @@
-module SC
+require File.expand_path(File.join(File.dirname(__FILE__), 'manifest'))
- # Builds a manifest or a single entry from a manifest
+module SC
class Tools
+
+ desc "build [TARGET..]", "Builds one or more targets"
+ method_options(
+ MANIFEST_OPTIONS.merge(:entries => :optional, :clean => false))
+
+ def build(*targets)
+
+ # Copy some key props to the env
+ SC.env.build_prefix = options.buildroot if options.buildroot
+ SC.env.stating_prefix = options.stageroot if options.stageroot
+ SC.env.use_symlink = options.symlink
+ SC.env.clean = options.clean
+
+ # Get entries option
+ entry_filters = nil
+ if options[:entries]
+ entry_filters = options[:entries].split(',')
+ end
+
+ # Get the manifests to build
+ manifests = build_manifests(targets)
+
+ # Now build entries for each manifest...
+ manifests.each do |manifest|
+
+ # get entries. If "entries" option was specified, use to filter
+ # filename. Must match end of filename.
+ entries = manifest.entries
+ if entry_filters
+ entries = entries.select do |entry|
+ is_allowed = false
+ entry_filters.each do |filter|
+ is_allowed = entry.filename =~ /#{filter}$/
+ break if is_allowed
+ end
+ is_allowed
+ end
+ end
+
+ # if there are entries to build, log and build
+ if entries.size > 0
+ info "Building entries for #{manifest.target.target_name}:#{manifest.language}..."
+
+ # if clean is enabled, first delete the build_root dir for the
+ # manifest.
+ FileUtils.rm_r(manifest.build_root) if SC.env.clean
+
+ entries.each do |entry|
+ info " #{entry.filename} -> #{entry.build_path}"
+ entry.build!
+ end
+ end
+ end
+
+ end
+
end
-
end
-
@@ -9,13 +9,14 @@ class Tools
:format => :optional,
:output => :output,
:all => false,
- :only => :optional,
- :except => :optional,
- :hidden => false,
['--include-required', '-r'] => false }
desc "manifest [TARGET..]", "Generates a manifest for the specified targets"
- method_options(MANIFEST_OPTIONS)
+ method_options(MANIFEST_OPTIONS.merge(
+ :format => :optional,
+ :only => :optional,
+ :except => :optional,
+ :hidden => false ))
def manifest(*targets)
# Copy some key props to the env
@@ -44,39 +45,11 @@ def manifest(*targets)
except_keys = nil if except_keys.size == 0
end
- requires_project! # get project
-
- # If targets are specified, build a manifest specifically for those
- # targets. Otherwise, build for all targets in the project.
- if (targets = find_targets(*targets)).size == 0
- targets = project.targets.values
- unless options.all? # remove those with autobuild turned off in config
- targets.reject! { |t| !t.config.autobuild? }
- end
- end
- SC.logger.info "Building targets: #{targets.map { |t| t.target_name } * ","}"
-
- # Use passed languages. If none are specified, merge installed
- # languages for all app targets.
- if (languages = options.languages).nil?
- languages = targets.map { |t| t.installed_languages }
- else
- languages = languages.split(':').map { |l| l.to_sym }
- end
- languages = languages.flatten.uniq.compact
- SC.logger.info "Building languages: #{ languages * "," }"
-
- # Now fetch the manifests to build. One per target/language
- manifests = targets.map do |target|
- languages.map { |l| target.manifest_for :language => l }
- end
- manifests.flatten!
-
- # Build'em
+ # call core method to actually build the manifests...
+ manifests = build_manifests(*targets)
+
+ # now convert them to hashes...
manifests.map! do |manifest|
- SC.logger.info "Building manifest for: #{manifest.target.target_name}:#{manifest.language}"
- manifest.build!
-
manifest.to_hash :hidden => options.hidden,
:only => only_keys, :except => except_keys
end

0 comments on commit 12ac78d

Please sign in to comment.