diff --git a/Rakefile b/Rakefile index 5176f04e..70c8ab32 100644 --- a/Rakefile +++ b/Rakefile @@ -43,10 +43,11 @@ end desc 'Run tests for all middleman gems' task :test do + Rake::Task['rubocop'].invoke + GEM_PATHS.each do |g| Dir.chdir("#{File.join(ROOT, g)}") { sh "#{Gem.ruby} -S rake test" } end - Rake::Task['rubocop'].invoke end desc 'Run specs for all middleman gems' diff --git a/middleman-core/features/cli_init.feature b/middleman-core/features/cli_init.feature index d6d5b4b4..1bde5a54 100644 --- a/middleman-core/features/cli_init.feature +++ b/middleman-core/features/cli_init.feature @@ -98,3 +98,54 @@ Feature: Middleman CLI | config.rb | | config.ru | | 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 + """ diff --git a/middleman-core/lib/middleman-core/cli/init.rb b/middleman-core/lib/middleman-core/cli/init.rb index d9541161..08b6c4e6 100644 --- a/middleman-core/lib/middleman-core/cli/init.rb +++ b/middleman-core/lib/middleman-core/cli/init.rb @@ -40,6 +40,11 @@ module Middleman::Cli type: :boolean, default: false, desc: 'Skip Git ignores and keeps' + method_option 'force', + type: :boolean, + default: false, + desc: 'Overwrite existing files without any question' + # The init task # @param [String] name def init(name='.') diff --git a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb index da5897f7..b7b099d3 100644 --- a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb +++ b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb @@ -182,7 +182,7 @@ module Middleman::CoreExtensions rescue ::EOFError rescue ::IOError rescue ::Errno::ENOENT - "" + '' end begin diff --git a/middleman-core/lib/middleman-core/templates/default.rb b/middleman-core/lib/middleman-core/templates/default.rb index 6eea9b44..64d77533 100644 --- a/middleman-core/lib/middleman-core/templates/default.rb +++ b/middleman-core/lib/middleman-core/templates/default.rb @@ -19,17 +19,17 @@ class Middleman::Templates::Default < Middleman::Templates::Base # Actually output the files # @return [void] def build_scaffold! - template 'shared/config.tt', File.join(location, 'config.rb') - copy_file 'default/source/index.html.erb', File.join(location, 'source/index.html.erb') - copy_file 'default/source/layouts/layout.erb', File.join(location, 'source/layouts/layout.erb') - empty_directory File.join(location, 'source', options[:css_dir]) - copy_file 'default/source/stylesheets/all.css', File.join(location, 'source', options[:css_dir], 'all.css') - copy_file 'default/source/stylesheets/normalize.css', File.join(location, 'source', options[:css_dir], 'normalize.css') - empty_directory File.join(location, 'source', options[:js_dir]) - copy_file 'default/source/javascripts/all.js', File.join(location, 'source', options[:js_dir], 'all.js') - empty_directory File.join(location, 'source', options[:images_dir]) - copy_file 'default/source/images/background.png', File.join(location, 'source', options[:images_dir], 'background.png') - copy_file 'default/source/images/middleman.png', File.join(location, 'source', options[:images_dir], 'middleman.png') + 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'), force: options[:force] + 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]), force: options[:force] + 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'), force: options[:force] + 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'), force: options[:force] + 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'), force: options[:force] + copy_file 'default/source/images/middleman.png', File.join(location, 'source', options[:images_dir], 'middleman.png'), force: options[:force] end end diff --git a/middleman-core/lib/middleman-core/templates/empty.rb b/middleman-core/lib/middleman-core/templates/empty.rb index 1ae364c5..58d25693 100644 --- a/middleman-core/lib/middleman-core/templates/empty.rb +++ b/middleman-core/lib/middleman-core/templates/empty.rb @@ -13,8 +13,8 @@ class Middleman::Templates::Empty < Middleman::Templates::Base # Actually output the files # @return [void] def build_scaffold! - create_file File.join(location, 'config.rb'), "\n" - empty_directory File.join(location, 'source') + create_file File.join(location, 'config.rb'), "\n", force: options[:force] + empty_directory File.join(location, 'source'), force: options[:force] end end diff --git a/middleman-core/lib/middleman-core/templates/html5.rb b/middleman-core/lib/middleman-core/templates/html5.rb index 56422032..77b7e544 100644 --- a/middleman-core/lib/middleman-core/templates/html5.rb +++ b/middleman-core/lib/middleman-core/templates/html5.rb @@ -19,9 +19,9 @@ class Middleman::Templates::Html5 < Middleman::Templates::Base # Output the files # @return [void] def build_scaffold! - template 'shared/config.tt', File.join(location, 'config.rb') - directory 'html5/source', File.join(location, 'source') - empty_directory File.join(location, 'source') + template 'shared/config.tt', File.join(location, 'config.rb'), force: options[:force] + directory 'html5/source', File.join(location, 'source'), force: options[:force] + empty_directory File.join(location, 'source'), force: options[:force] end end diff --git a/middleman-core/lib/middleman-core/templates/local.rb b/middleman-core/lib/middleman-core/templates/local.rb index 08d35932..9d8c5594 100644 --- a/middleman-core/lib/middleman-core/templates/local.rb +++ b/middleman-core/lib/middleman-core/templates/local.rb @@ -9,7 +9,7 @@ class Middleman::Templates::Local < Middleman::Templates::Base # Just copy from the template path # @return [void] def build_scaffold! - directory options[:template].to_s, location + directory options[:template].to_s, location, force: options[:force] end end diff --git a/middleman-core/lib/middleman-core/templates/mobile.rb b/middleman-core/lib/middleman-core/templates/mobile.rb index 8137c0dd..ba02cbb2 100644 --- a/middleman-core/lib/middleman-core/templates/mobile.rb +++ b/middleman-core/lib/middleman-core/templates/mobile.rb @@ -14,9 +14,9 @@ class Middleman::Templates::Mobile < Middleman::Templates::Base # Output the files # @return [void] def build_scaffold! - template 'shared/config.tt', File.join(location, 'config.rb') - directory 'mobile/source', File.join(location, 'source') - empty_directory File.join(location, 'source') + template 'shared/config.tt', File.join(location, 'config.rb'), force: options[:force] + directory 'mobile/source', File.join(location, 'source'), force: options[:force] + empty_directory File.join(location, 'source'), force: options[:force] end end