-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathnpm-wrapper.js
254 lines (232 loc) · 7.71 KB
/
npm-wrapper.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/env node
const minimist = require("minimist");
const { build, validate, clean, deployLocal } = require("./main.js");
const {buildLab, deployLab,validation} = require("./lab_build/lab_gen.js");
const { BuildEnvs, validBuildEnv } = require("./enums.js");
const log = require("./logger");
const path = require("path");
function help(){
console.log("Usage: npx @virtual-labs/buildexp [command]");
console.log("Options:");
console.log("Commands:");
console.log(" build-exp Build the experiment");
console.log(" build-exp-deploy Build the experiment and deploy locally");
console.log(" build-exp-noplugin Build the experiment without using any plugins");
console.log(" clean-build-exp Clean and build the experiment");
console.log(" validate Validate the code and content");
console.log(" clean Clean the build and plugins");
console.log(" deploy Deploy the experiment locally");
console.log(" build-lab Build the lab");
console.log(" deploy-lab Deploy the lab locally");
console.log(" build-and-deploy-lab Build and deploy the lab locally");
console.log(" help Display help for command");
}
function main() {
// console.log("Vlabs Build Exp");
const args = minimist(process.argv.slice(2));
// for backwards compatibility if the env is not given assume it to
// be testing.
const build_options = {};
if (args.env) {
build_options.env = validBuildEnv(args.env);
} else {
build_options.env = BuildEnvs.TESTING;
}
// if the path is not provided assume "." for backward
// compatability.
let src = ".";
if (args.src) {
src = args.src;
}
let isDebug = args.debug || false;
if (isDebug) {
log.addDebug();
log.info("Debug mode enabled");
} else {
log.addInfo();
}
let option = "";
if (args._.length === 1) {
option = args._[0];
} else {
log.error("Invalid Arguments");
console.log("Invalid Arguments");
help();
return;
}
let release = args.release || "minor";
let labpath = "";
// options
let isClean = false;
let isESLINT = false;
let isExpDesc = false;
let isDeploy = false;
let isPlugin = false;
switch (option) {
case "build-exp":
isESLINT = true;
isExpDesc = true;
isPlugin = true;
log.info("Calling build with options: ");
log.info(`isClean: ${isClean}`);
log.info(`isESLINT: ${isESLINT}`);
log.info(`isExpDesc: ${isExpDesc}`);
log.info(`isDeploy: ${isDeploy}`);
log.info(`isPlugin: ${isPlugin}`);
build(
isClean,
isESLINT,
isExpDesc,
isDeploy,
isPlugin,
src,
build_options
);
log.info("Build Complete");
break;
case "clean-build-exp":
isClean = true;
isESLINT = true;
isExpDesc = true;
isPlugin = true;
log.info("Calling build with options: ");
log.info(`isClean: ${isClean}`);
log.info(`isESLINT: ${isESLINT}`);
log.info(`isExpDesc: ${isExpDesc}`);
log.info(`isDeploy: ${isDeploy}`);
log.info(`isPlugin: ${isPlugin}`);
build(
isClean,
isESLINT,
isExpDesc,
isDeploy,
isPlugin,
src,
build_options
);
log.info("Build Complete");
break;
case "build-exp-deploy":
isESLINT = true;
isExpDesc = true;
isPlugin = true;
isDeploy = true;
log.info("Calling build with options: ");
log.info(`isClean: ${isClean}`);
log.info(`isESLINT: ${isESLINT}`);
log.info(`isExpDesc: ${isExpDesc}`);
log.info(`isDeploy: ${isDeploy}`);
log.info(`isPlugin: ${isPlugin}`);
build(
isClean,
isESLINT,
isExpDesc,
isDeploy,
isPlugin,
src,
build_options
);
log.info("Build Complete");
break;
case "build-exp-noplugin":
isClean = true;
log.info("Calling build with options: ");
log.info(`isClean: ${isClean}`);
log.info(`isESLINT: ${isESLINT}`);
log.info(`isExpDesc: ${isExpDesc}`);
log.info(`isDeploy: ${isDeploy}`);
log.info(`isPlugin: ${isPlugin}`);
build(
isClean,
isESLINT,
isExpDesc,
isDeploy,
isPlugin,
src,
build_options
);
log.info("Build Complete");
break;
case "build-exp-noplugin":
isClean = true;
isPlugin = true;
log.info("Calling build with options: ");
log.info(`isClean: ${isClean}`);
log.info(`isESLINT: ${isESLINT}`);
log.info(`isExpDesc: ${isExpDesc}`);
log.info(`isDeploy: ${isDeploy}`);
log.info(`isPlugin: ${isPlugin}`);
build(
isClean,
isESLINT,
isExpDesc,
isDeploy,
isPlugin,
src,
build_options
);
log.info("Build Complete");
break;
case "validate":
let isESLINTValidate = true;
let isExpDescValidate = true;
log.info("Calling validate with options: ");
log.info(`isESLINT: ${isESLINTValidate}`);
log.info(`isExpDesc: ${isExpDescValidate}`);
validate(isESLINTValidate, isExpDescValidate, src);
break;
case "clean":
log.info("Calling clean");
clean(src);
log.info("Clean Complete");
break;
case "deploy":
log.info("Calling deploy");
deployLocal(src);
break;
case "build-lab":
log.info("Calling buildLab");
labpath = path.resolve(src);
if (validation(labpath)) {
buildLab(labpath);
log.info("BuildLab Complete");
if (args.deploy) {
log.info("Calling deploy Lab");
deployLab(labpath, release);
log.info("Deploy Lab Complete");
}
}
break;
case "deploy-lab":
release = "patch";
log.info("Calling deploy Lab");
labpath = path.resolve(src);
if (validation(labpath)) {
deployLab(src, release);
log.info("Deploy Lab Complete");
break;
}
case "build-and-deploy-lab":
log.info("Calling buildLab");
labpath = path.resolve(src);
args.deploy = true;
if (validation(labpath)) {
buildLab(labpath);
log.info("BuildLab Complete");
if (args.deploy) {
log.info("Calling deploy Lab");
deployLab(labpath, release);
log.info("Deploy Lab Complete");
}
}
break;
case "help":
help();
break;
default:
log.error("Invalid Arguments");
help();
break;
}
}
main();