#!/usr/bin/env ruby $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) require 'frank' require 'optparse' begin # try to use bundler if its available require 'bundler' begin Bundler.require rescue Bundler::GemfileNotFound # revert to using local frank install $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) end rescue LoadError # revert to using local frank install $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) end options = {:server => {}} banner = <<-USAGE Usage: frank new PROJECT_PATH frank server [options] frank export PATH [options] Description: The `frank new' command generates a frank template project with the default directory structure and configuration at the given path. Once you have a frank project you can use the `frank server' or the aliased 'frank up' commands to start the development server and begin developing your project. When you are finished working and ready to export you can use the `frank export' or aliased `frank out' commands. Example: frank new ~/Dev/blah.com cd ~/Dev/blah.com frank server # do some development frank export ~/Dev/html/blah.com USAGE opts = OptionParser.new do |opts| opts.banner = banner opts.separator '' opts.separator 'Options:' opts.on('--server [HANDLER]', 'Set the server handler (frank server)') do |handler| options[:server]['handler'] = handler unless handler.nil? end opts.on('--hostname [HOSTNAME]', 'Set the server hostname (frank server)') do |hostname| options[:server]['hostname'] = hostname unless hostname.nil? end opts.on('--port [PORT]', 'Set the server port (frank server)') do |port| options[:server]['port'] = port unless port.nil? end opts.on('--dynamic_folder [FOLDER]', 'Set the dynamic folder (frank server)') do |folder| options[:dynamic_folder] = folder unless folder.nil? end opts.on('--static_folder [FOLDER]', 'Set the static folder (frank server)') do |folder| options[:static_folder] = folder unless folder.nil? end opts.on('--production', 'Production ready export (frank export) i.e. ([FOLDER]/index.html)') do |handler| options[:production] = true end opts.on('-v', '--version', 'Show the frank version and exit') do puts "Frank v#{Frank::VERSION}" exit end opts.on( '-h', '--help', 'Display this help' ) do puts opts exit end end opts.parse! if ARGV.empty? puts opts exit else if %w[server up export out upgrade s e].include? ARGV.first begin Frank.bootstrap(Dir.pwd) rescue Errno::ENOENT if File.exist? File.join(Dir.pwd, 'helpers.rb') puts "Frank could not find setup.rb, perhaps you need to upgrade with the `frank upgrade' command" else puts "Frank could not find setup.rb" end end end case ARGV.first when 'new', 'n' # stub out the project Frank.stub(ARGV[1]) when 'server', 's', 'up' # setup server from options server_options = options[:server] Frank.server.handler = server_options['handler'] if server_options['handler'] Frank.server.hostname = server_options['hostname'] if server_options['hostname'] Frank.server.port = server_options['port'] if server_options['port'] # setup folder options Frank.dynamic_folder = options[:dynamic_folder] if options[:dynamic_folder] Frank.static_folder = options[:static_folder] if options[:static_folder] Frank.new when 'export', 'e', 'out' Frank.production! if options[:production] Frank::Output.new do set :environment, :output set :output_folder, ARGV[1] end.dump(options[:production]) when 'upgrade' Frank.upgrade! end end