middleman-cli 4.0.0.alpha.5 → 4.0.0.alpha.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f162eeb45e53839a938b4b953897c48cc7e66779
4
- data.tar.gz: fc1a73359a99e139764c339809505e38a6035b8e
3
+ metadata.gz: 8b4d71b08b02fed014baba761ddb5021c93e3149
4
+ data.tar.gz: c5c2046bf5f453504550008aba3db227353c83c0
5
5
  SHA512:
6
- metadata.gz: 3ebc8c7230c9af7ab540a3703990c55e6eda8a3884d3347239434e5232862086567edbae858a4b8c4094d7567487990766a8a049db3a70d4b92ca9339b73100a
7
- data.tar.gz: 1f0ad9d9765b2c7ee6f8bfde7da432d5c3b9e9c8b467ba5d94d61dc04ca34420c457bbb39fc314ae089c347a6ff651f25d1101ee83273d34b98630133656e122
6
+ metadata.gz: ea071324738707a762be53f986e8ecbc5d9f47bef1e9e4268010bde865dc71f4a42af782a5fc5714030399eb0be8c196d2b851df7bf4959578f2a1fab0dc31ab
7
+ data.tar.gz: 120cac0b58998fde7737ba7c5c07d6b387dd70ebcffc102cca5f3a184ca21977fc59518bdd8cb18df06aff30cf0d7455abbd4e4fd6bd0b4bf517ea9291925727
@@ -14,5 +14,10 @@ require "middleman-cli"
14
14
  # Change directory to the root
15
15
  Dir.chdir(ENV["MM_ROOT"]) if ENV["MM_ROOT"]
16
16
 
17
+ # Default command is server
18
+ if ARGV[0] != 'help' && (ARGV.length < 1 || ARGV.first.include?('-'))
19
+ ARGV.unshift('server')
20
+ end
21
+
17
22
  # Start the CLI
18
- Middleman::Cli::Base.start
23
+ Middleman::Cli::Base.start(ARGV)
@@ -6,81 +6,18 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
6
6
 
7
7
  # Require Thor since that's what the whole CLI is built around
8
8
  require 'thor'
9
- require 'thor/group'
10
9
 
11
10
  # CLI Module
12
- module Middleman
13
- module Cli
14
- # The base task from which everything else extends
15
- class Base < Thor
16
- class << self
17
- def start(*args)
18
- # Change flag to a module
19
- ARGV.unshift('help') if ARGV.delete('--help')
20
-
21
- # Default command is server
22
- if ARGV[0] != 'help' && (ARGV.length < 1 || ARGV.first.include?('-'))
23
- ARGV.unshift('server')
24
- end
25
-
26
- super
27
- end
28
- end
29
-
30
- desc 'version', 'Show version'
31
- def version
32
- say "Middleman #{Middleman::VERSION}"
33
- end
34
-
35
- desc 'help', 'Show help'
36
-
37
- # Override the Thor help method to find help for subtasks
38
- # @param [Symbol, String, nil] meth
39
- # @param [Boolean] subcommand
40
- # @return [void]
41
- # rubocop:disable UnusedMethodArgument
42
- def help(meth=nil, subcommand=false)
43
- if meth && !self.respond_to?(meth)
44
- klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
45
- klass.start(['-h', task].compact, shell: shell)
46
- else
47
- list = []
48
- Thor::Util.thor_classes_in(Middleman::Cli).each do |thor_class|
49
- list += thor_class.printable_tasks(false)
50
- end
51
- list.sort! { |a, b| a[0] <=> b[0] }
52
-
53
- shell.say 'Tasks:'
54
- shell.print_table(list, ident: 2, truncate: true)
55
- shell.say %(\nSee 'middleman help <command>' for more information on specific command.)
56
- shell.say
57
- end
58
- end
59
-
60
- # Intercept missing methods and search subtasks for them
61
- # @param [Symbol] meth
62
- def method_missing(meth, *args)
63
- meth = meth.to_s
64
- meth = self.class.map[meth] if self.class.map.key?(meth)
65
-
66
- klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
67
-
68
- if klass.nil?
69
- tasks_dir = File.join(Dir.pwd, 'tasks')
70
-
71
- if File.exist?(tasks_dir)
72
- Dir[File.join(tasks_dir, '**/*_task.rb')].each { |f| require f }
73
- klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
74
- end
75
- end
11
+ module Middleman::Cli
12
+ # The base task from which everything else extends
13
+ class Base < ::Thor
14
+ desc 'version', 'Show version'
15
+ def version
16
+ say "Middleman #{Middleman::VERSION}"
17
+ end
76
18
 
