#!/usr/bin/env ruby # Copyright (c) 2010 Cory Ondrejka. All rights reserved. # See MIT.LICENSE for licensing details. jasnode_base = File.expand_path File.join(File.dirname(__FILE__), '..', 'lib') $LOAD_PATH.unshift(jasnode_base) unless $LOAD_PATH.include?(jasnode_base) require 'rubygems' require 'commander/import' require 'jasnode' def get_version require "yaml" v = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "..", "VERSION.yml"))) "#{v[:major]}.#{v[:minor]}.#{v[:build]}.#{v[:patch]}" end program :name, 'jasnode' program :version, get_version program :description, 'Easy Jasmine BDD with Node.js' program :formatter, :compact default_command :help command :spec do |c| c.syntax = 'jasnode spec [options]' c.description = 'Runs spec using jasmine and node.js' c.option "--verbose", "Run verbosely" c.option "--log", "Log output to [logfile] if defined, otherwise to logfile.txt" c.option "--logfile FILE", "Destination for logging, implies --log" c.action do |args, options| if options.logfile options.log = true end options.default :logfile => "logfile.txt" results = Jasnode::Spec.spec(options.verbose, options.log ? options.logfile : nil) puts results if results =~ /(\d+) failure/ exit($1.to_i) else exit(-1) end end end command :init do |c| c.syntax = 'jasnode init ' c.description = 'Initiazlie a project directory for node.js that jasnode can test' c.example 'Create a new project directory ready for jasmine testing called "myproject"', 'jasnode init myproject' c.action do |args, options| projectname = args.shift or raise 'Project name required' Jasnode::Init.template(projectname) say "Project template initialized at `#{projectname}'" say <<-eos #{projectname} |-- bin | `-- hello_world <- replace with your main executable |-- lib | `-- server.js <- your libraries go here |-- Rakefile `-- spec |-- README.md |-- runner.js <- you'll need to add your libraries here |-- server | |-- server_spec.js <- test specs, replace with your own | `-- spec_server.js `-- spec.js eos end end