This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
72 lines (54 loc) · 1.79 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
/* eslint-env node */
'use strict';
const DEFAULT_CFG_PATH = 'config/flagpole';
const DEFAULT_PROPERTY_NAME = 'featureFlags';
module.exports = {
name: 'ember-cli-flagpole',
flagpoleConfigPath: DEFAULT_CFG_PATH,
flagpolePropertyName: DEFAULT_PROPERTY_NAME,
flagpoleOmitFalseFlags: false,
init() {
this._super.init && this._super.init.apply(this, arguments);
const Registry = require('./lib/registry');
this._flagRegistry = new Registry();
this.flag = require('./lib/flag')(this._flagRegistry);
},
included(app) {
const options = app.options['ember-cli-flagpole'] || {};
if (options.configPath) {
this.flagpoleConfigPath = options.configPath.replace(/\.js$/, '');
}
if (options.propertyName) {
this.flagpolePropertyName = options.propertyName;
}
this.flagpoleOmitFalseFlags = !!options.omitFalseFlags;
},
config(env/* , baseConfig */) {
const resolve = require('path').resolve;
const existsSync = require('fs').existsSync;
// TODO: support use as a nested addon?
const projectRoot = this.project.root;
const resolved = resolve(projectRoot, this.flagpoleConfigPath);
if (existsSync(resolved + '.js')) {
const flagpoleConfig = require(resolved);
switch (typeof flagpoleConfig) {
case 'object': {
require('./lib/convert-object')(this.flag, flagpoleConfig);
break;
}
case 'function': {
flagpoleConfig(this.flag);
break;
}
default: throw new TypeError('flagpole.js must export either a function or an object');
}
const flagSet = this._flagRegistry.collectFor(env, {
omitFalseFlags: this.flagpoleOmitFalseFlags
});
return {
[this.flagpolePropertyName]: flagSet
};
}
return {};
},
};