Skip to content

Commit

Permalink
unify prod/dev add-on build
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Mar 7, 2016
1 parent e89d5d7 commit 3364685
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 52 deletions.
32 changes: 16 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
var path = require('path');
var SilentError = require('silent-error');

function add(options, name, array) {
var option = options[name] = options[name] || [];
option.push.apply(option, array);
}

module.exports = {
name: 'ember-data',

Expand All @@ -22,7 +27,9 @@ module.exports = {

init: function() {
var bowerDeps = this.project.bowerDependencies();

var VersionChecker = require('ember-cli-version-checker');
var options = this.options = this.options || {};

var checker = new VersionChecker(this);
// prevent errors when ember-cli-shims is no longer required
Expand Down Expand Up @@ -84,28 +91,21 @@ module.exports = {

var version = require('./lib/version');
var merge = require('broccoli-merge-trees');
var addonTree = merge([version(), dir]);

if (process.env.EMBER_ENV === 'production') {
var strippedBuild = require('./lib/stripped-build');

// blacklist es6.modules so the modules are not compiled but simply the
// debug statements / features are stripped; this is taken from
// ember-cli-babel:
// https://github.com/babel/ember-cli-babel/blob/master/index.js#L71
var strippedAddon = strippedBuild('ember-data', addonTree, {
blacklist: ['es6.modules', 'useStrict']
});

return this._super.treeForAddon.call(this, strippedAddon);
}

return this._super.treeForAddon.call(this, addonTree);
return this._super.treeForAddon.call(this, merge([
version(),
dir
]));
},

included: function(app) {
this._super.included.apply(this, arguments);

if (process.env.EMBER_ENV === 'production') {
add(this.options.babel, 'blacklist', ['es6.modules', 'useStrict']);
add(this.options.babel, 'plugins', require('./lib/stripped-build-plugins')());
}

if (this._forceBowerUsage) {
this.app.import({
development: app.bowerDirectory + '/ember-data/ember-data.js',
Expand Down
39 changes: 39 additions & 0 deletions lib/stripped-build-plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var fs = require('fs');
var path = require('path');
var filterImports = require('babel-plugin-filter-imports');
var featureFlags = require('babel-plugin-feature-flags');

module.exports = function() {
var featuresJsonPath = __dirname + '/../config/features.json';
var featuresJson = fs.readFileSync(featuresJsonPath, { encoding: 'utf8' });
var features = JSON.parse(featuresJson);

// TODO explicitly set all features which are not enabled to `false`, so
// they are stripped --> make this configurable or pass features
//
// for (var feature in features) {
// if (features[feature] !== true) {
// features[feature] = false;
// }
// }

return [
featureFlags({
import: { module: 'ember-data/-private/features' },
features: features
}),

filterImports({
'ember-data/-private/debug': [
'assert',
'assertPolymorphicType',
'debug',
'deprecate',
'info',
'runInDebug',
'warn',
'debugSeal'
]
})
];
};
36 changes: 2 additions & 34 deletions lib/stripped-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,11 @@ var path = require('path');
var filterImports = require('babel-plugin-filter-imports');
var featureFlags = require('babel-plugin-feature-flags');
var babelBuild = require('./babel-build');
var strippedBuildPlugins = require('./stripped-build-plugins');

module.exports = function(packageName, tree, _options) {
var featuresJsonPath = path.join(__dirname, '../config/features.json');
var featuresJson = fs.readFileSync(featuresJsonPath, { encoding: 'utf8' });
var features = JSON.parse(featuresJson);

// TODO explicitly set all features which are not enabled to `false`, so
// they are stripped --> make this configurable or pass features
//
// for (var feature in features) {
// if (features[feature] !== true) {
// features[feature] = false;
// }
// }

var plugins = [
featureFlags({
import: { module: 'ember-data/-private/features' },
features: features
}),

filterImports({
'ember-data/-private/debug': [
'assert',
'assertPolymorphicType',
'debug',
'deprecate',
'info',
'runInDebug',
'warn',
'debugSeal'
]
})
];

var options = _options || {};
options.plugins = plugins;
options.plugins = strippedBuildPlugins();

return babelBuild(packageName, tree, options);
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
"broccoli-yuidoc": "^2.1.0",
"ember-ajax": "0.7.1",
"ember-cli": "2.3.0",
"ember-cli-app-version": "0.5.0",
"ember-cli-app-version": "^1.0.0",
"ember-cli-blueprint-test-helpers": "^0.9.0",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-htmlbars": "0.7.9",
"ember-cli-htmlbars": "^1.0.3",
"ember-cli-htmlbars-inline-precompile": "^0.2.0",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-internal-test-helpers": "^0.8.1",
Expand Down

0 comments on commit 3364685

Please sign in to comment.