mushroom-cli 1.1.0-alpha.9 → 1.2.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/mr.js CHANGED
@@ -3,14 +3,15 @@
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
- const package = require("./package.json");
9
+ const pkg = require("./package.json");
9
10
  const checkUpdate = require("./check-update");
10
11
 
11
- const versionGroup = package.version.match(/([^-]+)(-(\w+).*)?/);
12
+ const versionGroup = pkg.version.match(/([^-]+)(-(\w+).*)?/);
12
13
  const currentDistTag = versionGroup[3] ? versionGroup[3] : "latest";
13
- console.log("Mushroom CLI version " + package.version);
14
+ console.log("Mushroom CLI version " + pkg.version);
14
15
 
15
16
  async function run(args) {
16
17
  let debugMode = false;
@@ -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`);
@@ -63,8 +65,8 @@ async function run(args) {
63
65
  if (checkUpdateTask !== null)
64
66
  try {
65
67
  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]}`);
68
+ if (data["dist-tags"] && data["dist-tags"][currentDistTag] && data["dist-tags"][currentDistTag] !== pkg.version) {
69
+ console.warn(`YOUR mushroom-cli VERSION IS NOT LATEST (dist-tags: ${currentDistTag}). PLEASE RUN: npm i mushroom-cli@${data["dist-tags"][currentDistTag]} OR yarn add mushroom-cli@^${data["dist-tags"][currentDistTag]}`);
68
70
  }
69
71
  }
70
72
  catch(e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mushroom-cli",
3
- "version": "1.1.0-alpha.9",
3
+ "version": "1.2.0-alpha.1",
4
4
  "description": "Mushroom CLI",
5
5
  "main": "mr.js",
6
6
  "scripts": {
@@ -17,10 +17,10 @@
17
17
  "author": "suco2007",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "jsdom": "^16.2.2",
21
- "json5": "^2.1.2",
22
- "node-fetch": "^2.6.0",
23
- "open": "^7.0.3",
20
+ "jsdom": "^21.0.0",
21
+ "json5": "^2.2.3",
22
+ "node-fetch": "^2.6.7",
23
+ "open": "^8.4.0",
24
24
  "readline-sync": "^1.4.10",
25
25
  "targz": "^1.0.1"
26
26
  }
@@ -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;