77
- if klass.nil?
78
- raise Thor::Error, "There's no '#{meth}' command for Middleman. Try 'middleman help' for a list of commands."
79
- else
80
- args.unshift(task) if task
81
- klass.start(args, shell: shell)
82
- end
83
- end
19
+ def self.exit_on_failure?
20
+ true
84
21
  end
85
22
  end
86
23
  end
@@ -1,39 +1,36 @@
1
1
  # CLI Module
2
2
  module Middleman::Cli
3
3
  # The CLI Build class
4
- class Build < Thor
4
+ class Build < Thor::Group
5
5
  include Thor::Actions
6
6
 
7
7
  check_unknown_options!
8
8
 
9
- namespace :build
10
-
11
- desc 'build [options]', 'Builds the static site for deployment'
12
- method_option :environment,
13
- aliases: '-e',
14
- default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'production',
15
- desc: 'The environment Middleman will run under'
16
- method_option :clean,
17
- type: :boolean,
18
- default: true,
19
- desc: 'Remove orphaned files from build (--no-clean to disable)'
20
- method_option :glob,
21
- type: :string,
22
- aliases: '-g',
23
- default: nil,
24
- desc: 'Build a subset of the project'
25
- method_option :verbose,
26
- type: :boolean,
27
- default: false,
28
- desc: 'Print debug messages'
29
- method_option :instrument,
30
- type: :string,
31
- default: false,
32
- desc: 'Print instrument messages'
33
- method_option :profile,
34
- type: :boolean,
35
- default: false,
36
- desc: 'Generate profiling report for the build'
9
+ class_option :environment,
10
+ aliases: '-e',
11
+ default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'production',
12
+ desc: 'The environment Middleman will run under'
13
+ class_option :clean,
14
+ type: :boolean,
15
+ default: true,
16
+ desc: 'Remove orphaned files from build (--no-clean to disable)'
17
+ class_option :glob,
18
+ type: :string,
19
+ aliases: '-g',
20
+ default: nil,
21
+ desc: 'Build a subset of the project'
22
+ class_option :verbose,
23
+ type: :boolean,
24
+ default: false,
25
+ desc: 'Print debug messages'
26
+ class_option :instrument,
27
+ type: :string,
28
+ default: false,
29
+ desc: 'Print instrument messages'
30
+ class_option :profile,
31
+ type: :boolean,
32
+ default: false,
33
+ desc: 'Generate profiling report for the build'
37
34
 
38
35
  # Core build Thor command
39
36
  # @return [void]
@@ -78,51 +75,49 @@ module Middleman::Cli
78
75
  end
79
76
  end
80
77
 
81
- # Tell Thor to send an exit status on a failure.
82
- def self.exit_on_failure?
83
- true
84
- end
78
+ protected
85
79
 
86
- no_tasks do
87
- # Handles incoming events from the builder.
88
- # @param [Symbol] event_type The type of event.
89
- # @param [String] contents The event contents.
90
- # @param [String] extra The extra information.
91
- # @return [void]
92
- def on_event(event_type, target, extra=nil)
93
- case event_type
94
- when :error
95
- say_status :error, target, :red
96
- shell.say extra, :red if options['verbose']
97
- when :deleted
98
- say_status :remove, target, :green
99
- when :created
100
- say_status :create, target, :green
101
- when :identical
102
- say_status :identical, target, :blue
103
- when :updated
104
- say_status :updated, target, :yellow
105
- else
106
- say_status event_type, extra, :blue
107
- end
80
+ # Handles incoming events from the builder.
81
+ # @param [Symbol] event_type The type of event.
82
+ # @param [String] contents The event contents.
83
+ # @param [String] extra The extra information.
84
+ # @return [void]
85
+ def on_event(event_type, target, extra=nil)
86
+ case event_type
87
+ when :error
88
+ say_status :error, target, :red
89
+ shell.say extra, :red if options['verbose']
90
+ when :deleted
91
+ say_status :remove, target, :green
92
+ when :created
93
+ say_status :create, target, :green
94
+ when :identical
95
+ say_status :identical, target, :blue
96
+ when :updated
97
+ say_status :updated, target, :yellow
98
+ else
99
+ say_status event_type, extra, :blue
108
100
  end
