2012-05-03 00:59:36 +02:00
|
|
|
# CLI Module
|
|
|
|
module Middleman::Cli
|
|
|
|
# A thor task for creating new projects
|
2015-01-04 21:23:35 +01:00
|
|
|
class Extension < Thor::Group
|
2012-05-03 00:59:36 +02:00
|
|
|
include Thor::Actions
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-05-03 00:59:36 +02:00
|
|
|
check_unknown_options!
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-05-03 00:59:36 +02:00
|
|
|
# Required path for the new project to be generated
|
2014-04-29 19:50:21 +02:00
|
|
|
argument :name, type: :string
|
2013-12-28 19:14:15 +01:00
|
|
|
|
2012-08-21 04:37:10 +02:00
|
|
|
# Template files are relative to this file
|
|
|
|
# @return [String]
|
|
|
|
def self.source_root
|
2014-01-03 01:34:08 +01:00
|
|
|
File.join(File.dirname(__FILE__), 'templates')
|
2012-08-21 04:37:10 +02:00
|
|
|
end
|
2013-12-28 19:14:15 +01:00
|
|
|
|
2015-01-04 21:23:35 +01:00
|
|
|
class_option 'skip-git',
|
|
|
|
type: :boolean,
|
|
|
|
default: false,
|
|
|
|
desc: 'Skip Git ignores and keeps'
|
|
|
|
|
|
|
|
# Output a .gitignore file
|
|
|
|
class_option :git, type: :boolean, default: true
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-05-03 00:59:36 +02:00
|
|
|
# The extension task
|
|
|
|
# @param [String] name
|
|
|
|
def extension
|
2014-03-11 12:08:41 +01:00
|
|
|
copy_file 'extension/gitignore', File.join(name, '.gitignore') unless options[:'skip-git']
|
2014-01-03 01:34:08 +01:00
|
|
|
template 'extension/Rakefile', File.join(name, 'Rakefile')
|
|
|
|
template 'extension/gemspec', File.join(name, "#{name}.gemspec")
|
|
|
|
template 'extension/Gemfile', File.join(name, 'Gemfile')
|
|
|
|
template 'extension/lib/middleman_extension.rb', File.join(name, 'lib', 'middleman_extension.rb')
|
|
|
|
template 'extension/lib/lib.rb', File.join(name, 'lib', "#{name}.rb")
|
|
|
|
template 'extension/features/support/env.rb', File.join(name, 'features', 'support', 'env.rb')
|
2013-12-28 01:26:31 +01:00
|
|
|
empty_directory File.join(name, 'fixtures')
|
2012-05-03 00:59:36 +02:00
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2015-01-04 21:23:35 +01:00
|
|
|
# Add to CLI
|
|
|
|
Base.register(self, 'extension', 'extension [options]', 'Create a new Middleman extension')
|
2012-05-03 00:59:36 +02:00
|
|
|
end
|
|
|
|
end
|