From d60ff13952122f823b3e8ad599ce66d846c56b30 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Tue, 26 Jul 2011 21:05:13 -0700 Subject: [PATCH 1/9] fix typo --- lib/middleman.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleman.rb b/lib/middleman.rb index 026b0793..7bda7c68 100755 --- a/lib/middleman.rb +++ b/lib/middleman.rb @@ -51,7 +51,7 @@ # [Email the users group]: http://groups.google.com/group/middleman-users # [Submit bug reports]: https://github.com/tdreyno/middleman/issues -# Setup out load paths +# Setup our load paths libdir = File.dirname(__FILE__) $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) From 319871995f663424ade9891cfac4858ed6753e75 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Tue, 26 Jul 2011 21:05:29 -0700 Subject: [PATCH 2/9] stop requiring rubygems where we don't need to --- lib/middleman.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/middleman.rb b/lib/middleman.rb index 7bda7c68..5f211d9f 100755 --- a/lib/middleman.rb +++ b/lib/middleman.rb @@ -55,9 +55,6 @@ libdir = File.dirname(__FILE__) $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) -# Require Rubygems (probably not necessary) -require 'rubygems' - # We're riding on Sinatra, so let's include it. require "sinatra/base" From b0dbb13f1e6a17541032c8877dd0217b710e52df Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Tue, 26 Jul 2011 21:06:10 -0700 Subject: [PATCH 3/9] create CLI class that pulls in mm-* binary commands --- lib/middleman/cli.rb | 68 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 lib/middleman/cli.rb diff --git a/lib/middleman/cli.rb b/lib/middleman/cli.rb new file mode 100644 index 00000000..443b3cbb --- /dev/null +++ b/lib/middleman/cli.rb @@ -0,0 +1,68 @@ +require 'thor' +require 'middleman' +require "middleman/templates" + +module Middleman + class CLI < Thor + include Thor::Actions + default_task :server + + def initialize(*) + config_check + super + end + + desc "init NAME", "Create new Middleman project directory NAME" + available_templates = Middleman::Templates.registered_names.join(", ") + method_option :template, :aliases => "-T", :default => "default", :desc => "Optionally use a pre-defined 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' + def init(name) + key = options[:template].to_sym + key = :default unless Middleman::Templates.registered_templates.has_key?(key) + + Middleman::Templates.registered_templates[key].start + end + + desc "server [-p 4567] [-e development]", "Starts the Middleman preview server" + method_option "environment", :aliases => "-e", :default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development', :desc => "The environment Middleman will run under" + method_option "port", :aliases => "-p", :default => "4567", :desc => "The port Middleman will listen on" + method_option "livereload-port", :default => "35729", :desc => "The port Livereload will listen on" + method_option "livereload", :default => false, :type => :boolean, :desc => "Whether to enable Livereload or not" + def server + ENV['RACK_ENV'] = options[:environment] + livereload_options = {:port => options["livereload-port"]} if options["livereload"] + Middleman::Guard.start({:port => options[:port]}, livereload_options) + end + + desc "build", "Builds the static site for deployment" + method_option :relative, :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls' + def build + ENV['MM_ENV'] = "build" + Middleman::Builder.start + end + + desc "migrate", "Migrates an older Middleman project to the 2.0 structure" + def migrate + `mv public source` + `cp -R views/* source/` + `rm -rf views` + end + + private + + def config_check + if !File.exists?("config.rb") + $stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?" + exit 1 + end + + if File.exists?("views") || File.exists?("public") + $stderr.puts "== Error: The views and public folders are have been combined. Create a new 'source' folder, add the contents of views and public to it and then remove the empty views and public folders." + exit 1 + end + end + + end +end \ No newline at end of file From 0e18f26b86ad7b1fcb495f9a574aebf18465073f Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Tue, 26 Jul 2011 21:06:24 -0700 Subject: [PATCH 4/9] add an mm binary to invoke the CLI class --- bin/mm | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 bin/mm diff --git a/bin/mm b/bin/mm new file mode 100755 index 00000000..216f8e32 --- /dev/null +++ b/bin/mm @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require 'middleman/cli' +Middleman::CLI.start From 935a0d6abed16c1596d970243c742f52594efd74 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Tue, 26 Jul 2011 21:06:38 -0700 Subject: [PATCH 5/9] mention the new mm command in the changelog --- CHANGELOG | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 532f64c6..59bebfe1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,4 +9,5 @@ - Support YAML front-matter - Added callback to run code after Compass is configured - Added support for a compass.config file which is passed directly to Compass -- Blog-aware Feature (and project template) \ No newline at end of file +- Blog-aware Feature (and project template) +- Thor-based, unified `mm` binary \ No newline at end of file From 9b00ec1a139e72b428ae0ec8e210141dcfc7b8d5 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Tue, 26 Jul 2011 21:06:57 -0700 Subject: [PATCH 6/9] remove mm-* binaries --- bin/mm-build | 7 ------- bin/mm-init | 27 --------------------------- bin/mm-migrate | 5 ----- bin/mm-server | 46 ---------------------------------------------- 4 files changed, 85 deletions(-) delete mode 100755 bin/mm-build delete mode 100755 bin/mm-init delete mode 100755 bin/mm-migrate delete mode 100755 bin/mm-server diff --git a/bin/mm-build b/bin/mm-build deleted file mode 100755 index 196f4c34..00000000 --- a/bin/mm-build +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env ruby - -ENV['MM_ENV'] = "build" - -# Require app -require File.join(File.dirname(__FILE__), "..", "lib", "middleman") -Middleman::Builder.start \ No newline at end of file diff --git a/bin/mm-init b/bin/mm-init deleted file mode 100755 index 3a6c112b..00000000 --- a/bin/mm-init +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env ruby -require File.join(File.dirname(File.dirname(__FILE__)), 'lib', 'middleman') -require "middleman/templates" - -module Middleman - class Generator < ::Thor::Group - include Thor::Actions - - argument :location, :type => :string, :desc => "New project location" - - available_templates = Middleman::Templates.registered_names.join(", ") - class_option :template, :aliases => "-T", :default => "default", :desc => "Optionally use a pre-defined project template: #{available_templates}" - - class_option :css_dir, :default => "stylesheets", :desc => 'The path to the css files' - class_option :js_dir, :default => "javascripts", :desc => 'The path to the javascript files' - class_option :images_dir, :default => "images", :desc => 'The path to the image files' - - def create_project - key = options[:template].to_sym - key = :default unless Middleman::Templates.registered_templates.has_key?(key) - - Middleman::Templates.registered_templates[key].start - end - end -end - -Middleman::Generator.start diff --git a/bin/mm-migrate b/bin/mm-migrate deleted file mode 100755 index 293a91cb..00000000 --- a/bin/mm-migrate +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env ruby - -`mv public source` -`cp -R views/* source/` -`rm -rf views` \ No newline at end of file diff --git a/bin/mm-server b/bin/mm-server deleted file mode 100755 index ceac3ce5..00000000 --- a/bin/mm-server +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env ruby - -require "rubygems" -require "thor" -require "thor/group" - -# Require Middleman -require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman') - -module Middleman - class GuardServer < ::Thor::Group - include Thor::Actions - - class_option :environment, :aliases => "-e", :default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development' - - class_option :port, :aliases => "-p", :default => "4567" - class_option :"livereload-port", :default => "35729" - class_option :"livereload", :default => false, :type => :boolean - - def start_guard - if !File.exists?("config.rb") - $stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?" - return - end - - # If the old directories exists, use it, but issue warning - if File.exists?("views") || File.exists?("public") - $stderr.puts "== Error: The views and public folders are have been combined. Create a new 'source' folder, add the contents of views and public to it and then remove the empty views and public folders." - return - end - - ENV['RACK_ENV'] = options[:environment] - - livereload_options = { - :port => options[:"livereload-port"] - } - livereload_options = nil unless options[:"livereload"] - - ::Middleman::Guard.start({ - :port => options[:port], - }, livereload_options) - end - end -end - -Middleman::GuardServer.start \ No newline at end of file From 40b3444e717458868a9e5cd486f274709dc87729 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Tue, 26 Jul 2011 21:25:48 -0700 Subject: [PATCH 7/9] standardize on string-named options --- lib/middleman/cli.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/middleman/cli.rb b/lib/middleman/cli.rb index 443b3cbb..9ea5cfe8 100644 --- a/lib/middleman/cli.rb +++ b/lib/middleman/cli.rb @@ -14,10 +14,10 @@ module Middleman desc "init NAME", "Create new Middleman project directory NAME" available_templates = Middleman::Templates.registered_names.join(", ") - method_option :template, :aliases => "-T", :default => "default", :desc => "Optionally use a pre-defined 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 "template", :aliases => "-T", :default => "default", :desc => "Optionally use a pre-defined 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' def init(name) key = options[:template].to_sym key = :default unless Middleman::Templates.registered_templates.has_key?(key) @@ -37,7 +37,7 @@ module Middleman end desc "build", "Builds the static site for deployment" - method_option :relative, :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls' + method_option "relative", :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls' def build ENV['MM_ENV'] = "build" Middleman::Builder.start From 5b8da9d8b809fbae93197f65b92e799209c74e69 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Tue, 26 Jul 2011 21:26:10 -0700 Subject: [PATCH 8/9] unknown options should raise an error --- lib/middleman/cli.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/middleman/cli.rb b/lib/middleman/cli.rb index 9ea5cfe8..79c7d15a 100644 --- a/lib/middleman/cli.rb +++ b/lib/middleman/cli.rb @@ -5,6 +5,7 @@ require "middleman/templates" module Middleman class CLI < Thor include Thor::Actions + check_unknown_options! default_task :server def initialize(*) From 4e0c7a01424f6f8903fae5450c4124c22dc8579d Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Tue, 26 Jul 2011 21:26:25 -0700 Subject: [PATCH 9/9] enable --help option for all subcommands --- lib/middleman/cli.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/middleman/cli.rb b/lib/middleman/cli.rb index 79c7d15a..7a7083f9 100644 --- a/lib/middleman/cli.rb +++ b/lib/middleman/cli.rb @@ -8,9 +8,11 @@ module Middleman check_unknown_options! default_task :server + class_option "help", :type => :boolean, :default => false, :aliases => "-h" def initialize(*) - config_check super + config_check + help_check end desc "init NAME", "Create new Middleman project directory NAME" @@ -65,5 +67,10 @@ module Middleman end end + def help_check + help self.class.send(:retrieve_task_name, ARGV.dup) + exit 0 + end + end end \ No newline at end of file