101
+ end
109
102
 
110
- # Find empty directories in the build folder and remove them.
111
- # @return [Boolean]
112
- def clean_directories!
113
- all_build_files = File.join(@app.config[:build_dir], '**', '*')
103
+ # Find empty directories in the build folder and remove them.
104
+ # @return [Boolean]
105
+ def clean_directories!
106
+ all_build_files = File.join(@app.config[:build_dir], '**', '*')
114
107
 
115
- empty_directories = Dir[all_build_files].select do |d|
116
- File.directory?(d)
117
- end
108
+ empty_directories = Dir[all_build_files].select do |d|
109
+ File.directory?(d)
110
+ end
118
111
 
119
- empty_directories.each do |d|
120
- remove_file d, force: true if Pathname(d).children.empty?
121
- end
112
+ empty_directories.each do |d|
113
+ remove_file d, force: true if Pathname(d).children.empty?
122
114
  end
123
115
  end
124
- end
125
116
 
126
- # Alias "b" to "build"
127
- Base.map('b' => 'build')
117
+ # Add to CLI
118
+ Base.register(self, 'build', 'build [options]', 'Builds the static site for deployment')
119
+
120
+ # Map "b" to "build"
121
+ Base.map('b' => 'build')
122
+ end
128
123
  end
@@ -1,25 +1,19 @@
1
1
  # CLI Module
2
2
  module Middleman::Cli
3
- # Alias "c" to "console"
4
- Base.map(c: 'console')
5
-
6
3
  # The CLI Console class
7
- class Console < Thor
4
+ class Console < Thor::Group
8
5
  include Thor::Actions
9
6
 
10
7
  check_unknown_options!
11
8
 
12
- namespace :console
13
-
14
- desc 'console [options]', 'Start an interactive console in the context of your Middleman application'
15
- method_option :environment,
16
- aliases: '-e',
17
- default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
18
- desc: 'The environment Middleman will run under'
19
- method_option :verbose,
20
- type: :boolean,
21
- default: false,
22
- desc: 'Print debug messages'
9
+ class_option :environment,
10
+ aliases: '-e',
11
+ default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
12
+ desc: 'The environment Middleman will run under'
13
+ class_option :verbose,
14
+ type: :boolean,
15
+ default: false,
16
+ desc: 'Print debug messages'
23
17
  def console
24
18
  require 'middleman-core'
25
19
  require 'irb'
@@ -42,5 +36,11 @@ module Middleman::Cli
42
36
  require 'irb/ext/multi-irb'
43
37
  IRB.irb nil, @app
44
38
  end
39
+
40
+ # Add to CLI
41
+ Base.register(self, 'console', 'console [options]', 'Start an interactive console in the context of your Middleman application')
42
+
43
+ # Map "c" to "console"
44
+ Base.map('c' => 'console')
45
45
  end
46
46
  end
@@ -1,13 +1,11 @@
1
1
  # CLI Module
2
2
  module Middleman::Cli
3
3
  # A thor task for creating new projects
4
- class Extension < Thor
4
+ class Extension < Thor::Group
5
5
  include Thor::Actions
6
6
 
7
7
  check_unknown_options!
8
8
 
9
- namespace :extension
10
-
11
9
  # Required path for the new project to be generated
12
10
  argument :name, type: :string
13
11
 
@@ -17,11 +15,13 @@ module Middleman::Cli
17
15
  File.join(File.dirname(__FILE__), 'templates')
18
16
  end
19
17
 
20
- desc 'extension [options]', 'Create Middleman extension scaffold NAME'
21
- method_option 'skip-git',
22
- type: :boolean,
23
- default: false,
24
- desc: 'Skip Git ignores and keeps'
18
+ class_option 'skip-git',
19
+ type: :boolean,
20
+ default: false,
21
+ desc: 'Skip Git ignores and keeps'
22
+
23
+ # Output a .gitignore file
24
+ class_option :git, type: :boolean, default: true
25
25
 
26
26
  # The extension task
27
27
  # @param [String] name
@@ -36,7 +36,7 @@ module Middleman::Cli
36
36
  empty_directory File.join(name, 'fixtures')
37
37
  end
38
38
 
