#!/usr/bin/env ruby require 'spinebox' # use node runtime due to current rubyracer bug ENV['EXECJS_RUNTIME'] ||= "Node" Spinebox::Command.dispatch do # Version on "--version, -v", "Show the version", :if => proc { ['--version', '-v'].include?(ARGV.first) }, :type => :option do puts "Spinebox #{Spinebox::VERSION}" exit(0) end # Help on "--help, -h", "Show this help", :if => proc { ['--help', '-h'].include?(ARGV.first) or ARGV.empty? }, :type => :option do Spinebox::Command.help exit(0) end # New application on "new APP", "Create a new APP", :if => proc { ['new', 'n'].include?(ARGV.first) }, :type => :action do ARGV.shift Spinebox::Generator::Application.new(ARGV.first) puts "Successfully created '#{ARGV.first}'".green exit(0) end # Compile on "compile, precompile", "Compile files to the public dir", :if => proc { ['compile', 'precompile'].include?(ARGV.first) }, :type => :action do Spinebox.boot! Spinebox::Compiler.compile puts "Successfully compiled to 'public'".green exit(0) end # Run server on "server, s", "Run the development server", :if => proc { ['server', 's'].include?(ARGV.first) }, :type => :action do Rack::Handler::Thin.run(Spinebox.app, :Port => 3000) end # Model Generator on "generate model MODEL [attributes]", "Generate a model with attributes", :if => proc { ['generate', 'g'].include?(ARGV.first) and ['model', 'm'].include?(ARGV[1])}, :type => :generator do ARGV.shift ARGV.shift name = ARGV.shift model = Spinebox::Generator::Model.new(name, ARGV) puts "Successfully created model '#{model.name}'".green exit(0) end # Controller Generator on "generate controller CONTROLLER", "Generate a controller", :if => proc { ['generate', 'g'].include?(ARGV.first) and ['controller', 'c'].include?(ARGV[1])}, :type => :generator do ARGV.shift ARGV.shift controller = Spinebox::Generator::Controller.new(ARGV.first) puts "Successfully created controller '#{controller.name}'".green exit(0) end # View Generator on "generate view VIEW", "Generate a view", :if => proc { ['generate', 'g'].include?(ARGV.first) and ['view', 'v'].include?(ARGV[1])}, :type => :generator do ARGV.shift ARGV.shift view = Spinebox::Generator::View.new(ARGV.first) puts "Successfully created view '#{view.name}'".green exit(0) end # Scaffold Generator on "generate scaffold MODEL [attributes]", "Scaffold a model, view and a controller", :if => proc { ['generate', 'g'].include?(ARGV.first) and ['scaffold', 's'].include?(ARGV[1])}, :type => :scaffold do ARGV.shift ARGV.shift name = ARGV.shift model = Spinebox::Generator::Model.new(name, ARGV) view = Spinebox::Generator::View.new(name) controller = Spinebox::Generator::Controller.new(name) puts "Successfully scaffolded model, view and controller '#{model.name}'".green exit(0) end end