Sha256: 09fa5d8f13f56f7ba41f107bfd0aaa3c305bb836f2b1aa7f0f2324e9cf714d29

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

require 'middleman-core/templates'

# CLI Module
module Middleman::Cli

  # A thor task for creating new projects
  class Init < Thor
    check_unknown_options!

    namespace :init

    desc 'init NAME [options]', 'Create new project NAME'
    available_templates = ::Middleman::Templates.registered.keys.join(', ')
    method_option 'template',
      :aliases => '-T',
      :default => 'default',
      :desc    => "Use a project template: #{available_templates}"
    method_option 'css_dir',
      # :default => "stylesheets",
      :desc    => 'The path to the css files'
    method_option 'js_dir',
      # :default => "javascripts",
      :desc    => 'The path to the javascript files'
    method_option 'images_dir',
      # :default => "images",
      :desc    => 'The path to the image files'
    method_option 'rack',
      :type    => :boolean,
      :default => false,
      :desc    => 'Include a config.ru file'
    method_option 'skip-gemfile',
      :type    => :boolean,
      :default => false,
      :desc    => "Don't create a Gemfile"
    method_option 'skip-bundle',
      :type    => :boolean,
      :aliases => '-B',
      :default => false,
      :desc    => "Don't run bundle install"
    method_option 'skip-git',
      :type    => :boolean,
      :default => false,
      :desc    => 'Skip Git ignores and keeps'
    # The init task
    # @param [String] name
    def init(name = '.')
      key = options[:template].to_sym
      unless ::Middleman::Templates.registered.has_key?(key)
        raise Thor::Error.new "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

  # Map "i", "new" and "n" to "init"
  Base.map({
    'i'   => 'init',
    'new' => 'init',
    'n'   => 'init'
  })
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
middleman-core-3.3.2 lib/middleman-core/cli/init.rb
middleman-core-3.3.1 lib/middleman-core/cli/init.rb
middleman-core-3.3.0 lib/middleman-core/cli/init.rb