#!/usr/bin/env ruby $: << File.expand_path(File.join(File.dirname(__FILE__), "../lib")) begin require 'ninjs' require 'optparse' rescue LoadError require 'rubygems' require 'ninjs' require 'optparse' end create = <<-CREATE create Creates a new ninjs application in the current working directory or sub directory within. Arguments: application name - Name of the ninjs application subdirectory* - Directory where the application will be installed (created if non existent) examples: ninjs create myapp ninjs create myapp subdirectory CREATE generate = <<-GEN generate Generates scoffolding for the given component file type. Arguments: type - Type of application scaffold to create (module, elements, model). name* - Name of the module to generate the scaffold for Options: -a, --alias name* - Create an alias of the application object (defaults to "app"), passing a name is optional -e, --elements - Generate an elements file -m, --model - Generate a model file examples: ninjs generate module mymodule -em (generates module, elements and model) ninjs generate module mymodule -a (generates an application alias) ninjs generate elements mymodule -m (generates an elements and a model file) ninjs generate model mymodule (generates an model file) GEN compile = <<-COMP compile Compiles the ninjs project in the current working directory. Options: -c, --compress - Compress output with JsMin example: ninjs compile COMP watch = <<-WATCH watch Watches the current working directory for file changes and compiles when changes are detected. example: ninjs watch WATCH upd = <<-UPDATE update Updates your application's core files to the latest version. UPDATE footer = <<-FOOTER * optional argument FOOTER help = { :create => create, :generate => generate, :compile => compile, :watch => watch, :update => upd, :footer => footer } command = ARGV[0] options = { :alias => nil, :elements => false, :model => false, :help => false, :compress => nil } optparse = OptionParser.new do |opts| opts.on( '-h', '--help', 'Display this screen' ) do options[:help] = true end opts.on( '-v', '--version', 'Display the version') do time = Time.now puts Ninjs::Notification.notice 'ninjs ' + Ninjs::VERSION puts Ninjs::Notification.notice "Copyright (c) #{time.year} Dayton Nolan" puts Ninjs::Notification.notice "Released under the MIT License" exit end opts.on( '-a', '--alias [alias]', 'Generate application alias') do |als| options[:alias] = als || "app" end opts.on( '-d', '--dest [dest]', 'Module destination directory') do |dest| options[:dest] = dest end opts.on('-e', '--elements', 'Generate elements file') do options[:elements] = true end opts.on('-m', '--model', 'Generate model file') do options[:model] = true end opts.on('-c', '--compress', 'Compress with JsMin') do options[:compress] = true end end optparse.parse! case command # create when "create" if options[:help] puts help[:create] exit end app_name = ARGV[1] sub_dir = ARGV[2] || nil if app_name.nil? puts "Error! Application name is required (ninjs create app_name)" exit end Ninjs::Command.create({ :name => app_name, :directory => sub_dir }) # generate when "generate" if options[:help] puts help[:generate] exit end errors = Hash.new type = ARGV[1] name = ARGV[2] als = options[:alias] || nil dest = options[:dest] || nil errors[:type] = "Error! Scaffold type is required (ninjs generate module mymodule)" if type.nil? errors[:name] = "Error! Module name is required (ninjs generate module mymodule)" if name.nil? unless errors.empty? errors.each do |error| puts error end exit end dependencies = { :model => options[:model], :elements => options[:elements] } Ninjs::Command.generate({ :project => Ninjs::Project.new, :type => type, :name => name, :alias => als, :dest => dest, :dependencies => dependencies }) # compile when "compile" if options[:help] puts help[:compile] exit end unless options[:compress].nil? Ninjs::Command.compile(options[:compress]) else Ninjs::Command.compile() end # watch when "watch" if options[:help] puts help[:watch] exit end Ninjs::Command.watch # update when "update" if options[:help] puts help[:update] exit end Ninjs::Command.update else help.each do |section| puts section.last + "\n" end exit end