mushroom-cli 1.2.8 → 2.0.0-alpha.1

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Mushroom CLI
2
2
 
3
+ > In the examples below, `[...]` marks an optional argument and `|` separates alternatives. They are notation, not
4
+ > characters to type. Quote any argument containing spaces, for example
5
+ > `npx mushroom-cli config add "./my api/project.json"`.
6
+
3
7
  ## Init
4
8
 
5
9
  Init a mushroom json file
@@ -8,10 +12,10 @@ Init a mushroom json file
8
12
  npx mushroom-cli init json ./api/SampleProject.json [silent]
9
13
  ```
10
14
 
11
- Init a DotNet Core project which pre-install Mushroom Server
15
+ Init a DotNet project
12
16
 
13
17
  ```bash
14
- npx mushroom-cli init netcore [projectName]
18
+ npx mushroom-cli init netcore [projectName] [--version latest|alpha|0.2|0.3]
15
19
  ```
16
20
 
17
21
  ## Configure
@@ -31,19 +35,19 @@ npx mushroom-cli config gen projectName docs ./wwwroot/docs.html [alias aliasNam
31
35
  Config gen database docs
32
36
 
33
37
  ```bash
34
- npx mushroom-cli config gen projectName "db-docs" ./wwwroot/db-docs.html [alias aliasName] [features file,auth,mail]
38
+ npx mushroom-cli config gen projectName db-docs ./wwwroot/db-docs.html [alias aliasName] [features file,auth,mail]
35
39
  ```
36
40
 
37
41
  Config gen javascript driver
38
42
 
39
43
  ```bash
40
- npx mushroom-cli config gen projectName "js-driver" ./src/api/mushroom.api.js [alias aliasName] [roles Admin,User-Contributor] [tarball tarballName]
44
+ npx mushroom-cli config gen projectName js-driver ./src/api/mushroom.api.js [alias aliasName] [roles Admin,User-Contributor]
41
45
  ```
42
46
 
43
47
  Config gen typescript driver
44
48
 
45
49
  ```bash
46
- npx mushroom-cli config gen projectName "ts-driver" ./src/api/mushroom.api.ts [alias aliasName] [roles Admin,User-Contributor]
50
+ npx mushroom-cli config gen projectName ts-driver ./src/api/mushroom.api.ts [alias aliasName] [roles Admin,User-Contributor]
47
51
  ```
48
52
 
49
53
  Config gen entities for Mushroom project in CSharp and using MongoDb
@@ -58,36 +62,30 @@ Config gen entities for CSharp project which calls Mushroom API
58
62
  npx mushroom-cli config gen projectName "c#-driver" ./API/Generated.cs [roles Admin,User-Contributor] [alias aliasName] [access-modifier public] [features file,auth,mail]
59
63
  ```
60
64
 
61
- ## Genarate
65
+ ## Generate
62
66
 
63
67
  Generate docs api (html format)
64
68
 
65
69
  ```bash
66
- npx mushroom-cli gen projectName[@aliasName] docs [v1] [tmp]
70
+ npx mushroom-cli gen projectName[@aliasName] docs [tmp]
67
71
  ```
68
72
 
69
73
  Generate database docs (html format)
70
74
 
71
75
  ```bash
72
- npx mushroom-cli gen projectName[@aliasName] "db-docs" [tmp]
73
- ```
74
-
75
- Generate npm package (tarball file)
76
-
77
- ```bash
78
- npx mushroom-cli gen projectName[@aliasName] "js-driver-tarball"
76
+ npx mushroom-cli gen projectName[@aliasName] db-docs [tmp]
79
77
  ```
80
78
 
81
79
  Generate javascript driver
82
80
 
83
81
  ```bash
84
- npx mushroom-cli gen projectName[@aliasName] "js-driver"
82
+ npx mushroom-cli gen projectName[@aliasName] js-driver
85
83
  ```
86
84
 
87
85
  Generate typescript driver
88
86
 
89
87
  ```bash
90
- npx mushroom-cli gen projectName[@aliasName] "ts-driver"
88
+ npx mushroom-cli gen projectName[@aliasName] ts-driver
91
89
  ```
92
90
 
93
91
  Generate entities for Mushroom project in CSharp and using MongoDb
