mushroom-cli 1.1.0-alpha.9 → 1.1.0
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 +38 -22
- package/common.js +109 -5
- package/config.js +8 -8
- package/docs/doc-mt.js +421 -0
- package/docs/docs.html +5129 -0
- package/docs/mt-dom-1.0.js +1268 -0
- package/docs/mt.extension.js +174 -0
- package/gen/gen-api-docs.js +5 -5
- package/gen/gen-csharp.js +543 -50
- package/gen/gen-db-docs.js +1 -1
- package/gen/gen-js-driver-tarball.js +4 -2
- package/gen/gen-js-driver.js +23 -10
- package/gen/gen-ts-driver.js +14 -11
- package/gen.js +2 -2
- package/help.js +14 -14
- package/init/init-json.js +106 -0
- package/init/init-netcore.js +32 -0
- package/init.js +4 -108
- package/master-file/master-file.js +4 -4
- package/mr.js +9 -7
- package/package.json +6 -6
- package/update/tsCode.js +20 -0
- package/update.js +24 -0
package/README.md
CHANGED
|
@@ -1,75 +1,91 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Mushroom CLI
|
|
2
|
+
|
|
3
|
+
## Init
|
|
2
4
|
|
|
3
5
|
Init a mushroom json file
|
|
4
6
|
|
|
5
|
-
npx
|
|
7
|
+
npx mushroom-cli init json ./api/SampleProject.json [silent]
|
|
6
8
|
|
|
7
|
-
Init a
|
|
9
|
+
Init a DotNet Core project which pre-install Mushroom Server
|
|
8
10
|
|
|
9
|
-
npx
|
|
11
|
+
npx mushroom-cli init netcore [projectName]
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
## Configure
|
|
12
14
|
|
|
13
15
|
Add the mushroom json file into mushroom-config.json
|
|
14
16
|
|
|
15
|
-
npx
|
|
17
|
+
npx mushroom-cli config add ./api/yourProjectName.json
|
|
16
18
|
|
|
17
19
|
Config gen docs api
|
|
18
20
|
|
|
19
|
-
npx
|
|
21
|
+
npx mushroom-cli config gen projectName docs ./wwwroot/docs.html [alias aliasName] [features file,auth,mail,driver] [roles Admin,User-Contributor]
|
|
20
22
|
|
|
21
23
|
Config gen database docs
|
|
22
24
|
|
|
23
|
-
npx
|
|
25
|
+
npx mushroom-cli config gen projectName db-docs ./wwwroot/db-docs.html [alias aliasName] [features file,auth,mail]
|
|
24
26
|
|
|
25
27
|
Config gen javascript driver
|
|
26
28
|
|
|
27
|
-
npx
|
|
29
|
+
npx mushroom-cli config gen projectName js-driver ./src/api/mushroom.api.js [alias aliasName] [roles Admin,User-Contributor] [tarball tarballName]
|
|
28
30
|
|
|
29
31
|
Config gen typescript driver
|
|
30
32
|
|
|
31
|
-
npx
|
|
33
|
+
npx mushroom-cli config gen projectName ts-driver ./src/api/mushroom.api.ts [alias aliasName] [roles Admin,User-Contributor]
|
|
32
34
|
|
|
33
35
|
Config gen entities for Mushroom project in CSharp and using MongoDb
|
|
34
36
|
|
|
35
|
-
npx
|
|
37
|
+
npx mushroom-cli config gen projectName c#-mongo ./API/Generated.cs [alias aliasName]
|
|
36
38
|
|
|
37
39
|
Config gen entities for CSharp project which calls Mushroom API
|
|
38
40
|
|
|
39
|
-
npx
|
|
41
|
+
npx mushroom-cli config gen projectName c#-driver ./API/Generated.cs [roles Admin,User-Contributor] [alias aliasName] [access-modifier public] [features file,auth,mail]
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
## Genarate
|
|
42
44
|
|
|
43
45
|
Generate docs api (html format)
|
|
44
46
|
|
|
45
|
-
npx
|
|
47
|
+
npx mushroom-cli gen projectName[@aliasName] docs [tmp]
|
|
46
48
|
|
|
47
49
|
Generate database docs (html format)
|
|
48
50
|
|
|
49
|
-
npx
|
|
51
|
+
npx mushroom-cli gen projectName[@aliasName] db-docs [tmp]
|
|
50
52
|
|
|
51
53
|
Generate npm package (tarball file)
|
|
52
54
|
|
|
53
|
-
npx
|
|
55
|
+
npx mushroom-cli gen projectName[@aliasName] js-driver-tarball
|
|
54
56
|
|
|
55
57
|
Generate javascript driver
|
|
56
58
|
|
|
57
|
-
npx
|
|
59
|
+
npx mushroom-cli gen projectName[@aliasName] js-driver
|
|
58
60
|
|
|
59
61
|
Generate typescript driver
|
|
60
62
|
|
|
61
|
-
npx
|
|
63
|
+
npx mushroom-cli gen projectName[@aliasName] ts-driver
|
|
62
64
|
|
|
63
65
|
Generate entities for Mushroom project in CSharp and using MongoDb
|
|
64
66
|
|
|
65
|
-
npx
|
|
67
|
+
npx mushroom-cli gen projectName[@aliasName] c#-mongo
|
|
66
68
|
|
|
67
69
|
Generate entities for CSharp project which calls Mushroom API
|
|
68
70
|
|
|
69
|
-
npx
|
|
71
|
+
npx mushroom-cli gen projectName[@aliasName] c#-driver
|
|
72
|
+
|
|
73
|
+
## Update
|
|
74
|
+
|
|
75
|
+
Update ts code
|
|
76
|
+
|
|
77
|
+
npx mushroom-cli update ts-code [file-path.ts] [remote-ts-code-url]
|
|
70
78
|
|
|
71
|
-
|
|
79
|
+
## Other
|
|
72
80
|
|
|
73
81
|
Disable checking for update:
|
|
74
82
|
|
|
75
|
-
npx
|
|
83
|
+
npx mushroom-cli parameters --no-check-update
|
|
84
|
+
|
|
85
|
+
## Version
|
|
86
|
+
|
|
87
|
+
### 1.1.0
|
|
88
|
+
|
|
89
|
+
Support MushroomServer 0.2.25.4 or later
|
|
90
|
+
|
|
91
|
+
Support mushroomjs 1.1.0 or later
|
package/common.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const readlineSync = require("readline-sync");
|
|
2
4
|
|
|
3
|
-
function ensureFolder(path) {
|
|
5
|
+
function ensureFolder(path, isFolder) {
|
|
4
6
|
const index = path.lastIndexOf("/");
|
|
5
|
-
if (index <= 0){
|
|
7
|
+
if (!isFolder && index <= 0){
|
|
6
8
|
return;
|
|
7
9
|
}
|
|
8
|
-
path = path.
|
|
10
|
+
if (!isFolder) path = path.substring(0, index);
|
|
9
11
|
if (path === "." || path === "..")
|
|
10
12
|
return;
|
|
11
13
|
|
|
@@ -125,8 +127,110 @@ function getEntities(projectApiConfiguration, roles, getAll) {
|
|
|
125
127
|
return entities;
|
|
126
128
|
}
|
|
127
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
|
+
|
|
128
231
|
module.exports = {
|
|
129
232
|
ensureFolder: ensureFolder,
|
|
130
|
-
getRootUrl
|
|
131
|
-
getEntities
|
|
233
|
+
getRootUrl: getRootUrl,
|
|
234
|
+
getEntities: getEntities,
|
|
235
|
+
processTemplate: processTemplate
|
|
132
236
|
};
|
package/config.js
CHANGED
|
@@ -75,8 +75,8 @@ function configGenDocs(args, mushroomConfig, projectName){
|
|
|
75
75
|
const strRoles = args[index];
|
|
76
76
|
if (strRoles) {
|
|
77
77
|
const minusIndex = strRoles.indexOf("-");
|
|
78
|
-
let grantedRoles = minusIndex == -1 ? strRoles : strRoles.
|
|
79
|
-
const deniedRoles = minusIndex == -1 ? "" : strRoles.
|
|
78
|
+
let grantedRoles = minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
|
|
79
|
+
const deniedRoles = minusIndex == -1 ? "" : strRoles.substring(minusIndex + 1);
|
|
80
80
|
if (!grantedRoles)
|
|
81
81
|
grantedRoles = "*";
|
|
82
82
|
parameters.allowRoles = grantedRoles.split(",");
|
|
@@ -173,8 +173,8 @@ function configGenJavascriptDriver(args, mushroomConfig, projectName){
|
|
|
173
173
|
const strRoles = args[index];
|
|
174
174
|
if (strRoles) {
|
|
175
175
|
const minusIndex = strRoles.indexOf("-");
|
|
176
|
-
let grantedRoles = minusIndex == -1 ? strRoles : strRoles.
|
|
177
|
-
const deniedRoles = minusIndex == -1 ? "" : strRoles.
|
|
176
|
+
let grantedRoles = minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
|
|
177
|
+
const deniedRoles = minusIndex == -1 ? "" : strRoles.substring(minusIndex + 1);
|
|
178
178
|
if (!grantedRoles)
|
|
179
179
|
grantedRoles = "*";
|
|
180
180
|
parameters.allowRoles = grantedRoles.split(",");
|
|
@@ -233,8 +233,8 @@ function configGenTypescriptDriver(args, mushroomConfig, projectName){
|
|
|
233
233
|
const strRoles = args[index];
|
|
234
234
|
if (strRoles) {
|
|
235
235
|
const minusIndex = strRoles.indexOf("-");
|
|
236
|
-
let grantedRoles = minusIndex == -1 ? strRoles : strRoles.
|
|
237
|
-
const deniedRoles = minusIndex == -1 ? "" : strRoles.
|
|
236
|
+
let grantedRoles = minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
|
|
237
|
+
const deniedRoles = minusIndex == -1 ? "" : strRoles.substring(minusIndex + 1);
|
|
238
238
|
if (!grantedRoles)
|
|
239
239
|
grantedRoles = "*";
|
|
240
240
|
parameters.allowRoles = grantedRoles.split(",");
|
|
@@ -325,8 +325,8 @@ function configGenCSharpDriver(args, mushroomConfig, projectName){
|
|
|
325
325
|
const strRoles = args[index];
|
|
326
326
|
if (strRoles) {
|
|
327
327
|
const minusIndex = strRoles.indexOf("-");
|
|
328
|
-
let grantedRoles = minusIndex == -1 ? strRoles : strRoles.
|
|
329
|
-
const deniedRoles = minusIndex == -1 ? "" : strRoles.
|
|
328
|
+
let grantedRoles = minusIndex == -1 ? strRoles : strRoles.substring(0, minusIndex);
|
|
329
|
+
const deniedRoles = minusIndex == -1 ? "" : strRoles.substring(minusIndex + 1);
|
|
330
330
|
if (!grantedRoles)
|
|
331
331
|
grantedRoles = "*";
|
|
332
332
|
parameters.allowRoles = grantedRoles.split(",");
|