forked from html-next/smoke-and-mirrors
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
99 lines (77 loc) · 2.71 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
// jscs: disable
/* jshint node: true */
'use strict';
var chalk = require('chalk');
var stripClassCallCheck = require('babel5-plugin-strip-class-callcheck');
var filterImports = require('babel-plugin-filter-imports');
var Funnel = require('broccoli-funnel');
module.exports = {
name: 'smoke-and-mirrors',
init: function() {
this._super.init && this._super.init.apply(this, arguments);
this.options = this.options || {};
},
_hasSetupBabelOptions: false,
_setupBabelOptions: function(env) {
if (this._hasSetupBabelOptions) {
return;
}
var babelOptions = this.options.babel = this.options.babel || {};
babelOptions.plugins = babelOptions.plugins || [];
babelOptions.plugins.push({ transformer: stripClassCallCheck, position: 'after' });
if (/production/.test(env) || /test/.test(env)) {
babelOptions.plugins.push(
filterImports({
'smoke-and-mirrors/-debug/helpers': [
'assert',
'warn',
'debug',
'instrument',
'deprecate',
'stripInProduction'
]})
);
}
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('smoke-and-mirrors 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)) {
this.ui.write(
chalk.grey("\n===================================================================\n") +
chalk.cyan("\tSmoke-and-mirrors\n") +
chalk.grey("\t:: Including CSS for Visual Debugger\n") +
chalk.grey("\t:: (included in non production builds only)\n") +
chalk.grey("\t:: To use, set ") + chalk.yellow("{{vertical-collection debug=true}}") +
chalk.grey("\n===================================================================\n")
);
app.import('./vendor/debug.css');
}
},
treeForAddon: function() {
var tree = this._super.treeForAddon.apply(this, arguments);
if (/production/.test(this._env) || /test/.test(this._env)) {
tree = new Funnel(tree, { exclude: [ /-debug/ ] });
}
return tree;
},
treeForApp: function() {
var tree = this._super.treeForApp.apply(this, arguments);
if (/production/.test(this._env) || /test/.test(this._env)) {
tree = new Funnel(tree, { exclude: [ /initializers/ ] });
}
return tree;
},
isDevelopingAddon: function() {
return false;
}
};