@@ -113,13 +111,13 @@ npx mushroom-cli merge output-path.json
113
111
  Update ts code (configuration was stored in mushroom-config.json file)
114
112
 
115
113
  ```bash
116
- npx mushroom-cli update "ts-code"
114
+ npx mushroom-cli update ts-code
117
115
  ```
118
116
 
119
117
  Update ts code (simple call)
120
118
 
121
119
  ```bash
122
- npx mushroom-cli update "ts-code" file-path.ts remote-ts-code-url
120
+ npx mushroom-cli update ts-code file-path.ts remote-ts-code-url
123
121
  ```
124
122
 
125
123
  ## Other
@@ -132,6 +130,53 @@ npx mushroom-cli parameters --no-check-update
132
130
 
133
131
  ## Version
134
132
 
133
+ ### 2.0.0-alpha.1
134
+
135
+ Bug fixes:
136
+
137
+ - gen docs: fix trailing comma on the last field of each object in data specs and code snippet.
138
+ - gen docs: copy buttons no longer copy extra text
139
+
140
+ Improvement:
141
+
142
+ - gen docs: add copy buttons to data specs
143
+
144
+ ### 2.0.0-alpha.0
145
+
146
+ Breaking changes:
147
+
148
+ - gen docs: remove the docs engine v1. The `v1` parameter is now ignored with a warning and the v1.2 engine is always
149
+ used
150
+ - gen js-driver: remove the `js-driver-tarball` command, the `tarball tarballName` option of `config gen js-driver`
151
+ and the `jsDriver.alias.*.tarballName` field in mushroom-config.json
152
+ - gen c#-mongo: generated code now requires Mushroom Server 0.3 or higher
153
+ - require Node.js `>=14.13.1`
154
+
155
+ New features:
156
+
157
+ - init netcore: `npx mushroom-cli init netcore [--version 0.2|0.3|latest|alpha]` to select the template branch
158
+ - init netcore: the `replace` step accepts wildcards in the file name, for example `./api/*.json` or
159
+ `./api/dulich-*.json`, and resolves them recursively including sub-folders
160
+ - gen c#-mongo: support `routes` in the master file (`path`, `pathMode`, `caseInsensitive`, `httpMethod`, `grant`,
161
+ `deny`, `logRetentionMode`, `delegator`, `codeHint`)
162
+ - gen c#-mongo: support `extensions` in the master file (`startup`, `config`, `ensureIndex`, `routes`) and generate
163
+ the matching extension event handlers
164
+ - gen c#-mongo: new registration signatures `RegisterJob`, `RegisterBeforeEvent`, `RegisterAfterEvent`,
165
+ `RegisterCustomLoginAsyncHandler`, `RegisterGetAuthLogInfoAsyncHandler`, `RegisterLoginSuccessHandler`,
166
+ `RegisterSendCodeItemHandler`, `RegisterCustomVnTextBuilderMethod`
167
+
168
+ Improvement/Changes:
169
+
170
+ - gen docs: inline `bootstrap.min.css`, `bootstrap-theme.min.css`, `bootstrap.min.js` and `jquery.min.js` into the
171
+ html. The generated docs is now a single self-contained file and no static file is copied next to it
172
+ - gen docs: build the whole document in memory and write it once, about 4 times faster
173
+ - gen c#-mongo, gen c#-driver: escape descriptions for XML docs comments
174
+ - init netcore: clone the template with `--depth 1`
175
+ - replace `minify` with `html-minifier-terser` and use `open` 8: installing the CLI drops from 84 packages (75 MB) to
176
+ 36 packages (20 MB) and works on Node.js 14 again
177
+ - the `only-allow npm` check moved from `preinstall` to `prepare` so it no longer runs when the CLI is installed as a
178
+ dependency
179
+
135
180
  ### 1.2.8
136
181
 
137
182
  Improvement
package/dist/common.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { fileURLToPath } from 'url';
4
- import readlineSync from 'readline-sync';
5
4
  const __filename = fileURLToPath(import.meta.url);
6
5
  const __dirname = path.dirname(__filename);
7
6
  export function getPackageVersion() {
@@ -131,148 +130,6 @@ export function filterRoles(roleList, allowRoleList) {
131
130
  });
132
131
  return roles;
133
132
  }
