From d1f0e6f6161002b2ce49c0463555d672c92d06a6 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Mon, 16 Jan 2012 14:55:08 -0800 Subject: [PATCH] fix errant MM bootup during CLI. Make an autodiscoverable tasks/ directory --- .../fixtures/3rd-party-command/config.rb | 10 ---------- .../3rd-party-command/tasks/hello_task.rb | 6 ++++++ middleman-core/lib/middleman-core/cli.rb | 18 ++++++++++++++++-- middleman-core/lib/middleman-core/cli/build.rb | 8 +++++--- middleman-core/lib/middleman-core/watcher.rb | 5 +++-- 5 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 middleman-core/fixtures/3rd-party-command/tasks/hello_task.rb diff --git a/middleman-core/fixtures/3rd-party-command/config.rb b/middleman-core/fixtures/3rd-party-command/config.rb index f7bded87..e69de29b 100644 --- a/middleman-core/fixtures/3rd-party-command/config.rb +++ b/middleman-core/fixtures/3rd-party-command/config.rb @@ -1,10 +0,0 @@ -class HelloWorld < Thor - default_task :say_hi - - desc "hello", "Say hello" - def say_hi - puts "Hello World" - end -end - -Middleman::Cli::Base.register(HelloWorld, :hello, "hello", "Say hello") \ No newline at end of file diff --git a/middleman-core/fixtures/3rd-party-command/tasks/hello_task.rb b/middleman-core/fixtures/3rd-party-command/tasks/hello_task.rb new file mode 100644 index 00000000..d6d217bb --- /dev/null +++ b/middleman-core/fixtures/3rd-party-command/tasks/hello_task.rb @@ -0,0 +1,6 @@ +class Hello < Thor + desc "hello", "Say hello" + def hello + puts "Hello World" + end +end \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/cli.rb b/middleman-core/lib/middleman-core/cli.rb index 5d890a65..694e077d 100644 --- a/middleman-core/lib/middleman-core/cli.rb +++ b/middleman-core/lib/middleman-core/cli.rb @@ -45,8 +45,22 @@ module Middleman::Cli end klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}") - args.unshift(task) if task - klass.start(args, :shell => self.shell) + + if klass.nil? + tasks_dir = File.join(Dir.pwd, "tasks") + + if File.exists?(tasks_dir) + Dir[File.join(tasks_dir, "**/*_task.rb")].each { |f| require f } + klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}") + end + end + + if klass.nil? + super + else + args.unshift(task) if task + klass.start(args, :shell => self.shell) + end end end end diff --git a/middleman-core/lib/middleman-core/cli/build.rb b/middleman-core/lib/middleman-core/cli/build.rb index a0e30d2b..1f28ae5c 100644 --- a/middleman-core/lib/middleman-core/cli/build.rb +++ b/middleman-core/lib/middleman-core/cli/build.rb @@ -85,10 +85,12 @@ module Middleman::Cli sess end end - end - # Set the root path to the Middleman::Base's root - source_root(shared_instance.root) + # Set the root path to the Middleman::Base's root + def source_root + shared_instance.root + end + end # Ignore following method desc "", "", :hide => true diff --git a/middleman-core/lib/middleman-core/watcher.rb b/middleman-core/lib/middleman-core/watcher.rb index d7b6f1cd..553b91e7 100644 --- a/middleman-core/lib/middleman-core/watcher.rb +++ b/middleman-core/lib/middleman-core/watcher.rb @@ -70,12 +70,13 @@ module Middleman # @return [void] def bootup env = (@options[:environment] || "development").to_sym - is_logging = @options.has_key?(:debug) && (@options[:debug] == "true") + is_logging = @options.has_key?(:debug) && @options[:debug] + app = ::Middleman.server.inst do set :environment, env set :logging, is_logging end - + $stderr.puts "Is logging?: #{is_logging}" app_rack = app.class.to_rack_app opts = @options.dup