2014-03-11 12:07:55 +01:00
|
|
|
require 'middleman-templates'
|
2012-04-14 22:51:02 +02:00
|
|
|
|
2011-12-29 07:52:51 +01:00
|
|
|
# CLI Module
|
2011-12-21 21:13:28 +01:00
|
|
|
module Middleman::Cli
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2011-12-29 07:52:51 +01:00
|
|
|
# A thor task for creating new projects
|
2011-12-21 21:13:28 +01:00
|
|
|
class Init < Thor
|
2011-12-21 20:03:45 +01:00
|
|
|
check_unknown_options!
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2011-12-21 21:13:28 +01:00
|
|
|
namespace :init
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2013-12-28 01:26:31 +01:00
|
|
|
desc 'init NAME [options]', 'Create new project NAME'
|
|
|
|
available_templates = ::Middleman::Templates.registered.keys.join(', ')
|
|
|
|
method_option 'template',
|
|
|
|
:aliases => '-T',
|
|
|
|
:default => 'default',
|
2011-12-21 20:03:45 +01:00
|
|
|
:desc => "Use a project template: #{available_templates}"
|
2013-12-28 01:26:31 +01:00
|
|
|
method_option 'css_dir',
|
2012-08-14 00:39:06 +02:00
|
|
|
# :default => "stylesheets",
|
2011-12-21 20:03:45 +01:00
|
|
|
:desc => 'The path to the css files'
|
2013-12-28 01:26:31 +01:00
|
|
|
method_option 'js_dir',
|
2012-08-14 00:39:06 +02:00
|
|
|
# :default => "javascripts",
|
2011-12-21 20:03:45 +01:00
|
|
|
:desc => 'The path to the javascript files'
|
2013-12-28 01:26:31 +01:00
|
|
|
method_option 'images_dir',
|
2012-08-14 00:39:06 +02:00
|
|
|
# :default => "images",
|
2011-12-21 20:03:45 +01:00
|
|
|
:desc => 'The path to the image files'
|
2013-12-28 01:26:31 +01:00
|
|
|
method_option 'rack',
|
2012-08-14 00:39:06 +02:00
|
|
|
:type => :boolean,
|
|
|
|
:default => false,
|
2011-12-21 20:03:45 +01:00
|
|
|
:desc => 'Include a config.ru file'
|
2013-12-28 01:26:31 +01:00
|
|
|
method_option 'skip-bundle',
|
2012-09-15 08:31:44 +02:00
|
|
|
:type => :boolean,
|
2013-12-28 01:26:31 +01:00
|
|
|
:aliases => '-B',
|
2012-09-15 08:31:44 +02:00
|
|
|
:default => false,
|
|
|
|
:desc => "Don't run bundle install"
|
2013-12-28 01:26:31 +01:00
|
|
|
method_option 'skip-git',
|
2012-09-15 08:31:44 +02:00
|
|
|
:type => :boolean,
|
|
|
|
:default => false,
|
|
|
|
:desc => 'Skip Git ignores and keeps'
|
2011-12-29 07:52:51 +01:00
|
|
|
# The init task
|
|
|
|
# @param [String] name
|
2014-02-20 08:13:59 +01:00
|
|
|
def init(name = '.')
|
2011-12-21 20:03:45 +01:00
|
|
|
key = options[:template].to_sym
|
|
|
|
unless ::Middleman::Templates.registered.has_key?(key)
|
|
|
|
raise Thor::Error.new "Unknown project template '#{key}'"
|
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2011-12-21 20:03:45 +01:00
|
|
|
thor_group = ::Middleman::Templates.registered[key]
|
|
|
|
thor_group.new([name], options).invoke_all
|
|
|
|
end
|
|
|
|
end
|
2012-03-19 00:30:25 +01:00
|
|
|
|
|
|
|
def self.exit_on_failure?
|
|
|
|
true
|
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2011-12-29 07:52:51 +01:00
|
|
|
# Map "i", "new" and "n" to "init"
|
2011-12-21 20:03:45 +01:00
|
|
|
Base.map({
|
2013-12-28 01:26:31 +01:00
|
|
|
'i' => 'init',
|
|
|
|
'new' => 'init',
|
|
|
|
'n' => 'init'
|
2011-12-21 20:03:45 +01:00
|
|
|
})
|
2012-03-19 00:30:25 +01:00
|
|
|
end
|