mushroom-cli 1.2.0-alpha.11 → 1.2.0-alpha.13

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.
Files changed (43) hide show
  1. package/README.md +233 -223
  2. package/dist/check-update.js +5 -0
  3. package/dist/common.js +260 -0
  4. package/dist/config.js +394 -0
  5. package/dist/docs/docs.v2.js +1907 -0
  6. package/dist/gen/gen-api-docs-v1.js +110 -0
  7. package/dist/gen/gen-api-docs.js +295 -0
  8. package/{gen → dist/gen}/gen-csharp.js +1265 -1399
  9. package/{gen → dist/gen}/gen-db-docs.js +204 -222
  10. package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
  11. package/{gen → dist/gen}/gen-js-driver.js +116 -133
  12. package/{gen → dist/gen}/gen-ts-driver.js +427 -467
  13. package/{gen.js → dist/gen.js} +109 -124
  14. package/{help.js → dist/help.js} +53 -55
  15. package/dist/init/init-json.js +91 -0
  16. package/dist/init/init-netcore.js +30 -0
  17. package/dist/init.js +23 -0
  18. package/dist/master-file/master-file.js +185 -0
  19. package/dist/merge.js +70 -0
  20. package/dist/mr.js +75 -0
  21. package/dist/types.js +1 -0
  22. package/dist/update/tsCode.js +82 -0
  23. package/dist/update.js +20 -0
  24. package/package.json +55 -29
  25. package/check-update.js +0 -9
  26. package/common.js +0 -283
  27. package/config.js +0 -445
  28. package/docs/docs.v2.js +0 -1633
  29. package/gen/gen-api-docs-v1.js +0 -125
  30. package/gen/gen-api-docs.js +0 -298
  31. package/init/init-json.js +0 -106
  32. package/init/init-netcore.js +0 -32
  33. package/init.js +0 -28
  34. package/master-file/master-file.js +0 -234
  35. package/merge.js +0 -84
  36. package/mr.js +0 -82
  37. package/update/tsCode.js +0 -20
  38. package/update.js +0 -24
  39. /package/{docs → dist/docs}/doc-mt.js +0 -0
  40. /package/{docs → dist/docs}/docs.html +0 -0
  41. /package/{docs → dist/docs}/docs.v2.html +0 -0
  42. /package/{docs → dist/docs}/mt-dom-1.0.js +0 -0
  43. /package/{docs → dist/docs}/mt.extension.js +0 -0
