Merge pull request #1369 from dg-ratiodata/feature/force_init
Add force option to "middleman init"
This commit is contained in:
commit
2ff64fe3a3
3
Rakefile
3
Rakefile
|
@ -43,10 +43,11 @@ end
|
||||||
|
|
||||||
desc 'Run tests for all middleman gems'
|
desc 'Run tests for all middleman gems'
|
||||||
task :test do
|
task :test do
|
||||||
|
Rake::Task['rubocop'].invoke
|
||||||
|
|
||||||
GEM_PATHS.each do |g|
|
GEM_PATHS.each do |g|
|
||||||
Dir.chdir("#{File.join(ROOT, g)}") { sh "#{Gem.ruby} -S rake test" }
|
Dir.chdir("#{File.join(ROOT, g)}") { sh "#{Gem.ruby} -S rake test" }
|
||||||
end
|
end
|
||||||
Rake::Task['rubocop'].invoke
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Run specs for all middleman gems'
|
desc 'Run specs for all middleman gems'
|
||||||
|
|
|
@ -98,3 +98,54 @@ Feature: Middleman CLI
|
||||||
| config.rb |
|
| config.rb |
|
||||||
| config.ru |
|
| config.ru |
|
||||||
| Gemfile |
|
| Gemfile |
|
||||||
|
|
||||||
|
Scenario: Enforce creation of Mobile HTML5 project
|
||||||
|
When I run `middleman init MY_PROJECT --template=mobile`
|
||||||
|
When I run `middleman init MY_PROJECT --template=mobile --force`
|
||||||
|
Then a directory named "MY_PROJECT" should exist
|
||||||
|
And the output should contain:
|
||||||
|
"""
|
||||||
|
identical
|
||||||
|
"""
|
||||||
|
And the output should contain:
|
||||||
|
"""
|
||||||
|
exist
|
||||||
|
"""
|
||||||
|
Scenario: Enforce creation of HTML5 project
|
||||||
|
When I run `middleman init MY_PROJECT --template=html5`
|
||||||
|
When I run `middleman init MY_PROJECT --template=html5 --force`
|
||||||
|
Then a directory named "MY_PROJECT" should exist
|
||||||
|
And the output should contain:
|
||||||
|
"""
|
||||||
|
identical
|
||||||
|
"""
|
||||||
|
And the output should contain:
|
||||||
|
"""
|
||||||
|
exist
|
||||||
|
"""
|
||||||
|
|
||||||
|
Scenario: Enforce creation of default project
|
||||||
|
When I run `middleman init MY_PROJECT --template=default`
|
||||||
|
When I run `middleman init MY_PROJECT --template=default --force`
|
||||||
|
Then a directory named "MY_PROJECT" should exist
|
||||||
|
And the output should contain:
|
||||||
|
"""
|
||||||
|
identical
|
||||||
|
"""
|
||||||
|
And the output should contain:
|
||||||
|
"""
|
||||||
|
exist
|
||||||
|
"""
|
||||||
|
|
||||||
|
Scenario: Enforce creation of empty project
|
||||||
|
When I run `middleman init MY_PROJECT --template=empty`
|
||||||
|
When I run `middleman init MY_PROJECT --template=empty --force`
|
||||||
|
Then a directory named "MY_PROJECT" should exist
|
||||||
|
And the output should contain:
|
||||||
|
"""
|
||||||
|
identical
|
||||||
|
"""
|
||||||
|
And the output should contain:
|
||||||
|
"""
|
||||||
|
exist
|
||||||
|
"""
|
||||||
|
|
|
@ -40,6 +40,11 @@ module Middleman::Cli
|
||||||
type: :boolean,
|
type: :boolean,
|
||||||
default: false,
|
default: false,
|
||||||
desc: 'Skip Git ignores and keeps'
|
desc: 'Skip Git ignores and keeps'
|
||||||
|
method_option 'force',
|
||||||
|
type: :boolean,
|
||||||
|
default: false,
|
||||||
|
desc: 'Overwrite existing files without any question'
|
||||||
|
|
||||||
# The init task
|
# The init task
|
||||||
# @param [String] name
|
# @param [String] name
|
||||||
def init(name='.')
|
def init(name='.')
|
||||||
|
|
|
@ -182,7 +182,7 @@ module Middleman::CoreExtensions
|
||||||
rescue ::EOFError
|
rescue ::EOFError
|
||||||
rescue ::IOError
|
rescue ::IOError
|
||||||
rescue ::Errno::ENOENT
|
rescue ::Errno::ENOENT
|
||||||
""
|
''
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -19,17 +19,17 @@ class Middleman::Templates::Default < Middleman::Templates::Base
|
||||||
# Actually output the files
|
# Actually output the files
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def build_scaffold!
|
def build_scaffold!
|
||||||
template 'shared/config.tt', File.join(location, 'config.rb')
|
template 'shared/config.tt', File.join(location, 'config.rb'), force: options[:force]
|
||||||
copy_file 'default/source/index.html.erb', File.join(location, 'source/index.html.erb')
|
copy_file 'default/source/index.html.erb', File.join(location, 'source/index.html.erb'), force: options[:force]
|
||||||
copy_file 'default/source/layouts/layout.erb', File.join(location, 'source/layouts/layout.erb')
|
copy_file 'default/source/layouts/layout.erb', File.join(location, 'source/layouts/layout.erb'), force: options[:force]
|
||||||
empty_directory File.join(location, 'source', options[:css_dir])
|
empty_directory File.join(location, 'source', options[:css_dir]), force: options[:force]
|
||||||
copy_file 'default/source/stylesheets/all.css', File.join(location, 'source', options[:css_dir], 'all.css')
|
copy_file 'default/source/stylesheets/all.css', File.join(location, 'source', options[:css_dir], 'all.css'), force: options[:force]
|
||||||
copy_file 'default/source/stylesheets/normalize.css', File.join(location, 'source', options[:css_dir], 'normalize.css')
|
copy_file 'default/source/stylesheets/normalize.css', File.join(location, 'source', options[:css_dir], 'normalize.css'), force: options[:force]
|
||||||
empty_directory File.join(location, 'source', options[:js_dir])
|
empty_directory File.join(location, 'source', options[:js_dir]), force: options[:force]
|
||||||
copy_file 'default/source/javascripts/all.js', File.join(location, 'source', options[:js_dir], 'all.js')
|
copy_file 'default/source/javascripts/all.js', File.join(location, 'source', options[:js_dir], 'all.js'), force: options[:force]
|
||||||
empty_directory File.join(location, 'source', options[:images_dir])
|
empty_directory File.join(location, 'source', options[:images_dir]), force: options[:force]
|
||||||
copy_file 'default/source/images/background.png', File.join(location, 'source', options[:images_dir], 'background.png')
|
copy_file 'default/source/images/background.png', File.join(location, 'source', options[:images_dir], 'background.png'), force: options[:force]
|
||||||
copy_file 'default/source/images/middleman.png', File.join(location, 'source', options[:images_dir], 'middleman.png')
|
copy_file 'default/source/images/middleman.png', File.join(location, 'source', options[:images_dir], 'middleman.png'), force: options[:force]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ class Middleman::Templates::Empty < Middleman::Templates::Base
|
||||||
# Actually output the files
|
# Actually output the files
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def build_scaffold!
|
def build_scaffold!
|
||||||
create_file File.join(location, 'config.rb'), "\n"
|
create_file File.join(location, 'config.rb'), "\n", force: options[:force]
|
||||||
empty_directory File.join(location, 'source')
|
empty_directory File.join(location, 'source'), force: options[:force]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,9 @@ class Middleman::Templates::Html5 < Middleman::Templates::Base
|
||||||
# Output the files
|
# Output the files
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def build_scaffold!
|
def build_scaffold!
|
||||||
template 'shared/config.tt', File.join(location, 'config.rb')
|
template 'shared/config.tt', File.join(location, 'config.rb'), force: options[:force]
|
||||||
directory 'html5/source', File.join(location, 'source')
|
directory 'html5/source', File.join(location, 'source'), force: options[:force]
|
||||||
empty_directory File.join(location, 'source')
|
empty_directory File.join(location, 'source'), force: options[:force]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Middleman::Templates::Local < Middleman::Templates::Base
|
||||||
# Just copy from the template path
|
# Just copy from the template path
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def build_scaffold!
|
def build_scaffold!
|
||||||
directory options[:template].to_s, location
|
directory options[:template].to_s, location, force: options[:force]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,9 @@ class Middleman::Templates::Mobile < Middleman::Templates::Base
|
||||||
# Output the files
|
# Output the files
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def build_scaffold!
|
def build_scaffold!
|
||||||
template 'shared/config.tt', File.join(location, 'config.rb')
|
template 'shared/config.tt', File.join(location, 'config.rb'), force: options[:force]
|
||||||
directory 'mobile/source', File.join(location, 'source')
|
directory 'mobile/source', File.join(location, 'source'), force: options[:force]
|
||||||
empty_directory File.join(location, 'source')
|
empty_directory File.join(location, 'source'), force: options[:force]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue