mushroom-cli 1.2.0-alpha.2 → 1.2.0-alpha.20
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/README.md +273 -111
- package/dist/check-update.js +6 -0
- package/dist/common.js +273 -0
- package/dist/config.js +394 -0
- package/dist/docs/bootstrap-theme.min.css +6 -0
- package/dist/docs/bootstrap.min.css +6 -0
- package/dist/docs/bootstrap.min.js +7 -0
- package/{docs → dist/docs}/doc-mt.js +103 -1
- package/{docs → dist/docs}/docs.html +83 -22
- package/dist/docs/docs.v2.html +5097 -0
- package/dist/docs/docs.v2.js +1907 -0
- package/dist/docs/jquery.min.js +4 -0
- package/dist/gen/gen-api-docs-v1.js +110 -0
- package/dist/gen/gen-api-docs.js +306 -0
- package/{gen → dist/gen}/gen-csharp.js +1246 -1414
- package/{gen → dist/gen}/gen-db-docs.js +204 -222
- package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
- package/{gen → dist/gen}/gen-js-driver.js +116 -133
- package/dist/gen/gen-ts-driver.js +596 -0
- package/{gen.js → dist/gen.js} +109 -120
- package/{help.js → dist/help.js} +53 -55
- package/dist/init/init-json.js +92 -0
- package/dist/init/init-netcore.js +30 -0
- package/dist/init.js +23 -0
- package/dist/master-file/master-file.js +185 -0
- package/dist/merge.js +70 -0
- package/dist/mr.js +77 -0
- package/dist/types.js +1 -0
- package/dist/update/tsCode.js +82 -0
- package/dist/update.js +20 -0
- package/package.json +64 -27
- package/check-update.js +0 -9
- package/common.js +0 -236
- package/config.js +0 -445
- package/gen/gen-api-docs.js +0 -125
- package/gen/gen-ts-driver.js +0 -460
- package/init/init-json.js +0 -106
- package/init/init-netcore.js +0 -32
- package/init.js +0 -28
- package/master-file/master-file.js +0 -234
- package/merge.js +0 -84
- package/mr.js +0 -82
- package/update/tsCode.js +0 -20
- package/update.js +0 -24
- /package/{docs → dist/docs}/mt-dom-1.0.js +0 -0
- /package/{docs → dist/docs}/mt.extension.js +0 -0
package/common.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const readlineSync = require("readline-sync");
|
|
4
|
-
|
|
5
|
-
function ensureFolder(path, isFolder) {
|
|
6
|
-
const index = path.lastIndexOf("/");
|
|
7
|
-
if (!isFolder && index <= 0){
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (!isFolder) path = path.substring(0, index);
|
|
11
|
-
if (path === "." || path === "..")
|
|
12
|
-
return;
|
|
13
|
-
|
|
14
|
-
if (!fs.existsSync(path)) {
|
|
15
|
-
fs.mkdirSync(path, { recursive: true, mode: 0755 });
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getRootUrl(projectApiConfiguration) {
|
|
20
|
-
return projectApiConfiguration.codeHint && projectApiConfiguration.codeHint.rootUrl
|
|
21
|
-
? projectApiConfiguration.codeHint.rootUrl
|
|
22
|
-
: projectApiConfiguration.rootUrl;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function getEntities(projectApiConfiguration, roles, getAll) {
|
|
26
|
-
if (!projectApiConfiguration || !projectApiConfiguration.entities || !Array.isArray(projectApiConfiguration.entities))
|
|
27
|
-
return {};
|
|
28
|
-
|
|
29
|
-
const entities = {};
|
|
30
|
-
projectApiConfiguration.entities.forEach(entity => {
|
|
31
|
-
|
|
32
|
-
if (entity.disabled)
|
|
33
|
-
return;
|
|
34
|
-
|
|
35
|
-
if (getAll) {
|
|
36
|
-
entities[entity.name] = entity;
|
|
37
|
-
entity.storageName = entity.storageName ? entity.storageName : entity.name;
|
|
38
|
-
if (!roles || !roles.length)
|
|
39
|
-
roles = ["*"];
|
|
40
|
-
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
for (var actionName in entity.actions) {
|
|
45
|
-
if (!entity.actions.hasOwnProperty(actionName))
|
|
46
|
-
continue;
|
|
47
|
-
|
|
48
|
-
entity.actions[actionName].forEach(action => {
|
|
49
|
-
if (!action.grant || !action.enabled || action.codeHint && action.codeHint.disabled)
|
|
50
|
-
return;
|
|
51
|
-
|
|
52
|
-
var allow = roles.indexOf("*") !== -1 || action.grant === "*";
|
|
53
|
-
|
|
54
|
-
if (!allow)
|
|
55
|
-
action.grant.split("|").forEach(function (roleGroup) {
|
|
56
|
-
if (!roleGroup)
|
|
57
|
-
return;
|
|
58
|
-
roleGroup.split("+").forEach(function (grantedRole) {
|
|
59
|
-
if (roles.indexOf(grantedRole) !== -1)
|
|
60
|
-
allow = true;
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
if (!allow)
|
|
65
|
-
return;
|
|
66
|
-
|
|
67
|
-
if (!(entity.name in entities))
|
|
68
|
-
entities[entity.name] = {
|
|
69
|
-
description: entity.description,
|
|
70
|
-
storageName: entity.storageName ? entity.storageName : entity.name,
|
|
71
|
-
fields: entity.fields,
|
|
72
|
-
actions: {},
|
|
73
|
-
views: {}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
if (!entities[entity.name].actions[actionName])
|
|
77
|
-
entities[entity.name].actions[actionName] = [];
|
|
78
|
-
|
|
79
|
-
entities[entity.name].actions[actionName].push(action);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
for (var viewName in entity.views) {
|
|
85
|
-
if (!entity.views.hasOwnProperty(viewName))
|
|
86
|
-
continue;
|
|
87
|
-
|
|
88
|
-
entity.views[viewName].forEach(function(view) {
|
|
89
|
-
if (!view.grant || !view.enabled)
|
|
90
|
-
return;
|
|
91
|
-
|
|
92
|
-
var allow = roles.indexOf("*") !== -1 || view.grant === "*";
|
|
93
|
-
|
|
94
|
-
view.grant.split("|").forEach(function (roleGroup) {
|
|
95
|
-
if (!roleGroup)
|
|
96
|
-
return;
|
|
97
|
-
roleGroup.split("+").forEach(function (grantedRole) {
|
|
98
|
-
if (roles.indexOf(grantedRole) !== -1)
|
|
99
|
-
allow = true;
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
if (!allow)
|
|
104
|
-
return;
|
|
105
|
-
|
|
106
|
-
if (!(entity.name in entities))
|
|
107
|
-
entities[entity.name] = {
|
|
108
|
-
description: entity.description,
|
|
109
|
-
storageName: entity.storageName ? entity.storageName : entity.name,
|
|
110
|
-
fields: entity.fields,
|
|
111
|
-
actions: {},
|
|
112
|
-
views: {}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
if (!entities[entity.name].views[viewName])
|
|
116
|
-
entities[entity.name].views[viewName] = [];
|
|
117
|
-
|
|
118
|
-
entities[entity.name].views[viewName].push(view);
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (entity.name in entities) {
|
|
123
|
-
entities[entity.name].features = entity.features;
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
return entities;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function processTemplate(basePath, templatePath) {
|
|
131
|
-
const templateJsonContent = fs.readFileSync(path.join(basePath, templatePath)).toString();
|
|
132
|
-
const template = JSON.parse(templateJsonContent);
|
|
133
|
-
if (template && typeof template !== "object") {
|
|
134
|
-
throw new TypeError(`Invalid template file ${templatePath}`);
|
|
135
|
-
}
|
|
136
|
-
const commands = template.steps;
|
|
137
|
-
if (!Array.isArray(commands)) {
|
|
138
|
-
throw new TypeError(`Invalid template file ${templatePath}`);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const variables = {};
|
|
142
|
-
commands.forEach(command => processCommand(command, basePath, variables));
|
|
143
|
-
return variables;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function processCommand(command, basePath, variables) {
|
|
147
|
-
switch (command.command) {
|
|
148
|
-
case "input":
|
|
149
|
-
processInputCommand(command, variables);
|
|
150
|
-
return;
|
|
151
|
-
case "set":
|
|
152
|
-
processSetCommand(command, variables);
|
|
153
|
-
return;
|
|
154
|
-
case "rename":
|
|
155
|
-
processRenameCommand(command, basePath, variables);
|
|
156
|
-
return;
|
|
157
|
-
case "delete":
|
|
158
|
-
processDeleteCommand(command, basePath, variables);
|
|
159
|
-
return;
|
|
160
|
-
case "replace":
|
|
161
|
-
processReplaceCommand(command, basePath, variables);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function processInputCommand(command, variables) {
|
|
167
|
-
const value = readlineSync.question(command.message ?? "");
|
|
168
|
-
if (command.validation) {
|
|
169
|
-
if (command.validation.required) {
|
|
170
|
-
if (value === "") throw new TypeError(`${command.variable} is required`);
|
|
171
|
-
}
|
|
172
|
-
if (command.validation.pattern) {
|
|
173
|
-
if (!new RegExp(command.validation.pattern).test(value)) throw new Error(`${value} is not valid`);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
variables[command.variable] = value;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function processSetCommand(command, variables) {
|
|
180
|
-
switch (command["function"]) {
|
|
181
|
-
case "New-GUID":
|
|
182
|
-
processSetGuidCommand(command.variable, variables);
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function processSetGuidCommand(variable, variables) {
|
|
188
|
-
variables[variable] = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
189
|
-
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
190
|
-
return v.toString(16);
|
|
191
|
-
}).toUpperCase();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function processRenameCommand(command, basePath, variables) {
|
|
195
|
-
const input = replaceVariables(command.input, variables);
|
|
196
|
-
const output = replaceVariables(command.output, variables);
|
|
197
|
-
|
|
198
|
-
fs.renameSync(path.join(basePath, input), path.join(basePath, output));
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function processDeleteCommand(command, basePath, variables) {
|
|
202
|
-
const input = replaceVariables(command.input, variables);
|
|
203
|
-
|
|
204
|
-
const deletedPath = path.join(basePath, input);
|
|
205
|
-
if (fs.lstatSync(deletedPath).isDirectory()) {
|
|
206
|
-
// fs.rmdirSync(deletedPath, {recursive: true, force: true});
|
|
207
|
-
fs.rmSync(deletedPath, {recursive: true, force: true});
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
fs.rmSync(deletedPath, {force: true});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function processReplaceCommand(command, basePath, variables) {
|
|
215
|
-
const files = command.input;
|
|
216
|
-
const pattern = new RegExp(command.pattern, "g");
|
|
217
|
-
const replacement = replaceVariables(command.replacement, variables);
|
|
218
|
-
|
|
219
|
-
files.forEach(file => {
|
|
220
|
-
const filePath = replaceVariables(file, variables);
|
|
221
|
-
let content = fs.readFileSync(path.join(basePath, filePath)).toString();
|
|
222
|
-
content = content.replace(pattern, () => replacement);
|
|
223
|
-
fs.writeFileSync(path.join(basePath, filePath), content);
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function replaceVariables(str, variables) {
|
|
228
|
-
return str.replace(/\$\{(\w+)\}/g, (_, varName) => variables[varName] ?? "");
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
module.exports = {
|
|
232
|
-
ensureFolder: ensureFolder,
|
|
233
|
-
getRootUrl: getRootUrl,
|
|
234
|
-
getEntities: getEntities,
|
|
235
|
-
processTemplate: processTemplate
|
|
236
|
-
};
|
package/config.js
DELETED
|
@@ -1,445 +0,0 @@
|
|
|
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;
|