#!/usr/bin/env ruby UKI_ROOT = File.expand_path File.join(File.dirname(__FILE__), '..') require 'rubygems' require 'commander/import' require File.join(UKI_ROOT, 'lib', 'uki') program :name, 'uki tools' program :version, File.read(File.join(UKI_ROOT, 'VERSION')) program :description, 'uki development tools' command :"new project" do |c| c.syntax = 'uki new project ' c.summary = 'Create uki project' c.description = 'Create uki project template within folder. The template includes uki framework, cotainer html, project files and directrories. Additionaly JSpec will be installed. You can prevent that with --nojspec option' c.option '-J', '--nojspec', 'Install JSpec into the project template' c.when_called do |args, options| dest = args.shift or raise 'Project name required' project = Uki::Project.new(dest) project.create :jspec => !options.nojspec say "Uki project crated at `#{dest}'" end end command :'new view' do |c| c.syntax = 'uki new view ' c.summary = 'Create uki view' c.description = "Create template for uki view with given and add include to the project file" c.example "Create myapp.view.MyView", "uki new view MyView" c.example "Create view in arbitary package", "uki new view mypackage.MyView" c.when_called do |args, options| path = args.shift or raise 'View name required' project = Uki::Project.new('.') path = "#{project.name}.view.#{path}" project.create_class 'view.js', path say "View #{path} created" end end command :'new model' do |c| c.syntax = 'uki new view ' c.summary = 'Create uki model' c.description = "Create template for uki model with given and add include to the project file" c.example "Create myapp.model.MyModel", "uki new model MyModel" c.example "Create view in arbitary package", "uki new model mypackage.MyModel" c.when_called do |args, options| path = args.shift or raise 'Model name required' project = Uki::Project.new('.') path = "#{project.name}.model.#{path}" project.create_class 'model.js', path say "Model #{path} created" end end command :'new layout' do |c| c.syntax = 'uki new layout ' c.summary = 'Create uki layout' c.description = "Create template for uki layout with given and add include to the project file" c.example "Create myapp.layout.editor()", "uki new layout editor" c.example "Create view in arbitary package", "uki new layout mypackage.editor" c.when_called do |args, options| path = args.shift or raise 'Layout name required' project = Uki::Project.new('.') path = "#{project.name}.layout.#{path}" project.create_function 'layout.js', path say "Layout #{path} created" end end command :'new controller' do |c| c.syntax = 'uki new controller ' c.summary = 'Create uki controller' c.description = "Create template for uki controller with given and add include to the project file" c.example "Create myapp.controller.editor()", "uki new controller editor" c.example "Create view in arbitary package", "uki new controller mypackage.editor" c.when_called do |args, options| path = args.shift or raise 'Controller name required' project = Uki::Project.new('.') path = "#{project.name}.controller.#{path}" project.create_function 'controller.js', path say "Controller #{path} created" end end command :run do |c| c.syntax = 'uki run [host[:port]]' c.summary = 'Run development server' c.description = 'Run development server on [host]:[port]. Server can process .cjs calls to merge javascript files. You can add aditional processing to the server by creating server.rb in your project root. Then use sinatra (http://sinatrarb.com) routes' c.when_called do |args, options| require 'uki/server.rb' server = Uki::Server.new(args.shift) require 'server.rb' if File.exists? 'server.rb' server.start! end end command :build do |c| c.syntax = 'uki build [file1 [, file2]]' c.summary = 'Build current project' c.description = 'Merges and compresses javascript files. Merges all include() and include_css() in js files. Merged output is processed through google clousure compiler. Supports .js and .html files as parameters. By default builds index.html file in current directory and puts them into build dir. Note that output dir will be cleared before merging' c.option '-C', '--nocompress', 'Disable Google Closure Compiler/Yahoo Compressor' c.option '-o output', '--output output', 'Directory to output to' c.when_called do |args, option| files = args.empty? ? ['index.html'] : args output = option.output || 'build' project = Uki::Project.new('.') project.build files, :compress => !option.nocompress, :output => output, :images => args.empty?, :clean_output => args.empty? say "Build complete at '#{output}'" end end command :ie_images do |c| c.syntax = 'uki ie_images [file]' c.summary = 'Creates image files for IE6,7' c.description = 'Creates image files for IE6,7 from data urls in the theme file. [file] defaults to /theme.js ' c.when_called do |args, option| project = Uki::Project.new('.') target = args.shift || File.join(project.name, 'theme.js') place = project.ie_images target say "IE images are at #{place}" end end