mushroom-cli 1.2.0-alpha.9 → 1.2.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.
Files changed (52) hide show
  1. package/README.md +199 -161
  2. package/dist/check-update.js +6 -0
  3. package/dist/common.js +280 -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/dist/docs/doc-mt.js +633 -0
  9. package/dist/docs/docs.html +5380 -0
  10. package/{docs → dist/docs}/docs.v2.html +5205 -5065
  11. package/dist/docs/docs.v2.js +2036 -0
  12. package/dist/docs/jquery.min.js +4 -0
  13. package/dist/docs/mt-dom-1.0.js +1398 -0
  14. package/dist/docs/mt.extension.js +199 -0
  15. package/dist/gen/gen-api-docs-v1.js +110 -0
  16. package/dist/gen/gen-api-docs.js +327 -0
  17. package/{gen → dist/gen}/gen-csharp.js +1256 -1399
  18. package/{gen → dist/gen}/gen-db-docs.js +204 -222
  19. package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
  20. package/{gen → dist/gen}/gen-js-driver.js +116 -133
  21. package/dist/gen/gen-ts-driver.js +600 -0
  22. package/{gen.js → dist/gen.js} +109 -124
  23. package/{help.js → dist/help.js} +53 -55
  24. package/dist/init/init-json.js +92 -0
  25. package/dist/init/init-netcore.js +30 -0
  26. package/dist/init.js +23 -0
  27. package/dist/master-file/master-file.js +185 -0
  28. package/dist/merge.js +70 -0
  29. package/dist/mr.js +77 -0
  30. package/dist/types.js +1 -0
  31. package/dist/update/tsCode.js +82 -0
  32. package/dist/update.js +20 -0
  33. package/package.json +64 -29
  34. package/check-update.js +0 -9
  35. package/common.js +0 -273
  36. package/config.js +0 -445
  37. package/docs/doc-mt.js +0 -523
  38. package/docs/docs.html +0 -5190
  39. package/docs/docs.v2.js +0 -1558
  40. package/docs/mt-dom-1.0.js +0 -1268
  41. package/docs/mt.extension.js +0 -174
  42. package/gen/gen-api-docs-v1.js +0 -125
  43. package/gen/gen-api-docs.js +0 -298
  44. package/gen/gen-ts-driver.js +0 -471
  45. package/init/init-json.js +0 -106
  46. package/init/init-netcore.js +0 -32
  47. package/init.js +0 -28
  48. package/master-file/master-file.js +0 -234
  49. package/merge.js +0 -84
  50. package/mr.js +0 -82
  51. package/update/tsCode.js +0 -20
  52. package/update.js +0 -24