134
- export function processTemplate(basePath, templatePath) {
135
- const templateJsonContent = fs.readFileSync(path.join(basePath, templatePath)).toString();
136
- const template = JSON.parse(templateJsonContent);
137
- if (template && typeof template !== 'object') {
138
- throw new TypeError(`Invalid template file ${templatePath}`);
139
- }
140
- const commands = template.steps;
141
- if (!Array.isArray(commands)) {
142
- throw new TypeError(`Invalid template file ${templatePath}`);
143
- }
144
- const variables = {};
145
- commands.forEach((command) => processCommand(command, basePath, variables));
146
- return variables;
147
- }
148
- function processCommand(command, basePath, variables) {
149
- const commandName = command.command;
150
- switch (commandName) {
151
- case 'input':
152
- processInputCommand(command, variables);
153
- return;
154
- case 'set':
155
- processSetCommand(command, variables);
156
- return;
157
- case 'rename':
158
- processRenameCommand(command, basePath, variables);
159
- return;
160
- case 'delete':
161
- processDeleteCommand(command, basePath, variables);
162
- return;
163
- case 'replace':
164
- processReplaceCommand(command, basePath, variables);
165
- return;
166
- default:
167
- throw new Error(`Unknown command: ${commandName}`);
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 === '')
175
- throw new TypeError(`${command.variable} is required`);
176
- }
177
- if (command.validation.pattern) {
178
- if (!new RegExp(command.validation.pattern).test(value))
179
- throw new Error(`${value} is not valid`);
180
- }
181
- }
182
- variables[command.variable] = value;
183
- }
184
- function processSetCommand(command, variables) {
185
- switch (command['function']) {
186
- case 'New-GUID':
187
- processSetNewGuidCommand(command.variable, variables);
188
- break;
189
- case 'New-RandomNumber':
190
- processSetNewRandomNumberCommand(command.variable, variables, command.min, command.max);
191
- break;
192
- case 'New-RandomString':
193
- processSetNewRandomStringCommand(command.variable, variables, command.length, command.characterPool);
194
- break;
195
- case 'ToLowerCase':
196
- toLowerCommand(command.variable, variables, command.input);
197
- break;
198
- case 'ToUpperCase':
199
- toUpperCaseCommand(command.variable, variables, command.input);
200
- break;
201
- case 'Trim':
202
- trimCommand(command.variable, variables, command.input);
203
- break;
204
- case 'Replace':
205
- replaceCommand(command.variable, variables, command.input, command.replacement, command.pattern, command.mode);
206
- break;
207
- default:
208
- throw new Error(`Unknown set-command: ${command['function']}`);
209
- }
210
- }
211
- function processSetNewGuidCommand(variable, variables) {
212
- variables[variable] = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
213
- .replace(/[xy]/g, (c) => {
214
- const r = (Math.random() * 16) | 0;
215
- const v = c == 'x' ? r : (r & 0x3) | 0x8;
216
- return v.toString(16);
217
- })
218
- .toUpperCase();
219
- }
220
- function processSetNewRandomNumberCommand(variable, variables, min = 0, max = (1 << 30) * 4) {
221
- variables[variable] = Math.floor(min + Math.random() * (max - min)).toString();
222
- }
223
- function processSetNewRandomStringCommand(variable, variables, length, characterPool = '1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM') {
224
- let result = '';
225
- for (let i = 0; i < length; i++) {
226
- result += characterPool.charAt(Math.floor(Math.random() * characterPool.length));
227
- }
228
- variables[variable] = result;
229
- }
230
- function toLowerCommand(variable, variables, input) {
231
- variables[variable] = variables[input].toLowerCase();
232
- }
233
- function toUpperCaseCommand(variable, variables, input) {
234
- variables[variable] = variables[input].toUpperCase();
235
- }
236
- function trimCommand(variable, variables, input) {
237
- variables[variable] = variables[input].trim();
238
- }
239
- function replaceCommand(variable, variables, input, replacement, pattern, mode) {
240
- const regex = new RegExp(pattern, mode);
241
- variables[variable] = variables[input].replace(regex, replacement);
242
- }
243
- function processRenameCommand(command, basePath, variables) {
244
- const input = replaceVariables(command.input, variables);
245
- const output = replaceVariables(command.output, variables);
246
- fs.renameSync(path.join(basePath, input), path.join(basePath, output));
247
- }
248
- function processDeleteCommand(command, basePath, variables) {
249
- const input = replaceVariables(command.input, variables);
250
- const deletedPath = path.join(basePath, input);
251
- if (fs.lstatSync(deletedPath).isDirectory()) {
252
- fs.rmSync(deletedPath, { recursive: true, force: true });
253
- }
254
- else {
255
- fs.rmSync(deletedPath, { force: true });
256
- }
257
- }
258
- function processReplaceCommand(command, basePath, variables) {
259
- const files = command.input;
260
- const pattern = new RegExp(command.pattern ?? '', 'g');
261
- const replacement = replaceVariables(command.replacement ?? '', variables);
262
- files.forEach((file) => {
263
- const filePath = path.join(basePath, replaceVariables(file, variables));
264
- if (!fs.existsSync(filePath)) {
265
- console.warn(`File ${file} does not exist, skipping...`);
266
- return;
267
- }
268
- let content = fs.readFileSync(filePath).toString();
269
- content = content.replace(pattern, () => replacement);
270
- fs.writeFileSync(filePath, content);
271
- });
272
- }
273
- function replaceVariables(str, variables) {
274
- return str.replace(/\$\{(\w+)\}/g, (_, varName) => variables[varName] ?? '');
275
- }
276
133
  export function logInfo(message, ...parameters) {
277
134
  console.log(message, ...parameters);
278
135
  }
