mushroom-cli 1.2.0-alpha.2 → 1.2.0-alpha.21

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 (46) hide show
  1. package/README.md +280 -111
  2. package/dist/check-update.js +6 -0
  3. package/dist/common.js +272 -0
  4. package/dist/config.js +394 -0
  5. package/dist/docs/bootstrap-theme.min.css +6 -0
  6. package/dist/docs/bootstrap.min.css +6 -0
  7. package/dist/docs/bootstrap.min.js +7 -0
  8. package/{docs → dist/docs}/doc-mt.js +103 -1
  9. package/{docs → dist/docs}/docs.html +83 -22
  10. package/dist/docs/docs.v2.html +5086 -0
  11. package/dist/docs/docs.v2.js +1922 -0
  12. package/dist/docs/jquery.min.js +4 -0
  13. package/dist/gen/gen-api-docs-v1.js +110 -0
  14. package/dist/gen/gen-api-docs.js +306 -0
  15. package/{gen → dist/gen}/gen-csharp.js +1246 -1414
  16. package/{gen → dist/gen}/gen-db-docs.js +204 -222
  17. package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
  18. package/{gen → dist/gen}/gen-js-driver.js +116 -133
  19. package/dist/gen/gen-ts-driver.js +596 -0
  20. package/{gen.js → dist/gen.js} +109 -120
  21. package/{help.js → dist/help.js} +53 -55
  22. package/dist/init/init-json.js +92 -0
  23. package/dist/init/init-netcore.js +30 -0
  24. package/dist/init.js +23 -0
  25. package/dist/master-file/master-file.js +185 -0
  26. package/dist/merge.js +70 -0
  27. package/dist/mr.js +77 -0
  28. package/dist/types.js +1 -0
  29. package/dist/update/tsCode.js +82 -0
  30. package/dist/update.js +20 -0
  31. package/package.json +64 -27
  32. package/check-update.js +0 -9
  33. package/common.js +0 -236
  34. package/config.js +0 -445
  35. package/gen/gen-api-docs.js +0 -125
  36. package/gen/gen-ts-driver.js +0 -460
  37. package/init/init-json.js +0 -106
  38. package/init/init-netcore.js +0 -32
  39. package/init.js +0 -28
  40. package/master-file/master-file.js +0 -234
  41. package/merge.js +0 -84
  42. package/mr.js +0 -82
  43. package/update/tsCode.js +0 -20
  44. package/update.js +0 -24
  45. /package/{docs → dist/docs}/mt-dom-1.0.js +0 -0
  46. /package/{docs → dist/docs}/mt.extension.js +0 -0
