mushroom-cli 1.2.0-alpha.11 → 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 -223
  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 -467
  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 -283
  30. package/config.js +0 -445
  31. package/docs/docs.html +0 -5190
  32. package/docs/docs.v2.html +0 -5095
  33. package/docs/docs.v2.js +0 -1633
  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
package/common.js DELETED
@@ -1,283 +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.includes("*") || 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 filterRoles(roleList, allowRoleList) {
133
- const roles = !allowRoleList || allowRoleList.includes("*") ? [...roleList] : roleList.filter(role => allowRoleList.includes(role.name));
134
- roles.push({
135
- name: "[Mọi người dùng]",
136
- description: "Tất cả người dùng (kể cả chưa đăng nhập)"
137
- });
138
- return roles;
139
- }
140
-
141
- function processTemplate(basePath, templatePath) {
142
- const templateJsonContent = fs.readFileSync(path.join(basePath, templatePath)).toString();
143
- const template = JSON.parse(templateJsonContent);
144
- if (template && typeof template !== "object") {
145
- throw new TypeError(`Invalid template file ${templatePath}`);
146
- }
147
- const commands = template.steps;
148
- if (!Array.isArray(commands)) {
149
- throw new TypeError(`Invalid template file ${templatePath}`);
150
- }
151
-
152
- const variables = {};
153
- commands.forEach(command => processCommand(command, basePath, variables));
154
- return variables;
155
- }
156
-
157
- function processCommand(command, basePath, variables) {
158
- switch (command.command) {
159
- case "input":
160
- processInputCommand(command, variables);
161
- return;
162
- case "set":
163
- processSetCommand(command, variables);
164
- return;
165
- case "rename":
166
- processRenameCommand(command, basePath, variables);
167
- return;
168
- case "delete":
169
- processDeleteCommand(command, basePath, variables);
170
- return;
171
- case "replace":
172
- processReplaceCommand(command, basePath, variables);
173
- return;
174
- default:
175
- throw new Error(`Unknown command: ${command.command}`);
176
- }
177
- }
178
-
179
- function processInputCommand(command, variables) {
180
- const value = readlineSync.question(command.message ?? "");
181
- if (command.validation) {
182
- if (command.validation.required) {
183
- if (value === "") throw new TypeError(`${command.variable} is required`);
184
- }
185
- if (command.validation.pattern) {
186
- if (!new RegExp(command.validation.pattern).test(value)) throw new Error(`${value} is not valid`);
187
- }
188
- }
189
- variables[command.variable] = value;
190
- }
191
-
192
- function processSetCommand(command, variables) {
193
- switch (command["function"]) {
194
- case "New-GUID":
195
- processSetGuidCommand(command.variable, variables);
196
- break;
197
- case "ToLowerCase":
198
- toLowerCommand(command.variable, variables, command.input);
199
- break;
200
- case "ToUpperCase":
201
- toUpperCaseCommand(command.variable, variables, command.input);
202
- break;
203
- case "Trim":
204
- trimCommand(command.variable, variables, command.input);
205
- break;
206
- case "Replace":
207
- replaceCommand(command.variable, variables, command.input, command.replacement, command.pattern, command.mode);
208
- break;
209
- default:
210
- throw new Error(`Unknown set-command: ${command["function"]}`);
211
- }
212
- }
213
-
214
- //#region set-commands
215
- function processSetGuidCommand(variable, variables) {
216
- variables[variable] = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
217
- var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
218
- return v.toString(16);
219
- }).toUpperCase();
220
- }
221
-
222
- function toLowerCommand(variable, variables, input) {
223
- variables[variable] = (variables[input] || "").toLowerCase();
224
- }
225
-
226
- function toUpperCaseCommand(variable, variables, input) {
227
- variables[variable] = (variables[input] || "").toUpperCase();
228
- }
229
-
230
- function trimCommand(variable, variables, input) {
231
- variables[variable] = (variables[input] || "").trim();
232
- }
233
-
234
- function replaceCommand(variable, variables, input, replacement, pattern, mode) {
235
- var regex = new RegExp(pattern, mode);
236
- variables[variable] = (variables[input] || "").replace(regex, replacement === undefined || replacement === null ? "" : replacement);
237
- }
238
- //#endregion
239
-
240
- function processRenameCommand(command, basePath, variables) {
241
- const input = replaceVariables(command.input, variables);
242
- const output = replaceVariables(command.output, variables);
243
-
244
- fs.renameSync(path.join(basePath, input), path.join(basePath, output));
245
- }
246
-
247
- function processDeleteCommand(command, basePath, variables) {
248
- const input = replaceVariables(command.input, variables);
249
-
250
- const deletedPath = path.join(basePath, input);
251
- if (fs.lstatSync(deletedPath).isDirectory()) {
252
- // fs.rmdirSync(deletedPath, {recursive: true, force: true});
253
- fs.rmSync(deletedPath, {recursive: true, force: true});
254
- }
255
- else {
256
- fs.rmSync(deletedPath, {force: true});
257
- }
258
- }
259
-
260
- function processReplaceCommand(command, basePath, variables) {
261
- const files = command.input;
262
- const pattern = new RegExp(command.pattern, "g");
263
- const replacement = replaceVariables(command.replacement, variables);
264
-
265
- files.forEach(file => {
266
- const filePath = replaceVariables(file, variables);
267
- let content = fs.readFileSync(path.join(basePath, filePath)).toString();
268
- content = content.replace(pattern, () => replacement);
269
- fs.writeFileSync(path.join(basePath, filePath), content);
270
- });
271
- }
272
-
273
- function replaceVariables(str, variables) {
274
- return str.replace(/\$\{(\w+)\}/g, (_, varName) => variables[varName] ?? "");
275
- }
276
-
277
- module.exports = {
278
- ensureFolder: ensureFolder,
279
- getRootUrl: getRootUrl,
280
- getEntities: getEntities,
281
- filterRoles:filterRoles,
282
- processTemplate: processTemplate
283
- };