-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
139 lines (108 loc) · 4.4 KB
/
index.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { ParametersGetter, TCommandLineParameters } from 'ajlm.utils';
import { TreeBuilder } from "./tree-builder";
import { Logger } from './logger';
import { TreeExecutor, TExecutionOptions, TTreeExecOptions, TAllExecOptions } from './tree-executor';
import { TSpec } from 'repository-specs-reader';
import { Configuration, DefaultConfiguration } from './configuration';
// Init Conf
// @TODO can we imagine making this customizable as a sub package basis ?
Configuration.getInstance().initialize( DefaultConfiguration.defaultCfg );
// module entry point
let actionsMap: { [actionKey: string] : (param: TCommandLineParameters, options: TExecutionOptions) => Promise<void>;} = {
"build_pkg" : async (param: TCommandLineParameters, options: TExecutionOptions) => {
let pck: string = param["pkg"];
let tb: TreeBuilder = new TreeBuilder();
await tb.buildPackage(pck, options);
},
"build_repo" : async (param: TCommandLineParameters, options: TExecutionOptions) => {
let pck: string = param["repo"];
let tb: TreeBuilder = new TreeBuilder();
options.forceAll = param["forceAll"] != undefined;
await tb.buildRepository(pck, options);
},
"exec_pkg": async (param: TCommandLineParameters, options: TExecutionOptions) => {
let pck: string = param["pkg"];
let cmd: string = param["exec"];
let tc = new TreeExecutor();
await tc.execCmdOnPackage(pck, cmd, options);
},
"exec_repo": async (param: TCommandLineParameters, options: TExecutionOptions) => {
let pck: string = param["repo"];
let cmd: string = param["exec"];
let tc = new TreeExecutor();
await tc.execCmdOnRepository(pck, cmd, options);
},
"enum_repo": async (param: TCommandLineParameters, options: TExecutionOptions) => {
let pck: string = param["repo"];
let tc = new TreeExecutor();
await tc.execCmdOnRepository(pck, getNodeEnumerator(options), options);
},
"enum_pkg": async (param: TCommandLineParameters, options: TExecutionOptions) => {
let pkg: string = param["pkg"];
let tc = new TreeExecutor();
await tc.execCmdOnPackage(pkg, getNodeEnumerator(options), options);
}
};
let param: TCommandLineParameters = (new ParametersGetter()).getParameters();
// Return a method that enumerate package names
// Depending on exec options, print delimiters for grouped nodes
let getNodeEnumerator: (options: TExecutionOptions) => (node: TSpec, index: number, group: TSpec[])=> Promise<void> =
(options: TExecutionOptions) => {
let isGrouped: boolean = false;
if((<TTreeExecOptions>options).tree){
isGrouped = true;
}
return async (node: TSpec, index: number, group: TSpec[]) => {
if(isGrouped && index == 0){
Logger.info(`** Group`);
}
Logger.info(`\t${node.name}`);
if(isGrouped && index == group.length - 1){
Logger.info(`** End`);
}
};
};
// Wrapper to know how much time we spent
let execute = async ( cb: (param: TCommandLineParameters, options: TExecutionOptions) => Promise<void>, options: TExecutionOptions ) => {
Logger.info(`Starting tasks`);
let now: number = Date.now();
await cb(param, options);
Logger.info(`Executed in ${Date.now() - now} ms`);
};
// Find out which request to fill
let fetchCommandLine = async () => {
for(var key in actionsMap){
let keys: string[] = key.split("_");
let action = actionsMap[key];
let options: TExecutionOptions = {
tree: {
parallel: true
}
};
let presentKeys = keys.filter(k => param[k] != undefined);
if(presentKeys.length == keys.length) {
if(param["all"]){
options = {
all: {
parallel: param["parallel"] ? true : false
}
};
}
else if(param["tree"]){
options = {
tree: {
parallel: param["parallel"] ? true : false
}
};
}
await execute(action, options);
return;
}
}
throw new Error("Cannot Work with inputs");
};
// Start
fetchCommandLine()
.catch((error)=>{
Logger.error(" -> Stopped due to error");
});