mushroom-cli 1.0.17 → 1.1.0-alpha.4

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
@@ -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
@@ -2,7 +2,7 @@ const fetch = require('node-fetch');
2
2
 
3
3
 
4
4
  function checkUpdate() {
5
- return fetch('https://registry.npmjs.org/mushroom-cli/latest')
5
+ return fetch('https://registry.npmjs.org/mushroom-cli/')
6
6
  .then(res => res.json());
7
7
  }
8
8
 
@@ -1,7 +1,8 @@
1
1
  const fs = require("fs");
2
2
  const path = require('path');
3
3
  var targz = require('targz');
4
- const genJavascriptDriver = require("./gen-js-driver");
4
+ const javascriptDriverGenerator = require("./gen-js-driver");
5
+ const typescriptDriverGenerator = require("./gen-ts-driver");
5
6
 
6
7
  function compressAsync(src, dest, folderName) {
7
8
  return new Promise((resolve, reject) => {
@@ -30,22 +31,23 @@ function compressAsync(src, dest, folderName) {
30
31
  }
31
32
 
32
33
  async function genJavascriptDriverTarball(args, projectName, project, alias, source) {
33
- genJavascriptDriver(args, projectName, project, alias, source);
34
-
35
34
  const aliasProject = ((project.jsDriver || {}).alias || {})[alias];
36
35
 
37
36
  let tarballName = aliasProject.tarballName ? aliasProject.tarballName : projectName;
38
37
  tarballName = tarballName.toLowerCase().replace(/[^a-z-]/g, "-");
39
38
 
40
39
  const dirPath = path.join(path.dirname(aliasProject.output), tarballName);
41
- const mainFileName = path.basename(aliasProject.output);
40
+ //const mainFileName = path.basename(aliasProject.output);
41
+ //const dtsFileName = mainFileName.replace(/\.js$/i, ".d.ts");
42
42
 
43
43
  const packageContent = `{
44
+ "version": "1.0.${new Date().getTime()}",
44
45
  "name": "${tarballName}",
45
46
  "private": true,
46
- "main": "${mainFileName}",
47
+ "main": "${tarballName}.js",
48
+ "types": "${tarballName}.d.ts",
47
49
  "dependencies": {
48
- "mushroomjs": "^1.0.4"
50
+ "mushroomjs": "^1.1.0-alpha.7"${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? ',\n "mushroomjs-auth": "^1.1.0-alpha.4"' : ""}${Array.isArray(aliasProject.features) && aliasProject.features.includes("file") ? ',\n "mushroomjs-file": "^1.1.0-alpha.1"' : ""}
49
51
  }
50
52
  }`;
51
53
 
@@ -65,16 +67,21 @@ async function genJavascriptDriverTarball(args, projectName, project, alias, sou
65
67
 
66
68
  fs.mkdirSync(dirPath, { recursive: true, mode: 0755 });
67
69
 
70
+ console.log("Generating main file: " + tarballName + ".js");
71
+ let code = javascriptDriverGenerator.genJavascriptDriverString(aliasProject, source);
72
+ fs.writeFileSync(path.join(dirPath, tarballName + ".js"), code);
68
73
 
69
- console.log("Generating tarball file " + tarballFileName);
70
-
71
- fs.copyFileSync(aliasProject.output, path.join(dirPath, mainFileName));
74
+ console.log("Generating types file: " + tarballName + ".d.ts");
75
+ code = typescriptDriverGenerator.genDtsString(aliasProject, source);
76
+ fs.writeFileSync(path.join(dirPath, tarballName + ".d.ts"), code);
72
77
 
78
+ console.log("Generating package file: package.json");
73
79
  fs.writeFileSync(path.join(dirPath, "package.json"), packageContent);
74
80
 
81
+ console.log("Generating tarball file: " + tarballFileName);
75
82
  await compressAsync(dirPath, tarballFileName, tarballName);
76
83
 
77
- console.log(`Generated tarball file ${aliasProject.output}`);
84
+ console.log("Generated tarball file");
78
85
  fs.rmdirSync(dirPath, { recursive: true });
79
86
  console.log("Cleaned up tarball folder");
80
87
  }
@@ -1,5 +1,6 @@
1
1
  const fs = require("fs");
2
2
  const common = require("../common.js");
3
+ const typescriptDriverGenerator = require("./gen-ts-driver");
3
4
 
4
5
  function isAllowCache(actions, defaultValue) {
5
6
  let result = defaultValue;
@@ -22,22 +23,19 @@ function isAllowCache(actions, defaultValue) {
22
23
  return result;
23
24
  }
24
25
 
25
- function genJavascriptDriver(args, projectName, project, alias, source) {
26
- const aliasProject = ((project.jsDriver || {}).alias || {})[alias];
27
-
26
+ function genJavascriptDriverString(aliasProject, source) {
28
27
  if (!aliasProject) {
29
- throw new Error(`Not found gen js-driver configuration. Please run 'npx mr config gen ${projectName} js-driver OUTPUT_FILE.js${alias === "default" ? "" : " alias " + alias}' first`);
28
+ return "";
30
29
  }
31
30
 
32
31
  const entities = common.getEntities(source, aliasProject.allowRoles);
33
32
 
34
- let code = `import mushroom from "mushroomjs";
33
+ let code = `import mushroom, {defineAsyncResource} from "mushroomjs";
34
+ ${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? 'import { useAuth, AuthLocalStorage } from "mushroomjs-auth";' : ""}
35
+ ${Array.isArray(aliasProject.features) && aliasProject.features.includes("file") ? 'import { useFile } from "mushroomjs-file";' : ""}
35
36
 
36
37
  "use strict";
37
38
 
38
-
39
- const rootApiUrl = ${JSON.stringify(common.getRootUrl(source))};
40
-
41
39
  `;
42
40
  for (let entityName in entities) {
43
41
  if (!entities.hasOwnProperty(entityName))
@@ -62,18 +60,42 @@ const rootApiUrl = ${JSON.stringify(common.getRootUrl(source))};
62
60
 
63
61
  views[viewName] = {};
64
62
  }
65
- code += `mushroom._defineAsyncResource({name:${JSON.stringify(entityName)},actions:${JSON.stringify(actions)},views:${JSON.stringify(views)}});
63
+ code += `defineAsyncResource({name:${JSON.stringify(entityName)},actions:${JSON.stringify(actions)},views:${JSON.stringify(views)}});
66
64
  `;
67
65
  }
68
66
  code += `
69
- mushroom.$using(rootApiUrl);
67
+ mushroom.$using(${JSON.stringify(common.getRootUrl(source))});
68
+
69
+ ${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? "useAuth(AuthLocalStorage);" : ""}
70
+ ${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? "useFile();" : ""}
70
71
 
71
72
  export default mushroom;`;
72
73
 
74
+ return code;
75
+ }
76
+
77
+ function genJavascriptDriver(args, projectName, project, alias, source) {
78
+ const aliasProject = ((project.jsDriver || {}).alias || {})[alias];
79
+
80
+ if (!aliasProject) {
81
+ throw new Error(`Not found gen js-driver configuration. Please run 'npx mr config gen ${projectName} js-driver OUTPUT_FILE.js${alias === "default" ? "" : " alias " + alias}' first`);
82
+ }
83
+
84
+ let code = genJavascriptDriverString(aliasProject, source);
85
+
73
86
  common.ensureFolder(aliasProject.output);
74
87
 
75
88
  fs.writeFileSync(aliasProject.output, code);
76
- console.log(`Generated Javascript driver for ${projectName}@${alias} to ${aliasProject.output}`);
89
+ console.log(`Generated ${aliasProject.output}`);
90
+
91
+ code = typescriptDriverGenerator.genDtsString(aliasProject, source);
92
+ const dtsFilePath = aliasProject.output.replace(/\.js$/i, ".d.ts");
93
+ fs.writeFileSync(dtsFilePath, code);
94
+ console.log(`Generated ${dtsFilePath}`);
95
+ console.log(`Generated Javascript driver for ${projectName}@${alias}`);
77
96
  }
78
97
 
79
- module.exports = genJavascriptDriver;
98
+ module.exports = {
99
+ genJavascriptDriver,
100
+ genJavascriptDriverString
101
+ };
@@ -90,32 +90,42 @@ function generateTypescriptClass(objectDefination, indent) {
90
90
  return code;
91
91
  }
92
92
 
93
- function genTypescriptDriver(args, projectName, project, alias, source) {
94
- const aliasProject = ((project.tsDriver || {}).alias || {})[alias];
93
+ function generateTypescriptClassFromViewParameters(parameters) {
94
+ if (Array.isArray(parameters)){
95
+ return '{\n' + parameters.map(p => ` ${p.field}?: ${getCSharpTypeFromMushroomType(p.type || "string")}${p.isArray ? "[]" : ""}`).join(',\n') + '\n}';
96
+ }
97
+ return '{}';
98
+ }
95
99
 
100
+ function genTypescriptDriverString(aliasProject, source) {
96
101
  if (!aliasProject) {
97
- throw new Error(`Not found gen ts-driver configuration. Please run 'npx mr config gen ${projectName} ts-driver OUTPUT_FILE.ts${alias === "default" ? "" : " alias " + alias}' first`);
102
+ return "";
98
103
  }
99
104
 
100
105
  const entities = common.getEntities(source, aliasProject.allowRoles);
101
106
 
102
- 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, MushroomError } from "mushroomjs";
107
+ 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
+ ${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? 'import { IMushroomAuth, useAuth, AuthLocalStorage } from "mushroomjs-auth";' : ""}
109
+ ${Array.isArray(aliasProject.features) && aliasProject.features.includes("file") ? 'import { IMushroomFile, useFile } from "mushroomjs-file";' : ""}
103
110
 
104
111
  export type ISODateValue = string | Date;
105
112
  export type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoIncLong" ? "number" : "string"};
106
113
 
107
114
  `;
115
+ let iApiClassBody = "";
108
116
  for (let entityName in entities) {
109
117
  if (!entities.hasOwnProperty(entityName))
110
118
  continue;
111
119
 
112
120
  const entity = entities[entityName];
113
-
114
- code += `interface ${toTypeScriptClassName(entityName)} ${generateTypescriptClass(entity.fields)}
121
+ const typescriptClassName = toTypeScriptClassName(entityName);
122
+ code += `interface ${typescriptClassName} ${generateTypescriptClass(entity.fields)};
115
123
  `;
116
124
 
117
125
 
118
126
  const actions = {};
127
+ iApiClassBody += ` ${entityName}: MushroomResourceBase`;
128
+ let customMethodCode = "";
119
129
  for (const actionName in entity.actions) {
120
130
  if (!entity.actions.hasOwnProperty(actionName))
121
131
  continue;
@@ -123,23 +133,264 @@ export type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoI
123
133
  actions[actionName] = {
124
134
  clientCache: (actionName === "findById" || actionName === "findMany") && isAllowCache(entity.actions[actionName], true) ? true : undefined
125
135
  };
136
+
137
+ switch (actionName) {
138
+ case "findMany": {
139
+ iApiClassBody += ` & MushroomListResource<${typescriptClassName}>`;
140
+ break;
141
+ }
142
+ case "findById": {
143
+ iApiClassBody += ` & MushroomFindByIdResource<${typescriptClassName}>`;
144
+ break;
145
+ }
146
+ case "createOne": {
147
+ iApiClassBody += ` & MushroomCreateResource<${typescriptClassName}>`;
148
+ break;
149
+ }
150
+ case "createMany": {
151
+ iApiClassBody += ` & MushroomBatchCreateResource<${typescriptClassName}>`;
152
+ break;
153
+ }
154
+ case "updateOne": {
155
+ iApiClassBody += ` & MushroomUpdateResource<${typescriptClassName}>`;
156
+ break;
157
+ }
158
+ case "updateMany": {
159
+ iApiClassBody += ` & MushroomBatchUpdateResource<${typescriptClassName}>`;
160
+ break;
161
+ }
162
+ case "updatePartially": {
163
+ iApiClassBody += ` & MushroomPartialUpdateResource<${typescriptClassName}>`;
164
+ break;
165
+ }
166
+ case "deleteOne": {
167
+ iApiClassBody += " & MushroomDeleteResource";
168
+ break;
169
+ }
170
+ case "deleteMany": {
171
+ iApiClassBody += " & MushroomBatchDeleteResource";
172
+ break;
173
+ }
174
+ default: {
175
+ if (actionName.indexOf("_raw_http_method_") === 0) {
176
+ customMethodCode += ` ${actionName.substr("_raw_http_method_".length)}Async: (rawRequest: MushroomRequest) => Promise<MushroomResponse<any>>,
177
+ `;
178
+ break;
179
+ }
180
+ else {
181
+ console.warn(`Unknown action name: ${entityName}.${actionName}`);
182
+ break;
183
+ }
184
+ }
185
+ }
186
+ }
187
+
188
+ if (customMethodCode) {
189
+ code += `interface ${typescriptClassName}$CustomMethodResource {
190
+ ${customMethodCode}}
191
+ `;
192
+ iApiClassBody += ` & ${typescriptClassName}$CustomMethodResource`;
126
193
  }
127
194
 
128
195
  const views = {};
196
+ let viewCode = "";
129
197
  for (const viewName in entity.views) {
130
- if (!entity.views.hasOwnProperty(viewName))
131
- continue;
198
+ if (!entity.views.hasOwnProperty(viewName)) continue;
199
+
200
+ const viewRoles = entity.views[viewName];
201
+ if (!Array.isArray(viewRoles) || !viewRoles.length) continue;
132
202
 
133
203
  views[viewName] = { clientCache: true };
204
+
205
+ const viewParameterTypes = viewRoles.map(view => {
206
+ const type = `${typescriptClassName}$ViewsResource_${viewName}View_${view.grant === "*" ? "" : toTypeScriptClassName(view.grant)}Parameters`;
207
+ code += `interface ${type} ${generateTypescriptClassFromViewParameters(view.parameters)};
208
+ `;
209
+ return `MushroomViewFunction<any, ${type}>`;
210
+ });
211
+ viewCode += `
212
+ ${viewName}Async: ${viewParameterTypes.join(' & ')},`;
134
213
  }
135
- code += `defineAsyncResource<${toTypeScriptClassName(entityName)}>(${JSON.stringify({ name: entityName, actions: actions, views: views })});
214
+
215
+ if (viewCode) {
216
+ code += `interface ${typescriptClassName}$ViewsResource {
217
+ views: {${viewCode}
218
+ }
219
+ }
220
+ `;
221
+ iApiClassBody += ` & ${typescriptClassName}$ViewsResource`;
222
+ }
223
+
224
+ iApiClassBody +=`,
225
+ `;
226
+
227
+ code += `defineAsyncResource<${typescriptClassName}>(${JSON.stringify({ name: entityName, actions: actions, views: views })});
136
228
 
137
229
  `;
138
230
  }
231
+
139
232
  code += `
233
+ ${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? "useAuth(AuthLocalStorage);" : ""}
234
+ ${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? "useFile();" : ""}
140
235
  mushroom.$using(${JSON.stringify(common.getRootUrl(source))});
141
236
 
142
- export default mushroom;`;
237
+ interface IApi extends IMushroom {
238
+ ${iApiClassBody}};
239
+
240
+ type Api = ${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? "IMushroomAuth & " : ""}${Array.isArray(aliasProject.features) && aliasProject.features.includes("file") ? "IMushroomFile & " : ""}IApi;
241
+
242
+ export default mushroom as Api;`;
243
+
244
+ return code;
245
+ }
246
+
247
+ function genDtsString(aliasProject, source) {
248
+ if (!aliasProject) {
249
+ return "";
250
+ }
251
+
252
+ const entities = common.getEntities(source, aliasProject.allowRoles);
253
+
254
+ 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
+ ${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? 'import { IMushroomAuth } from "mushroomjs-auth";' : ""}
256
+ ${Array.isArray(aliasProject.features) && aliasProject.features.includes("file") ? 'import { IMushroomFile } from "mushroomjs-file";' : ""}
257
+
258
+ export declare type ISODateValue = string | Date;
259
+ export declare type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoIncLong" ? "number" : "string"};
260
+
261
+ `;
262
+ let iApiClassBody = "";
263
+ for (let entityName in entities) {
264
+ if (!entities.hasOwnProperty(entityName))
265
+ continue;
266
+
267
+ const entity = entities[entityName];
268
+ const typescriptClassName = toTypeScriptClassName(entityName);
269
+ code += `interface ${typescriptClassName} ${generateTypescriptClass(entity.fields)};
270
+ `;
271
+
272
+
273
+ const actions = {};
274
+ iApiClassBody += ` ${entityName}: MushroomResourceBase`;
275
+ let customMethodCode = "";
276
+ for (const actionName in entity.actions) {
277
+ if (!entity.actions.hasOwnProperty(actionName))
278
+ continue;
279
+
280
+ actions[actionName] = {
281
+ clientCache: (actionName === "findById" || actionName === "findMany") && isAllowCache(entity.actions[actionName], true) ? true : undefined
282
+ };
283
+
284
+ switch (actionName) {
285
+ case "findMany": {
286
+ iApiClassBody += ` & MushroomListResource<${typescriptClassName}>`;
287
+ break;
288
+ }
289
+ case "findById": {
290
+ iApiClassBody += ` & MushroomFindByIdResource<${typescriptClassName}>`;
291
+ break;
292
+ }
293
+ case "createOne": {
294
+ iApiClassBody += ` & MushroomCreateResource<${typescriptClassName}>`;
295
+ break;
296
+ }
297
+ case "createMany": {
298
+ iApiClassBody += ` & MushroomBatchCreateResource<${typescriptClassName}>`;
299
+ break;
300
+ }
301
+ case "updateOne": {
302
+ iApiClassBody += ` & MushroomUpdateResource<${typescriptClassName}>`;
303
+ break;
304
+ }
305
+ case "updateMany": {
306
+ iApiClassBody += ` & MushroomBatchUpdateResource<${typescriptClassName}>`;
307
+ break;
308
+ }
309
+ case "updatePartially": {
310
+ iApiClassBody += ` & MushroomPartialUpdateResource<${typescriptClassName}>`;
311
+ break;
312
+ }
313
+ case "deleteOne": {
314
+ iApiClassBody += " & MushroomDeleteResource";
315
+ break;
316
+ }
317
+ case "deleteMany": {
318
+ iApiClassBody += " & MushroomBatchDeleteResource";
319
+ break;
320
+ }
321
+ default: {
322
+ if (actionName.indexOf("_raw_http_method_") === 0) {
323
+ customMethodCode += ` ${actionName.substr("_raw_http_method_".length)}Async: (rawRequest: MushroomRequest) => Promise<MushroomResponse<any>>,
324
+ `;
325
+ break;
326
+ }
327
+ else {
328
+ console.warn(`Unknown action name: ${entityName}.${actionName}`);
329
+ break;
330
+ }
331
+ }
332
+ }
333
+ }
334
+
335
+ if (customMethodCode) {
336
+ code += `interface ${typescriptClassName}$CustomMethodResource {
337
+ ${customMethodCode}}
338
+ `;
339
+ iApiClassBody += ` & ${typescriptClassName}$CustomMethodResource`;
340
+ }
341
+
342
+ const views = {};
343
+ let viewCode = "";
344
+ for (const viewName in entity.views) {
345
+ if (!entity.views.hasOwnProperty(viewName)) continue;
346
+
347
+ const viewRoles = entity.views[viewName];
348
+ if (!Array.isArray(viewRoles) || !viewRoles.length) continue;
349
+
350
+ views[viewName] = { clientCache: true };
351
+
352
+ const viewParameterTypes = viewRoles.map(view => {
353
+ const type = `${typescriptClassName}$ViewsResource_${viewName}View_${view.grant === "*" ? "" : toTypeScriptClassName(view.grant)}Parameters`;
354
+ code += `interface ${type} ${generateTypescriptClassFromViewParameters(view.parameters)};
355
+ `;
356
+ return `MushroomViewFunction<any, ${type}>`;
357
+ });
358
+ viewCode += `
359
+ ${viewName}Async: ${viewParameterTypes.join(' & ')},`;
360
+ }
361
+
362
+ if (viewCode) {
363
+ code += `interface ${typescriptClassName}$ViewsResource {
364
+ views: {${viewCode}
365
+ }
366
+ }
367
+ `;
368
+ iApiClassBody += ` & ${typescriptClassName}$ViewsResource`;
369
+ }
370
+
371
+ iApiClassBody +=`,
372
+ `;
373
+ }
374
+
375
+ code += `
376
+ interface IApi extends IMushroom {
377
+ ${iApiClassBody}};
378
+
379
+ declare type Api = ${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? "IMushroomAuth & " : ""}${Array.isArray(aliasProject.features) && aliasProject.features.includes("file") ? "IMushroomFile & " : ""}IApi;
380
+ declare const _default: Api;
381
+ export default _default;`;
382
+
383
+ return code;
384
+ }
385
+
386
+ function genTypescriptDriver(args, projectName, project, alias, source) {
387
+ const aliasProject = ((project.tsDriver || {}).alias || {})[alias];
388
+
389
+ if (!aliasProject) {
390
+ throw new Error(`Not found gen ts-driver configuration. Please run 'npx mr config gen ${projectName} ts-driver OUTPUT_FILE.ts${alias === "default" ? "" : " alias " + alias}' first`);
391
+ }
392
+
393
+ const code = genTypescriptDriverString(aliasProject, source);
143
394
 
144
395
  common.ensureFolder(aliasProject.output);
145
396
 
@@ -147,4 +398,8 @@ export default mushroom;`;
147
398
  console.log(`Generated Typescript driver for ${projectName}@${alias} to ${aliasProject.output}`);
148
399
  }
149
400
 
150
- module.exports = genTypescriptDriver;
401
+ module.exports = {
402
+ genTypescriptDriver,
403
+ genTypescriptDriverString,
404
+ genDtsString
405
+ };
package/gen.js CHANGED
@@ -7,9 +7,9 @@ const masterFile = require("./master-file/master-file");
7
7
 
8
8
  const genApiDocs = require("./gen/gen-api-docs");
9
9
  const genDatabaseDocs = require("./gen/gen-db-docs");
10
- const genJavascriptDriver = require("./gen/gen-js-driver");
10
+ const javascriptDriverGenerator = require("./gen/gen-js-driver");
11
11
  const genJavascriptDriverTarball = require("./gen/gen-js-driver-tarball");
12
- const genTypescriptDriver = require("./gen/gen-ts-driver");
12
+ const typescriptDriverGenerator = require("./gen/gen-ts-driver");
13
13
  const csharp = require("./gen/gen-csharp");
14
14
 
15
15
 
@@ -91,13 +91,13 @@ async function gen(args) {
91
91
  genDatabaseDocs(args, projectName, project, alias, source);
92
92
  break;
93
93
  case "js-driver":
94
- genJavascriptDriver(args, projectName, project, alias, source);
94
+ javascriptDriverGenerator.genJavascriptDriver(args, projectName, project, alias, source);
95
95
  break;
96
96
  case "js-driver-tarball":
97
97
  await genJavascriptDriverTarball(args, projectName, project, alias, source);
98
98
  break;
99
99
  case "ts-driver":
100
- genTypescriptDriver(args, projectName, project, alias, source);
100
+ typescriptDriverGenerator.genTypescriptDriver(args, projectName, project, alias, source);
101
101
  break;
102
102
  case "c#-mongo":
103
103
  csharp.genCSharpMongoDbClasses(args, projectName, project, alias, source);
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) {
@@ -58,9 +62,9 @@ async function run(args) {
58
62
 
59
63
  if (checkUpdateTask !== null)
60
64
  try {
61
- var data = await checkUpdateTask;
62
- if (data.version && data.version !== package.version) {
63
- console.warn("YOUR mushroom-cli VERSION IS NOT LATEST. PLEASE RUN: npm i mushroom-cli@" + data.version);
65
+ var data = await checkUpdateTask;
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) {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "mushroom-cli",
3
- "version": "1.0.17",
3
+ "version": "1.1.0-alpha.4",
4
4
  "description": "Mushroom CLI",
5
5
  "main": "mr.js",
6
6
  "scripts": {
7
- "release": "npm publish --access public"
7
+ "release": "npm publish --access public --tag alpha"
8
8
  },
9
9
  "keywords": [
10
10
  "Mushroom",