package/dist/config.js CHANGED
@@ -170,13 +170,6 @@ function configGenJavascriptDriver(args, mushroomConfig, projectName) {
170
170
  alias = strAlias;
171
171
  break;
172
172
  }
173
- case 'tarball': {
174
- index++;
175
- const strTarball = args[index];
176
- if (strTarball)
177
- parameters.tarballName = strTarball;
178
- break;
179
- }
180
173
  }
181
174
  index++;
182
175
  }
@@ -1310,8 +1310,8 @@
1310
1310
  // fieldName: value
1311
1311
  };
1312
1312
  try {
1313
- const newId = await mushroom.<span data-mt-attr='{"text": "$entityName"}'></span>.createAsync(<span data-mt-attr='{"text": "$entityName"}'></span>_object);
1314
- console.log("Thêm mới thành công, new id: %o", newId);
1313
+ const response = await mushroom.<span data-mt-attr='{"text": "$entityName"}'></span>.createAsync(<span data-mt-attr='{"text": "$entityName"}'></span>_object);
1314
+ console.log("Thêm mới thành công, new id: %o", response.result);
1315
1315
  } catch (error) {
1316
1316
  console.error("Có lỗi: %o", error);
1317
1317
  }</pre>
@@ -4845,9 +4845,9 @@ API.get{{EntityName}}().getViews().{{viewName}}Async(arg, result -> {
4845
4845
  <div>
4846
4846
  <h4>Dữ liệu trả về</h4>
4847
4847
  Trường hợp không có <code>$fields</code>, kết quả trả về có dạng:
4848
- <pre class="output-without-fields"></pre>
4848
+ <pre class="output-without-fields" data-language="object-spec"></pre>
4849
4849
  Trường hợp <code class="separated-items">$fields=<span class="field-list"></span></code>, kết quả trả về có dạng:
4850
- <pre class="output-with-fields"></pre>
4850
+ <pre class="output-with-fields" data-language="object-spec"></pre>
4851
4851
  <div class="filters">
4852
4852
  <h4>Lọc dữ liệu</h4>
4853
4853
  <div class="defaultFilters">
@@ -4900,9 +4900,9 @@ API.get{{EntityName}}().getViews().{{viewName}}Async(arg, result -> {
4900
4900
  <div>
4901
4901
  <h4>Dữ liệu trả về</h4>
4902
4902
  Trường hợp không có <code>$fields</code>, kết quả trả về có dạng:
4903
- <pre class="output-without-fields"></pre>
4903
+ <pre class="output-without-fields" data-language="object-spec"></pre>
4904
4904
  Trường hợp <code class="separated-items">$fields=<span class="field-list"></span></code>, kết quả trả về có dạng:
4905
- <pre class="output-with-fields"></pre>
4905
+ <pre class="output-with-fields" data-language="object-spec"></pre>
4906
4906
  </div>
4907
4907
  <div class="cache"></div>
4908
4908
  <div class="description">
@@ -4922,7 +4922,7 @@ API.get{{EntityName}}().getViews().{{viewName}}Async(arg, result -> {
4922
4922
  </div>
4923
4923
  <div>
4924
4924
  <h4>Dữ liệu gửi lên</h4>
4925
- <pre class="input-model"></pre>
4925
+ <pre class="input-model" data-language="object-spec"></pre>
4926
4926
  </div>
4927
4927
  <div>
4928
4928
  <h4>Dữ liệu trả lại</h4>
@@ -4958,7 +4958,7 @@ API.get{{EntityName}}().getViews().{{viewName}}Async(arg, result -> {
4958
4958
  X-Mushroom-Create-Many: true
4959
4959
 
4960
4960
  <h4>Dữ liệu gửi lên: Mảng của các đối tượng</h4>
4961
- <pre class="input-model"></pre>
4961
+ <pre class="input-model" data-language="object-spec"></pre>
4962
4962
  </div>
4963
4963
  <div>
4964
4964
  <h4>Dữ liệu trả lại</h4>
@@ -4985,7 +4985,7 @@ API.get{{EntityName}}().getViews().{{viewName}}Async(arg, result -> {
4985
4985
  </div>
4986
4986
  <div>
4987
4987
  <h4>Dữ liệu gửi lên: </h4>
4988
- <pre class="input-model"></pre>
4988
+ <pre class="input-model" data-language="object-spec"></pre>
4989
4989
  </div>
4990
4990
  <div>
4991
4991
  <h4>Dữ liệu trả lại</h4>
@@ -5012,7 +5012,7 @@ API.get{{EntityName}}().getViews().{{viewName}}Async(arg, result -> {
5012
5012
  </div>
5013
5013
  <div>
5014
5014
  <h4>Dữ liệu gửi lên: Mảng của các đối tượng</h4>
5015
- <pre class="input-model"></pre>
5015
+ <pre class="input-model" data-language="object-spec"></pre>
5016
5016
  </div>
5017
5017
  <div>
5018
5018
  <h4>Dữ liệu trả lại</h4>
@@ -5039,7 +5039,7 @@ API.get{{EntityName}}().getViews().{{viewName}}Async(arg, result -> {
5039
5039
  </div>
5040
5040
  <div>
5041
5041
  <h4>Dữ liệu gửi lên: </h4>
5042
- <pre class="input-model"></pre>
5042
+ <pre class="input-model" data-language="object-spec"></pre>
5043
5043
  Lưu ý:
5044
5044
  <ul>
5045
5045
  <li>Chỉ những trường dữ liệu gửi lên mới được cập nhật</li>
@@ -5125,11 +5125,11 @@ API.get{{EntityName}}().getViews().{{viewName}}Async(arg, result -> {
5125
5125
  </div>
5126
5126
  <div class="request-body">
5127
5127
  <h4>Request body</h4>
5128
- <pre class="request-body-model"></pre>
5128
+ <pre class="request-body-model" data-language="object-spec"></pre>
5129
5129
  </div>
5130
5130
  <div class="response-body">
5131
5131
  <h4>Response body</h4>
5132
- <pre class="response-body-model"></pre>
5132
+ <pre class="response-body-model" data-language="object-spec"></pre>
5133
5133
  </div>
5134
5134
  </div>
5135
5135
 
@@ -5178,11 +5178,11 @@ API.get{{EntityName}}().getViews().{{viewName}}Async(arg, result -> {
5178
5178
  <h4>Dữ liệu trả về</h4>
5179
5179
  <div class="output-model">
5180
5180
  Mảng các object:
5181
- <pre>{{outputModel:html}}</pre>
5181
+ <pre data-language="object-spec">{{outputModel:html}}</pre>
5182
5182
  </div>
5183
5183
  <div class="output-epmty-result">
5184
5184
  Nếu không có phần tử nào, mảng giá trị sau sẽ được trả về:
5185
- <pre>{{outputEmptyResult}}</pre>
5185
+ <pre data-language="object-spec">{{outputEmptyResult}}</pre>
5186
5186
  </div>
5187
5187
  </div>
5188
5188
  </div>