2011-07-27 00:06:10 -04:00
|
|
|
require 'thor'
|
|
|
|
|
|
|
|
module Middleman
|
|
|
|
class CLI < Thor
|
|
|
|
include Thor::Actions
|
2011-07-27 00:26:10 -04:00
|
|
|
check_unknown_options!
|
2011-07-27 00:06:10 -04:00
|
|
|
default_task :server
|
|
|
|
|
2011-07-27 00:26:25 -04:00
|
|
|
class_option "help", :type => :boolean, :default => false, :aliases => "-h"
|
2011-07-27 00:06:10 -04:00
|
|
|
def initialize(*)
|
|
|
|
super
|
2011-07-27 02:19:43 -04:00
|
|
|
help_check if options[:help]
|
2011-07-27 00:06:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "init NAME", "Create new Middleman project directory NAME"
|
|
|
|
available_templates = Middleman::Templates.registered_names.join(", ")
|
2011-07-27 00:25:48 -04:00
|
|
|
method_option "template", :aliases => "-T", :default => "default", :desc => "Optionally use a pre-defined project template: #{available_templates}"
|
|
|
|
method_option "css_dir", :default => "stylesheets", :desc => 'The path to the css files'
|
|
|
|
method_option "js_dir", :default => "javascripts", :desc => 'The path to the javascript files'
|
|
|
|
method_option "images_dir", :default => "images", :desc => 'The path to the image files'
|
2011-08-05 13:44:41 -04:00
|
|
|
method_option "rack", :type => :boolean, :default => false, :desc => 'Include a config.ru file'
|
2011-08-06 17:56:05 -04:00
|
|
|
method_option "bundler", :type => :boolean, :default => false, :desc => 'Create a Gemfile and use Bundler to manage gems'
|
2011-07-27 00:06:10 -04:00
|
|
|
def init(name)
|
|
|
|
key = options[:template].to_sym
|
2011-07-27 02:19:43 -04:00
|
|
|
unless Middleman::Templates.registered_templates.has_key?(key)
|
|
|
|
key = :default
|
|
|
|
end
|
|
|
|
|
|
|
|
thor_group = Middleman::Templates.registered_templates[key]
|
|
|
|
thor_group.new([name], options).invoke_all
|
2011-07-27 00:06:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "server [-p 4567] [-e development]", "Starts the Middleman preview server"
|
|
|
|
method_option "environment", :aliases => "-e", :default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development', :desc => "The environment Middleman will run under"
|
|
|
|
method_option "port", :aliases => "-p", :default => "4567", :desc => "The port Middleman will listen on"
|
|
|
|
method_option "livereload", :default => false, :type => :boolean, :desc => "Whether to enable Livereload or not"
|
2011-07-27 02:19:43 -04:00
|
|
|
method_option "livereload-port", :default => "35729", :desc => "The port Livereload will listen on"
|
2011-07-27 00:06:10 -04:00
|
|
|
def server
|
2011-08-03 20:10:16 -04:00
|
|
|
v1_check
|
2011-07-27 02:19:43 -04:00
|
|
|
|
2011-08-09 17:46:50 -04:00
|
|
|
if options["livereload"]
|
|
|
|
livereload_options = {:port => options["livereload-port"]}
|
2011-08-09 17:37:55 -04:00
|
|
|
end
|
2011-08-09 17:46:50 -04:00
|
|
|
|
|
|
|
Middleman::Guard.start({
|
|
|
|
:port => options[:port],
|
|
|
|
:environment => options[:environment]
|
|
|
|
}, livereload_options)
|
2011-07-27 00:06:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "build", "Builds the static site for deployment"
|
2011-07-27 00:25:48 -04:00
|
|
|
method_option "relative", :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
|
2011-07-27 00:06:10 -04:00
|
|
|
def build
|
2011-08-03 20:10:16 -04:00
|
|
|
v1_check
|
2011-07-27 02:19:43 -04:00
|
|
|
thor_group = Middleman::Builder.new([], options).invoke_all
|
2011-07-27 00:06:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "migrate", "Migrates an older Middleman project to the 2.0 structure"
|
|
|
|
def migrate
|
2011-07-27 02:19:43 -04:00
|
|
|
return if File.exists?("source")
|
2011-07-27 00:06:10 -04:00
|
|
|
`mv public source`
|
|
|
|
`cp -R views/* source/`
|
|
|
|
`rm -rf views`
|
|
|
|
end
|
|
|
|
|
2011-08-03 17:43:02 -04:00
|
|
|
desc "version", "Show Middleman version"
|
|
|
|
def version
|
|
|
|
require 'middleman/version'
|
|
|
|
say "Middleman #{Middleman::VERSION}"
|
|
|
|
end
|
|
|
|
|
2011-07-27 00:06:10 -04:00
|
|
|
private
|
2011-08-03 01:27:16 -04:00
|
|
|
|
|
|
|
def v1_check
|
2011-07-27 00:06:10 -04:00
|
|
|
if File.exists?("views") || File.exists?("public")
|
2011-08-03 20:10:16 -04:00
|
|
|
$stderr.puts "== Error: The views and public folders are have been combined. Use the 'middleman migrate' command to merge your folders automatically."
|
2011-07-27 00:06:10 -04:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-27 00:26:25 -04:00
|
|
|
def help_check
|
|
|
|
help self.class.send(:retrieve_task_name, ARGV.dup)
|
|
|
|
exit 0
|
|
|
|
end
|
|
|
|
|
2011-07-27 00:06:10 -04:00
|
|
|
end
|
|
|
|
end
|