package/common.js DELETED
@@ -1,273 +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: 0o755 });
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
- name: entity.name,
70
- description: entity.description,
71
- storageName: entity.storageName ? entity.storageName : entity.name,
72
- fields: entity.fields,
73
- actions: {},
74
- views: {}
75
- };
76
-
77
- if (!entities[entity.name].actions[actionName])
78
- entities[entity.name].actions[actionName] = [];
79
-
80
- entities[entity.name].actions[actionName].push(action);
81
- });
82
-
83
- }
84
-
85
- for (var viewName in entity.views) {
86
- if (!entity.views.hasOwnProperty(viewName))
87
- continue;
88
-
89
- entity.views[viewName].forEach(function(view) {
90
- if (!view.grant || !view.enabled)
91
- return;
92
-
93
- var allow = roles.indexOf("*") !== -1 || view.grant === "*";
94
-
95
- view.grant.split("|").forEach(function (roleGroup) {
96
- if (!roleGroup)
97
- return;
98
- roleGroup.split("+").forEach(function (grantedRole) {
99
- if (roles.indexOf(grantedRole) !== -1)
100
- allow = true;
101
- });
102
- });
103
-
104
- if (!allow)
105
- return;
106
-
107
- if (!(entity.name in entities))
108
- entities[entity.name] = {
109
- name: entity.name,
110
- description: entity.description,
111
- storageName: entity.storageName ? entity.storageName : entity.name,
112
- fields: entity.fields,
113
- actions: {},
114
- views: {}
115
- };
116
-
117
- if (!entities[entity.name].views[viewName])
118
- entities[entity.name].views[viewName] = [];
119
-
120
- entities[entity.name].views[viewName].push(view);
121
- });
122
- }
123
-
124
- if (entity.name in entities) {
125
- entities[entity.name].features = entity.features;
126
- }
127
- });
128
-
129
- return entities;
130
- }
131
-
132
- function processTemplate(basePath, templatePath) {
133
- const templateJsonContent = fs.readFileSync(path.join(basePath, templatePath)).toString();
134
- const template = JSON.parse(templateJsonContent);
135
- if (template && typeof template !== "object") {
136
- throw new TypeError(`Invalid template file ${templatePath}`);
137
- }
138
- const commands = template.steps;
139
- if (!Array.isArray(commands)) {
140
- throw new TypeError(`Invalid template file ${templatePath}`);
141
- }
142
-
143
- const variables = {};
144
- commands.forEach(command => processCommand(command, basePath, variables));
145
- return variables;
146
- }
147
-
148
- function processCommand(command, basePath, variables) {
149
- switch (command.command) {
150
- case "input":
151
- processInputCommand(command, variables);
152
- return;
153
- case "set":
154
- processSetCommand(command, variables);
155
- return;
156
- case "rename":
157
- processRenameCommand(command, basePath, variables);
158
- return;
159
- case "delete":
160
- processDeleteCommand(command, basePath, variables);
161
- return;
162
- case "replace":
163
- processReplaceCommand(command, basePath, variables);
164
- return;
165
- default:
166
- throw new Error(`Unknown command: ${command.command}`);
167
- }
168
- }
169
-
170
- function processInputCommand(command, variables) {
171
- const value = readlineSync.question(command.message ?? "");
172
- if (command.validation) {
173
- if (command.validation.required) {
174
- if (value === "") throw new TypeError(`${command.variable} is required`);
175
- }
176
- if (command.validation.pattern) {
177
- if (!new RegExp(command.validation.pattern).test(value)) throw new Error(`${value} is not valid`);
178
- }
179
- }
180
- variables[command.variable] = value;
181
- }
182
-
183
- function processSetCommand(command, variables) {
184
- switch (command["function"]) {
185
- case "New-GUID":
186
- processSetGuidCommand(command.variable, variables);
187
- break;
188
- case "ToLowerCase":
189
- toLowerCommand(command.variable, variables, command.input);
190
- break;
191
- case "ToUpperCase":
192
- toUpperCaseCommand(command.variable, variables, command.input);
193
- break;
194
- case "Trim":
195
- trimCommand(command.variable, variables, command.input);
196
- break;
197
- case "Replace":
198
- replaceCommand(command.variable, variables, command.input, command.replacement, command.pattern, command.mode);
199
- break;
200
- default:
201
- throw new Error(`Unknown set-command: ${command["function"]}`);
202
- }
203
- }
204
-
205
- //#region set-commands
206
- function processSetGuidCommand(variable, variables) {
207
- variables[variable] = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
208
- var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
209
- return v.toString(16);
210
- }).toUpperCase();
211
- }
212
-
213
- function toLowerCommand(variable, variables, input) {
214
- variables[variable] = (variables[input] || "").toLowerCase();
215
- }
216
-
217
- function toUpperCaseCommand(variable, variables, input) {
218
- variables[variable] = (variables[input] || "").toUpperCase();
219
- }
220
-
221
- function trimCommand(variable, variables, input) {
222
- variables[variable] = (variables[input] || "").trim();
223
- }
224
-
225
- function replaceCommand(variable, variables, input, replacement, pattern, mode) {
226
- var regex = new RegExp(pattern, mode);
227
- variables[variable] = (variables[input] || "").replace(regex, replacement === undefined || replacement === null ? "" : replacement);
228
- }
229
- //#endregion
230
-
231
- function processRenameCommand(command, basePath, variables) {
232
- const input = replaceVariables(command.input, variables);
233
- const output = replaceVariables(command.output, variables);
234
-
235
- fs.renameSync(path.join(basePath, input), path.join(basePath, output));
236
- }
237
-
238
- function processDeleteCommand(command, basePath, variables) {
239
- const input = replaceVariables(command.input, variables);
240
-
241
- const deletedPath = path.join(basePath, input);
242
- if (fs.lstatSync(deletedPath).isDirectory()) {
243
- // fs.rmdirSync(deletedPath, {recursive: true, force: true});
244
- fs.rmSync(deletedPath, {recursive: true, force: true});
245
- }
246
- else {
247
- fs.rmSync(deletedPath, {force: true});
248
- }
249
- }
250
-
251
- function processReplaceCommand(command, basePath, variables) {
252
- const files = command.input;
253
- const pattern = new RegExp(command.pattern, "g");
254
- const replacement = replaceVariables(command.replacement, variables);
255
-
256
- files.forEach(file => {
257
- const filePath = replaceVariables(file, variables);
258
- let content = fs.readFileSync(path.join(basePath, filePath)).toString();
259
- content = content.replace(pattern, () => replacement);
260
- fs.writeFileSync(path.join(basePath, filePath), content);
261
- });
262
- }
263
-
264
- function replaceVariables(str, variables) {
265
- return str.replace(/\$\{(\w+)\}/g, (_, varName) => variables[varName] ?? "");
266
- }
267
-
268
- module.exports = {
269
- ensureFolder: ensureFolder,
270
- getRootUrl: getRootUrl,
271
- getEntities: getEntities,
272
- processTemplate: processTemplate
273
- };