39
- # Output a .gitignore file
40
- class_option :git, type: :boolean, default: true
39
+ # Add to CLI
40
+ Base.register(self, 'extension', 'extension [options]', 'Create a new Middleman extension')
41
41
  end
42
42
  end
@@ -1,28 +1,28 @@
1
1
  # CLI Module
2
2
  module Middleman::Cli
3
3
  # A thor task for creating new projects
4
- class Init < Thor
4
+ class Init < Thor::Group
5
5
  include Thor::Actions
6
+
6
7
  check_unknown_options!
7
8
 
8
- namespace :init
9
+ argument :target, type: :string, default: '.'
9
10
 
10
- desc 'init TARGET [options]', 'Create new project at TARGET'
11
- method_option 'template',
12
- aliases: '-T',
13
- default: 'middleman/middleman-templates-default',
14
- desc: 'Use a project template'
11
+ class_option 'template',
12
+ aliases: '-T',
13
+ default: 'middleman/middleman-templates-default',
14
+ desc: 'Use a project template'
15
15
 
16
16
  # Do not run bundle install
17
- method_option 'skip-bundle',
18
- type: :boolean,
19
- aliases: '-B',
20
- default: false,
21
- desc: 'Skip bundle install'
17
+ class_option 'skip-bundle',
18
+ type: :boolean,
19
+ aliases: '-B',
20
+ default: false,
21
+ desc: 'Skip bundle install'
22
22
 
23
23
  # The init task
24
- # @param [String] name
25
- def init(target='.')
24
+ def init
25
+ require 'fileutils'
26
26
  require 'tmpdir'
27
27
 
28
28
  repo_path, repo_branch = if shortname?(options[:template])
@@ -37,8 +37,8 @@ module Middleman::Cli
37
37
  data['links']['github']
38
38
  data['links']['github'].split('#')
39
39
  rescue ::OpenURI::HTTPError
40
- puts "Template `#{options[:template]}` not found in Middleman Directory."
41
- puts 'Did you mean to use a full `user/repo` path?'
40
+ say "Template `#{options[:template]}` not found in Middleman Directory."
41
+ say 'Did you mean to use a full `user/repo` path?'
42
42
  exit
43
43
  end
44
44
  else
@@ -46,18 +46,29 @@ module Middleman::Cli
46
46
  [repository_path(repo_name), repo_branch]
47
47
  end
48
48
 
49
- Dir.mktmpdir do |dir|
50
- cmd = repo_branch ? "clone -b #{repo_branch}" : 'clone'
49
+ dir = Dir.mktmpdir
50
+
51
+ begin
52
+ branch_cmd = repo_branch ? "-b #{repo_branch} " : ''
53
+
54
+ run("git clone --depth 1 #{branch_cmd}#{repo_path} #{dir}")
51
55
 
52
- run("git #{cmd} #{repo_path} #{dir}")
56
+ inside(target) do
57
+ thorfile = File.join(dir, 'Thorfile')
53
58
 
54
- source_paths << dir
59
+ if File.exist?(thorfile)
60
+ ::Thor::Util.load_thorfile(thorfile)
55
61
 
56
- directory dir, target, exclude_pattern: /\.git\/|\.gitignore$/
62
+ invoke 'middleman:generator'
63
+ else
64
+ source_paths << dir
65
+ directory dir, '.', exclude_pattern: /\.git\/|\.gitignore$/
66
+ end
57
67
 
58
- inside(target) do
59
- run('bundle install')
60
- end unless ENV['TEST'] || options[:'skip-bundle']
68
+ run('bundle install') unless ENV['TEST'] || options[:'skip-bundle']
69
+ end
70
+ ensure
71
+ FileUtils.remove_entry(dir)
61
72
  end
62
73
  end
63
74
 
@@ -70,16 +81,15 @@ module Middleman::Cli
70
81
  def repository_path(repo)
71
82
  "git://github.com/#{repo}.git"
72
83
  end
73
- end
74
84
 
75
- def self.exit_on_failure?
76
- true
77
- end
85
+ # Add to CLI
86
+ Base.register(self, 'init', 'init TARGET [options]', 'Create new project at TARGET')
78
87
 
