Move some extension setup to ready event

This commit is contained in:
Thomas Reynolds 2015-08-20 17:45:18 -07:00
parent 3485f49f74
commit 9ed0796b4a
9 changed files with 17 additions and 8 deletions

View file

@ -13,12 +13,17 @@ module Middleman::Cli
def console def console
require 'json' require 'json'
require 'middleman-core' require 'middleman-core'
require 'middleman-core/logger'
opts = { opts = {
environment: options['environment'] environment: options['environment']
} }
# Don't output info messages
::Middleman::Logger.singleton(2, false)
app = ::Middleman::Application.new do app = ::Middleman::Application.new do
config[:exit_before_ready] = true
config[:environment] = opts[:environment].to_sym if opts[:environment] config[:environment] = opts[:environment].to_sym if opts[:environment]
end end

View file

@ -92,6 +92,10 @@ module Middleman
# @return [String] # @return [String]
define_setting :source, 'source', 'Name of the source directory' define_setting :source, 'source', 'Name of the source directory'
# If we should exit before ready event.
# @return [Boolean]
define_setting :exit_before_ready, false, 'If we should exit before ready event.'
# Middleman mode. Defaults to :server, set to :build by the build process # Middleman mode. Defaults to :server, set to :build by the build process
# @return [String] # @return [String]
define_setting :mode, ((ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :server), 'Middleman mode. Defaults to :server' define_setting :mode, ((ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :server), 'Middleman mode. Defaults to :server'
@ -274,7 +278,7 @@ module Middleman
execute_callbacks(:after_configuration) execute_callbacks(:after_configuration)
# Everything is stable # Everything is stable
execute_callbacks(:ready) execute_callbacks(:ready) unless config[:exit_before_ready]
end end
# Eval config # Eval config

View file

@ -11,7 +11,7 @@ module Middleman::CoreExtensions
app.config.define_setting :show_exceptions, ENV['TEST'] ? false : true, 'Whether to catch and display exceptions' app.config.define_setting :show_exceptions, ENV['TEST'] ? false : true, 'Whether to catch and display exceptions'
end end
def after_configuration def ready
app.use ::Rack::ShowExceptions if !app.build? && app.config[:show_exceptions] app.use ::Rack::ShowExceptions if !app.build? && app.config[:show_exceptions]
end end
end end

View file

@ -7,7 +7,7 @@ class Middleman::Extensions::AssetHost < ::Middleman::Extension
option :sources, %w(.htm .html .php .css .js), 'List of extensions that are searched for bustable assets.' option :sources, %w(.htm .html .php .css .js), 'List of extensions that are searched for bustable assets.'
option :ignore, [], 'Regexes of filenames to skip adding query strings to' option :ignore, [], 'Regexes of filenames to skip adding query strings to'
def after_configuration def ready
app.use ::Middleman::Middleware::InlineURLRewriter, app.use ::Middleman::Middleware::InlineURLRewriter,
id: :asset_host, id: :asset_host,
url_extensions: options.exts, url_extensions: options.exts,

View file

@ -16,7 +16,7 @@ class Middleman::Extensions::ExternalPipeline < ::Middleman::Extension
latency: options[:latency] latency: options[:latency]
end end
def after_configuration def ready
if app.build? if app.build?
logger.info "== Executing: `#{options[:command]}`" logger.info "== Executing: `#{options[:command]}`"
watch_command! watch_command!

View file

@ -9,7 +9,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
SassCompressor SassCompressor
}, 'Set the CSS compressor to use.' }, 'Set the CSS compressor to use.'
def after_configuration def ready
# Setup Rack middleware to minify CSS # Setup Rack middleware to minify CSS
app.use Rack, compressor: options[:compressor], app.use Rack, compressor: options[:compressor],
ignore: Array(options[:ignore]) + [/\.min\./], ignore: Array(options[:ignore]) + [/\.min\./],

View file

@ -9,7 +9,7 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
::Uglifier.new ::Uglifier.new
}, 'Set the JS compressor to use.' }, 'Set the JS compressor to use.'
def after_configuration def ready
# Setup Rack middleware to minify CSS # Setup Rack middleware to minify CSS
app.use Rack, compressor: options[:compressor], app.use Rack, compressor: options[:compressor],
ignore: Array(options[:ignore]) + [/\.min\./], ignore: Array(options[:ignore]) + [/\.min\./],

View file

@ -12,7 +12,7 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
require 'middleman-core/middleware/inline_url_rewriter' require 'middleman-core/middleware/inline_url_rewriter'
end end
def after_configuration def ready
app.use ::Middleman::Middleware::InlineURLRewriter, app.use ::Middleman::Middleware::InlineURLRewriter,
id: :asset_hash, id: :asset_hash,
url_extensions: options.exts, url_extensions: options.exts,