mushroom-cli 1.2.0-alpha.10 → 1.2.0-alpha.12

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 -211
  2. package/dist/check-update.js +5 -0
  3. package/dist/common.js +260 -0
  4. package/dist/config.js +394 -0
  5. package/{docs → dist/docs}/doc-mt.js +471 -523
  6. package/dist/docs/docs.v2.js +1758 -0
  7. package/{docs → dist/docs}/mt-dom-1.0.js +1025 -1268
  8. package/{docs → dist/docs}/mt.extension.js +142 -174
  9. package/dist/gen/gen-api-docs-v1.js +106 -0
  10. package/dist/gen/gen-api-docs.js +292 -0
  11. package/{gen → dist/gen}/gen-csharp.js +1265 -1399
  12. package/{gen → dist/gen}/gen-db-docs.js +204 -222
  13. package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
  14. package/{gen → dist/gen}/gen-js-driver.js +116 -133
  15. package/{gen → dist/gen}/gen-ts-driver.js +427 -471
  16. package/{gen.js → dist/gen.js} +109 -124
  17. package/{help.js → dist/help.js} +53 -55
  18. package/dist/init/init-json.js +91 -0
  19. package/dist/init/init-netcore.js +30 -0
  20. package/dist/init.js +23 -0
  21. package/dist/master-file/master-file.js +185 -0
  22. package/dist/merge.js +70 -0
  23. package/dist/mr.js +75 -0
  24. package/dist/types.js +1 -0
  25. package/dist/update/tsCode.js +82 -0
  26. package/dist/update.js +20 -0
  27. package/package.json +54 -29
  28. package/check-update.js +0 -9
  29. package/common.js +0 -273
  30. package/config.js +0 -445
  31. package/docs/docs.html +0 -5190
  32. package/docs/docs.v2.html +0 -5066
  33. package/docs/docs.v2.js +0 -1563
  34. package/gen/gen-api-docs-v1.js +0 -125
  35. package/gen/gen-api-docs.js +0 -298
  36. package/init/init-json.js +0 -106
  37. package/init/init-netcore.js +0 -32
  38. package/init.js +0 -28
  39. package/master-file/master-file.js +0 -234
  40. package/merge.js +0 -84
  41. package/mr.js +0 -82
  42. package/update/tsCode.js +0 -20
  43. package/update.js +0 -24