79
- # Map "i", "new" and "n" to "init"
80
- Base.map(
81
- 'i' => 'init',
82
- 'new' => 'init',
83
- 'n' => 'init'
84
- )
88
+ # Map "i", "new" and "n" to "init"
89
+ Base.map(
90
+ 'i' => 'init',
91
+ 'new' => 'init',
92
+ 'n' => 'init'
93
+ )
94
+ end
85
95
  end
@@ -1,50 +1,47 @@
1
1
  # CLI Module
2
2
  module Middleman::Cli
3
3
  # Server thor task
4
- class Server < Thor
4
+ class Server < Thor::Group
5
5
  check_unknown_options!
6
6
 
7
- namespace :server
8
-
9
- desc 'server [options]', 'Start the preview server'
10
- method_option :environment,
11
- aliases: '-e',
12
- default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
13
- desc: 'The environment Middleman will run under'
14
- method_option :host,
15
- type: :string,
16
- aliases: '-h',
17
- default: '0.0.0.0',
18
- desc: 'Bind to HOST address'
19
- method_option :port,
20
- aliases: '-p',
21
- default: '4567',
22
- desc: 'The port Middleman will listen on'
23
- method_option :verbose,
24
- type: :boolean,
25
- default: false,
26
- desc: 'Print debug messages'
27
- method_option :instrument,
28
- type: :string,
29
- default: false,
30
- desc: 'Print instrument messages'
31
- method_option :disable_watcher,
32
- type: :boolean,
33
- default: false,
34
- desc: 'Disable the file change and delete watcher process'
35
- method_option :profile,
36
- type: :boolean,
37
- default: false,
38
- desc: 'Generate profiling report for server startup'
39
- method_option :force_polling,
40
- type: :boolean,
41
- default: false,
42
- desc: 'Force file watcher into polling mode'
43
- method_option :latency,
44
- type: :numeric,
45
- aliases: '-l',
46
- default: 0.25,
47
- desc: 'Set file watcher latency, in seconds'
7
+ class_option :environment,
8
+ aliases: '-e',
9
+ default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
10
+ desc: 'The environment Middleman will run under'
11
+ class_option :host,
12
+ type: :string,
13
+ aliases: '-h',
14
+ default: '0.0.0.0',
15
+ desc: 'Bind to HOST address'
16
+ class_option :port,
17
+ aliases: '-p',
18
+ default: '4567',
19
+ desc: 'The port Middleman will listen on'
20
+ class_option :verbose,
21
+ type: :boolean,
22
+ default: false,
23
+ desc: 'Print debug messages'
24
+ class_option :instrument,
25
+ type: :string,
26
+ default: false,
27
+ desc: 'Print instrument messages'
28
+ class_option :disable_watcher,
29
+ type: :boolean,
30
+ default: false,
31
+ desc: 'Disable the file change and delete watcher process'
32
+ class_option :profile,
33
+ type: :boolean,
34
+ default: false,
35
+ desc: 'Generate profiling report for server startup'
36
+ class_option :force_polling,
37
+ type: :boolean,
38
+ default: false,
39
+ desc: 'Force file watcher into polling mode'
40
+ class_option :latency,
41
+ type: :numeric,
42
+ aliases: '-l',
43
+ default: 0.25,
44
+ desc: 'Set file watcher latency, in seconds'
48
45
 
49
46
  # Start the server
50
47
  def server
@@ -71,12 +68,11 @@ module Middleman::Cli
71
68
  puts '== The Middleman is loading'
72
69
  ::Middleman::PreviewServer.start(params)
73
70
  end
74
- end
75
71
 
76
- def self.exit_on_failure?
77
- true
78
- end
72
+ # Add to CLI
73
+ Base.register(self, 'server', 'server [options]', 'Start the preview server')
79
74
 
80
- # Map "s" to "server"
81
- Base.map('s' => 'server')
75
+ # Map "s" to "server"
76
+ Base.map('s' => 'server')
77
+ end
82
78
  end
@@ -24,7 +24,7 @@ class MyExtension < ::Middleman::Extension
24
24
  # def manipulate_resource_list(resources)
25
25
  # end
26
26
 
27
- # module do
27
+ # helpers do
28
28
  # def a_helper
29
29
  # end
30
30
  # end
@@ -1,2 +1,2 @@
1
1
  # Backwards compat
2
- require 'middleman-cli'
2
+ require 'middleman-cli'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.alpha.5
4
+ version: 4.0.0.alpha.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Reynolds
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-26 00:00:00.000000000 Z
12
+ date: 2015-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor