#!/usr/bin/env ruby # BUILD SPROUTCORE APPLICATIONS # This script will build SproutCore applications for you. Usage: # # sc-build build all clients # sc-build bundle-name build just the named bundle # sc-build -l library_root path to the library you want to load bundles from # sc-build -t build_root set optional build root # sc-build -e development|production defaults to production # sc-build bundle-name -r builds bundle and dependent bundles but none others APP_ROOT = File.expand_path(Dir.pwd) SC_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) $:.unshift File.join(SC_ROOT,'lib') ; # Require SproutCore require 'rubygems' require 'rubigen' require 'sproutcore' require 'optparse' ############################################################ ## Define Helper Methods ## def not_found(bundle_name) SC.logger.fatal("Could not find a bundle named: #{bundle_name}") exit(1) end ############################################################ ## Process Options ## # Setup defaults build_mode = :production build_root = File.join(APP_ROOT,'tmp','build') bundle_name = ARGV.shift if (ARGV.size > 0 && ARGV[0][0..0] != '-') library_root = APP_ROOT include_dependencies = false verbose = false # show debug level languages = nil clean = false opts = OptionParser.new do |opts| opts.version = SproutCore::VERSION::STRING opts.banner = "Usage: sc-build {bundle-name} {options}" opts.define_head "Build Tool for SproutCore applications" opts.separator '*'*80 opts.separator 'If no flags are given, sc-build will try to build all of the bundles in the current directory' opts.separator '*'*80 opts.on("-e", "--enviroment=MODE", "Set the build mode for the system. Normally you want to build in production mode (which is the default if you do not include this option), but you can use this switch to build in development mode for testing.") do |opt_build_mode| build_mode = opt_build_mode.to_s.downcase.to_sym end opts.on("-t", "--target=PATH", "Set the target path for your build. Normally this will be set to tmp/build in the working directory") do |opt_target| build_root = File.expand_path(opt_target) end opts.on("-l", "--library=PATH", "The library root you want to use. Normally sc-build will use the working directory. If you want to point to another project on disk to build from, use this option.") do |opt_library| library_root = File.expand_path(opt_library) end opts.on("-r", "--[no-]include-required", "If passed when building a single client, then the build tool will also find any required bundles and build them as well.") do |opt_req| include_dependencies = !!opt_req end opts.on("-v", "--[no-]verbose", "If set, extra debug output will be displayed during the build") do |opt_verbose| verbose = !!opt_verbose end opts.on("-L", "--languages=LANGUAGE", "Pass a comma separated list of the specific languages you want to build. If you do not pass this option, the build tool will build all languages required by the bundles to function") do |opt_lang| languages = opt_lang.split(',').map { |x| x.to_sym } end opts.on("-c", "--[no-]clean", "If set, then the build tool will delete a bundle's output before it builds it, so you get a clean build") do |opt_clean| clean = !!opt_clean end end opts.parse! ############################################################ ## SETUP ENVIRONMENT ## # Configure logger SC.logger.level = (verbose) ? Logger::DEBUG : Logger::INFO SC.logger.progname = $0 # Load Library library = SC.library_for(library_root, :public_root => build_root, :url_prefix => '', :build_mode => build_mode) ############################################################ ## FIND BUNDLES TO BUILD ## puts "build_root = #{build_root}" # Find the bundles to build. if bundle_name # Get bundle bundle = library.bundle_for(bundle_name.to_sym) not_found(bundle) if bundle.nil? # If dependencies are required, get those bundles as well if include_dependencies bundles = bundle.all_required_bundles else bundles = [bundle] end SC.logger.info("Building: #{bundles.map { |x| x.bundle_name } * ', ' }...") # No bundle provided, get all bundles for library else bundles = library.bundles SC.logger.info("Building ALL bundles:\n #{bundles.map { |x| x.bundle_name } * ', '}...") end ############################################################ ## BUILD EACH BUNDLE ## # Detect required languages to build languages = bundles.map { |b| b.installed_languages }.flatten.uniq if languages.nil? SC.logger.info("Selected Languages: #{languages.join(', ')}") SC.logger.info('') bundles.each do |bundle| SC.logger.info("Building #{bundle.bundle_name} > #{bundle.build_root}...") if clean SC.logger.debug("~ Cleaning #{bundle.build_root}") FileUtils.rm_rf(bundle.build_root) end bundle.build(*languages) end SC.logger.debug("")