Skip to content

Commit

Permalink
Configuring the environment based on the flags
Browse files Browse the repository at this point in the history
  • Loading branch information
thoov committed Feb 14, 2018
1 parent 02f3782 commit ff271df
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
let app = new EmberAddon(defaults, {
'ember-2-legacy': {
'ember-binding': false
},
// required to work around https://github.com/ember-cli/ember-cli/issues/7505
trees: {
vendor: null,
Expand Down
35 changes: 33 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@ const writeFile = require('broccoli-file-creator');
const VersionChecker = require('ember-cli-version-checker');

const minEmberVersion = '3.0.0-beta.3';
const flagToEnvironment = {
'ember-k': '_ENABLE_EMBER_K_SUPPORT',
'safe-string': '_ENABLE_SAFE_STRING_SUPPORT',
'enumerable-contains': '_ENABLE_ENUMERABLE_CONTAINS_SUPPORT',
'underscore-actions': '_ENABLE_UNDERSCORE_ACTIONS_SUPPORT',
'reversed-observer': '_ENABLE_REVERSED_OBSERVER_SUPPORT',
'initializer-arity': '_ENABLE_INITIALIZER_ARGUMENTS_SUPPORT',
'router-resource': '_ENABLE_ROUTER_RESOURCE',
'current-when': '_ENABLE_CURRENT_WHEN_SUPPORT',
'controller-wrapped': '_ENABLE_CONTROLLER_WRAPPED_SUPPORT',
'application-registry': '_ENABLE_DEPRECATED_REGISTRY_SUPPORT',
'immediate-observer': '_ENABLE_IMMEDIATE_OBSERVER_SUPPORT',
'string-fmt': '_ENABLE_STRING_FMT_SUPPORT',
'ember-freezable': '_ENABLE_FREEZABLE_SUPPORT',
'component-defaultlayout': '_ENABLE_COMPONENT_DEFAULTLAYOUT_SUPPORT',
'ember-binding': '_ENABLE_BINDING_SUPPORT',
'input-transform': '_ENABLE_INPUT_TRANSFORM_SUPPORT',
'deprecation-options': '_ENABLE_DEPRECATION_OPTIONS_SUPPORT',
'orphaned-outlets': '_ENABLE_ORPHANED_OUTLETS_SUPPORT',
'warn-options': '_ENABLE_WARN_OPTIONS_SUPPORT',
'resolver-function': '_ENABLE_RESOLVER_FUNCTION_SUPPORT',
'init-attrs': '_ENABLE_DID_INIT_ATTRS_SUPPORT',
'render-support': '_ENABLE_RENDER_SUPPORT',
'property-required': '_ENABLE_PROPERTY_REQUIRED_SUPPORT'
};

module.exports = {
name: 'ember-2-legacy',
Expand All @@ -31,12 +56,18 @@ module.exports = {
included() {
this._super.included.apply(this, arguments);

// This configures EmberENV in a "hacky" way as the 'config' hook is called
// before the options from EmberApp are provided. Do not copy these lines :-)
Object.keys(flagToEnvironment).forEach(flag => {
this.project.configCache.get(this.app.env).EmberENV[flagToEnvironment[flag]] = !!this.flagValue(flag);
});

// Always register the version
this.import('vendor/ember-2-legacy/register-version.js');

// do nothing if running with Ember 2.x
if (this.emberVersion.lt(minEmberVersion)) {
debug(`Not including polyfills as we are running on ${this.emberVersion()} and require a min of ${minEmberVersion}.`);
debug(`Not including polyfills as we are running on ${this.emberVersion()} and require a min of ${minEmberVersion}.`);
return;
}

Expand Down Expand Up @@ -87,7 +118,7 @@ module.exports = {

flagValue(flag) {
let options = this.app.options[this.name] || {};
return options[flag];
return options[flag] === false ? false : true;
},

importUnlessFlagged(path, flags) {
Expand Down

0 comments on commit ff271df

Please sign in to comment.