package/dist/common.js ADDED
@@ -0,0 +1,260 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import readlineSync from 'readline-sync';
4
+ export function ensureFolder(path, isFolder) {
5
+ const index = path.lastIndexOf('/');
6
+ if (!isFolder && index <= 0) {
7
+ return;
8
+ }
9
+ if (!isFolder)
10
+ path = path.substring(0, index);
11
+ if (path === '.' || path === '..')
12
+ return;
13
+ if (!fs.existsSync(path)) {
14
+ fs.mkdirSync(path, { recursive: true, mode: 0o755 });
15
+ }
16
+ }
17
+ export function getRootUrl(projectApiConfiguration) {
18
+ return projectApiConfiguration.codeHint && projectApiConfiguration.codeHint.rootUrl
19
+ ? projectApiConfiguration.codeHint.rootUrl
20
+ : projectApiConfiguration.rootUrl;
21
+ }
22
+ export function getEntities(projectApiConfiguration, roles, getAll) {
23
+ if (!projectApiConfiguration || !projectApiConfiguration.entities || !Array.isArray(projectApiConfiguration.entities))
24
+ return {};
25
+ const entities = {};
26
+ projectApiConfiguration.entities.forEach((entity) => {
27
+ if (entity.disabled)
28
+ return;
29
+ if (getAll) {
30
+ entities[entity.name] = entity;
31
+ entity.storageName = entity.storageName ? entity.storageName : entity.name;
32
+ if (!roles || !roles.length)
33
+ roles = ['*'];
34
+ return;
35
+ }
36
+ for (const actionName in entity.actions) {
37
+ entity.actions[actionName].forEach((action) => {
38
+ var _a;
39
+ if (!action.grant || !action.enabled || (action.codeHint && action.codeHint.disabled))
40
+ return;
41
+ let allow = roles?.includes('*') || action.grant === '*';
42
+ if (!allow)
43
+ action.grant.split('|').forEach(function (roleGroup) {
44
+ if (!roleGroup)
45
+ return;
46
+ roleGroup.split('+').forEach(function (grantedRole) {
47
+ if (roles?.indexOf(grantedRole) !== -1)
48
+ allow = true;
49
+ });
50
+ });
51
+ if (!allow)
52
+ return;
53
+ if (!(entity.name in entities)) {
54
+ entities[entity.name] = {
55
+ name: entity.name,
56
+ description: entity.description,
57
+ storageName: entity.storageName ? entity.storageName : entity.name,
58
+ fields: entity.fields,
59
+ views: {},
60
+ };
61
+ }
62
+ const actions = ((_a = entities[entity.name]).actions ?? (_a.actions = {}));
63
+ actions[actionName] ?? (actions[actionName] = []);
64
+ actions[actionName].push(action);
65
+ });
66
+ }
67
+ for (const viewName in entity.views) {
68
+ entity.views[viewName].forEach(function (view) {
69
+ var _a;
70
+ if (!view.grant || !view.enabled)
71
+ return;
72
+ let allow = roles?.indexOf('*') !== -1 || view.grant === '*';
73
+ view.grant.split('|').forEach(function (roleGroup) {
74
+ if (!roleGroup)
75
+ return;
76
+ roleGroup.split('+').forEach(function (grantedRole) {
77
+ if (roles?.indexOf(grantedRole) !== -1)
78
+ allow = true;
79
+ });
80
+ });
81
+ if (!allow)
82
+ return;
83
+ if (!(entity.name in entities)) {
84
+ entities[entity.name] = {
85
+ name: entity.name,
86
+ description: entity.description,
87
+ storageName: entity.storageName ? entity.storageName : entity.name,
88
+ fields: entity.fields,
89
+ actions: {},
90
+ views: {},
91
+ };
92
+ }
93
+ const views = ((_a = entities[entity.name]).views ?? (_a.views = {}));
94
+ views[viewName] ?? (views[viewName] = []);
95
+ views[viewName].push(view);
96
+ });
97
+ }
98
+ if (entity.name in entities) {
99
+ entities[entity.name].features = entity.features;
100
+ }
101
+ });
102
+ return entities;
103
+ }
104
+ export function filterRoles(roleList, allowRoleList) {
105
+ const roles = !allowRoleList || allowRoleList.includes('*')
106
+ ? [...roleList]
107
+ : roleList.filter((role) => allowRoleList.includes(role.name));
108
+ roles.push({
109
+ name: '[Mọi người dùng]',
110
+ description: 'Tất cả người dùng (kể cả chưa đăng nhập)',
111
+ });
112
+ return roles;
113
+ }
114
+ export function processTemplate(basePath, templatePath) {
115
+ const templateJsonContent = fs.readFileSync(path.join(basePath, templatePath)).toString();
116
+ const template = JSON.parse(templateJsonContent);
117
+ if (template && typeof template !== 'object') {
118
+ throw new TypeError(`Invalid template file ${templatePath}`);
119
+ }
120
+ const commands = template.steps;
121
+ if (!Array.isArray(commands)) {
122
+ throw new TypeError(`Invalid template file ${templatePath}`);
123
+ }
124
+ const variables = {};
125
+ commands.forEach((command) => processCommand(command, basePath, variables));
126
+ return variables;
127
+ }
128
+ function processCommand(command, basePath, variables) {
129
+ const commandName = command.command;
130
+ switch (commandName) {
131
+ case 'input':
132
+ processInputCommand(command, variables);
133
+ return;
134
+ case 'set':
135
+ processSetCommand(command, variables);
136
+ return;
137
+ case 'rename':
138
+ processRenameCommand(command, basePath, variables);
139
+ return;
140
+ case 'delete':
141
+ processDeleteCommand(command, basePath, variables);
142
+ return;
143
+ case 'replace':
144
+ processReplaceCommand(command, basePath, variables);
145
+ return;
146
+ default:
147
+ throw new Error(`Unknown command: ${commandName}`);
148
+ }
149
+ }
150
+ function processInputCommand(command, variables) {
151
+ const value = readlineSync.question(command.message ?? '');
152
+ if (command.validation) {
153
+ if (command.validation.required) {
154
+ if (value === '')
155
+ throw new TypeError(`${command.variable} is required`);
156
+ }
157
+ if (command.validation.pattern) {
158
+ if (!new RegExp(command.validation.pattern).test(value))
159
+ throw new Error(`${value} is not valid`);
160
+ }
161
+ }
162
+ variables[command.variable] = value;
163
+ }
164
+ function processSetCommand(command, variables) {
165
+ switch (command['function']) {
166
+ case 'New-GUID':
167
+ processSetNewGuidCommand(command.variable, variables);
168
+ break;
169
+ case 'New-RandomNumber':
170
+ processSetNewRandomNumberCommand(command.variable, variables, command.min, command.max);
171
+ break;
172
+ case 'New-RandomString':
173
+ processSetNewRandomStringCommand(command.variable, variables, command.length, command.characterPool);
174
+ break;
175
+ case 'ToLowerCase':
176
+ toLowerCommand(command.variable, variables, command.input);
177
+ break;
178
+ case 'ToUpperCase':
179
+ toUpperCaseCommand(command.variable, variables, command.input);
180
+ break;
181
+ case 'Trim':
182
+ trimCommand(command.variable, variables, command.input);
183
+ break;
184
+ case 'Replace':
185
+ replaceCommand(command.variable, variables, command.input, command.replacement, command.pattern, command.mode);
186
+ break;
187
+ default:
188
+ throw new Error(`Unknown set-command: ${command['function']}`);
189
+ }
190
+ }
191
+ function processSetNewGuidCommand(variable, variables) {
192
+ variables[variable] = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
193
+ .replace(/[xy]/g, (c) => {
194
+ const r = (Math.random() * 16) | 0;
195
+ const v = c == 'x' ? r : (r & 0x3) | 0x8;
196
+ return v.toString(16);
197
+ })
198
+ .toUpperCase();
199
+ }
200
+ function processSetNewRandomNumberCommand(variable, variables, min = 0, max = (1 << 30) * 4) {
201
+ variables[variable] = Math.floor(min + Math.random() * (max - min)).toString();
202
+ }
203
+ function processSetNewRandomStringCommand(variable, variables, length, characterPool = '1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM') {
204
+ let result = '';
205
+ for (let i = 0; i < length; i++) {
206
+ result += characterPool.charAt(Math.floor(Math.random() * characterPool.length));
207
+ }
208
+ variables[variable] = result;
209
+ }
210
+ function toLowerCommand(variable, variables, input) {
211
+ variables[variable] = variables[input].toLowerCase();
212
+ }
213
+ function toUpperCaseCommand(variable, variables, input) {
214
+ variables[variable] = variables[input].toUpperCase();
215
+ }
216
+ function trimCommand(variable, variables, input) {
217
+ variables[variable] = variables[input].trim();
218
+ }
219
+ function replaceCommand(variable, variables, input, replacement, pattern, mode) {
220
+ const regex = new RegExp(pattern, mode);
221
+ variables[variable] = variables[input].replace(regex, replacement);
222
+ }
223
+ function processRenameCommand(command, basePath, variables) {
224
+ const input = replaceVariables(command.input, variables);
225
+ const output = replaceVariables(command.output, variables);
226
+ fs.renameSync(path.join(basePath, input), path.join(basePath, output));
227
+ }
228
+ function processDeleteCommand(command, basePath, variables) {
229
+ const input = replaceVariables(command.input, variables);
230
+ const deletedPath = path.join(basePath, input);
231
+ if (fs.lstatSync(deletedPath).isDirectory()) {
232
+ fs.rmSync(deletedPath, { recursive: true, force: true });
233
+ }
234
+ else {
235
+ fs.rmSync(deletedPath, { force: true });
236
+ }
237
+ }
238
+ function processReplaceCommand(command, basePath, variables) {
239
+ const files = command.input;
240
+ const pattern = new RegExp(command.pattern ?? '', 'g');
241
+ const replacement = replaceVariables(command.replacement ?? '', variables);
242
+ files.forEach((file) => {
243
+ const filePath = replaceVariables(file, variables);
244
+ let content = fs.readFileSync(path.join(basePath, filePath)).toString();
245
+ content = content.replace(pattern, () => replacement);
246
+ fs.writeFileSync(path.join(basePath, filePath), content);
247
+ });
248
+ }
249
+ function replaceVariables(str, variables) {
250
+ return str.replace(/\$\{(\w+)\}/g, (_, varName) => variables[varName] ?? '');
251
+ }
252
+ export function logInfo(message, ...parameters) {
253
+ console.log(message, ...parameters);
254
+ }
255
+ export function logWarning(message, ...parameters) {
256
+ console.warn(message, ...parameters);
257
+ }
258
+ export function logError(message, ...parameters) {
259
+ console.error(message, ...parameters);
260
+ }
package/dist/config.js ADDED
@@ -0,0 +1,394 @@
1
+ import fs from 'fs';
2
+ import JSON5 from 'json5';
3
+ import help from './help.js';
4
+ import * as common from './common.js';
5
+ function saveConfig(mushroomConfig, success) {
6
+ mushroomConfig['$schema'] = 'http://schema.siten.vn/mushroom/mushroom-cli.json';
7
+ fs.writeFile('./mushroom-config.json', JSON.stringify(mushroomConfig, null, ' '), (err) => {
8
+ if (err)
9
+ throw err;
10
+ if (typeof success === 'function')
11
+ success();
12
+ });
13
+ }
14
+ function copyProperties(source, destination) {
15
+ for (const key in source) {
16
+ destination[key] = source[key];
17
+ }
18
+ }
19
+ function configAdd(args) {
20
+ const filePath = args[2];
21
+ if (!filePath) {
22
+ help('config add', true);
23
+ return;
24
+ }
25
+ const fileContent = fs.readFileSync(filePath).toString();
26
+ const project = JSON5.parse(fileContent);
27
+ if (!project.name) {
28
+ throw new TypeError(`Missing name in ${filePath}`);
29
+ }
30
+ let mushroomConfigContent;
31
+ try {
32
+ mushroomConfigContent = fs.readFileSync('./mushroom-config.json').toString();
33
+ }
34
+ catch {
35
+ mushroomConfigContent = null;
36
+ }
37
+ const mushroomConfig = mushroomConfigContent ? JSON.parse(mushroomConfigContent) : {};
38
+ mushroomConfig.projects = mushroomConfig.projects || {};
39
+ mushroomConfig.projects[project.name] = mushroomConfig.projects[project.name] || {};
40
+ mushroomConfig.projects[project.name].src = filePath;
41
+ saveConfig(mushroomConfig, () => common.logInfo('Added', filePath, 'in project', project.name));
42
+ }
43
+ function configGenDocs(args, mushroomConfig, projectName) {
44
+ const path = args[4];
45
+ if (!path) {
46
+ help(args);
47
+ return;
48
+ }
49
+ let index = 5;
50
+ const parameters = {
51
+ output: path,
52
+ features: [],
53
+ allowRoles: ['*'],
54
+ denyRoles: [],
55
+ };
56
+ let alias = 'default';
57
+ while (index < args.length) {
58
+ switch (args[index]) {
59
+ case 'features': {
60
+ index++;
61
+ const strFeatures = args[index];
62
+ if (strFeatures)
63
+ parameters.features = strFeatures.split(',');
64
+ break;
65
+ }
66
+ case 'roles': {
67
+ index++;
68
+ const strRoles = args[index];
69
+ if (strRoles) {
70
+ const minusIndex = strRoles.indexOf('-');
71
+ let grantedRoles = minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
72
+ const deniedRoles = minusIndex == -1 ? '' : strRoles.substring(minusIndex + 1);
73
+ if (!grantedRoles)
74
+ grantedRoles = '*';
75
+ parameters.allowRoles = grantedRoles.split(',');
76
+ if (deniedRoles)
77
+ parameters.denyRoles = deniedRoles.split(',');
78
+ }
79
+ break;
80
+ }
81
+ case 'alias': {
82
+ index++;
83
+ const strAlias = args[index];
84
+ if (strAlias)
85
+ alias = strAlias;
86
+ break;
87
+ }
88
+ }
89
+ index++;
90
+ }
91
+ const project = mushroomConfig.projects[projectName];
92
+ const docs = project.docs || {};
93
+ docs.alias = docs.alias || {};
94
+ const projectAlias = (docs.alias[alias] = docs.alias[alias] || {});
95
+ copyProperties(parameters, projectAlias);
96
+ saveConfig(mushroomConfig, () => common.logInfo(`Saved configuration of gen docs for ${projectName}@${alias}`));
97
+ }
98
+ function configGenDatabaseDocs(args, mushroomConfig, projectName) {
99
+ const path = args[4];
100
+ if (!path) {
101
+ help(args);
102
+ return;
103
+ }
104
+ let index = 5;
105
+ const parameters = {
106
+ output: path,
107
+ features: [],
108
+ };
109
+ let alias = 'default';
110
+ while (index < args.length) {
111
+ switch (args[index]) {
112
+ case 'features': {
113
+ index++;
114
+ const strFeatures = args[index];
115
+ if (strFeatures)
116
+ parameters.features = strFeatures.split(',');
117
+ break;
118
+ }
119
+ case 'alias': {
120
+ index++;
121
+ const strAlias = args[index];
122
+ if (strAlias)
123
+ alias = strAlias;
124
+ break;
125
+ }
126
+ }
127
+ index++;
128
+ }
129
+ const project = mushroomConfig.projects[projectName];
130
+ const dbDocs = project.dbDocs || {};
131
+ dbDocs.alias = dbDocs.alias || {};
132
+ const projectAlias = (dbDocs.alias[alias] = dbDocs.alias[alias] || {});
133
+ copyProperties(parameters, projectAlias);
134
+ saveConfig(mushroomConfig, () => common.logInfo(`Saved configuration of gen db-docs for ${projectName}@${alias}`));
135
+ }
136
+ function configGenJavascriptDriver(args, mushroomConfig, projectName) {
137
+ const path = args[4];
138
+ if (!path) {
139
+ help(args);
140
+ return;
141
+ }
142
+ let index = 5;
143
+ const parameters = {
144
+ output: path,
145
+ allowRoles: ['*'],
146
+ denyRoles: [],
147
+ };
148
+ let alias = 'default';
149
+ while (index < args.length) {
150
+ switch (args[index]) {
151
+ case 'roles': {
152
+ index++;
153
+ const strRoles = args[index];
154
+ if (strRoles) {
155
+ const minusIndex = strRoles.indexOf('-');
156
+ let grantedRoles = minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
157
+ const deniedRoles = minusIndex == -1 ? '' : strRoles.substring(minusIndex + 1);
158
+ if (!grantedRoles)
159
+ grantedRoles = '*';
160
+ parameters.allowRoles = grantedRoles.split(',');
161
+ if (deniedRoles)
162
+ parameters.denyRoles = deniedRoles.split(',');
163
+ }
164
+ break;
165
+ }
166
+ case 'alias': {
167
+ index++;
168
+ const strAlias = args[index];
169
+ if (strAlias)
170
+ alias = strAlias;
171
+ break;
172
+ }
173
+ case 'tarball': {
174
+ index++;
175
+ const strTarball = args[index];
176
+ if (strTarball)
177
+ parameters.tarballName = strTarball;
178
+ break;
179
+ }
180
+ }
181
+ index++;
182
+ }
183
+ const project = mushroomConfig.projects[projectName];
184
+ const jsDriver = project.jsDriver || {};
185
+ jsDriver.alias = jsDriver.alias || {};
186
+ const projectAlias = (jsDriver.alias[alias] = jsDriver.alias[alias] || {});
187
+ copyProperties(parameters, projectAlias);
188
+ saveConfig(mushroomConfig, () => common.logInfo(`Saved configuration of gen javascript driver for ${projectName}@${alias}`));
189
+ }
190
+ function configGenTypescriptDriver(args, mushroomConfig, projectName) {
191
+ const path = args[4];
192
+ if (!path) {
193
+ help(args);
194
+ return;
195
+ }
196
+ let index = 5;
197
+ const parameters = {
198
+ output: path,
199
+ allowRoles: ['*'],
200
+ denyRoles: [],
201
+ };
202
+ let alias = 'default';
203
+ while (index < args.length) {
204
+ switch (args[index]) {
205
+ case 'roles': {
206
+ index++;
207
+ const strRoles = args[index];
208
+ if (strRoles) {
209
+ const minusIndex = strRoles.indexOf('-');
210
+ let grantedRoles = minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
211
+ const deniedRoles = minusIndex == -1 ? '' : strRoles.substring(minusIndex + 1);
212
+ if (!grantedRoles)
213
+ grantedRoles = '*';
214
+ parameters.allowRoles = grantedRoles.split(',');
215
+ if (deniedRoles)
216
+ parameters.denyRoles = deniedRoles.split(',');
217
+ }
218
+ break;
219
+ }
220
+ case 'alias': {
221
+ index++;
222
+ const strAlias = args[index];
223
+ if (strAlias)
224
+ alias = strAlias;
225
+ break;
226
+ }
227
+ }
228
+ index++;
229
+ }
230
+ const project = mushroomConfig.projects[projectName];
231
+ const tsDriver = project.tsDriver || {};
232
+ tsDriver.alias = tsDriver.alias || {};
233
+ const projectAlias = (tsDriver.alias[alias] = tsDriver.alias[alias] || {});
234
+ copyProperties(parameters, projectAlias);
235
+ saveConfig(mushroomConfig, () => common.logInfo(`Saved configuration of gen javascript driver for ${projectName}@${alias}`));
236
+ }
237
+ function configGenCSharpMongo(args, mushroomConfig, projectName) {
238
+ const path = args[4];
239
+ if (!path) {
240
+ help(args);
241
+ return;
242
+ }
243
+ let index = 5;
244
+ const parameters = {
245
+ output: path,
246
+ };
247
+ let alias = 'default';
248
+ while (index < args.length) {
249
+ switch (args[index]) {
250
+ case 'alias': {
251
+ index++;
252
+ const strAlias = args[index];
253
+ if (strAlias)
254
+ alias = strAlias;
255
+ break;
256
+ }
257
+ }
258
+ index++;
259
+ }
260
+ const project = mushroomConfig.projects[projectName];
261
+ const csharpMongo = project.csharpMongo || {};
262
+ csharpMongo.alias = csharpMongo.alias || {};
263
+ const projectAlias = (csharpMongo.alias[alias] = csharpMongo.alias[alias] || {});
264
+ copyProperties(parameters, projectAlias);
265
+ saveConfig(mushroomConfig, () => common.logInfo(`Saved configuration of gen CSharp/MongoDb classes for ${projectName}@${alias}`));
266
+ }
267
+ function configGenCSharpDriver(args, mushroomConfig, projectName) {
268
+ const path = args[4];
269
+ if (!path) {
270
+ help(args);
271
+ return;
272
+ }
273
+ let index = 5;
274
+ const parameters = {
275
+ output: path,
276
+ allowRoles: ['*'],
277
+ denyRoles: [],
278
+ features: ['auth', 'file', 'mail'],
279
+ accessModifier: 'internal',
280
+ };
281
+ let alias = 'default';
282
+ while (index < args.length) {
283
+ switch (args[index]) {
284
+ case 'roles': {
285
+ index++;
286
+ const strRoles = args[index];
287
+ if (strRoles) {
288
+ const minusIndex = strRoles.indexOf('-');
289
+ let grantedRoles = minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
290
+ const deniedRoles = minusIndex == -1 ? '' : strRoles.substring(minusIndex + 1);
291
+ if (!grantedRoles)
292
+ grantedRoles = '*';
293
+ parameters.allowRoles = grantedRoles.split(',');
294
+ if (deniedRoles)
295
+ parameters.denyRoles = deniedRoles.split(',');
296
+ }
297
+ break;
298
+ }
299
+ case 'alias': {
300
+ index++;
301
+ const strAlias = args[index];
302
+ if (strAlias)
303
+ alias = strAlias;
304
+ break;
305
+ }
306
+ case 'access-modifier': {
307
+ index++;
308
+ const strAccessModifier = args[index];
309
+ if (strAccessModifier)
310
+ parameters.accessModifier = strAccessModifier;
311
+ break;
312
+ }
313
+ case 'features': {
314
+ index++;
315
+ const strFeatures = args[index];
316
+ if (strFeatures) {
317
+ parameters.features = strFeatures.split(',');
318
+ }
319
+ break;
320
+ }
321
+ }
322
+ index++;
323
+ }
324
+ const project = mushroomConfig.projects[projectName];
325
+ const csharpDriver = project.csharpDriver || {};
326
+ csharpDriver.alias = csharpDriver.alias || {};
327
+ const projectAlias = (csharpDriver.alias[alias] = csharpDriver.alias[alias] || {});
328
+ copyProperties(parameters, projectAlias);
329
+ saveConfig(mushroomConfig, () => common.logInfo(`Saved configuration of gen CSharp driver for ${projectName}@${alias}`));
330
+ }
331
+ function configGen(args) {
332
+ const projectName = args[2];
333
+ let mushroomConfig;
334
+ try {
335
+ const mushroomConfigContent = fs.readFileSync('./mushroom-config.json').toString();
336
+ mushroomConfig = JSON.parse(mushroomConfigContent);
337
+ }
338
+ catch (e) {
339
+ common.logError('mushroom-config.json not found or unable to parse');
340
+ throw e;
341
+ }
342
+ if (!mushroomConfig || !mushroomConfig.projects || !mushroomConfig.projects[projectName])
343
+ throw new Error(`Project not found (${projectName})`);
344
+ const type = args[3];
345
+ switch (type) {
346
+ case 'docs':
347
+ configGenDocs(args, mushroomConfig, projectName);
348
+ break;
349
+ case 'db-docs':
350
+ configGenDatabaseDocs(args, mushroomConfig, projectName);
351
+ break;
352
+ case 'js-driver':
353
+ configGenJavascriptDriver(args, mushroomConfig, projectName);
354
+ break;
355
+ case 'ts-driver':
356
+ configGenTypescriptDriver(args, mushroomConfig, projectName);
357
+ break;
358
+ case 'c#-mongo':
359
+ configGenCSharpMongo(args, mushroomConfig, projectName);
360
+ break;
361
+ case 'c#-driver':
362
+ configGenCSharpDriver(args, mushroomConfig, projectName);
363
+ break;
364
+ case '':
365
+ case undefined:
366
+ case 'help':
367
+ case 'man':
368
+ help(args);
369
+ break;
370
+ default:
371
+ help(args, true);
372
+ break;
373
+ }
374
+ }
375
+ export default function config(args) {
376
+ const configCommand = args[1];
377
+ switch (configCommand) {
378
+ case 'add':
379
+ configAdd(args);
380
+ break;
381
+ case 'gen':
382
+ configGen(args);
383
+ break;
384
+ case '':
385
+ case undefined:
386
+ case 'help':
387
+ case 'man':
388
+ help('config');
389
+ break;
390
+ default:
391
+ help(args, true);
392
+ break;
393
+ }
394
+ }