Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environments #1293

Merged
merged 1 commit into from Jun 13, 2014
Merged

Environments #1293

merged 1 commit into from Jun 13, 2014

Conversation

@tdreyno
Copy link
Member

tdreyno commented Jun 6, 2014

This PR creates the concept of an Application mode which can be either :server or :build. This frees environment to be able to represent a targeted set of functionality.

The default environment is :development. This can be overridden on the CLI with:

middleman build -e production
middleman server -e production

config.rb is loaded as usual and applies to all environments. As before, per-environment config can be set in config.rb using:

configure :production do
  activate :minify_css
end

However, now Middleman optionally loads a corresponding config file at: environments/production.rb.

Also included in this PR is a slight tweak to auto-activating extensions to let them only activate in specific modes. For example, we don't replace exceptions with an HTML error page in build.

@sandstrom

This comment has been minimized.

Copy link
Contributor

sandstrom commented Jun 7, 2014

Wonderful! ⛵️

@gferraz

This comment has been minimized.

Copy link

gferraz commented Jun 9, 2014

Beautiful! Thanks.

@karlfreeman

This comment has been minimized.

Copy link
Member

karlfreeman commented Jun 9, 2014

👍

The only thing to add would be ensuring this PR makes its way to to the guides, documentation and extensions. As well as to the wider extensions. How are you currently tracking breaking/big changes gearing up for v4?

@tdreyno

This comment has been minimized.

Copy link
Member Author

tdreyno commented Jun 9, 2014

@karlfreeman CHANGELOG. Will probably have a fairly long beta period for v4, during which those docs can be written.

Rakefile Outdated
@@ -46,7 +46,7 @@ task :test do
GEM_PATHS.each do |g|
Dir.chdir("#{File.join(ROOT, g)}") { sh "#{Gem.ruby} -S rake test" }
end
Rake::Task['rubocop'].invoke
# Rake::Task['rubocop'].invoke

This comment has been minimized.

Copy link
@bhollis

bhollis Jun 10, 2014

Member

Did you mean to leave this out?

This comment has been minimized.

Copy link
@tdreyno

tdreyno Jun 11, 2014

Author Member

Nope :-p

@@ -58,18 +62,26 @@ def build
@debugging = Middleman::Cli::Base.respond_to?(:debugging) && Middleman::Cli::Base.debugging
self.had_errors = false

self.class.shared_instance(options['verbose'], options['instrument'])
env = options['environment'].to_sym
verbose = options['verbose'] ? 0 : 1

This comment has been minimized.

Copy link
@bhollis

bhollis Jun 10, 2014

Member

Shouldn't verbose be a boolean?

@@ -71,7 +67,10 @@ def register(name, extension_class=nil, options={}, &block)
raise 'You must provide a Middleman::Extension or a block that returns a Middleman::Extension'
end

@auto_activate[options[:auto_activate]] << name if options[:auto_activate]
if options[:auto_activate]
descriptor = AutoActivation.new(name, options[:modes] || :all)

This comment has been minimized.

Copy link
@bhollis

bhollis Jun 10, 2014

Member

What's the idea behind :all as an activation mode and of modes being a list? When would you want to auton activate an extension multiple times?

This comment has been minimized.

Copy link
@tdreyno

tdreyno Jun 11, 2014

Author Member

An extension might run in all modes: test, build, server, whatever else we add. Like Compass.

Or if might run in a subset, server-only, like LiveReload.

@bhollis

This comment has been minimized.

Copy link
Member

bhollis commented Jun 10, 2014

Cool, I like the change. People have been wanting multiple environments for a while, though I'm not exactly sure how one would best use them.

@lolmaus

This comment has been minimized.

Copy link
Contributor

lolmaus commented Jun 10, 2014

My use for an extra environment is to have Middleman display CSS outlines and JS debug messages in a "debug" environment.

@sandstrom

This comment has been minimized.

Copy link
Contributor

sandstrom commented Jun 10, 2014

