-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
65 lines (53 loc) · 1.46 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
'use strict';
const VersionChecker = require('ember-cli-version-checker');
const MINIMUM_NAMED_BLOCKS_VERSION = '3.25.0-beta.0';
const FALSE = ['false', 'disable', 'no', 'off', '0'];
module.exports = {
name: require('./package').name,
_usePolyfill: flag(process.env.USE_NAMED_BLOCKS_POLYFILL),
usePolyfill() {
if (this._usePolyfill === undefined) {
let version = new VersionChecker(this.project).for(`ember-source`);
this._usePolyfill = version.lt(MINIMUM_NAMED_BLOCKS_VERSION);
}
return this._usePolyfill;
},
setupPreprocessorRegistry(_type, registry) {
if (this.usePolyfill()) {
let plugin = this._buildTemplatePlugin();
registry.add('htmlbars-ast-plugin', plugin);
}
},
treeForAddon() {
if (this.usePolyfill()) {
return this._super.treeForAddon.apply(this, arguments);
}
},
treeForApp() {
if (this.usePolyfill()) {
return this._super.treeForApp.apply(this, arguments);
}
},
_buildTemplatePlugin() {
let plugin = require('./lib/named-blocks-polyfill-plugin.js');
return {
name: 'named-blocks-polyfill',
plugin,
baseDir() { return __dirname; },
parallelBabel: {
requireFile: __filename,
buildUsing: '_buildTemplatePlugin',
params: {},
}
};
},
};
function flag(flag) {
if (flag === undefined) {
return undefined;
} else if (FALSE.includes(flag.toLowerCase())) {
return false;
} else {
return true;
}
}