mushroom-cli 1.1.0-alpha.19 → 1.1.0-alpha.20

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,75 +1,83 @@
1
- # Init
1
+ # Mushroom CLI
2
+
3
+ ## Init
2
4
 
3
5
  Init a mushroom json file
4
6
 
5
- npx mr init json ./api/SampleProject.json [silent]
7
+ npx mushroom-cli init json ./api/SampleProject.json [silent]
6
8
 
7
- Init a dotnet core project which pre-install Mushroom Server
9
+ Init a DotNet Core project which pre-install Mushroom Server
8
10
 
9
- npx mr init netcore projectName [features file,auth,mail]
11
+ npx mushroom-cli init netcore [projectName]
10
12
 
11
- # Configure
13
+ ## Configure
12
14
 
13
15
  Add the mushroom json file into mushroom-config.json
14
16
 
15
- npx mr config add ./api/yourProjectName.json
17
+ npx mushroom-cli config add ./api/yourProjectName.json
16
18
 
17
19
  Config gen docs api
18
20
 
19
- npx mr config gen projectName docs ./wwwroot/docs.html [alias aliasName] [features file,auth,mail,driver] [roles Admin,User-Contributor]
21
+ npx mushroom-cli config gen projectName docs ./wwwroot/docs.html [alias aliasName] [features file,auth,mail,driver] [roles Admin,User-Contributor]
20
22
 
21
23
  Config gen database docs
22
24
 
23
- npx mr config gen projectName db-docs ./wwwroot/db-docs.html [alias aliasName] [features file,auth,mail]
25
+ npx mushroom-cli config gen projectName db-docs ./wwwroot/db-docs.html [alias aliasName] [features file,auth,mail]
24
26
 
25
27
  Config gen javascript driver
26
28
 
27
- npx mr config gen projectName js-driver ./src/api/mushroom.api.js [alias aliasName] [roles Admin,User-Contributor] [tarball tarballName]
29
+ npx mushroom-cli config gen projectName js-driver ./src/api/mushroom.api.js [alias aliasName] [roles Admin,User-Contributor] [tarball tarballName]
28
30
 
29
31
  Config gen typescript driver
30
32
 
31
- npx mr config gen projectName ts-driver ./src/api/mushroom.api.ts [alias aliasName] [roles Admin,User-Contributor]
33
+ npx mushroom-cli config gen projectName ts-driver ./src/api/mushroom.api.ts [alias aliasName] [roles Admin,User-Contributor]
32
34
 
33
35
  Config gen entities for Mushroom project in CSharp and using MongoDb
34
36
 
35
- npx mr config gen projectName c#-mongo ./API/Generated.cs [alias aliasName]
37
+ npx mushroom-cli config gen projectName c#-mongo ./API/Generated.cs [alias aliasName]
36
38
 
37
39
  Config gen entities for CSharp project which calls Mushroom API
38
40
 
39
- npx mr config gen projectName c#-driver ./API/Generated.cs [roles Admin,User-Contributor] [alias aliasName] [access-modifier public] [features file,auth,mail]
41
+ npx mushroom-cli config gen projectName c#-driver ./API/Generated.cs [roles Admin,User-Contributor] [alias aliasName] [access-modifier public] [features file,auth,mail]
40
42
 
41
- # Genarate
43
+ ## Genarate
42
44
 
43
45
  Generate docs api (html format)
44
46
 
45
- npx mr gen projectName[@aliasName] docs [tmp]
47
+ npx mushroom-cli gen projectName[@aliasName] docs [tmp]
46
48
 
47
49
  Generate database docs (html format)
48
50
 
49
- npx mr gen projectName[@aliasName] db-docs [tmp]
51
+ npx mushroom-cli gen projectName[@aliasName] db-docs [tmp]
50
52
 
51
53
  Generate npm package (tarball file)
52
54
 
53
- npx mr gen projectName[@aliasName] js-driver-tarball
55
+ npx mushroom-cli gen projectName[@aliasName] js-driver-tarball
54
56
 
55
57
  Generate javascript driver
56
58
 
57
- npx mr gen projectName[@aliasName] js-driver
59
+ npx mushroom-cli gen projectName[@aliasName] js-driver
58
60
 
59
61
  Generate typescript driver
60
62
 
61
- npx mr gen projectName[@aliasName] ts-driver
63
+ npx mushroom-cli gen projectName[@aliasName] ts-driver
62
64
 
63
65
  Generate entities for Mushroom project in CSharp and using MongoDb
64
66
 