@@ -1,133 +1,116 @@
1
- const fs = require("fs");
2
- const common = require("../common.js");
3
- const typescriptDriverGenerator = require("./gen-ts-driver");
4
-
5
- function isAllowCache(actions, defaultValue) {
6
- let result = defaultValue;
7
- for (let i = 0; i < actions.length; i++) {
8
- const action = actions[i];
9
-
10
- if (!action ||
11
- !action.cache ||
12
- !action.cache.client ||
13
- !action.cache.client.policy ||
14
- action.cache.client.policy === "unset")
15
- continue;
16
-
17
- if (action.cache.client.policy === "disabled")
18
- return false;
19
-
20
- if (action.cache.client.policy === "allow" || action.cache.client.policy === "required")
21
- result = true;
22
- }
23
- return result;
24
- }
25
-
26
- function genJavascriptDriverString(aliasProject, source) {
27
- if (!aliasProject) {
28
- return "";
29
- }
30
-
31
- const entities = common.getEntities(source, aliasProject.allowRoles);
32
-
33
- let extensionsImportLines = [];
34
- let extensionsExportLines = [];
35
- let extensionsCodeLines = [];
36
-
37
- if (Array.isArray(aliasProject.features)) {
38
- if (aliasProject.features.includes("auth")) {
39
- extensionsImportLines.push('//import * as AuthExtension from "mushroomjs-auth";');
40
- extensionsImportLines.push('var AuthExtension = require("mushroomjs-auth");');
41
- extensionsExportLines.push('Auth: AuthExtension');
42
- extensionsCodeLines.push("AuthExtension.useAuth(AuthExtension.AuthLocalStorage, mushroom_1.default);");
43
- }
44
- if (aliasProject.features.includes("file")) {
45
- extensionsImportLines.push('//import * as FileExtension from "mushroomjs-file";');
46
- extensionsImportLines.push('var FileExtension = require("mushroomjs-file");');
47
- extensionsExportLines.push('File: FileExtension');
48
- extensionsCodeLines.push("FileExtension.useFile(mushroom_1.default);");
49
- }
50
- }
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
-
61
- ${extensionsImportLines.join("\n")}
62
- //export const extensions = {
63
- var extensions = {
64
- ${extensionsExportLines.join(",\n ")}
65
- };
66
- exports.extensions = extensions;
67
-
68
- "use strict";
69
-
70
- `;
71
- for (let entityName in entities) {
72
- if (!entities.hasOwnProperty(entityName))
73
- continue;
74
-
75
- const entity = entities[entityName];
76
-
77
- const actions = {};
78
- for (const actionName in entity.actions) {
79
- if (!entity.actions.hasOwnProperty(actionName))
80
- continue;
81
-
82
- actions[actionName] = {
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
85
- };
86
- }
87
-
88
- const views = {};
89
- for (const viewName in entity.views) {
90
- if (!entity.views.hasOwnProperty(viewName))
91
- continue;
92
-
93
- views[viewName] = {};
94
- }
95
- code += `defineAsyncResource({name:${JSON.stringify(entityName)},actions:${JSON.stringify(actions)},views:${JSON.stringify(views)}});
96
- `;
97
- }
98
- code += `
99
- mushroom.$using(${JSON.stringify(common.getRootUrl(source))});
100
-
101
- ${extensionsCodeLines.join('\n')}
102
-
103
- //export default mushroom;
104
- exports.default = mushroom;`;
105
-
106
- return code;
107
- }
108
-
109
- function genJavascriptDriver(args, projectName, project, alias, source) {
110
- const aliasProject = ((project.jsDriver || {}).alias || {})[alias];
111
-
112
- if (!aliasProject) {
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`);
114
- }
115
-
116
- let code = genJavascriptDriverString(aliasProject, source);
117
-
118
- common.ensureFolder(aliasProject.output);
119
-
120
- fs.writeFileSync(aliasProject.output, code);
121
- console.log(`Generated ${aliasProject.output}`);
122
-
123
- code = typescriptDriverGenerator.genDtsString(aliasProject, source);
124
- const dtsFilePath = aliasProject.output.replace(/\.js$/i, ".d.ts");
125
- fs.writeFileSync(dtsFilePath, code);
126
- console.log(`Generated ${dtsFilePath}`);
127
- console.log(`Generated Javascript driver for ${projectName}@${alias}`);
128
- }
129
-
130
- module.exports = {
131
- genJavascriptDriver,
132
- genJavascriptDriverString
133
- };
1
+ import fs from 'fs';
2
+ import * as common from '../common.js';
3
+ import * as typescriptDriverGenerator from './gen-ts-driver.js';
4
+ function isAllowCache(actions, defaultValue) {
5
+ let result = defaultValue;
6
+ for (let i = 0; i < actions.length; i++) {
7
+ const action = actions[i];
8
+ if (!action ||
9
+ !action.cache ||
10
+ !action.cache.client ||
11
+ !action.cache.client.policy ||
12
+ action.cache.client.policy === 'unset')
13
+ continue;
14
+ if (action.cache.client.policy === 'disabled')
15
+ return false;
16
+ if (action.cache.client.policy === 'allow' || action.cache.client.policy === 'required')
17
+ result = true;
18
+ }
19
+ return result;
20
+ }
21
+ export function genJavascriptDriverString(aliasProject, source) {
22
+ if (!aliasProject) {
23
+ return '';
24
+ }
25
+ const entities = common.getEntities(source, aliasProject.allowRoles);
26
+ const extensionsImportLines = [];
27
+ const extensionsExportLines = [];
28
+ const extensionsCodeLines = [];
29
+ if (Array.isArray(aliasProject.features)) {
30
+ if (aliasProject.features.includes('auth')) {
31
+ extensionsImportLines.push('//import * as AuthExtension from "mushroomjs-auth";');
32
+ extensionsImportLines.push('var AuthExtension = require("mushroomjs-auth");');
33
+ extensionsExportLines.push('Auth: AuthExtension');
34
+ extensionsCodeLines.push('AuthExtension.useAuth(AuthExtension.AuthLocalStorage, mushroom_1.default);');
35
+ }
36
+ if (aliasProject.features.includes('file')) {
37
+ extensionsImportLines.push('//import * as FileExtension from "mushroomjs-file";');
38
+ extensionsImportLines.push('var FileExtension = require("mushroomjs-file");');
39
+ extensionsExportLines.push('File: FileExtension');
40
+ extensionsCodeLines.push('FileExtension.useFile(mushroom_1.default);');
41
+ }
42
+ }
43
+ let code = `//import mushroom, {defineAsyncResource} from "mushroomjs";
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ var mushroom_1 = require("mushroomjs");
46
+ var mushroom = mushroom_1.default;
47
+ var defineAsyncResource = mushroom_1.defineAsyncResource;
48
+
49
+ //export * from "mushroomjs";
50
+ for (var m in mushroom_1) exports[m] = mushroom_1[m];
51
+
52
+ ${extensionsImportLines.join('\n')}
53
+ //export const extensions = {
54
+ var extensions = {
55
+ ${extensionsExportLines.join(',\n ')}
56
+ };
57
+ exports.extensions = extensions;
58
+
59
+ "use strict";
60
+
61
+ `;
62
+ for (const entityName in entities) {
63
+ const entity = entities[entityName];
64
+ const actions = {};
65
+ for (const actionName in entity.actions) {
66
+ let clientCache = undefined;
67
+ let includeTotal = undefined;
68
+ let offlineMode = undefined;
69
+ if ((actionName === 'findById' || actionName === 'findMany') && entity.actions[actionName]) {
70
+ if (isAllowCache(entity.actions[actionName], true))
71
+ clientCache = true;
72
+ if (actionName === 'findMany' && entity.actions[actionName].some((a) => a.includeTotal))
73
+ includeTotal = true;
74
+ if (entity.actions[actionName].some((a) => a.offlineMode === 'disallow'))
75
+ offlineMode = 'disallow';
76
+ else if (!entity.actions[actionName].length ||
77
+ entity.actions[actionName].some((a) => a.offlineMode === 'allow'))
78
+ offlineMode = 'allow';
79
+ }
80
+ actions[actionName] = {
81
+ clientCache,
82
+ includeTotal,
83
+ offlineMode,
84
+ };
85
+ }
86
+ const views = {};
87
+ for (const viewName in entity.views) {
88
+ views[viewName] = {};
89
+ }
90
+ code += `defineAsyncResource({name:${JSON.stringify(entityName)},actions:${JSON.stringify(actions)},views:${JSON.stringify(views)}});
91
+ `;
92
+ }
93
+ code += `
94
+ mushroom.$using(${JSON.stringify(common.getRootUrl(source))});
95
+
96
+ ${extensionsCodeLines.join('\n')}
97
+
98
+ //export default mushroom;
99
+ exports.default = mushroom;`;
100
+ return code;
101
+ }
102
+ export function genJavascriptDriver(args, projectName, project, alias, source) {
103
+ const aliasProject = ((project.jsDriver || {}).alias || {})[alias];
104
+ if (!aliasProject) {
105
+ 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`);
106
+ }
107
+ let code = genJavascriptDriverString(aliasProject, source);
108
+ common.ensureFolder(aliasProject.output);
109
+ fs.writeFileSync(aliasProject.output, code);
110
+ common.logInfo('Generated', aliasProject.output);
111
+ code = typescriptDriverGenerator.genDtsString(aliasProject, source);
112
+ const dtsFilePath = aliasProject.output.replace(/\.js$/i, '.d.ts');
113
+ fs.writeFileSync(dtsFilePath, code);
114
+ common.logInfo('Generated', dtsFilePath);
115
+ common.logInfo(`Generated Javascript driver for ${projectName}@${alias}`);
116
+ }