-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtsv.js
36 lines (32 loc) · 1.09 KB
/
tsv.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
let constants = require('./constants');
let allFlags = {};
constants.envs.forEach(env => allFlags[env] = require(`./flags/${env}.json`));
let combinedFlags = [];
constants.envs.forEach(env => {
allFlags[env].forEach(ff => {
let flag = combinedFlags.find(f => f.name === ff.name);
if(!flag) {
flag = Object.assign({}, ff);
flag.value = {};
combinedFlags.push(flag);
}
flag.value[env] = ff.value;
});
});
let valueToString = (env, ff) => {
let value = ff.value[env];
if (ff.type === 'date-range') return `${value.start} till ${value.end}`;
return JSON.stringify(value);
};
let tsv = ['name\ttype\ttags\tdescription\tprod\timp\tdev\tdev-pre'];
combinedFlags.forEach(ff => {
let data = [];
data.push(ff.name);
data.push(ff.type);
data.push(ff.tags.sort());
data.push(ff.description);
constants.envs.forEach(env => data.push(valueToString(env, ff)));
tsv.push(data.join('\t'));
});
console.info('writing file ./generated/flags.tsv');
require('fs').writeFileSync('./generated/flags.tsv', tsv.join('\n'));