-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.ts
69 lines (42 loc) · 1.36 KB
/
cmd.ts
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
#!/usr/bin/env node
import logger from './modules/logger'
import scan from './modules/scan';
import writer from './modules/writer';
import { getOptions, initializeOptions } from './modules/options';
function profileSelector(profiles, profile) {
const hash = { [profile]: true }
let ref = profiles[profile] ? profiles[profile].obj : {}
let track = [{ ...ref }]
while (ref.inherit) {
if (hash[ref.inherit]) {
throw "circular inheritance detected";
}
hash[ref.inherit] = true;
const toRef = profiles[ref.inherit] ? profiles[ref.inherit].obj : {}
ref = toRef
track.push(toRef);
}
track = track.reverse()
const final = {}
track.forEach(t => {
Object.keys(t).forEach(key => {
final[key] = t[key];
})
})
const returnAble = profiles[profile] || {};
returnAble.obj = final;
if (returnAble.obj.inherit) {
delete returnAble.obj.inherit
}
returnAble.str = JSON.stringify(final);
return returnAble;
}
// get command line args
const args = process.argv.splice(2);
initializeOptions(args)
const options = getOptions()
const profiles = scan();
const profile = profileSelector(profiles, options.profile) || {};
writer(profile.str);
logger(`active profile = ${profile.name}`)
// scan profiles folder to get all available profiles