commit
4569d597f5
8 changed files with 82 additions and 90 deletions
|
@ -10,3 +10,4 @@
|
||||||
- Added callback to run code after Compass is configured
|
- Added callback to run code after Compass is configured
|
||||||
- Added support for a compass.config file which is passed directly to Compass
|
- Added support for a compass.config file which is passed directly to Compass
|
||||||
- Blog-aware Feature (and project template)
|
- Blog-aware Feature (and project template)
|
||||||
|
- Thor-based, unified `mm` binary
|
3
bin/mm
Executable file
3
bin/mm
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
require 'middleman/cli'
|
||||||
|
Middleman::CLI.start
|
|
@ -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
|
|
27
bin/mm-init
27
bin/mm-init
|
@ -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
|
|
|
@ -1,5 +0,0 @@
|
||||||
#!/usr/bin/env ruby
|
|
||||||
|
|
||||||
`mv public source`
|
|
||||||
`cp -R views/* source/`
|
|
||||||
`rm -rf views`
|
|
|
@ -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
|
|
|
@ -51,13 +51,10 @@
|
||||||
# [Email the users group]: http://groups.google.com/group/middleman-users
|
# [Email the users group]: http://groups.google.com/group/middleman-users
|
||||||
# [Submit bug reports]: https://github.com/tdreyno/middleman/issues
|
# [Submit bug reports]: https://github.com/tdreyno/middleman/issues
|
||||||
|
|
||||||
# Setup out load paths
|
# Setup our load paths
|
||||||
libdir = File.dirname(__FILE__)
|
libdir = File.dirname(__FILE__)
|
||||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
$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.
|
# We're riding on Sinatra, so let's include it.
|
||||||
require "sinatra/base"
|
require "sinatra/base"
|
||||||
|
|
||||||
|
|
76
lib/middleman/cli.rb
Normal file
76
lib/middleman/cli.rb
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
require 'thor'
|
||||||
|
require 'middleman'
|
||||||
|
require "middleman/templates"
|
||||||
|
|
||||||
|
module Middleman
|
||||||
|
class CLI < Thor
|
||||||
|
include Thor::Actions
|
||||||
|
check_unknown_options!
|
||||||
|
default_task :server
|
||||||
|
|
||||||
|
class_option "help", :type => :boolean, :default => false, :aliases => "-h"
|
||||||
|
def initialize(*)
|
||||||
|
super
|
||||||
|
config_check
|
||||||
|
help_check
|
||||||
|
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
|
||||||
|
|
||||||
|
def help_check
|
||||||
|
help self.class.send(:retrieve_task_name, ARGV.dup)
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue