module Xmvc class BuilderManager class << self def dispatch(name, *params) name = name.to_sym options = params.shift || {} case name when :setup setup(options) else begin @jammit = jammit(options) @jammit.invoke(:build, [name]) rescue Jammit::Error => e raise Xmvc::BuilderError.new(e.message) end end end private def setup(options) begin ## # Invoke jammit init app-name so that Jammit creates it's config/assets.yml # Note that we must pass-in the name of the newly created app @name so that # Jammit appends that to its config_path, otherwise it would create its config file # in the pwd. @asset_root = options[:asset_root] || File.expand_path('.') app_assets jammit = Jammit::CLI.new([], options) jammit.invoke(:init) jammit.invoke(:config, ["set", "javascripts", { "mvc" => mvc_assets, "app" => app_assets }]) jammit.invoke(:build) rescue Jammit::Error => e raise Xmvc::BuilderError.new(e.message) end end def jammit(options={}) Jammit::CLI.new([], options) end def mvc_assets YAML.load(File.read(File.join(@asset_root, 'vendor', 'mvc', 'build'))).map {|f| File.join('vendor', 'mvc', f) } end def app_assets [ 'app/App.js', 'config/application.js', 'config/routes.js', 'vendor/plugins/*/**.js', 'overrides/*.js', 'app/models/*.js', 'app/controllers/*.js', 'app/views/*/**.js' ] end end end end