-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
91 lines (73 loc) · 2.42 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
/* jshint node: true */
'use strict';
const calculateCacheKeyForTree = require('calculate-cache-key-for-tree');
const Funnel = require('broccoli-funnel');
const chalk = require('chalk');
// We import these to merge the instrumentation options into the base classes
// we do this instead of overriding the core commands because other high profile
// addons such as ember-cordova, ember-cli-nwjs, and ember-electron have had to override
const serveCommand = require('ember-cli/lib/commands/serve');
const buildCommand = require('ember-cli/lib/commands/build');
const testCommand = require('ember-cli/lib/commands/test');
function hasOption(options, name) {
for (let i = 0, l = options.length; i < l; i++) {
if (options[i].name === name) {
return true;
}
}
return false;
}
function patchCommand(command, newOption) {
const options = command.prototype.availableOptions;
if (!hasOption(options, newOption.name)) {
options.push(newOption);
}
}
function assert(msg, test) {
if (!test) {
throw new Error(msg);
}
}
module.exports = {
name: 'ember-heimdall',
_isInstrumented: null,
isInstrumented: function() {
if (this._isInstrumented !== null) {
return this._isInstrumented;
}
let INSTRUMENT_HEIMDALL = process.argv.indexOf('--instrument') !== -1;
if (INSTRUMENT_HEIMDALL) {
this.ui.writeLine(chalk.yellow(
'Heimdall.js will be included in your build output and instrumentation will not be stripped.'
));
}
this._isInstrumented = INSTRUMENT_HEIMDALL;
return INSTRUMENT_HEIMDALL;
},
includedCommands: function() {
let instrumentOption = { name: 'instrument', type: Boolean, default: false };
patchCommand(serveCommand, instrumentOption);
patchCommand(buildCommand, instrumentOption);
patchCommand(testCommand, instrumentOption);
},
included: function() {
if (this.isInstrumented()) {
assert(`Cannot use ember-heimdall with this version of ember-cli`, typeof this.import === 'function');
this.import('vendor/heimdalljs/heimdalljs.iife.js', { prepend: true });
}
},
cacheKeyForTree(treeType) {
return calculateCacheKeyForTree(treeType, this);
},
treeForVendor: function() {
if (this.isInstrumented()) {
const heimdallTree = new Funnel('node_modules/heimdalljs/dist', {
destDir: 'heimdalljs'
});
return heimdallTree;
}
},
isDevelopingAddon: function() {
return false;
}
};