This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
forked from html-next/vertical-collection
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
155 lines (126 loc) · 3.91 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* eslint-env node */
'use strict';
var StripClassCallCheck = require('babel6-plugin-strip-class-callcheck');
var FilterImports = require('babel-plugin-filter-imports');
var RemoveImports = require('./lib/babel-plugin-remove-imports');
var Funnel = require('broccoli-funnel');
var Rollup = require('broccoli-rollup');
var merge = require('broccoli-merge-trees');
function isProductionEnv() {
var isProd = /production/.test(process.env.EMBER_ENV);
var isTest = process.env.EMBER_CLI_TEST_COMMAND;
return isProd && !isTest;
}
module.exports = {
name: 'vertical-collection',
init: function() {
this._super.init && this._super.init.apply(this, arguments);
this.options = this.options || {};
},
treeForAddon: function(tree) {
let babel = this.addons.find(addon => addon.name === 'ember-cli-babel');
let withPrivate = new Funnel(tree, { include: ['-private/**'] });
let withoutPrivate = new Funnel(tree, {
exclude: [
'**/**.hbs',
'-private',
isProductionEnv() ? '-debug' : false
].filter(Boolean),
destDir: 'vertical-collection'
});
var privateTree = babel.transpileTree(withPrivate, {
babel: this.buildBabelOptions(),
'ember-cli-babel': {
compileModules: false
}
});
var templateTree = new Funnel(tree, {
include: ['**/**.hbs']
});
// use the default options
var addonTemplateTree = this._super(templateTree);
var publicTree = babel.transpileTree(withoutPrivate);
privateTree = new Rollup(privateTree, {
rollup: {
entry: '-private/index.js',
targets: [
{ dest: 'vertical-collection/-private.js', format: 'amd', moduleId: 'vertical-collection/-private' }
],
external: [
'ember',
'vertical-collection/-debug/helpers'
],
// cache: true|false Defaults to true
}
});
// the output of treeForAddon is required to be modules/<your files>
publicTree = new Funnel(publicTree, { destDir: 'modules' });
privateTree = new Funnel(privateTree, { destDir: 'modules' });
return merge([
addonTemplateTree,
publicTree,
privateTree
]);
},
_hasSetupBabelOptions: false,
buildBabelOptions() {
let opts = {
loose: true,
plugins: [],
postTransformPlugins: [StripClassCallCheck],
exclude: [
'transform-es2015-block-scoping',
'transform-es2015-typeof-symbol'
]
};
if (isProductionEnv()) {
var strippedImports = {
'vertical-collection/-debug/helpers': [
'assert',
'warn',
'debug',
'debugOnError',
'deprecate',
'stripInProduction'
]
};
opts.plugins.push(
[FilterImports, strippedImports],
[RemoveImports, 'vertical-collection/-debug/helpers']
);
}
opts.plugins.push(
['transform-es2015-block-scoping', { 'throwIfClosureRequired': true }]
);
return opts;
},
_setupBabelOptions: function() {
if (this._hasSetupBabelOptions) {
return;
}
this.options.babel = this.buildBabelOptions();
this._hasSetupBabelOptions = true;
},
included: function(app) {
this._super.included.apply(this, arguments);
while (typeof app.import !== 'function' && app.app) {
app = app.app;
}
if (typeof app.import !== 'function') {
throw new Error('vertical-collection is being used within another addon or engine ' +
'and is having trouble registering itself to the parent application.');
}
this._env = app.env;
this._setupBabelOptions(app.env);
if (!/production/.test(app.env) && !/test/.test(app.env)) {
app.import('vendor/debug.css');
}
},
treeForApp: function() {
var tree = this._super.treeForApp.apply(this, arguments);
if (isProductionEnv()) {
tree = new Funnel(tree, { exclude: [ /initializers/ ] });
}
return tree;
}
};