@bhollis here are a few use-cases:

  • build + development => when developing mobile apps [new]
  • build + staging => when deploying the website to a staging server [new]
  • server + test => if running javascript tests in a browser, e.g. QUnit or Mocha [new]
  • build + test => when running headless js-tests, e.g. on PhantomJS [new]
  • server + development => the classic dev environment [exist today]
  • build + production => when deploying a website to production [exist today]
@bhollis

This comment has been minimized.

Copy link
Member

bhollis commented Jun 11, 2014

@lolmaus that makes a lot of sense, though I would have done it just with a "debug" setting:

set :my_debug, true

@sandstrom how would those environments differ - for example, what does "build + development for mobile apps" actually mean? What changes in test environment?

@sandstrom

This comment has been minimized.

Copy link
Contributor

sandstrom commented Jun 11, 2014

@bhollis The usefulness of environment flags extends beyond the framework.

It typically determines various settings, hostnames, error handling, logging, obfuscation, performance tuning, etc. We make adjustment to all of these depending on the environment.

Being able to use the middleman environment instead of a second, custom, environment variable such as my_env in parallell is neat.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Jun 11, 2014

Coverage Status

Coverage decreased (-0.24%) when pulling a21dca0 on environments into d035b44 on master.

@tdreyno

This comment has been minimized.

Copy link
Member Author

tdreyno commented Jun 13, 2014

I use this daily, so... good chance it's going to get merged :)

Any opinions on the code or missing edge cases?

@bhollis

This comment has been minimized.

Copy link
Member

bhollis commented Jun 13, 2014

@sandstrom I was just trying to get people to explain why they're doing all this stuff, so that I can understand why we're adding a feature that we'll have to support going forward. You just explained that you did that stuff, but not why you are doing it, which is what's interesting to me.

@tdreyno explained his usecase to me though, and I'm OK to accept it, and as I said before, it's a good refactoring of the code anyway.

tdreyno added a commit that referenced this pull request Jun 13, 2014
Environments
@tdreyno tdreyno merged commit c59cefd into master Jun 13, 2014
1 check passed
1 check passed
continuous-integration/travis-ci The Travis CI build passed
Details
@tdreyno tdreyno deleted the environments branch Jun 13, 2014
@timurvafin timurvafin mentioned this pull request Aug 4, 2014
@vasco

This comment has been minimized.

Copy link

vasco commented Jan 21, 2015

I'm not able to get this to work (tried with 3.3.7 with jruby).

Running: bundle exec middleman server -e production

The #environment method, correctly returns :production, however:

  • environments/production.rb isn't loaded, and
  • the following code raises NoMethodError: undefined method 'production_config' for Middleman::Application::MiddlemanApplication1:Class
configure :production do
 # ...
end

Am I doing something wrong?

Confirmed that with gem "middleman", "~> 4.0.0.alpha.6" worked.

@sandstrom

This comment has been minimized.

Copy link
Contributor

sandstrom commented Jan 21, 2015

@vasco Version 3.3.7 of Middleman? I don't think it's in the v3 branch, only v4. If you haven't, try with master and see if it works.

@vasco

This comment has been minimized.

Copy link

vasco commented Jan 22, 2015

@sandstrom This PR didn't land in middleman's 3.3.7 version. When I first wrote my comment, I was wrongly getting v4, I fixed that and I can now confirm that, with middleman version 4.0.0.alpha.6, everything works.

I'm doing: gem "middleman", "~> 4.0.0.alpha.6".

@tdreyno

This comment has been minimized.

Copy link
Member Author

tdreyno commented Jan 22, 2015

Yup, this is in v4. That said... "alpha" release so be careful.

@equinusocio

This comment has been minimized.

Copy link

equinusocio commented Jul 22, 2016

How i can set multiple environments through rb files? What i have to put inside this, there is an example?

environments/development.rb
environments/build.rb

There is some alpha/beta doc? Thanks :)

@sandstrom

This comment has been minimized.

Copy link
Contributor

sandstrom commented Jul 22, 2016

@equinusocio here are the docs: https://middlemanapp.com/advanced/configuration/#environment-specific-settings

(this question is better suited for Stackoverflow, btw)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

9 participants
You can’t perform that action at this time.