mushroom-cli 1.1.0-alpha.1 → 1.1.0-alpha.10
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 +12 -0
- package/check-update.js +1 -1
- package/gen/gen-api-docs.js +11 -1
- package/gen/gen-js-driver-tarball.js +13 -3
- package/gen/gen-js-driver.js +27 -6
- package/gen/gen-ts-driver.js +61 -18
- package/mr.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,10 @@ Config gen javascript driver
|
|
|
26
26
|
|
|
27
27
|
npx mr config gen projectName js-driver ./src/api/mushroom.api.js [alias aliasName] [roles Admin,User-Contributor] [tarball tarballName]
|
|
28
28
|
|
|
29
|
+
Config gen typescript driver
|
|
30
|
+
|
|
31
|
+
npx mr config gen projectName ts-driver ./src/api/mushroom.api.ts [alias aliasName] [roles Admin,User-Contributor]
|
|
32
|
+
|
|
29
33
|
Config gen entities for Mushroom project in CSharp and using MongoDb
|
|
30
34
|
|
|
31
35
|
npx mr config gen projectName c#-mongo ./API/Generated.cs [alias aliasName]
|
|
@@ -44,10 +48,18 @@ Generate database docs (html format)
|
|
|
44
48
|
|
|
45
49
|
npx mr gen projectName[@aliasName] db-docs [tmp]
|
|
46
50
|
|
|
51
|
+
Generate npm package (tarball file)
|
|
52
|
+
|
|
53
|
+
npx mr gen projectName[@aliasName] js-driver-tarball
|
|
54
|
+
|
|
47
55
|
Generate javascript driver
|
|
48
56
|
|
|
49
57
|
npx mr gen projectName[@aliasName] js-driver
|
|
50
58
|
|
|
59
|
+
Generate typescript driver
|
|
60
|
+
|
|
61
|
+
npx mr gen projectName[@aliasName] ts-driver
|
|
62
|
+
|
|
51
63
|
Generate entities for Mushroom project in CSharp and using MongoDb
|
|
52
64
|
|
|
53
65
|
npx mr gen projectName[@aliasName] c#-mongo
|
package/check-update.js
CHANGED
package/gen/gen-api-docs.js
CHANGED
|
@@ -9,6 +9,8 @@ function processGenDocs(aliasProject, entities, source, html, args, projectName,
|
|
|
9
9
|
console.log('Received html');
|
|
10
10
|
console.log("Parsing html");
|
|
11
11
|
|
|
12
|
+
const roles = aliasProject.allowRoles.includes("*") ? source.roles : source.roles?.filter(r => aliasProject.allowRoles.includes(r.name));
|
|
13
|
+
|
|
12
14
|
html = html.replace(/^\uFEFF/, '');
|
|
13
15
|
html = html.replace(/<script src=(["'])\/\//g, "<script src=$1http://");
|
|
14
16
|
html = html.replace("</body>", `<script data-mt-cond='{"x": 1}'>
|
|
@@ -16,9 +18,11 @@ function processGenDocs(aliasProject, entities, source, html, args, projectName,
|
|
|
16
18
|
window.data.description = ${JSON.stringify(source.description)};
|
|
17
19
|
window.data.rootUrl = ${JSON.stringify(common.getRootUrl(source))};
|
|
18
20
|
window.data.environmentVariables = ${JSON.stringify(source.environmentVariables)};
|
|
21
|
+
window.data.roles = ${JSON.stringify(roles)};
|
|
19
22
|
window.data.entities = ${JSON.stringify(entities)};
|
|
20
23
|
window.data.features = ${JSON.stringify(aliasProject.features)};
|
|
21
|
-
try{
|
|
24
|
+
try {
|
|
25
|
+
console.info("MUSHROOM-CLI: START");
|
|
22
26
|
window.generateDocument();
|
|
23
27
|
console.info("MUSHROOM-CLI: FINISH");
|
|
24
28
|
}
|
|
@@ -31,6 +35,12 @@ function processGenDocs(aliasProject, entities, source, html, args, projectName,
|
|
|
31
35
|
return new Promise((resolve, reject) => {
|
|
32
36
|
const virtualConsole = new jsdom.VirtualConsole();
|
|
33
37
|
virtualConsole.on("info", function(msg, err) {
|
|
38
|
+
if (typeof msg != "string") return;
|
|
39
|
+
|
|
40
|
+
if (msg.indexOf("MUSHROOM-CLI:") === 0) {
|
|
41
|
+
console.log("GenDocEngine:" + msg.substr("MUSHROOM-CLI:".length));
|
|
42
|
+
}
|
|
43
|
+
|
|
34
44
|
if (msg === "MUSHROOM-CLI: FAIL"){
|
|
35
45
|
dom = null;
|
|
36
46
|
reject(err);
|
|
@@ -3,6 +3,7 @@ const path = require('path');
|
|
|
3
3
|
var targz = require('targz');
|
|
4
4
|
const javascriptDriverGenerator = require("./gen-js-driver");
|
|
5
5
|
const typescriptDriverGenerator = require("./gen-ts-driver");
|
|
6
|
+
const package = require("./../package.json");
|
|
6
7
|
|
|
7
8
|
function compressAsync(src, dest, folderName) {
|
|
8
9
|
return new Promise((resolve, reject) => {
|
|
@@ -37,9 +38,18 @@ async function genJavascriptDriverTarball(args, projectName, project, alias, sou
|
|
|
37
38
|
tarballName = tarballName.toLowerCase().replace(/[^a-z-]/g, "-");
|
|
38
39
|
|
|
39
40
|
const dirPath = path.join(path.dirname(aliasProject.output), tarballName);
|
|
40
|
-
//const mainFileName = path.basename(aliasProject.output);
|
|
41
|
-
//const dtsFileName = mainFileName.replace(/\.js$/i, ".d.ts");
|
|
42
41
|
|
|
42
|
+
const versionGroup = package.version.match(/([^-]+)(-(\w+).*)?/);
|
|
43
|
+
const currentDistTag = versionGroup[3] ? versionGroup[3] : "latest";
|
|
44
|
+
|
|
45
|
+
const dependencies = [`"mushroomjs": "${currentDistTag}"`];
|
|
46
|
+
if (Array.isArray(aliasProject.features) && aliasProject.features.includes("auth")) {
|
|
47
|
+
dependencies.push(`"mushroomjs-auth": "${currentDistTag}"`);
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(aliasProject.features) && aliasProject.features.includes("file")) {
|
|
50
|
+
dependencies.push(`"mushroomjs-file": "${currentDistTag}"`);
|
|
51
|
+
}
|
|
52
|
+
|
|
43
53
|
const packageContent = `{
|
|
44
54
|
"version": "1.0.${new Date().getTime()}",
|
|
45
55
|
"name": "${tarballName}",
|
|
@@ -47,7 +57,7 @@ async function genJavascriptDriverTarball(args, projectName, project, alias, sou
|
|
|
47
57
|
"main": "${tarballName}.js",
|
|
48
58
|
"types": "${tarballName}.d.ts",
|
|
49
59
|
"dependencies": {
|
|
50
|
-
|
|
60
|
+
${dependencies.join(',\n ')}
|
|
51
61
|
}
|
|
52
62
|
}`;
|
|
53
63
|
|
package/gen/gen-js-driver.js
CHANGED
|
@@ -30,12 +30,31 @@ function genJavascriptDriverString(aliasProject, source) {
|
|
|
30
30
|
|
|
31
31
|
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
32
32
|
|
|
33
|
-
let
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
extensionsExportLines.push('Auth: AuthExtension');
|
|
41
|
+
extensionsCodeLines.push("AuthExtension.useAuth(AuthExtension.AuthLocalStorage);");
|
|
42
|
+
}
|
|
43
|
+
if (aliasProject.features.includes("file")) {
|
|
44
|
+
extensionsImportLines.push('import * as FileExtension from "mushroomjs-file";');
|
|
45
|
+
extensionsExportLines.push('File: FileExtension');
|
|
46
|
+
extensionsCodeLines.push("FileExtension.useFile();");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
36
49
|
|
|
50
|
+
let code = `import mushroom, {defineAsyncResource} from "mushroomjs";
|
|
51
|
+
export * from "mushroomjs";
|
|
52
|
+
${extensionsImportLines.join("\n")}
|
|
53
|
+
export const extensions = {
|
|
54
|
+
${extensionsExportLines.join(",\n ")}
|
|
55
|
+
};
|
|
37
56
|
|
|
38
|
-
|
|
57
|
+
"use strict";
|
|
39
58
|
|
|
40
59
|
`;
|
|
41
60
|
for (let entityName in entities) {
|
|
@@ -61,11 +80,13 @@ const rootApiUrl = ${JSON.stringify(common.getRootUrl(source))};
|
|
|
61
80
|
|
|
62
81
|
views[viewName] = {};
|
|
63
82
|
}
|
|
64
|
-
code += `
|
|
83
|
+
code += `defineAsyncResource({name:${JSON.stringify(entityName)},actions:${JSON.stringify(actions)},views:${JSON.stringify(views)}});
|
|
65
84
|
`;
|
|
66
85
|
}
|
|
67
86
|
code += `
|
|
68
|
-
mushroom.$using(
|
|
87
|
+
mushroom.$using(${JSON.stringify(common.getRootUrl(source))});
|
|
88
|
+
|
|
89
|
+
${extensionsCodeLines.join('\n')}
|
|
69
90
|
|
|
70
91
|
export default mushroom;`;
|
|
71
92
|
|
package/gen/gen-ts-driver.js
CHANGED
|
@@ -104,9 +104,32 @@ function genTypescriptDriverString(aliasProject, source) {
|
|
|
104
104
|
|
|
105
105
|
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
106
106
|
|
|
107
|
+
let extensionsImportLines = [];
|
|
108
|
+
let extensionsExportLines = [];
|
|
109
|
+
let extensionsTypes = [];
|
|
110
|
+
let extensionsCodeLines = [];
|
|
111
|
+
|
|
112
|
+
if (Array.isArray(aliasProject.features)) {
|
|
113
|
+
if (aliasProject.features.includes("auth")) {
|
|
114
|
+
extensionsImportLines.push('import * as AuthExtension from "mushroomjs-auth";');
|
|
115
|
+
extensionsExportLines.push('File: FileExtension');
|
|
116
|
+
extensionsTypes.push("AuthExtension.IMushroomAuth & ");
|
|
117
|
+
extensionsCodeLines.push("AuthExtension.useAuth(AuthExtension.AuthLocalStorage);");
|
|
118
|
+
}
|
|
119
|
+
if (aliasProject.features.includes("file")) {
|
|
120
|
+
extensionsImportLines.push('import * as FileExtension from "mushroomjs-file";');
|
|
121
|
+
extensionsExportLines.push('Auth: AuthExtension');
|
|
122
|
+
extensionsTypes.push("FileExtension.IMushroomFile & ");
|
|
123
|
+
extensionsCodeLines.push("FileExtension.useFile();");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
107
127
|
let code = `import mushroom, { defineAsyncResource, defineAsyncView, fireEvent, createRestfulAsyncFunction, IdType, IMushroom, Mushroom, MushroomRequest, MushroomRequestSetting, MushroomRestfulRequest, MushroomResponse, MushroomResourceBase, MushroomListResource, MushroomFindByIdResource, MushroomCreateResource, MushroomBatchCreateResource, MushroomUpdateResource, MushroomBatchUpdateResource, MushroomPartialUpdateResource, MushroomDeleteResource, MushroomBatchDeleteResource, MushroomExtensibleResource, MushroomViewFunction, MushroomError } from "mushroomjs";
|
|
108
|
-
|
|
109
|
-
${
|
|
128
|
+
export * from "mushroomjs";
|
|
129
|
+
${extensionsImportLines.join("\n")}
|
|
130
|
+
export const extensions = {
|
|
131
|
+
${extensionsExportLines.join(",\n ")}
|
|
132
|
+
};
|
|
110
133
|
|
|
111
134
|
export type ISODateValue = string | Date;
|
|
112
135
|
export type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoIncLong" ? "number" : "string"};
|
|
@@ -119,7 +142,7 @@ export type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoI
|
|
|
119
142
|
|
|
120
143
|
const entity = entities[entityName];
|
|
121
144
|
const typescriptClassName = toTypeScriptClassName(entityName);
|
|
122
|
-
code += `interface ${typescriptClassName} ${generateTypescriptClass(entity.fields)};
|
|
145
|
+
code += `export interface ${typescriptClassName} ${generateTypescriptClass(entity.fields)};
|
|
123
146
|
`;
|
|
124
147
|
|
|
125
148
|
|
|
@@ -186,7 +209,7 @@ export type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoI
|
|
|
186
209
|
}
|
|
187
210
|
|
|
188
211
|
if (customMethodCode) {
|
|
189
|
-
code += `interface ${typescriptClassName}$CustomMethodResource {
|
|
212
|
+
code += `export interface ${typescriptClassName}$CustomMethodResource {
|
|
190
213
|
${customMethodCode}}
|
|
191
214
|
`;
|
|
192
215
|
iApiClassBody += ` & ${typescriptClassName}$CustomMethodResource`;
|
|
@@ -204,7 +227,7 @@ ${customMethodCode}}
|
|
|
204
227
|
|
|
205
228
|
const viewParameterTypes = viewRoles.map(view => {
|
|
206
229
|
const type = `${typescriptClassName}$ViewsResource_${viewName}View_${view.grant === "*" ? "" : toTypeScriptClassName(view.grant)}Parameters`;
|
|
207
|
-
code += `interface ${type} ${generateTypescriptClassFromViewParameters(view.parameters)};
|
|
230
|
+
code += `export interface ${type} ${generateTypescriptClassFromViewParameters(view.parameters)};
|
|
208
231
|
`;
|
|
209
232
|
return `MushroomViewFunction<any, ${type}>`;
|
|
210
233
|
});
|
|
@@ -213,7 +236,7 @@ ${customMethodCode}}
|
|
|
213
236
|
}
|
|
214
237
|
|
|
215
238
|
if (viewCode) {
|
|
216
|
-
code += `interface ${typescriptClassName}$ViewsResource {
|
|
239
|
+
code += `export interface ${typescriptClassName}$ViewsResource {
|
|
217
240
|
views: {${viewCode}
|
|
218
241
|
}
|
|
219
242
|
}
|
|
@@ -230,14 +253,14 @@ ${customMethodCode}}
|
|
|
230
253
|
}
|
|
231
254
|
|
|
232
255
|
code += `
|
|
233
|
-
${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? "useAuth(AuthLocalStorage);" : ""}
|
|
234
|
-
${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? "useFile();" : ""}
|
|
235
256
|
mushroom.$using(${JSON.stringify(common.getRootUrl(source))});
|
|
236
257
|
|
|
237
|
-
|
|
258
|
+
${extensionsCodeLines.join('\n')}
|
|
259
|
+
|
|
260
|
+
export interface IApi extends IMushroom {
|
|
238
261
|
${iApiClassBody}};
|
|
239
262
|
|
|
240
|
-
type Api = ${
|
|
263
|
+
export type Api = ${extensionsTypes.join('')}IApi;
|
|
241
264
|
|
|
242
265
|
export default mushroom as Api;`;
|
|
243
266
|
|
|
@@ -251,9 +274,29 @@ function genDtsString(aliasProject, source) {
|
|
|
251
274
|
|
|
252
275
|
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
253
276
|
|
|
277
|
+
let extensionsImportLines = [];
|
|
278
|
+
let extensionsExportLines = [];
|
|
279
|
+
let extensionsTypes = [];
|
|
280
|
+
|
|
281
|
+
if (Array.isArray(aliasProject.features)) {
|
|
282
|
+
if (aliasProject.features.includes("auth")) {
|
|
283
|
+
extensionsImportLines.push('import * as AuthExtension from "mushroomjs-auth";');
|
|
284
|
+
extensionsExportLines.push('Auth: AuthExtension');
|
|
285
|
+
extensionsTypes.push("AuthExtension.IMushroomAuth & ");
|
|
286
|
+
}
|
|
287
|
+
if (aliasProject.features.includes("file")) {
|
|
288
|
+
extensionsImportLines.push('import * as FileExtension from "mushroomjs-file";');
|
|
289
|
+
extensionsExportLines.push('File: FileExtension');
|
|
290
|
+
extensionsTypes.push("FileExtension.IMushroomFile & ");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
254
294
|
let code = `import { IdType, IMushroom, Mushroom, MushroomRequest, MushroomRequestSetting, MushroomRestfulRequest, MushroomResponse, MushroomResourceBase, MushroomListResource, MushroomFindByIdResource, MushroomCreateResource, MushroomBatchCreateResource, MushroomUpdateResource, MushroomBatchUpdateResource, MushroomPartialUpdateResource, MushroomDeleteResource, MushroomBatchDeleteResource, MushroomExtensibleResource, MushroomViewFunction, MushroomError } from "mushroomjs";
|
|
255
|
-
|
|
256
|
-
${
|
|
295
|
+
export * from "mushroomjs";
|
|
296
|
+
${extensionsImportLines.join("\n")}
|
|
297
|
+
export declare const extensions = {
|
|
298
|
+
${extensionsExportLines.join(",\n ")}
|
|
299
|
+
};
|
|
257
300
|
|
|
258
301
|
export declare type ISODateValue = string | Date;
|
|
259
302
|
export declare type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoIncLong" ? "number" : "string"};
|
|
@@ -266,7 +309,7 @@ export declare type IdValue = ${source.idType == "AutoIncInt" || source.idType =
|
|
|
266
309
|
|
|
267
310
|
const entity = entities[entityName];
|
|
268
311
|
const typescriptClassName = toTypeScriptClassName(entityName);
|
|
269
|
-
code += `interface ${typescriptClassName} ${generateTypescriptClass(entity.fields)};
|
|
312
|
+
code += `export interface ${typescriptClassName} ${generateTypescriptClass(entity.fields)};
|
|
270
313
|
`;
|
|
271
314
|
|
|
272
315
|
|
|
@@ -333,7 +376,7 @@ export declare type IdValue = ${source.idType == "AutoIncInt" || source.idType =
|
|
|
333
376
|
}
|
|
334
377
|
|
|
335
378
|
if (customMethodCode) {
|
|
336
|
-
code += `interface ${typescriptClassName}$CustomMethodResource {
|
|
379
|
+
code += `export interface ${typescriptClassName}$CustomMethodResource {
|
|
337
380
|
${customMethodCode}}
|
|
338
381
|
`;
|
|
339
382
|
iApiClassBody += ` & ${typescriptClassName}$CustomMethodResource`;
|
|
@@ -351,7 +394,7 @@ ${customMethodCode}}
|
|
|
351
394
|
|
|
352
395
|
const viewParameterTypes = viewRoles.map(view => {
|
|
353
396
|
const type = `${typescriptClassName}$ViewsResource_${viewName}View_${view.grant === "*" ? "" : toTypeScriptClassName(view.grant)}Parameters`;
|
|
354
|
-
code += `interface ${type} ${generateTypescriptClassFromViewParameters(view.parameters)};
|
|
397
|
+
code += `export interface ${type} ${generateTypescriptClassFromViewParameters(view.parameters)};
|
|
355
398
|
`;
|
|
356
399
|
return `MushroomViewFunction<any, ${type}>`;
|
|
357
400
|
});
|
|
@@ -360,7 +403,7 @@ ${customMethodCode}}
|
|
|
360
403
|
}
|
|
361
404
|
|
|
362
405
|
if (viewCode) {
|
|
363
|
-
code += `interface ${typescriptClassName}$ViewsResource {
|
|
406
|
+
code += `export interface ${typescriptClassName}$ViewsResource {
|
|
364
407
|
views: {${viewCode}
|
|
365
408
|
}
|
|
366
409
|
}
|
|
@@ -373,10 +416,10 @@ ${customMethodCode}}
|
|
|
373
416
|
}
|
|
374
417
|
|
|
375
418
|
code += `
|
|
376
|
-
interface IApi extends IMushroom {
|
|
419
|
+
export interface IApi extends IMushroom {
|
|
377
420
|
${iApiClassBody}};
|
|
378
421
|
|
|
379
|
-
declare type Api = ${
|
|
422
|
+
declare type Api = ${extensionsTypes.join('')}IApi;
|
|
380
423
|
declare const _default: Api;
|
|
381
424
|
export default _default;`;
|
|
382
425
|
|
package/mr.js
CHANGED
|
@@ -8,6 +8,10 @@ const help = require("./help.js");
|
|
|
8
8
|
const package = require("./package.json");
|
|
9
9
|
const checkUpdate = require("./check-update");
|
|
10
10
|
|
|
11
|
+
const versionGroup = package.version.match(/([^-]+)(-(\w+).*)?/);
|
|
12
|
+
const currentDistTag = versionGroup[3] ? versionGroup[3] : "latest";
|
|
13
|
+
console.log("Mushroom CLI version " + package.version);
|
|
14
|
+
|
|
11
15
|
async function run(args) {
|
|
12
16
|
let debugMode = false;
|
|
13
17
|
if (args.indexOf("--debug") !== -1) {
|
|
@@ -59,8 +63,8 @@ async function run(args) {
|
|
|
59
63
|
if (checkUpdateTask !== null)
|
|
60
64
|
try {
|
|
61
65
|
var data = await checkUpdateTask;
|
|
62
|
-
if (data
|
|
63
|
-
console.warn(
|
|
66
|
+
if (data["dist-tags"] && data["dist-tags"][currentDistTag] && data["dist-tags"][currentDistTag] !== package.version) {
|
|
67
|
+
console.warn(`YOUR mushroom-cli VERSION IS NOT LATEST (dist-tags: ${currentDistTag}). PLEASE RUN: npm i mushroom-cli@${data["dist-tags"][currentDistTag]}`);
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
catch(e) {
|