forked from ember-m3/ember-m3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
89 lines (67 loc) · 2.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* eslint-env node */
'use strict';
const Funnel = require('broccoli-funnel');
const getDebugMacros = require('./src/debug-macros').debugMacros;
const VersionChecker = require('ember-cli-version-checker');
const CHECKED_PROJECT = new WeakSet();
function assertValidEmberData(project) {
if (CHECKED_PROJECT.has(project)) {
return;
}
let checker = VersionChecker.forProject(project);
// full ember-data brings store and model starting in 3.16
// so we do not need to check for full ember-data, just the specific packages
// we care about since our current support is 3.16+
let check = checker.check({
'@ember-data/store': '>= 3.16.0',
'@ember-data/model': '>= 3.16.0',
'ember-inflector': '>= 3.0.0',
});
check.assert(
'[ember-m3] requires either "ember-data" be installed (which brings the below packages) or at least the following versions of them.'
);
CHECKED_PROJECT.add(project);
}
module.exports = {
name: 'ember-m3',
included() {
this._super.included.call(this, ...arguments);
assertValidEmberData(this.project);
this.configureBabelOptions();
},
treeForAddon(tree) {
const isProd = process.env.EMBER_ENV === 'production';
if (isProd) {
tree = new Funnel(tree, {
exclude: ['-infra', 'adapters'],
});
}
return this._super.treeForAddon.call(this, tree);
},
treeForApp(tree) {
const isProd = process.env.EMBER_ENV === 'production';
if (isProd) {
tree = new Funnel(tree, {
exclude: ['data-adapter.js'],
});
}
return this._super.treeForApp.call(this, tree);
},
configureBabelOptions() {
let app = this._findHost();
this.options = this.options || {};
this.options.babel = this.options.babel || {};
let plugins = this.options.babel.plugins ? this.options.babel.plugins.slice() : [];
let newPlugins = getDebugMacros(app);
for (let newPlugin of newPlugins) {
let wasPreviouslyAdded = plugins.find(
(existingPlugin) => Array.isArray(existingPlugin) && existingPlugin[2] === newPlugin[2]
);
if (!wasPreviouslyAdded) {
plugins.push(newPlugin);
}
}
this.options.babel.plugins = plugins;
this.options.babel.loose = true;
},
};