mushroom-cli 1.1.2 → 1.2.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/config.js CHANGED
@@ -1,475 +1,445 @@
1
- const fs = require("fs");
2
- const help = require("./help.js");
3
- const JSON5 = require("json5");
4
-
5
- //#region common function
6
- function saveConfig(mushroomConfig, success) {
7
- mushroomConfig["$schema"] =
8
- "https://schema.siten.vn/mushroom/mushroom-cli.json";
9
- fs.writeFile(
10
- "./mushroom-config.json",
11
- JSON.stringify(mushroomConfig, null, " "),
12
- (err) => {
13
- if (err) throw err;
14
-
15
- if (typeof success === "function") success();
16
- },
17
- );
18
- }
19
- //#endregion
20
-
21
- //#region config add
22
- function configAdd(args) {
23
- const filePath = args[2];
24
-
25
- if (!filePath) {
26
- help("config add", true);
27
- return;
28
- }
29
-
30
- const fileContent = fs.readFileSync(filePath).toString();
31
- const project = JSON5.parse(fileContent);
32
- if (!project.name) {
33
- throw new TypeError(`Missing name in ${filePath}`);
34
- }
35
-
36
- let mushroomConfigContent;
37
- try {
38
- mushroomConfigContent = fs
39
- .readFileSync("./mushroom-config.json")
40
- .toString();
41
- } catch (e) {
42
- mushroomConfigContent = null;
43
- }
44
-
45
- let mushroomConfig = mushroomConfigContent
46
- ? JSON.parse(mushroomConfigContent)
47
- : {};
48
- mushroomConfig.projects = mushroomConfig.projects || {};
49
- mushroomConfig.projects[project.name] =
50
- mushroomConfig.projects[project.name] || {};
51
- mushroomConfig.projects[project.name].src = filePath;
52
-
53
- saveConfig(mushroomConfig, () =>
54
- console.log(`Added ${filePath}, project name: ${project.name}`),
55
- );
56
- }
57
- //#endregion
58
-
59
- //#region config gen
60
- function configGenDocs(args, mushroomConfig, projectName) {
61
- const path = args[4];
62
- if (!path) {
63
- help(args);
64
- return;
65
- }
66
-
67
- let index = 5;
68
- let parameters = {
69
- features: [],
70
- allowRoles: ["*"],
71
- denyRoles: [],
72
- };
73
- let alias = "default";
74
- while (index < args.length) {
75
- switch (args[index]) {
76
- case "features":
77
- index++;
78
- const strFeatures = args[index];
79
- if (strFeatures) parameters.features = strFeatures.split(",");
80
- break;
81
- case "roles":
82
- index++;
83
- const strRoles = args[index];
84
- if (strRoles) {
85
- const minusIndex = strRoles.indexOf("-");
86
- let grantedRoles =
87
- minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
88
- const deniedRoles =
89
- minusIndex == -1 ? "" : strRoles.substring(minusIndex + 1);
90
- if (!grantedRoles) grantedRoles = "*";
91
- parameters.allowRoles = grantedRoles.split(",");
92
- if (deniedRoles) parameters.denyRoles = deniedRoles.split(",");
93
- }
94
- break;
95
- case "alias":
96
- index++;
97
- const strAlias = args[index];
98
- if (strAlias) alias = strAlias;
99
- break;
100
- }
101
- index++;
102
- }
103
-
104
- const project = mushroomConfig.projects[projectName];
105
- project.docs = project.docs || {};
106
- project.docs.alias = project.docs.alias || {};
107
- const projectAlias = (project.docs.alias[alias] =
108
- project.docs.alias[alias] || {});
109
- for (const key in parameters) {
110
- if (parameters.hasOwnProperty(key)) {
111
- const value = parameters[key];
112
- projectAlias[key] = value;
113
- }
114
- }
115
- projectAlias.output = path;
116
- saveConfig(mushroomConfig, () =>
117
- console.log(`Saved configuration of gen docs for ${projectName}@${alias}`),
118
- );
119
- }
120
-
121
- function configGenDatabaseDocs(args, mushroomConfig, projectName) {
122
- const path = args[4];
123
- if (!path) {
124
- help(args);
125
- return;
126
- }
127
-
128
- let index = 5;
129
- let parameters = {
130
- features: [],
131
- };
132
- let alias = "default";
133
- while (index < args.length) {
134
- switch (args[index]) {
135
- case "features":
136
- index++;
137
- const strFeatures = args[index];
138
- if (strFeatures) parameters.features = strFeatures.split(",");
139
- break;
140
- case "alias":
141
- index++;
142
- const strAlias = args[index];
143
- if (strAlias) alias = strAlias;
144
- break;
145
- }
146
- index++;
147
- }
148
-
149
- const project = mushroomConfig.projects[projectName];
150
- project.dbDocs = project.dbDocs || {};
151
- project.dbDocs.alias = project.dbDocs.alias || {};
152
- const projectAlias = (project.dbDocs.alias[alias] =
153
- project.dbDocs.alias[alias] || {});
154
- for (const key in parameters) {
155
- if (parameters.hasOwnProperty(key)) {
156
- const value = parameters[key];
157
- projectAlias[key] = value;
158
- }
159
- }
160
- projectAlias.output = path;
161
- saveConfig(mushroomConfig, () =>
162
- console.log(
163
- `Saved configuration of gen db-docs for ${projectName}@${alias}`,
164
- ),
165
- );
166
- }
167
-
168
- function configGenJavascriptDriver(args, mushroomConfig, projectName) {
169
- const path = args[4];
170
- if (!path) {
171
- help(args);
172
- return;
173
- }
174
-
175
- let index = 5;
176
- let parameters = {
177
- allowRoles: ["*"],
178
- denyRoles: [],
179
- };
180
- let alias = "default";
181
- let tarball = undefined;
182
- while (index < args.length) {
183
- switch (args[index]) {
184
- case "roles":
185
- index++;
186
- const strRoles = args[index];
187
- if (strRoles) {
188
- const minusIndex = strRoles.indexOf("-");
189
- let grantedRoles =
190
- minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
191
- const deniedRoles =
192
- minusIndex == -1 ? "" : strRoles.substring(minusIndex + 1);
193
- if (!grantedRoles) grantedRoles = "*";
194
- parameters.allowRoles = grantedRoles.split(",");
195
- if (deniedRoles) parameters.denyRoles = deniedRoles.split(",");
196
- }
197
- break;
198
- case "alias":
199
- index++;
200
- const strAlias = args[index];
201
- if (strAlias) alias = strAlias;
202
- break;
203
- case "tarball":
204
- index++;
205
- const strTarball = args[index];
206
- if (strTarball) tarball = strTarball;
207
- break;
208
- }
209
- index++;
210
- }
211
-
212
- const project = mushroomConfig.projects[projectName];
213
- project.jsDriver = project.jsDriver || {};
214
- project.jsDriver.alias = project.jsDriver.alias || {};
215
- const projectAlias = (project.jsDriver.alias[alias] =
216
- project.jsDriver.alias[alias] || {});
217
- for (const key in parameters) {
218
- if (parameters.hasOwnProperty(key)) {
219
- const value = parameters[key];
220
- projectAlias[key] = value;
221
- }
222
- }
223
- projectAlias.tarballName = tarball;
224
- projectAlias.output = path;
225
- saveConfig(mushroomConfig, () =>
226
- console.log(
227
- `Saved configuration of gen javascript driver for ${projectName}@${alias}`,
228
- ),
229
- );
230
- }
231
-
232
- function configGenTypescriptDriver(args, mushroomConfig, projectName) {
233
- const path = args[4];
234
- if (!path) {
235
- help(args);
236
- return;
237
- }
238
-
239
- let index = 5;
240
- let parameters = {
241
- allowRoles: ["*"],
242
- denyRoles: [],
243
- };
244
- let alias = "default";
245
- while (index < args.length) {
246
- switch (args[index]) {
247
- case "roles":
248
- index++;
249
- const strRoles = args[index];
250
- if (strRoles) {
251
- const minusIndex = strRoles.indexOf("-");
252
- let grantedRoles =
253
- minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
254
- const deniedRoles =
255
- minusIndex == -1 ? "" : strRoles.substring(minusIndex + 1);
256
- if (!grantedRoles) grantedRoles = "*";
257
- parameters.allowRoles = grantedRoles.split(",");
258
- if (deniedRoles) parameters.denyRoles = deniedRoles.split(",");
259
- }
260
- break;
261
- case "alias":
262
- index++;
263
- const strAlias = args[index];
264
- if (strAlias) alias = strAlias;
265
- break;
266
- }
267
- index++;
268
- }
269
-
270
- const project = mushroomConfig.projects[projectName];
271
- project.tsDriver = project.tsDriver || {};
272
- project.tsDriver.alias = project.tsDriver.alias || {};
273
- const projectAlias = (project.tsDriver.alias[alias] =
274
- project.tsDriver.alias[alias] || {});
275
- for (const key in parameters) {
276
- if (parameters.hasOwnProperty(key)) {
277
- const value = parameters[key];
278
- projectAlias[key] = value;
279
- }
280
- }
281
- projectAlias.output = path;
282
- saveConfig(mushroomConfig, () =>
283
- console.log(
284
- `Saved configuration of gen javascript driver for ${projectName}@${alias}`,
285
- ),
286
- );
287
- }
288
-
289
- function configGenCSharpMongo(args, mushroomConfig, projectName) {
290
- const path = args[4];
291
- if (!path) {
292
- help(args);
293
- return;
294
- }
295
-
296
- let index = 5;
297
- let parameters = {};
298
- let alias = "default";
299
- while (index < args.length) {
300
- switch (args[index]) {
301
- case "alias":
302
- index++;
303
- const strAlias = args[index];
304
- if (strAlias) alias = strAlias;
305
- break;
306
- }
307
- index++;
308
- }
309
-
310
- const project = mushroomConfig.projects[projectName];
311
- project.csharpMongo = project.csharpMongo || {};
312
- project.csharpMongo.alias = project.csharpMongo.alias || {};
313
- const projectAlias = (project.csharpMongo.alias[alias] =
314
- project.csharpMongo.alias[alias] || {});
315
- for (const key in parameters) {
316
- if (parameters.hasOwnProperty(key)) {
317
- const value = parameters[key];
318
- projectAlias[key] = value;
319
- }
320
- }
321
- projectAlias.output = path;
322
- saveConfig(mushroomConfig, () =>
323
- console.log(
324
- `Saved configuration of gen CSharp/MongoDb classes for ${projectName}@${alias}`,
325
- ),
326
- );
327
- }
328
-
329
- function configGenCSharpDriver(args, mushroomConfig, projectName) {
330
- const path = args[4];
331
- if (!path) {
332
- help(args);
333
- return;
334
- }
335
-
336
- let index = 5;
337
- let parameters = {
338
- allowRoles: ["*"],
339
- denyRoles: [],
340
- features: ["auth", "file", "mail"],
341
- accessModifier: "internal",
342
- };
343
- let alias = "default";
344
- while (index < args.length) {
345
- switch (args[index]) {
346
- case "roles":
347
- index++;
348
- const strRoles = args[index];
349
- if (strRoles) {
350
- const minusIndex = strRoles.indexOf("-");
351
- let grantedRoles =
352
- minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
353
- const deniedRoles =
354
- minusIndex == -1 ? "" : strRoles.substring(minusIndex + 1);
355
- if (!grantedRoles) grantedRoles = "*";
356
- parameters.allowRoles = grantedRoles.split(",");
357
- if (deniedRoles) parameters.denyRoles = deniedRoles.split(",");
358
- }
359
- break;
360
- case "alias":
361
- index++;
362
- const strAlias = args[index];
363
- if (strAlias) alias = strAlias;
364
- break;
365
- case "access-modifier":
366
- index++;
367
- const strAccessModifier = args[index];
368
- if (strAccessModifier) parameters.accessModifier = strAccessModifier;
369
- break;
370
- case "features":
371
- index++;
372
- const strFeatures = args[index];
373
- if (strFeatures) {
374
- parameters.features = strFeatures.split(",");
375
- }
376
- break;
377
- }
378
- index++;
379
- }
380
-
381
- const project = mushroomConfig.projects[projectName];
382
- project.csharpDriver = project.csharpDriver || {};
383
- project.csharpDriver.alias = project.csharpDriver.alias || {};
384
- const projectAlias = (project.csharpDriver.alias[alias] =
385
- project.csharpDriver.alias[alias] || {});
386
- for (const key in parameters) {
387
- if (parameters.hasOwnProperty(key)) {
388
- const value = parameters[key];
389
- projectAlias[key] = value;
390
- }
391
- }
392
- projectAlias.output = path;
393
- saveConfig(mushroomConfig, () =>
394
- console.log(
395
- `Saved configuration of gen CSharp driver for ${projectName}@${alias}`,
396
- ),
397
- );
398
- }
399
-
400
- function configGen(args) {
401
- const projectName = args[2];
402
-
403
- let mushroomConfig;
404
- try {
405
- const mushroomConfigContent = fs
406
- .readFileSync("./mushroom-config.json")
407
- .toString();
408
- mushroomConfig = JSON.parse(mushroomConfigContent);
409
- } catch (e) {
410
- console.error("mushroom-config.json not found or unable to parse");
411
- throw e;
412
- }
413
-
414
- if (
415
- !mushroomConfig ||
416
- !mushroomConfig.projects ||
417
- !mushroomConfig.projects[projectName]
418
- )
419
- throw new Error(`Project not found (${projectName})`);
420
-
421
- const type = args[3];
422
- switch (type) {
423
- case "docs":
424
- configGenDocs(args, mushroomConfig, projectName);
425
- break;
426
- case "db-docs":
427
- configGenDatabaseDocs(args, mushroomConfig, projectName);
428
- break;
429
- case "js-driver":
430
- configGenJavascriptDriver(args, mushroomConfig, projectName);
431
- break;
432
- case "ts-driver":
433
- configGenTypescriptDriver(args, mushroomConfig, projectName);
434
- break;
435
- case "c#-mongo":
436
- configGenCSharpMongo(args, mushroomConfig, projectName);
437
- break;
438
- case "c#-driver":
439
- configGenCSharpDriver(args, mushroomConfig, projectName);
440
- break;
441
- case "":
442
- case undefined:
443
- case "help":
444
- case "man":
445
- help(args);
446
- break;
447
- default:
448
- help(args, true);
449
- break;
450
- }
451
- }
452
- //#endregion
453
-
454
- function config(args) {
455
- const configCommand = args[1];
456
- switch (configCommand) {
457
- case "add":
458
- configAdd(args);
459
- break;
460
- case "gen":
461
- configGen(args);
462
- break;
463
- case "":
464
- case undefined:
465
- case "help":
466
- case "man":
467
- help("config");
468
- break;
469
- default:
470
- help(args, true);
471
- break;
472
- }
473
- }
474
-
475
- module.exports = config;
1
+ const fs = require("fs");
2
+ const help = require("./help.js");
3
+ const JSON5 = require("json5");
4
+
5
+ //#region common function
6
+ function saveConfig(mushroomConfig, success) {
7
+ mushroomConfig["$schema"] = "http://schema.siten.vn/mushroom/mushroom-cli.json";
8
+ fs.writeFile("./mushroom-config.json", JSON.stringify(mushroomConfig, null, " "), err => {
9
+ if (err)
10
+ throw err;
11
+
12
+ if (typeof success === "function")
13
+ success();
14
+ });
15
+ }
16
+ //#endregion
17
+
18
+ //#region config add
19
+ function configAdd(args) {
20
+ const filePath = args[2];
21
+
22
+ if (!filePath){
23
+ help("config add", true);
24
+ return;
25
+ }
26
+
27
+ const fileContent = fs.readFileSync(filePath).toString();
28
+ var project = JSON5.parse(fileContent);
29
+ if (!project.name) {
30
+ throw new TypeError(`Missing name in ${filePath}`);
31
+ }
32
+
33
+ let mushroomConfigContent;
34
+ try {
35
+ mushroomConfigContent = fs.readFileSync("./mushroom-config.json").toString();
36
+ }
37
+ catch(e){
38
+ mushroomConfigContent = null;
39
+ }
40
+
41
+ let mushroomConfig = mushroomConfigContent ? JSON.parse(mushroomConfigContent) : {};
42
+ mushroomConfig.projects = mushroomConfig.projects || {};
43
+ mushroomConfig.projects[project.name] = mushroomConfig.projects[project.name] || { };
44
+ mushroomConfig.projects[project.name].src = filePath;
45
+
46
+ saveConfig(mushroomConfig, () => console.log(`Added ${filePath}, project name: ${project.name}`));
47
+ }
48
+ //#endregion
49
+
50
+ //#region config gen
51
+ function configGenDocs(args, mushroomConfig, projectName){
52
+ const path = args[4];
53
+ if (!path) {
54
+ help(args);
55
+ return;
56
+ }
57
+
58
+ let index = 5;
59
+ let parameters = {
60
+ features: [],
61
+ allowRoles: ["*"],
62
+ denyRoles: []
63
+ };
64
+ let alias = "default";
65
+ while (index < args.length) {
66
+ switch (args[index]) {
67
+ case "features":
68
+ index++;
69
+ const strFeatures = args[index];
70
+ if (strFeatures)
71
+ parameters.features = strFeatures.split(",");
72
+ break;
73
+ case "roles":
74
+ index++;
75
+ const strRoles = args[index];
76
+ if (strRoles) {
77
+ const minusIndex = strRoles.indexOf("-");
78
+ let grantedRoles = minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
79
+ const deniedRoles = minusIndex == -1 ? "" : strRoles.substring(minusIndex + 1);
80
+ if (!grantedRoles)
81
+ grantedRoles = "*";
82
+ parameters.allowRoles = grantedRoles.split(",");
83
+ if (deniedRoles)
84
+ parameters.denyRoles = deniedRoles.split(",");
85
+ }
86
+ break;
87
+ case "alias":
88
+ index++;
89
+ const strAlias = args[index];
90
+ if (strAlias)
91
+ alias = strAlias;
92
+ break;
93
+ }
94
+ index++;
95
+ }
96
+
97
+ const project = mushroomConfig.projects[projectName];
98
+ project.docs = project.docs || {};
99
+ project.docs.alias = project.docs.alias || {};
100
+ const projectAlias = project.docs.alias[alias] = project.docs.alias[alias] || {};
101
+ for (const key in parameters) {
102
+ if (parameters.hasOwnProperty(key)) {
103
+ const value = parameters[key];
104
+ projectAlias[key] = value;
105
+ }
106
+ }
107
+ projectAlias.output = path;
108
+ saveConfig(mushroomConfig, () => console.log(`Saved configuration of gen docs for ${projectName}@${alias}`));
109
+ }
110
+
111
+ function configGenDatabaseDocs(args, mushroomConfig, projectName){
112
+ const path = args[4];
113
+ if (!path) {
114
+ help(args);
115
+ return;
116
+ }
117
+
118
+ let index = 5;
119
+ let parameters = {
120
+ features: []
121
+ };
122
+ let alias = "default";
123
+ while (index < args.length) {
124
+ switch (args[index]) {
125
+ case "features":
126
+ index++;
127
+ const strFeatures = args[index];
128
+ if (strFeatures)
129
+ parameters.features = strFeatures.split(",");
130
+ break;
131
+ case "alias":
132
+ index++;
133
+ const strAlias = args[index];
134
+ if (strAlias)
135
+ alias = strAlias;
136
+ break;
137
+ }
138
+ index++;
139
+ }
140
+
141
+ const project = mushroomConfig.projects[projectName];
142
+ project.dbDocs = project.dbDocs || {};
143
+ project.dbDocs.alias = project.dbDocs.alias || {};
144
+ const projectAlias = project.dbDocs.alias[alias] = project.dbDocs.alias[alias] || {};
145
+ for (const key in parameters) {
146
+ if (parameters.hasOwnProperty(key)) {
147
+ const value = parameters[key];
148
+ projectAlias[key] = value;
149
+ }
150
+ }
151
+ projectAlias.output = path;
152
+ saveConfig(mushroomConfig, () => console.log(`Saved configuration of gen db-docs for ${projectName}@${alias}`));
153
+ }
154
+
155
+ function configGenJavascriptDriver(args, mushroomConfig, projectName){
156
+ const path = args[4];
157
+ if (!path) {
158
+ help(args);
159
+ return;
160
+ }
161
+
162
+ let index = 5;
163
+ let parameters = {
164
+ allowRoles: ["*"],
165
+ denyRoles: []
166
+ };
167
+ let alias = "default";
168
+ let tarball = undefined;
169
+ while (index < args.length) {
170
+ switch (args[index]) {
171
+ case "roles":
172
+ index++;
173
+ const strRoles = args[index];
174
+ if (strRoles) {
175
+ const minusIndex = strRoles.indexOf("-");
176
+ let grantedRoles = minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
177
+ const deniedRoles = minusIndex == -1 ? "" : strRoles.substring(minusIndex + 1);
178
+ if (!grantedRoles)
179
+ grantedRoles = "*";
180
+ parameters.allowRoles = grantedRoles.split(",");
181
+ if (deniedRoles)
182
+ parameters.denyRoles = deniedRoles.split(",");
183
+ }
184
+ break;
185
+ case "alias":
186
+ index++;
187
+ const strAlias = args[index];
188
+ if (strAlias)
189
+ alias = strAlias;
190
+ break;
191
+ case "tarball":
192
+ index++;
193
+ const strTarball = args[index];
194
+ if (strTarball)
195
+ tarball = strTarball;
196
+ break;
197
+ }
198
+ index++;
199
+ }
200
+
201
+ const project = mushroomConfig.projects[projectName];
202
+ project.jsDriver = project.jsDriver || {};
203
+ project.jsDriver.alias = project.jsDriver.alias || {};
204
+ const projectAlias = project.jsDriver.alias[alias] = project.jsDriver.alias[alias] || {};
205
+ for (const key in parameters) {
206
+ if (parameters.hasOwnProperty(key)) {
207
+ const value = parameters[key];
208
+ projectAlias[key] = value;
209
+ }
210
+ }
211
+ projectAlias.tarballName = tarball;
212
+ projectAlias.output = path;
213
+ saveConfig(mushroomConfig, () => console.log(`Saved configuration of gen javascript driver for ${projectName}@${alias}`));
214
+ }
215
+
216
+ function configGenTypescriptDriver(args, mushroomConfig, projectName){
217
+ const path = args[4];
218
+ if (!path) {
219
+ help(args);
220
+ return;
221
+ }
222
+
223
+ let index = 5;
224
+ let parameters = {
225
+ allowRoles: ["*"],
226
+ denyRoles: []
227
+ };
228
+ let alias = "default";
229
+ while (index < args.length) {
230
+ switch (args[index]) {
231
+ case "roles":
232
+ index++;
233
+ const strRoles = args[index];
234
+ if (strRoles) {
235
+ const minusIndex = strRoles.indexOf("-");
236
+ let grantedRoles = minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
237
+ const deniedRoles = minusIndex == -1 ? "" : strRoles.substring(minusIndex + 1);
238
+ if (!grantedRoles)
239
+ grantedRoles = "*";
240
+ parameters.allowRoles = grantedRoles.split(",");
241
+ if (deniedRoles)
242
+ parameters.denyRoles = deniedRoles.split(",");
243
+ }
244
+ break;
245
+ case "alias":
246
+ index++;
247
+ const strAlias = args[index];
248
+ if (strAlias)
249
+ alias = strAlias;
250
+ break;
251
+ }
252
+ index++;
253
+ }
254
+
255
+ const project = mushroomConfig.projects[projectName];
256
+ project.tsDriver = project.tsDriver || {};
257
+ project.tsDriver.alias = project.tsDriver.alias || {};
258
+ const projectAlias = project.tsDriver.alias[alias] = project.tsDriver.alias[alias] || {};
259
+ for (const key in parameters) {
260
+ if (parameters.hasOwnProperty(key)) {
261
+ const value = parameters[key];
262
+ projectAlias[key] = value;
263
+ }
264
+ }
265
+ projectAlias.output = path;
266
+ saveConfig(mushroomConfig, () => console.log(`Saved configuration of gen javascript driver for ${projectName}@${alias}`));
267
+ }
268
+
269
+ function configGenCSharpMongo(args, mushroomConfig, projectName){
270
+ const path = args[4];
271
+ if (!path) {
272
+ help(args);
273
+ return;
274
+ }
275
+
276
+ let index = 5;
277
+ let parameters = {
278
+ };
279
+ let alias = "default";
280
+ while (index < args.length) {
281
+ switch (args[index]) {
282
+ case "alias":
283
+ index++;
284
+ const strAlias = args[index];
285
+ if (strAlias)
286
+ alias = strAlias;
287
+ break;
288
+ }
289
+ index++;
290
+ }
291
+
292
+ const project = mushroomConfig.projects[projectName];
293
+ project.csharpMongo = project.csharpMongo || {};
294
+ project.csharpMongo.alias = project.csharpMongo.alias || {};
295
+ const projectAlias = project.csharpMongo.alias[alias] = project.csharpMongo.alias[alias] || {};
296
+ for (const key in parameters) {
297
+ if (parameters.hasOwnProperty(key)) {
298
+ const value = parameters[key];
299
+ projectAlias[key] = value;
300
+ }
301
+ }
302
+ projectAlias.output = path;
303
+ saveConfig(mushroomConfig, () => console.log(`Saved configuration of gen CSharp/MongoDb classes for ${projectName}@${alias}`));
304
+ }
305
+
306
+ function configGenCSharpDriver(args, mushroomConfig, projectName){
307
+ const path = args[4];
308
+ if (!path) {
309
+ help(args);
310
+ return;
311
+ }
312
+
313
+ let index = 5;
314
+ let parameters = {
315
+ allowRoles: ["*"],
316
+ denyRoles: [],
317
+ features: ["auth", "file", "mail"],
318
+ accessModifier: "internal"
319
+ };
320
+ let alias = "default";
321
+ while (index < args.length) {
322
+ switch (args[index]) {
323
+ case "roles":
324
+ index++;
325
+ const strRoles = args[index];
326
+ if (strRoles) {
327
+ const minusIndex = strRoles.indexOf("-");
328
+ let grantedRoles = minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
329
+ const deniedRoles = minusIndex == -1 ? "" : strRoles.substring(minusIndex + 1);
330
+ if (!grantedRoles)
331
+ grantedRoles = "*";
332
+ parameters.allowRoles = grantedRoles.split(",");
333
+ if (deniedRoles)
334
+ parameters.denyRoles = deniedRoles.split(",");
335
+ }
336
+ break;
337
+ case "alias":
338
+ index++;
339
+ const strAlias = args[index];
340
+ if (strAlias)
341
+ alias = strAlias;
342
+ break;
343
+ case "access-modifier":
344
+ index++;
345
+ const strAccessModifier = args[index];
346
+ if (strAccessModifier)
347
+ parameters.accessModifier = strAccessModifier;
348
+ break;
349
+ case "features":
350
+ index++;
351
+ const strFeatures = args[index];
352
+ if (strFeatures) {
353
+ parameters.features = strFeatures.split(",");
354
+ }
355
+ break;
356
+ }
357
+ index++;
358
+ }
359
+
360
+ const project = mushroomConfig.projects[projectName];
361
+ project.csharpDriver = project.csharpDriver || {};
362
+ project.csharpDriver.alias = project.csharpDriver.alias || {};
363
+ const projectAlias = project.csharpDriver.alias[alias] = project.csharpDriver.alias[alias] || {};
364
+ for (const key in parameters) {
365
+ if (parameters.hasOwnProperty(key)) {
366
+ const value = parameters[key];
367
+ projectAlias[key] = value;
368
+ }
369
+ }
370
+ projectAlias.output = path;
371
+ saveConfig(mushroomConfig, () => console.log(`Saved configuration of gen CSharp driver for ${projectName}@${alias}`));
372
+ }
373
+
374
+ function configGen(args) {
375
+ const projectName = args[2];
376
+
377
+ let mushroomConfig;
378
+ try {
379
+ const mushroomConfigContent = fs.readFileSync("./mushroom-config.json").toString();
380
+ mushroomConfig = JSON.parse(mushroomConfigContent);
381
+ }
382
+ catch (e) {
383
+ console.error("mushroom-config.json not found or unable to parse");
384
+ throw e;
385
+ }
386
+
387
+ if (!mushroomConfig || !mushroomConfig.projects || !mushroomConfig.projects[projectName])
388
+ throw new Error(`Project not found (${projectName})`);
389
+
390
+ const type = args[3];
391
+ switch (type) {
392
+ case "docs":
393
+ configGenDocs(args, mushroomConfig, projectName);
394
+ break;
395
+ case "db-docs":
396
+ configGenDatabaseDocs(args, mushroomConfig, projectName);
397
+ break;
398
+ case "js-driver":
399
+ configGenJavascriptDriver(args, mushroomConfig, projectName);
400
+ break;
401
+ case "ts-driver":
402
+ configGenTypescriptDriver(args, mushroomConfig, projectName);
403
+ break;
404
+ case "c#-mongo":
405
+ configGenCSharpMongo(args, mushroomConfig, projectName);
406
+ break;
407
+ case "c#-driver":
408
+ configGenCSharpDriver(args, mushroomConfig, projectName);
409
+ break;
410
+ case "":
411
+ case undefined:
412
+ case "help":
413
+ case "man":
414
+ help(args);
415
+ break;
416
+ default:
417
+ help(args, true);
418
+ break;
419
+ }
420
+ }
421
+ //#endregion
422
+
423
+ function config(args){
424
+ const configCommand = args[1];
425
+ switch(configCommand) {
426
+ case "add":
427
+ configAdd(args);
428
+ break;
429
+ case "gen":
430
+ configGen(args);
431
+ break;
432
+ case "":
433
+ case undefined:
434
+ case "help":
435
+ case "man":
436
+ help("config");
437
+ break;
438
+ default:
439
+ help(args, true);
440
+ break;
441
+ }
442
+
443
+ }
444
+
445
+ module.exports = config;