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/gen/gen-db-docs.js
CHANGED
|
@@ -175,7 +175,7 @@ function genDatabaseDocs(args, projectName, project, alias, source) {
|
|
|
175
175
|
const aliasProject = ((project.dbDocs || {}).alias || {})[alias];
|
|
176
176
|
|
|
177
177
|
if (!aliasProject) {
|
|
178
|
-
throw new Error(`Not found gen db-docs configuration. Please run 'npx
|
|
178
|
+
throw new Error(`Not found gen db-docs configuration. Please run 'npx mushroom-cli config ${projectName} gen db-docs OUTPUT_FILE.html${alias === "default" ? "" : " alias " + alias}' first`);
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
const entities = common.getEntities(source, aliasProject.allowRoles, true);
|
|
@@ -63,7 +63,8 @@ async function genJavascriptDriverTarball(args, projectName, project, alias, sou
|
|
|
63
63
|
|
|
64
64
|
if (fs.existsSync(dirPath)) {
|
|
65
65
|
console.log("Clean up tarball folder");
|
|
66
|
-
fs.rmdirSync(dirPath, { recursive: true });
|
|
66
|
+
// fs.rmdirSync(dirPath, { recursive: true });
|
|
67
|
+
fs.rmSync(dirPath, { recursive: true });
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
const tarballFileName = path.join(path.dirname(aliasProject.output), tarballName + ".tar.gz");
|
|
@@ -92,7 +93,8 @@ async function genJavascriptDriverTarball(args, projectName, project, alias, sou
|
|
|
92
93
|
await compressAsync(dirPath, tarballFileName, tarballName);
|
|
93
94
|
|
|
94
95
|
console.log("Generated tarball file");
|
|
95
|
-
fs.rmdirSync(dirPath, { recursive: true });
|
|
96
|
+
// fs.rmdirSync(dirPath, { recursive: true });
|
|
97
|
+
fs.rmSync(dirPath, { recursive: true });
|
|
96
98
|
console.log("Cleaned up tarball folder");
|
|
97
99
|
}
|
|
98
100
|
|
package/gen/gen-js-driver.js
CHANGED
|
@@ -36,23 +36,34 @@ function genJavascriptDriverString(aliasProject, source) {
|
|
|
36
36
|
|
|
37
37
|
if (Array.isArray(aliasProject.features)) {
|
|
38
38
|
if (aliasProject.features.includes("auth")) {
|
|
39
|
-
extensionsImportLines.push('import * as AuthExtension from "mushroomjs-auth";');
|
|
39
|
+
extensionsImportLines.push('//import * as AuthExtension from "mushroomjs-auth";');
|
|
40
|
+
extensionsImportLines.push('var AuthExtension = require("mushroomjs-auth");');
|
|
40
41
|
extensionsExportLines.push('Auth: AuthExtension');
|
|
41
|
-
extensionsCodeLines.push("AuthExtension.useAuth(AuthExtension.AuthLocalStorage);");
|
|
42
|
+
extensionsCodeLines.push("AuthExtension.useAuth(AuthExtension.AuthLocalStorage, mushroom_1.default);");
|
|
42
43
|
}
|
|
43
44
|
if (aliasProject.features.includes("file")) {
|
|
44
|
-
extensionsImportLines.push('import * as FileExtension from "mushroomjs-file";');
|
|
45
|
+
extensionsImportLines.push('//import * as FileExtension from "mushroomjs-file";');
|
|
46
|
+
extensionsImportLines.push('var FileExtension = require("mushroomjs-file");');
|
|
45
47
|
extensionsExportLines.push('File: FileExtension');
|
|
46
|
-
extensionsCodeLines.push("FileExtension.useFile();");
|
|
48
|
+
extensionsCodeLines.push("FileExtension.useFile(mushroom_1.default);");
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
let code =
|
|
51
|
-
|
|
52
|
+
let code = `//import mushroom, {defineAsyncResource} from "mushroomjs";
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
var mushroom_1 = require("mushroomjs");
|
|
55
|
+
var mushroom = mushroom_1.default;
|
|
56
|
+
var defineAsyncResource = mushroom_1.defineAsyncResource;
|
|
57
|
+
|
|
58
|
+
//export * from "mushroomjs";
|
|
59
|
+
for (var m in mushroom_1) exports[m] = mushroom_1[m];
|
|
60
|
+
|
|
52
61
|
${extensionsImportLines.join("\n")}
|
|
53
|
-
export const extensions = {
|
|
62
|
+
//export const extensions = {
|
|
63
|
+
var extensions = {
|
|
54
64
|
${extensionsExportLines.join(",\n ")}
|
|
55
65
|
};
|
|
66
|
+
exports.extensions = extensions;
|
|
56
67
|
|
|
57
68
|
"use strict";
|
|
58
69
|
|
|
@@ -69,7 +80,8 @@ export const extensions = {
|
|
|
69
80
|
continue;
|
|
70
81
|
|
|
71
82
|
actions[actionName] = {
|
|
72
|
-
clientCache: (actionName === "findById" || actionName === "findMany") && isAllowCache(entity.actions[actionName], true) ? true : undefined
|
|
83
|
+
clientCache: (actionName === "findById" || actionName === "findMany") && isAllowCache(entity.actions[actionName], true) ? true : undefined,
|
|
84
|
+
includeTotal: actionName === "findMany" && entity.actions[actionName].some(a => a.includeTotal) ? true: undefined
|
|
73
85
|
};
|
|
74
86
|
}
|
|
75
87
|
|
|
@@ -88,7 +100,8 @@ mushroom.$using(${JSON.stringify(common.getRootUrl(source))});
|
|
|
88
100
|
|
|
89
101
|
${extensionsCodeLines.join('\n')}
|
|
90
102
|
|
|
91
|
-
export default mushroom
|
|
103
|
+
//export default mushroom;
|
|
104
|
+
exports.default = mushroom;`;
|
|
92
105
|
|
|
93
106
|
return code;
|
|
94
107
|
}
|
|
@@ -97,7 +110,7 @@ function genJavascriptDriver(args, projectName, project, alias, source) {
|
|
|
97
110
|
const aliasProject = ((project.jsDriver || {}).alias || {})[alias];
|
|
98
111
|
|
|
99
112
|
if (!aliasProject) {
|
|
100
|
-
throw new Error(`Not found gen js-driver configuration. Please run 'npx
|
|
113
|
+
throw new Error(`Not found gen js-driver configuration. Please run 'npx mushroom-cli config gen ${projectName} js-driver OUTPUT_FILE.js${alias === "default" ? "" : " alias " + alias}' first`);
|
|
101
114
|
}
|
|
102
115
|
|
|
103
116
|
let code = genJavascriptDriverString(aliasProject, source);
|
package/gen/gen-ts-driver.js
CHANGED
|
@@ -38,7 +38,7 @@ function toTypeScriptClassName(str) {
|
|
|
38
38
|
return "_";
|
|
39
39
|
const name = toVietnameseNonTongue(str).replace(/\W/g, "_");
|
|
40
40
|
const c = name.charAt(0);
|
|
41
|
-
return ('0' <= c && c <= '9' ? '_' : "") + c.toUpperCase() + name.
|
|
41
|
+
return ('0' <= c && c <= '9' ? '_' : "") + c.toUpperCase() + name.substring(1);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
function getCSharpTypeFromMushroomType(type) {
|
|
@@ -114,19 +114,19 @@ function genTypescriptDriverString(aliasProject, source) {
|
|
|
114
114
|
extensionsImportLines.push('import * as AuthExtension from "mushroomjs-auth";');
|
|
115
115
|
extensionsExportLines.push('File: FileExtension');
|
|
116
116
|
extensionsTypes.push("AuthExtension.IMushroomAuth & ");
|
|
117
|
-
extensionsCodeLines.push("AuthExtension.useAuth(AuthExtension.AuthLocalStorage);");
|
|
117
|
+
extensionsCodeLines.push("AuthExtension.useAuth(AuthExtension.AuthLocalStorage, mushroom);");
|
|
118
118
|
}
|
|
119
119
|
if (aliasProject.features.includes("file")) {
|
|
120
120
|
extensionsImportLines.push('import * as FileExtension from "mushroomjs-file";');
|
|
121
121
|
extensionsExportLines.push('Auth: AuthExtension');
|
|
122
122
|
extensionsTypes.push("FileExtension.IMushroomFile & ");
|
|
123
|
-
extensionsCodeLines.push("FileExtension.useFile();");
|
|
123
|
+
extensionsCodeLines.push("FileExtension.useFile(mushroom);");
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
let code = `import mushroom, { defineAsyncResource, defineAsyncView, fireEvent, createRestfulAsyncFunction, IdType, IMushroom, Mushroom, MushroomRequest, MushroomRequestSetting, MushroomRestfulRequest, MushroomResponse, MushroomResourceBase, MushroomListResource, MushroomFindByIdResource, MushroomCreateResource, MushroomBatchCreateResource, MushroomUpdateResource, MushroomBatchUpdateResource, MushroomPartialUpdateResource, MushroomDeleteResource, MushroomBatchDeleteResource, MushroomExtensibleResource, MushroomViewFunction, MushroomError } from "mushroomjs";
|
|
128
|
-
export * from "mushroomjs";
|
|
129
128
|
${extensionsImportLines.join("\n")}
|
|
129
|
+
export * from "mushroomjs";
|
|
130
130
|
export const extensions = {
|
|
131
131
|
${extensionsExportLines.join(",\n ")}
|
|
132
132
|
};
|
|
@@ -154,7 +154,8 @@ export type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoI
|
|
|
154
154
|
continue;
|
|
155
155
|
|
|
156
156
|
actions[actionName] = {
|
|
157
|
-
clientCache: (actionName === "findById" || actionName === "findMany") && isAllowCache(entity.actions[actionName], true) ? true : undefined
|
|
157
|
+
clientCache: (actionName === "findById" || actionName === "findMany") && isAllowCache(entity.actions[actionName], true) ? true : undefined,
|
|
158
|
+
includeTotal: actionName === "findMany" && entity.actions[actionName].some(a => a.includeTotal) ? true: undefined
|
|
158
159
|
};
|
|
159
160
|
|
|
160
161
|
switch (actionName) {
|
|
@@ -196,7 +197,7 @@ export type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoI
|
|
|
196
197
|
}
|
|
197
198
|
default: {
|
|
198
199
|
if (actionName.indexOf("_raw_http_method_") === 0) {
|
|
199
|
-
customMethodCode += ` ${actionName.
|
|
200
|
+
customMethodCode += ` ${actionName.substring("_raw_http_method_".length)}Async: (rawRequest: MushroomRequest) => Promise<MushroomResponse<any>>,
|
|
200
201
|
`;
|
|
201
202
|
break;
|
|
202
203
|
}
|
|
@@ -255,7 +256,9 @@ ${customMethodCode}}
|
|
|
255
256
|
code += `
|
|
256
257
|
mushroom.$using(${JSON.stringify(common.getRootUrl(source))});
|
|
257
258
|
|
|
259
|
+
(function(){
|
|
258
260
|
${extensionsCodeLines.join('\n')}
|
|
261
|
+
})();
|
|
259
262
|
|
|
260
263
|
export interface IApi extends IMushroom {
|
|
261
264
|
${iApiClassBody}};
|
|
@@ -281,19 +284,19 @@ function genDtsString(aliasProject, source) {
|
|
|
281
284
|
if (Array.isArray(aliasProject.features)) {
|
|
282
285
|
if (aliasProject.features.includes("auth")) {
|
|
283
286
|
extensionsImportLines.push('import * as AuthExtension from "mushroomjs-auth";');
|
|
284
|
-
extensionsExportLines.push('Auth:
|
|
287
|
+
extensionsExportLines.push('Auth: AuthExtension');
|
|
285
288
|
extensionsTypes.push("AuthExtension.IMushroomAuth & ");
|
|
286
289
|
}
|
|
287
290
|
if (aliasProject.features.includes("file")) {
|
|
288
291
|
extensionsImportLines.push('import * as FileExtension from "mushroomjs-file";');
|
|
289
|
-
extensionsExportLines.push('File:
|
|
292
|
+
extensionsExportLines.push('File: FileExtension');
|
|
290
293
|
extensionsTypes.push("FileExtension.IMushroomFile & ");
|
|
291
294
|
}
|
|
292
295
|
}
|
|
293
296
|
|
|
294
297
|
let code = `import { IdType, IMushroom, Mushroom, MushroomRequest, MushroomRequestSetting, MushroomRestfulRequest, MushroomResponse, MushroomResourceBase, MushroomListResource, MushroomFindByIdResource, MushroomCreateResource, MushroomBatchCreateResource, MushroomUpdateResource, MushroomBatchUpdateResource, MushroomPartialUpdateResource, MushroomDeleteResource, MushroomBatchDeleteResource, MushroomExtensibleResource, MushroomViewFunction, MushroomError } from "mushroomjs";
|
|
295
|
-
export * from "mushroomjs";
|
|
296
298
|
${extensionsImportLines.join("\n")}
|
|
299
|
+
export * from "mushroomjs";
|
|
297
300
|
export declare const extensions = {
|
|
298
301
|
${extensionsExportLines.join(",\n ")}
|
|
299
302
|
};
|
|
@@ -363,7 +366,7 @@ export declare type IdValue = ${source.idType == "AutoIncInt" || source.idType =
|
|
|
363
366
|
}
|
|
364
367
|
default: {
|
|
365
368
|
if (actionName.indexOf("_raw_http_method_") === 0) {
|
|
366
|
-
customMethodCode += ` ${actionName.
|
|
369
|
+
customMethodCode += ` ${actionName.substring("_raw_http_method_".length)}Async: (rawRequest: MushroomRequest) => Promise<MushroomResponse<any>>,
|
|
367
370
|
`;
|
|
368
371
|
break;
|
|
369
372
|
}
|
|
@@ -430,7 +433,7 @@ function genTypescriptDriver(args, projectName, project, alias, source) {
|
|
|
430
433
|
const aliasProject = ((project.tsDriver || {}).alias || {})[alias];
|
|
431
434
|
|
|
432
435
|
if (!aliasProject) {
|
|
433
|
-
throw new Error(`Not found gen ts-driver configuration. Please run 'npx
|
|
436
|
+
throw new Error(`Not found gen ts-driver configuration. Please run 'npx mushroom-cli config gen ${projectName} ts-driver OUTPUT_FILE.ts${alias === "default" ? "" : " alias " + alias}' first`);
|
|
434
437
|
}
|
|
435
438
|
|
|
436
439
|
const code = genTypescriptDriverString(aliasProject, source);
|
package/gen.js
CHANGED
|
@@ -24,8 +24,8 @@ async function gen(args) {
|
|
|
24
24
|
|
|
25
25
|
const atIndex = projectName.indexOf("@");
|
|
26
26
|
if (atIndex !== -1) {
|
|
27
|
-
alias = projectName.
|
|
28
|
-
projectName = projectName.
|
|
27
|
+
alias = projectName.substring(atIndex + 1);
|
|
28
|
+
projectName = projectName.substring(0, atIndex);
|
|
29
29
|
if (!projectName) {
|
|
30
30
|
help(args);
|
|
31
31
|
return;
|
package/help.js
CHANGED
|
@@ -10,46 +10,46 @@ function help(key, wrong) {
|
|
|
10
10
|
}
|
|
11
11
|
else
|
|
12
12
|
console.log(`Init a mushroom json file
|
|
13
|
-
npx
|
|
13
|
+
npx mushroom-cli init json ./api/SampleProject.json [silent]
|
|
14
14
|
|
|
15
15
|
Init a dotnet core project which pre-install Mushroom Server
|
|
16
|
-
npx
|
|
16
|
+
npx mushroom-cli init netcore
|
|
17
17
|
|
|
18
18
|
Add the mushroom json file into mushroom-config.json
|
|
19
|
-
npx
|
|
19
|
+
npx mushroom-cli config add ./api/yourProjectName.json
|
|
20
20
|
|
|
21
21
|
Config gen docs api
|
|
22
|
-
npx
|
|
22
|
+
npx mushroom-cli config gen projectName docs ./wwwroot/docs.html [alias aliasName] [features file,auth,mail,driver] [roles Admin,User-Contributor]
|
|
23
23
|
|
|
24
24
|
Generate docs api (html format)
|
|
25
|
-
npx
|
|
25
|
+
npx mushroom-cli gen projectName[@aliasName] docs [tmp]
|
|
26
26
|
|
|
27
27
|
Config gen database docs
|
|
28
|
-
npx
|
|
28
|
+
npx mushroom-cli config gen projectName db-docs ./wwwroot/db-docs.html [alias aliasName] [features file,auth,mail]
|
|
29
29
|
|
|
30
30
|
Generate database docs (html format)
|
|
31
|
-
npx
|
|
31
|
+
npx mushroom-cli gen projectName[@aliasName] db-docs [tmp]
|
|
32
32
|
|
|
33
33
|
Config gen javascript driver
|
|
34
|
-
npx
|
|
34
|
+
npx mushroom-cli config gen projectName js-driver ./src/api/mushroom.api.js [alias aliasName] [roles Admin,User-Contributor] [tarball tarballName]
|
|
35
35
|
|
|
36
36
|
Generate javascript driver
|
|
37
|
-
npx
|
|
37
|
+
npx mushroom-cli gen projectName[@aliasName] js-driver
|
|
38
38
|
|
|
39
39
|
Config gen entities for Mushroom project in CSharp and using MongoDb
|
|
40
|
-
npx
|
|
40
|
+
npx mushroom-cli config gen projectName c#-mongo ./API/Generated.cs [alias aliasName]
|
|
41
41
|
|
|
42
42
|
Generate entities for Mushroom project in CSharp and using MongoDb
|
|
43
|
-
npx
|
|
43
|
+
npx mushroom-cli gen projectName[@aliasName] c#-mongo
|
|
44
44
|
|
|
45
45
|
Config gen entities for CSharp project which calls Mushroom API
|
|
46
|
-
npx
|
|
46
|
+
npx mushroom-cli config gen projectName c#-driver ./API/Generated.cs [roles Admin,User-Contributor] [alias aliasName]
|
|
47
47
|
|
|
48
48
|
Generate entities for CSharp project which calls Mushroom API
|
|
49
|
-
npx
|
|
49
|
+
npx mushroom-cli gen projectName[@aliasName] c#-driver
|
|
50
50
|
|
|
51
51
|
Disable checking for update:
|
|
52
|
-
npx
|
|
52
|
+
npx mushroom-cli parameters --no-check-update`);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
module.exports = help;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const fetch = require('node-fetch');
|
|
3
|
+
const readlineSync = require("readline-sync");
|
|
4
|
+
const help = require("../help.js");
|
|
5
|
+
const common = require("../common.js");
|
|
6
|
+
|
|
7
|
+
function initJson(args) {
|
|
8
|
+
const path = args[2];
|
|
9
|
+
if (!path) {
|
|
10
|
+
help(args);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (fs.existsSync(path)){
|
|
15
|
+
console.error(`File ${path} is already existed`);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (args[3] === "silent") {
|
|
20
|
+
console.log("Fetch http://api.siten.vn/gen/template/default.json");
|
|
21
|
+
fetch("http://api.siten.vn/gen/template/default.json").then(res => res.text()).then(text => {
|
|
22
|
+
common.ensureFolder(path);
|
|
23
|
+
|
|
24
|
+
fs.writeFile(path, text, err => {
|
|
25
|
+
if (err)
|
|
26
|
+
throw err;
|
|
27
|
+
console.log(`Initialized json at ${path}`);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
console.log("Fetch http://api.siten.vn/gen/template/template-def.json");
|
|
34
|
+
fetch("http://api.siten.vn/gen/template/template-def.json").then(res => res.json()).then(templateConfig => {
|
|
35
|
+
const info = {};
|
|
36
|
+
templateConfig.fields.forEach(field => {
|
|
37
|
+
while (true)
|
|
38
|
+
{
|
|
39
|
+
let question = `${field.required ? "[Required] " : ""}${field.label || field.name}`;
|
|
40
|
+
if (Array.isArray(field.list)) {
|
|
41
|
+
question += "\n";
|
|
42
|
+
let i = 1;
|
|
43
|
+
field.list.forEach(item => { question += "\t" + i++ + ". " + item + "\n"; });
|
|
44
|
+
question += "Please choose";
|
|
45
|
+
}
|
|
46
|
+
if (field.defaultValue !== undefined) {
|
|
47
|
+
question += ` (default: '${field.defaultValue}')`;
|
|
48
|
+
}
|
|
49
|
+
question += ": ";
|
|
50
|
+
let choice = readlineSync.question(question);
|
|
51
|
+
if (choice === "") {
|
|
52
|
+
if (field.defaultValue != undefined)
|
|
53
|
+
choice = field.defaultValue;
|
|
54
|
+
}
|
|
55
|
+
else if (Array.isArray(field.list)) {
|
|
56
|
+
if (choice !== null && choice !== "" && !isNaN(choice))
|
|
57
|
+
choice = field.list[choice - 1];
|
|
58
|
+
else
|
|
59
|
+
choice = undefined;
|
|
60
|
+
if (choice === undefined) {
|
|
61
|
+
console.warn("Invalid input");
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (choice === "" || choice === undefined || choice == null) {
|
|
67
|
+
choice = "";
|
|
68
|
+
|
|
69
|
+
if (field.required) {
|
|
70
|
+
console.warn("Required input value");
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (choice !== "" && field.pattern) {
|
|
76
|
+
const re = new RegExp(field.pattern, field.patternFlags);
|
|
77
|
+
if (!re.test(choice)) {
|
|
78
|
+
console.warn("Input doesn't match with pattern " + field.pattern);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
info[field.name] = choice;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
//console.log(info);
|
|
88
|
+
|
|
89
|
+
console.log(`Fetch ${templateConfig.templateUrl}`);
|
|
90
|
+
fetch(templateConfig.templateUrl).then(res => res.text()).then(json => {
|
|
91
|
+
json = json.replace(/\"\$\{([\w]+)\}\"/g, (s0, s1) => JSON.stringify(info[s1]));
|
|
92
|
+
json = json.replace(/\$\{([\w]+)\}/g, (s0, s1) => JSON.stringify(info[s1]).replace(/^\"|\"$/g, ""));
|
|
93
|
+
|
|
94
|
+
common.ensureFolder(path);
|
|
95
|
+
//console.log(json);
|
|
96
|
+
|
|
97
|
+
fs.writeFile(path, json, err => {
|
|
98
|
+
if (err)
|
|
99
|
+
throw err;
|
|
100
|
+
console.log(`Initialized json at ${path}`);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = initJson;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const { spawn } = require("child_process");
|
|
3
|
+
const common = require("../common.js");
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
function fetchFromGit() {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const git = spawn("git", ["clone", "https://tfs.siten.vn/tfs/Siten/CodeBase/_git/Mushroom", "-b", "full_extensions", "--single-branch"]);
|
|
9
|
+
git.stdout.on('data', (data) => {
|
|
10
|
+
console.log(`GIT: ${data}`);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
git.stderr.on('data', (data) => {
|
|
14
|
+
console.error(`GIT: ${data}`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
git.on('close', (code) => {
|
|
18
|
+
if (code) {
|
|
19
|
+
reject(new Error(`GIT exited with code ${code}`));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
resolve();
|
|
23
|
+
});
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function initNetCore(args) {
|
|
28
|
+
await fetchFromGit();
|
|
29
|
+
common.processTemplate("Mushroom", "mushroom-template.json");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = initNetCore;
|
package/init.js
CHANGED
|
@@ -1,120 +1,16 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const fetch = require('node-fetch');
|
|
3
|
-
const readlineSync = require("readline-sync");
|
|
4
1
|
const help = require("./help.js");
|
|
5
|
-
const common = require("./common.js");
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (!path) {
|
|
10
|
-
help(args);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (fs.existsSync(path)){
|
|
15
|
-
console.error(`File ${path} is already existed`);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (args[3] === "silent") {
|
|
20
|
-
console.log("Fetch http://api.siten.vn/gen/template/default.json");
|
|
21
|
-
fetch("http://api.siten.vn/gen/template/default.json").then(res => res.text()).then(text => {
|
|
22
|
-
common.ensureFolder(path);
|
|
23
|
-
|
|
24
|
-
fs.writeFile(path, text, err => {
|
|
25
|
-
if (err)
|
|
26
|
-
throw err;
|
|
27
|
-
console.log(`Initialized json at ${path}`);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
console.log("Fetch http://api.siten.vn/gen/template/template-def.json");
|
|
34
|
-
fetch("http://api.siten.vn/gen/template/template-def.json").then(res => res.json()).then(templateConfig => {
|
|
35
|
-
const info = {};
|
|
36
|
-
templateConfig.fields.forEach(field => {
|
|
37
|
-
while (true)
|
|
38
|
-
{
|
|
39
|
-
let question = `${field.required ? "[Required] " : ""}${field.label || field.name}`;
|
|
40
|
-
if (Array.isArray(field.list)) {
|
|
41
|
-
question += "\n";
|
|
42
|
-
let i = 1;
|
|
43
|
-
field.list.forEach(item => { question += "\t" + i++ + ". " + item + "\n"; });
|
|
44
|
-
question += "Please choose";
|
|
45
|
-
}
|
|
46
|
-
if (field.defaultValue !== undefined) {
|
|
47
|
-
question += ` (default: '${field.defaultValue}')`;
|
|
48
|
-
}
|
|
49
|
-
question += ": ";
|
|
50
|
-
let choice = readlineSync.question(question);
|
|
51
|
-
if (choice === "") {
|
|
52
|
-
if (field.defaultValue != undefined)
|
|
53
|
-
choice = field.defaultValue;
|
|
54
|
-
}
|
|
55
|
-
else if (Array.isArray(field.list)) {
|
|
56
|
-
if (choice !== null && choice !== "" && !isNaN(choice))
|
|
57
|
-
choice = field.list[choice - 1];
|
|
58
|
-
else
|
|
59
|
-
choice = undefined;
|
|
60
|
-
if (choice === undefined) {
|
|
61
|
-
console.warn("Invalid input");
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (choice === "" || choice === undefined || choice == null) {
|
|
67
|
-
choice = "";
|
|
68
|
-
|
|
69
|
-
if (field.required) {
|
|
70
|
-
console.warn("Required input value");
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (choice !== "" && field.pattern) {
|
|
76
|
-
const re = new RegExp(field.pattern, field.patternFlags);
|
|
77
|
-
if (!re.test(choice)) {
|
|
78
|
-
console.warn("Input doesn't match with pattern " + field.pattern);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
info[field.name] = choice;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
//console.log(info);
|
|
88
|
-
|
|
89
|
-
console.log(`Fetch ${templateConfig.templateUrl}`);
|
|
90
|
-
fetch(templateConfig.templateUrl).then(res => res.text()).then(json => {
|
|
91
|
-
json = json.replace(/\"\$\{([\w]+)\}\"/g, (s0, s1) => JSON.stringify(info[s1]));
|
|
92
|
-
json = json.replace(/\$\{([\w]+)\}/g, (s0, s1) => JSON.stringify(info[s1]).replace(/^\"|\"$/g, ""));
|
|
93
|
-
|
|
94
|
-
common.ensureFolder(path);
|
|
95
|
-
//console.log(json);
|
|
96
|
-
|
|
97
|
-
fs.writeFile(path, json, err => {
|
|
98
|
-
if (err)
|
|
99
|
-
throw err;
|
|
100
|
-
console.log(`Initialized json at ${path}`);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function initNetCore(args) {
|
|
107
|
-
console.log("init netcore is comming soon");
|
|
108
|
-
}
|
|
3
|
+
const initJson = require("./init/init-json");
|
|
4
|
+
const initNetCore = require("./init/init-netcore");
|
|
109
5
|
|
|
110
|
-
function init(args) {
|
|
6
|
+
async function init(args) {
|
|
111
7
|
const configCommand = args[1];
|
|
112
8
|
switch(configCommand) {
|
|
113
9
|
case "json":
|
|
114
10
|
initJson(args);
|
|
115
11
|
break;
|
|
116
12
|
case "netcore":
|
|
117
|
-
initNetCore(args);
|
|
13
|
+
await initNetCore(args);
|
|
118
14
|
break;
|
|
119
15
|
case "":
|
|
120
16
|
case undefined:
|
|
@@ -41,9 +41,9 @@ function transformViewNode(view) {
|
|
|
41
41
|
|
|
42
42
|
function mergeApiProject(totalProject, fragmentProject, options) {
|
|
43
43
|
if (totalProject.name != null && fragmentProject.name != null && fragmentProject.name != totalProject.name)
|
|
44
|
-
throw new Error(`Unable merge project '${fragmentProject.name}' into '${totalProject.name}`);
|
|
44
|
+
throw new Error(`Unable merge project '${fragmentProject.name}' into '${totalProject.name}'`);
|
|
45
45
|
if (totalProject.version != null && fragmentProject.version != null && fragmentProject.version != totalProject.version)
|
|
46
|
-
throw new Error(`Unable merge project '${fragmentProject.version}' into '${totalProject.version}`);
|
|
46
|
+
throw new Error(`Unable merge project '${fragmentProject.version}' into '${totalProject.version}'`);
|
|
47
47
|
|
|
48
48
|
if (fragmentProject.environmentVariables != null) {
|
|
49
49
|
totalProject.environmentVariables = totalProject.environmentVariables || {};
|
|
@@ -205,7 +205,7 @@ function processMasterFile(basePath, master) {
|
|
|
205
205
|
action.defaultSortings = action.sorting.split(',').map(f => {
|
|
206
206
|
const c = f.charAt(0);
|
|
207
207
|
return {
|
|
208
|
-
field: c === "+" || c === "-" ? f.
|
|
208
|
+
field: c === "+" || c === "-" ? f.substring(1) : f,
|
|
209
209
|
type: c === "-" ? "Desc" : "Asc"
|
|
210
210
|
}
|
|
211
211
|
});
|
|
@@ -216,7 +216,7 @@ function processMasterFile(basePath, master) {
|
|
|
216
216
|
action.allowSortings = action.allowSorting.split(',').map(f => {
|
|
217
217
|
const c = f.charAt(0);
|
|
218
218
|
return {
|
|
219
|
-
field: c === "+" || c === "-" ? f.
|
|
219
|
+
field: c === "+" || c === "-" ? f.substring(1) : f,
|
|
220
220
|
type: c === "-" ? "Desc" : c === "+" ? "Asc" : "Both"
|
|
221
221
|
}
|
|
222
222
|
});
|
package/mr.js
CHANGED
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
const init = require("./init.js");
|
|
4
4
|
const config = require("./config.js");
|
|
5
5
|
const gen = require("./gen.js");
|
|
6
|
+
const update = require("./update.js");
|
|
6
7
|
const help = require("./help.js");
|
|
7
8
|
|
|
8
|
-
const
|
|
9
|
+
const pkg = require("./package.json");
|
|
9
10
|
const checkUpdate = require("./check-update");
|
|
10
11
|
|
|
11
|
-
const versionGroup =
|
|
12
|
+
const versionGroup = pkg.version.match(/([^-]+)(-(\w+).*)?/);
|
|
12
13
|
const currentDistTag = versionGroup[3] ? versionGroup[3] : "latest";
|
|
13
|
-
console.log("Mushroom CLI version " +
|
|
14
|
+
console.log("Mushroom CLI version " + pkg.version);
|
|
14
15
|
|
|
15
16
|
async function run(args) {
|
|
16
17
|
let debugMode = false;
|
|
@@ -19,10 +20,8 @@ async function run(args) {
|
|
|
19
20
|
args = args.filter(arg => arg !== "--debug");
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
let noCheckUpdate = false;
|
|
23
23
|
let checkUpdateTask;
|
|
24
24
|
if (args.indexOf("--no-check-update") !== -1){
|
|
25
|
-
noCheckUpdate = true;
|
|
26
25
|
args = args.filter(arg => arg !== "--no-check-update");
|
|
27
26
|
checkUpdateTask = null;
|
|
28
27
|
}
|
|
@@ -42,6 +41,9 @@ async function run(args) {
|
|
|
42
41
|
case "gen":
|
|
43
42
|
await gen(args);
|
|
44
43
|
break;
|
|
44
|
+
case "update":
|
|
45
|
+
await update(args);
|
|
46
|
+
break;
|
|
45
47
|
case "":
|
|
46
48
|
case undefined:
|
|
47
49
|
console.log(`Mushroom CLI`);
|
|
@@ -63,8 +65,8 @@ async function run(args) {
|
|
|
63
65
|
if (checkUpdateTask !== null)
|
|
64
66
|
try {
|
|
65
67
|
var data = await checkUpdateTask;
|
|
66
|
-
if (data["dist-tags"] && data["dist-tags"][currentDistTag] && data["dist-tags"][currentDistTag] !==
|
|
67
|
-
console.warn(`YOUR mushroom-cli VERSION IS NOT LATEST (dist-tags: ${currentDistTag}). PLEASE RUN: npm i mushroom-cli@${data["dist-tags"][currentDistTag]}`);
|
|
68
|
+
if (data["dist-tags"] && data["dist-tags"][currentDistTag] && data["dist-tags"][currentDistTag] !== pkg.version) {
|
|
69
|
+
console.warn(`YOUR mushroom-cli VERSION IS NOT LATEST (dist-tags: ${currentDistTag}). PLEASE RUN: npm i mushroom-cli@${data["dist-tags"][currentDistTag]} OR yarn add mushroom-cli@^${data["dist-tags"][currentDistTag]}`);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
catch(e) {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mushroom-cli",
|
|
3
|
-
"version": "1.1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Mushroom CLI",
|
|
5
5
|
"main": "mr.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"release": "npm publish --access public
|
|
7
|
+
"release": "npm publish --access public"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"Mushroom",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"author": "suco2007",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"jsdom": "^
|
|
21
|
-
"json5": "^2.
|
|
22
|
-
"node-fetch": "^2.6.
|
|
23
|
-
"open": "^
|
|
20
|
+
"jsdom": "^21.0.0",
|
|
21
|
+
"json5": "^2.2.3",
|
|
22
|
+
"node-fetch": "^2.6.7",
|
|
23
|
+
"open": "^8.4.0",
|
|
24
24
|
"readline-sync": "^1.4.10",
|
|
25
25
|
"targz": "^1.0.1"
|
|
26
26
|
}
|