65
- npx mr gen projectName[@aliasName] c#-mongo
67
+ npx mushroom-cli gen projectName[@aliasName] c#-mongo
66
68
 
67
69
  Generate entities for CSharp project which calls Mushroom API
68
70
 
69
- npx mr gen projectName[@aliasName] c#-driver
71
+ npx mushroom-cli gen projectName[@aliasName] c#-driver
72
+
73
+ ## Update
74
+
75
+ Update ts code
76
+
77
+ npx mushroom-cli update ts-code [file-path.ts] [remote-ts-code-url]
70
78
 
71
- # Other
79
+ ## Other
72
80
 
73
81
  Disable checking for update:
74
82
 
75
- npx mr parameters --no-check-update
83
+ npx mushroom-cli parameters --no-check-update
@@ -125,8 +125,8 @@ function genTypescriptDriverString(aliasProject, source) {
125
125
  }
126
126
 
127
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";
128
- export * from "mushroomjs";
129
128
  ${extensionsImportLines.join("\n")}
129
+ export * from "mushroomjs";
130
130
  export const extensions = {
131
131
  ${extensionsExportLines.join(",\n ")}
132
132
  };
@@ -255,7 +255,9 @@ ${customMethodCode}}
255
255
  code += `
256
256
  mushroom.$using(${JSON.stringify(common.getRootUrl(source))});
257
257
 
258
+ (function(){
258
259
  ${extensionsCodeLines.join('\n')}
260
+ })();
259
261
 
260
262
  export interface IApi extends IMushroom {
261
263
  ${iApiClassBody}};
@@ -292,8 +294,8 @@ function genDtsString(aliasProject, source) {
292
294
  }
293
295
 
294
296
  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";
295
- export * from "mushroomjs";
296
297
  ${extensionsImportLines.join("\n")}
298
+ export * from "mushroomjs";
297
299
  export declare const extensions = {
298
300
  ${extensionsExportLines.join(",\n ")}
299
301
  };
package/mr.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const init = require("./init.js");
4
4
  const config = require("./config.js");
5
5
  const gen = require("./gen.js");
6
+ const update = require("./update.js");
6
7
  const help = require("./help.js");
7
8
 
8
9
  const pkg = require("./package.json");
@@ -19,10 +20,8 @@ async function run(args) {
19
20
  args = args.filter(arg => arg !== "--debug");
20
21
  }
21
22
 
22
- let noCheckUpdate = false;
23
23
  let checkUpdateTask;
24
24
  if (args.indexOf("--no-check-update") !== -1){
25
- noCheckUpdate = true;
26
25
  args = args.filter(arg => arg !== "--no-check-update");
27
26
  checkUpdateTask = null;
28
27
  }
@@ -42,6 +41,9 @@ async function run(args) {
42
41
  case "gen":
43
42
  await gen(args);
44
43
  break;
44
+ case "update":
45
+ await update(args);
46
+ break;
45
47
  case "":
46
48
  case undefined:
47
49
  console.log(`Mushroom CLI`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mushroom-cli",
3
- "version": "1.1.0-alpha.19",
3
+ "version": "1.1.0-alpha.20",
4
4
  "description": "Mushroom CLI",
5
5
  "main": "mr.js",
6
6
  "scripts": {
@@ -0,0 +1,20 @@
1
+ const fs = require("fs");
2
+ const fetch = require('node-fetch');
3
+
4
+ async function updateTsCode(options) {
5
+ if (!options.output) {
6
+ console.error("Missing output file path");
7
+ return;
8
+ }
9
+ if (!options.input) {
10
+ console.error("Missing remote url");
11
+ return;
12
+ }
13
+ console.log(`Fetch ${options.input}`);
14
+ const res = await fetch(options.input);
15
+ console.log(`Write to ${options.output}`);
16
+ fs.writeFileSync(options.output, await res.text());
17
+ console.log(`Finish update ts-code`);
18
+ }
19
+
20
+ module.exports = updateTsCode;
package/update.js ADDED
@@ -0,0 +1,24 @@
1
+ const help = require("./help.js");
2
+ const updateTsCode = require("./update/tsCode");
3
+
4
+ async function update(args) {
5
+ let command = args[1];
6
+
7
+ switch (command) {
8
+ case "ts-code":
9
+ await updateTsCode({
10
+ input: args[3],
11
+ output: args[2]
12
+ });
13
+ break;
14
+ case "help":
15
+ case "man":
16
+ help(args);
17
+ break;
18
+ default:
19
+ help(args, true);
20
+ break;
21
+ }
22
+ }
23
+
24
+ module.exports = update;