middleman/middleman-cli/lib/middleman-cli/init.rb

60 lines
1.7 KiB
Ruby
Raw Normal View History

2014-03-11 12:07:55 +01:00
require 'middleman-templates'
2011-12-29 07:52:51 +01:00
# CLI Module
2011-12-21 21:13:28 +01:00
module Middleman::Cli
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
check_unknown_options!
2011-12-21 21:13:28 +01:00
namespace :init
desc 'init NAME [options]', 'Create new project NAME'
available_templates = ::Middleman::Templates.registered.keys.join(', ')
method_option 'template',
2014-04-29 19:50:21 +02:00
aliases: '-T',
default: 'default',
desc: "Use a project template: #{available_templates}"
method_option 'css_dir',
2014-04-29 19:50:21 +02:00
desc: 'The path to the css files'
method_option 'js_dir',
2014-04-29 19:50:21 +02:00
desc: 'The path to the javascript files'
method_option 'images_dir',
2014-04-29 19:50:21 +02:00
desc: 'The path to the image files'
method_option 'rack',
2014-04-29 19:50:21 +02:00
type: :boolean,
default: false,
desc: 'Include a config.ru file'
method_option 'skip-bundle',
2014-04-29 19:50:21 +02:00
type: :boolean,
aliases: '-B',
default: false,
desc: "Don't run bundle install"
method_option 'skip-git',
2014-04-29 19:50:21 +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-04-29 19:50:21 +02:00
def init(name='.')
key = options[:template].to_sym
2014-04-29 19:50:21 +02:00
unless ::Middleman::Templates.registered.key?(key)
2014-04-29 01:02:18 +02:00
raise Thor::Error, "Unknown project template '#{key}'"
end
thor_group = ::Middleman::Templates.registered[key]
thor_group.new([name], options).invoke_all
end
end
def self.exit_on_failure?
true
end
2011-12-29 07:52:51 +01:00
# Map "i", "new" and "n" to "init"
2014-04-29 19:50:21 +02:00
Base.map(
'i' => 'init',
'new' => 'init',
'n' => 'init'
2014-04-29 19:50:21 +02:00
)
end