@@ -1,120 +1,109 @@
1
- const fs = require("fs");
2
- const path = require('path');
3
- const JSON5 = require("json5");
4
- const help = require("./help.js");
5
-
6
- const masterFile = require("./master-file/master-file");
7
-
8
- const genApiDocs = require("./gen/gen-api-docs");
9
- const genDatabaseDocs = require("./gen/gen-db-docs");
10
- const javascriptDriverGenerator = require("./gen/gen-js-driver");
11
- const genJavascriptDriverTarball = require("./gen/gen-js-driver-tarball");
12
- const typescriptDriverGenerator = require("./gen/gen-ts-driver");
13
- const csharp = require("./gen/gen-csharp");
14
-
15
-
16
- async function gen(args) {
17
- let projectName = args[1];
18
- let alias = "default";
19
-
20
- if (!projectName) {
21
- help(args);
22
- return;
23
- }
24
-
25
- const atIndex = projectName.indexOf("@");
26
- if (atIndex !== -1) {
27
- alias = projectName.substring(atIndex + 1);
28
- projectName = projectName.substring(0, atIndex);
29
- if (!projectName) {
30
- help(args);
31
- return;
32
- }
33
-
34
- if (!alias)
35
- alias = "default";
36
- }
37
-
38
- let mushroomConfig;
39
- try {
40
- const mushroomConfigContent = fs.readFileSync("./mushroom-config.json").toString();
41
- mushroomConfig = JSON.parse(mushroomConfigContent);
42
- }
43
- catch (e) {
44
- console.error("mushroom-config.json not found or unable to parse");
45
- throw e;
46
- }
47
-
48
- if (!mushroomConfig || typeof mushroomConfig !== "object")
49
- throw new Error(`Invalid configuration. Please re-check file mushroom-config.json`);
50
-
51
- if (!mushroomConfig || !mushroomConfig.projects || !mushroomConfig.projects[projectName])
52
- throw new Error(`Project not found (${projectName})`);
53
-
54
- const project = mushroomConfig.projects[projectName];
55
- if (!project.src)
56
- throw new Error("Project source (src) not found");
57
-
58
- var source;
59
- try {
60
- const sourceContent = fs.readFileSync(project.src).toString();
61
- source = JSON5.parse(sourceContent);
62
- }
63
- catch(e) {
64
- console.error(project.src + " not found or unable to parse");
65
- throw e;
66
- }
67
-
68
- if (!source || typeof source !== "object")
69
- throw new Error(`Invalid api project configuration. Please re-check file ${project.src}`);
70
-
71
- if (Array.isArray(source.fragments)) {
72
- console.log("Process master file: " + project.src);
73
- source = masterFile.processMasterFile(path.dirname(project.src), source);
74
- //console.log(source);
75
- }
76
-
77
- if (!source || typeof source !== "object") {
78
- throw new Error(`${!source}\t${typeof source}\tInvalid api project configuration. Please re-check file ${project.src}`);
79
- }
80
-
81
- if (source.name !== projectName) {
82
- throw new Error(`Project name is mismatched (${projectName} & ${source.name})`);
83
- }
84
-
85
- const type = args[2];
86
- switch (type) {
87
- case "docs":
88
- await genApiDocs(args, projectName, project, alias, source);
89
- break;
90
- case "db-docs":
91
- genDatabaseDocs(args, projectName, project, alias, source);
92
- break;
93
- case "js-driver":
94
- javascriptDriverGenerator.genJavascriptDriver(args, projectName, project, alias, source);
95
- break;
96
- case "js-driver-tarball":
97
- await genJavascriptDriverTarball(args, projectName, project, alias, source);
98
- break;
99
- case "ts-driver":
100
- typescriptDriverGenerator.genTypescriptDriver(args, projectName, project, alias, source);
101
- break;
102
- case "c#-mongo":
103
- csharp.genCSharpMongoDbClasses(args, projectName, project, alias, source);
104
- break;
105
- case "c#-driver":
106
- csharp.genCSharpDriver(args, projectName, project, alias, source);
107
- break;
108
- case "":
109
- case undefined:
110
- case "help":
111
- case "man":
112
- help(args);
113
- break;
114
- default:
115
- help(args, true);
116
- break;
117
- }
118
- }
119
-
120
- module.exports = gen;
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import JSON5 from 'json5';
4
+ import help from './help.js';
5
+ import * as common from './common.js';
6
+ import * as masterFile from './master-file/master-file.js';
7
+ import genApiDocs from './gen/gen-api-docs.js';
8
+ import genApiDocsV1 from './gen/gen-api-docs-v1.js';
9
+ import genDatabaseDocs from './gen/gen-db-docs.js';
10
+ import * as javascriptDriverGenerator from './gen/gen-js-driver.js';
11
+ import genJavascriptDriverTarball from './gen/gen-js-driver-tarball.js';
12
+ import * as typescriptDriverGenerator from './gen/gen-ts-driver.js';
13
+ import * as csharp from './gen/gen-csharp.js';
14
+ export default async function gen(args) {
15
+ let projectName = args[1];
16
+ let alias = 'default';
17
+ if (!projectName) {
18
+ help(args);
19
+ return;
20
+ }
21
+ const atIndex = projectName.indexOf('@');
22
+ if (atIndex !== -1) {
23
+ alias = projectName.substring(atIndex + 1);
24
+ projectName = projectName.substring(0, atIndex);
25
+ if (!projectName) {
26
+ help(args);
27
+ return;
28
+ }
29
+ if (!alias)
30
+ alias = 'default';
31
+ }
32
+ let mushroomConfig;
33
+ try {
34
+ const mushroomConfigContent = fs.readFileSync('./mushroom-config.json').toString();
35
+ mushroomConfig = JSON.parse(mushroomConfigContent);
36
+ }
37
+ catch (e) {
38
+ common.logError('mushroom-config.json not found or unable to parse');
39
+ throw e;
40
+ }
41
+ if (!mushroomConfig || typeof mushroomConfig !== 'object')
42
+ throw new Error(`Invalid configuration. Please re-check file mushroom-config.json`);
43
+ if (!mushroomConfig || !mushroomConfig.projects || !mushroomConfig.projects[projectName])
44
+ throw new Error(`Project not found (${projectName})`);
45
+ const project = mushroomConfig.projects[projectName];
46
+ if (!project.src)
47
+ throw new Error('Project source (src) not found');
48
+ let master;
49
+ try {
50
+ const sourceContent = fs.readFileSync(project.src).toString();
51
+ master = JSON5.parse(sourceContent);
52
+ }
53
+ catch (e) {
54
+ common.logError(project.src, 'not found or unable to parse');
55
+ throw e;
56
+ }
57
+ if (!master || typeof master !== 'object')
58
+ throw new Error(`Invalid api project configuration. Please re-check file ${project.src}`);
59
+ let source = null;
60
+ if (Array.isArray(master.fragments)) {
61
+ common.logInfo('Process master file', project.src);
62
+ source = masterFile.processMasterFile(path.dirname(project.src), master);
63
+ }
64
+ else {
65
+ source = master;
66
+ }
67
+ if (!source || typeof source !== 'object') {
68
+ throw new Error(`Invalid api project configuration. Please re-check file ${project.src}`);
69
+ }
70
+ if (source.name !== projectName) {
71
+ throw new Error(`Project name is mismatched (${projectName} & ${source.name})`);
72
+ }
73
+ const type = args[2];
74
+ switch (type) {
75
+ case 'docs':
76
+ if (args.includes('v1'))
77
+ await genApiDocsV1(args.filter((p) => p != 'v1'), projectName, project, alias, source);
78
+ else
79
+ await genApiDocs(args, projectName, project, alias, source);
80
+ break;
81
+ case 'db-docs':
82
+ genDatabaseDocs(args, projectName, project, alias, source);
83
+ break;
84
+ case 'js-driver':
85
+ javascriptDriverGenerator.genJavascriptDriver(args, projectName, project, alias, source);
86
+ break;
87
+ case 'js-driver-tarball':
88
+ await genJavascriptDriverTarball(args, projectName, project, alias, source);
89
+ break;
90
+ case 'ts-driver':
91
+ typescriptDriverGenerator.genTypescriptDriver(args, projectName, project, alias, source);
92
+ break;
93
+ case 'c#-mongo':
94
+ csharp.genCSharpMongoDbClasses(args, projectName, project, alias, source);
95
+ break;
96
+ case 'c#-driver':
97
+ csharp.genCSharpDriver(args, projectName, project, alias, source);
98
+ break;
99
+ case '':
100
+ case undefined:
101
+ case 'help':
102
+ case 'man':
103
+ help(args);
104
+ break;
105
+ default:
106
+ help(args, true);
107
+ break;
108
+ }
109
+ }
@@ -1,55 +1,53 @@
1
- function help(key, wrong) {
2
- if (Array.isArray(key))
3
- key = key.join(" ");
4
-
5
- if (key){
6
- if (wrong)
7
- console.log(`Invalid command '${key}'`);
8
- else
9
- console.log(`Document for '${key}' is comming soon`);
10
- }
11
- else
12
- console.log(`Init a mushroom json file
13
- npx mushroom-cli init json ./api/SampleProject.json [silent]
14
-
15
- Init a dotnet core project which pre-install Mushroom Server
16
- npx mushroom-cli init netcore
17
-
18
- Add the mushroom json file into mushroom-config.json
19
- npx mushroom-cli config add ./api/yourProjectName.json
20
-
21
- Config gen docs api
22
- npx mushroom-cli config gen projectName docs ./wwwroot/docs.html [alias aliasName] [features file,auth,mail,driver] [roles Admin,User-Contributor]
23
-
24
- Generate docs api (html format)
25
- npx mushroom-cli gen projectName[@aliasName] docs [tmp]
26
-
27
- Config gen database docs
28
- npx mushroom-cli config gen projectName db-docs ./wwwroot/db-docs.html [alias aliasName] [features file,auth,mail]
29
-
30
- Generate database docs (html format)
31
- npx mushroom-cli gen projectName[@aliasName] db-docs [tmp]
32
-
33
- Config gen javascript driver
34
- npx mushroom-cli config gen projectName js-driver ./src/api/mushroom.api.js [alias aliasName] [roles Admin,User-Contributor] [tarball tarballName]
35
-
36
- Generate javascript driver
37
- npx mushroom-cli gen projectName[@aliasName] js-driver
38
-
39
- Config gen entities for Mushroom project in CSharp and using MongoDb
40
- npx mushroom-cli config gen projectName c#-mongo ./API/Generated.cs [alias aliasName]
41
-
42
- Generate entities for Mushroom project in CSharp and using MongoDb
43
- npx mushroom-cli gen projectName[@aliasName] c#-mongo
44
-
45
- Config gen entities for CSharp project which calls Mushroom API
46
- npx mushroom-cli config gen projectName c#-driver ./API/Generated.cs [roles Admin,User-Contributor] [alias aliasName]
47
-
48
- Generate entities for CSharp project which calls Mushroom API
49
- npx mushroom-cli gen projectName[@aliasName] c#-driver
50
-
51
- Disable checking for update:
52
- npx mushroom-cli parameters --no-check-update`);
53
- }
54
-
55
- module.exports = help;
1
+ import * as common from './common.js';
2
+ export default function help(key, wrong) {
3
+ if (Array.isArray(key))
4
+ key = key.join(' ');
5
+ if (key) {
6
+ if (wrong)
7
+ common.logInfo(`Invalid command '${key}'`);
8
+ else
9
+ common.logInfo(`Document for '${key}' is comming soon`);
10
+ }
11
+ else
12
+ common.logInfo(`Init a mushroom json file
13
+ npx mushroom-cli init json ./api/SampleProject.json [silent]
14
+
15
+ Init a dotnet core project which pre-install Mushroom Server
16
+ npx mushroom-cli init netcore
17
+
18
+ Add the mushroom json file into mushroom-config.json
19
+ npx mushroom-cli config add ./api/yourProjectName.json
20
+
21
+ Config gen docs api
22
+ npx mushroom-cli config gen projectName docs ./wwwroot/docs.html [alias aliasName] [features file,auth,mail,driver] [roles Admin,User-Contributor]
23
+
24
+ Generate docs api (html format)
25
+ npx mushroom-cli gen projectName[@aliasName] docs [tmp]
26
+
27
+ Config gen database docs
28
+ npx mushroom-cli config gen projectName db-docs ./wwwroot/db-docs.html [alias aliasName] [features file,auth,mail]
29
+
30
+ Generate database docs (html format)
31
+ npx mushroom-cli gen projectName[@aliasName] db-docs [tmp]
32
+
33
+ Config gen javascript driver
34
+ npx mushroom-cli config gen projectName js-driver ./src/api/mushroom.api.js [alias aliasName] [roles Admin,User-Contributor] [tarball tarballName]
35
+
36
+ Generate javascript driver
37
+ npx mushroom-cli gen projectName[@aliasName] js-driver
38
+
39
+ Config gen entities for Mushroom project in CSharp and using MongoDb
40
+ npx mushroom-cli config gen projectName c#-mongo ./API/Generated.cs [alias aliasName]
41
+
42
+ Generate entities for Mushroom project in CSharp and using MongoDb
43
+ npx mushroom-cli gen projectName[@aliasName] c#-mongo
44
+
45
+ Config gen entities for CSharp project which calls Mushroom API
46
+ npx mushroom-cli config gen projectName c#-driver ./API/Generated.cs [roles Admin,User-Contributor] [alias aliasName]
47
+
48
+ Generate entities for CSharp project which calls Mushroom API
49
+ npx mushroom-cli gen projectName[@aliasName] c#-driver
50
+
51
+ Disable checking for update:
52
+ npx mushroom-cli parameters --no-check-update`);
53
+ }
@@ -0,0 +1,92 @@
1
+ import fs from 'fs';
2
+ import fetch from 'node-fetch';
3
+ import readlineSync from 'readline-sync';
4
+ import help from '../help.js';
5
+ import * as common from '../common.js';
6
+ export default function initJson(args) {
7
+ const path = args[2];
8
+ if (!path) {
9
+ help(args);
10
+ return;
11
+ }
12
+ if (fs.existsSync(path)) {
13
+ common.logError('File', path, 'is already existed');
14
+ return;
15
+ }
16
+ if (args[3] === 'silent') {
17
+ common.logInfo('Fetch https://api.siten.vn/gen/template/default.json');
18
+ fetch('https://api.siten.vn/gen/template/default.json')
19
+ .then((res) => res.text())
20
+ .then((text) => {
21
+ common.ensureFolder(path);
22
+ fs.writeFile(path, text, (err) => {
23
+ if (err)
24
+ throw err;
25
+ common.logInfo('Initialized json at', path);
26
+ });
27
+ });
28
+ return;
29
+ }
30
+ common.logInfo('Fetch https://api.siten.vn/gen/template/template-def.json');
31
+ fetch('https://api.siten.vn/gen/template/template-def.json')
32
+ .then((res) => res.json())
33
+ .then((templateDefination) => {
34
+ const templateConfig = templateDefination;
35
+ const info = {};
36
+ templateConfig.fields.forEach((field) => {
37
+ while (true) {
38
+ let question = `${field.required ? '[Required] ' : ''}${field.label || field.name}`;
39
+ if (Array.isArray(field.list)) {
40
+ question += '\n';
41
+ let i = 1;
42
+ field.list.forEach((item) => {
43
+ question += '\t' + i++ + '. ' + item + '\n';
44
+ });
45
+ question += 'Please choose';
46
+ }
47
+ if (field.defaultValue !== undefined) {
48
+ question += ` (default: '${field.defaultValue}')`;
49
+ }
50
+ question += ': ';
51
+ let input = readlineSync.question(question);
52
+ if (Array.isArray(field.list)) {
53
+ const index = parseInt(input);
54
+ if (input !== '' && isNaN(index)) {
55
+ common.logWarning('Invalid input');
56
+ continue;
57
+ }
58
+ input = input ? field.list[index - 1] : (field.defaultValue ?? '');
59
+ }
60
+ else if (input === '') {
61
+ input = field.defaultValue ?? '';
62
+ }
63
+ if (!input && field.required) {
64
+ common.logWarning('Required input value');
65
+ continue;
66
+ }
67
+ if (input !== '' && field.pattern) {
68
+ const re = new RegExp(field.pattern, field.patternFlags);
69
+ if (!re.test(input)) {
70
+ common.logWarning("Input doesn't match with pattern", field.pattern);
71
+ continue;
72
+ }
73
+ }
74
+ info[field.name] = input;
75
+ break;
76
+ }
77
+ });
78
+ common.logInfo('Fetch', templateConfig.templateUrl);
79
+ fetch(templateConfig.templateUrl)
80
+ .then((res) => res.text())
81
+ .then((json) => {
82
+ json = json.replace(/"\$\{([\w]+)\}"/g, (s0, s1) => JSON.stringify(info[s1]));
83
+ json = json.replace(/\$\{([\w]+)\}/g, (s0, s1) => JSON.stringify(info[s1]).replace(/^"|"$/g, ''));
84
+ common.ensureFolder(path);
85
+ fs.writeFile(path, json, (err) => {
86
+ if (err)
87
+ throw err;
88
+ common.logInfo('Initialized json at', path);
89
+ });
90
+ });
91
+ });
92
+ }
@@ -0,0 +1,30 @@
1
+ import { spawn } from 'child_process';
2
+ import * as common from '../common.js';
3
+ function fetchFromGit() {
4
+ return new Promise((resolve, reject) => {
5
+ const git = spawn('git', [
6
+ 'clone',
7
+ 'https://tfs.siten.vn/tfs/Siten/CodeBase/_git/Mushroom',
8
+ '-b',
9
+ 'full_extensions',
10
+ '--single-branch',
11
+ ]);
12
+ git.stdout.on('data', (data) => {
13
+ common.logInfo('GIT:', data?.toString());
14
+ });
15
+ git.stderr.on('data', (data) => {
16
+ common.logError('GIT:', data?.toString());
17
+ });
18
+ git.on('close', (code) => {
19
+ if (code) {
20
+ reject(new Error(`GIT exited with code ${code}`));
21
+ return;
22
+ }
23
+ resolve();
24
+ });
25
+ });
26
+ }
27
+ export default async function initNetCore(args) {
28
+ await fetchFromGit();
29
+ common.processTemplate('Mushroom', 'mushroom-template.json');
30
+ }
package/dist/init.js ADDED
@@ -0,0 +1,23 @@
1
+ import help from './help.js';
2
+ import initJson from './init/init-json.js';
3
+ import initNetCore from './init/init-netcore.js';
4
+ export default async function init(args) {
5
+ const configCommand = args[1];
6
+ switch (configCommand) {
7
+ case 'json':
8
+ initJson(args);
9
+ break;
10
+ case 'netcore':
11
+ await initNetCore(args);
12
+ break;
13
+ case '':
14
+ case undefined:
15
+ case 'help':
16
+ case 'man':
17
+ help('init');
18
+ break;
19
+ default:
20
+ help(args, true);
21
+ break;
22
+ }
23
+ }