cloudcc-cli 2.0.0 → 2.0.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,3 +1,12 @@
1
+ # ReleaseV2.0.1
2
+ #### Release Date: 2025-4-2
3
+ #### Release Scope: Full
4
+ #### Release Content
5
+ * Optimization
6
+ * update error message
7
+ * Add verification to the pull method
8
+ * publish plugin change http
9
+
1
10
  # ReleaseV2.0.0
2
11
  #### Release Date: 2025-4-2
3
12
  #### Release Scope: Full
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudcc-cli",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "cloudcc-cli",
5
5
  "keywords": [
6
6
  "cloudcc",
@@ -16,6 +16,10 @@ async function pull(name) {
16
16
  console.log();
17
17
  const classPath = path.join(process.cwd(), `classes/${name}/`);
18
18
  let configContent = JSON.parse(fs.readFileSync(classPath + "config.json", 'utf8'));
19
+ if (!configContent.id) {
20
+ console.log(chalk.red('Class ID is not exist, please publish first!'));
21
+ return;
22
+ }
19
23
  let body = {
20
24
  "id": configContent.id,
21
25
  }
@@ -40,7 +44,7 @@ async function pull(name) {
40
44
  fs.writeFileSync(classPath + `${name}.java`, newContent, 'utf8');
41
45
 
42
46
  } else {
43
- console.log(chalk.red('Fail:' + res.returnInfo));
47
+ console.log(chalk.red('Pull Fail:' + res.returnInfo));
44
48
  }
45
49
  }
46
50
  }
@@ -3,7 +3,7 @@ const { post } = require('../../utils/http');
3
3
  const fs = require('fs');
4
4
  const path = require("path")
5
5
  const chalk = require("chalk")
6
-
6
+ const { readCache, writeCache } = require("../../utils/cache")
7
7
  const { checkUpdate } = require("../../utils/checkVersion")
8
8
  const BaseUrl = "https://developer.apis.cloudcc.cn"
9
9
  const { getPackageJson } = require("../../utils/config.js")
@@ -28,7 +28,7 @@ class Builder {
28
28
  let config = this.options.devConsoleConfig
29
29
 
30
30
  if ("private" != this.options.devConsoleConfig.version) {
31
- config = { "accessToken": this.options.devConsoleConfig.pluginToken };
31
+ config = { "accessToken": this.options.devConsoleConfig.pluginToken || await this.getToken(config) };
32
32
  }
33
33
 
34
34
  let answers = { buildFileName: `${name}/${name}.vue` }
@@ -52,7 +52,32 @@ class Builder {
52
52
  }
53
53
  }
54
54
  }
55
+ async getToken(devConsoleConfig) {
56
+ const cache = readCache();
57
+ const cacheKey = `plugin_token_${devConsoleConfig.secretKey}`;
58
+ const now = Date.now();
59
+ const oneHour = 60 * 60 * 1000;
60
+
61
+ if (cache[cacheKey] &&
62
+ cache[cacheKey].token &&
63
+ cache[cacheKey].timestamp &&
64
+ (now - cache[cacheKey].timestamp) < oneHour) {
65
+ return cache[cacheKey].token;
66
+ }
55
67
 
68
+ let res = await post((this.options.devConsoleConfig.baseUrl || BaseUrl) + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
69
+ if (res.returnCode == 200) {
70
+ cache[cacheKey] = {
71
+ token: res.data.accessToken,
72
+ timestamp: now
73
+ };
74
+ writeCache(process.cwd(), cache);
75
+ return res.data.accessToken;
76
+ } else {
77
+ console.error(chalk.red(`Login failed`, JSON.stringify(res)));
78
+ return null;
79
+ }
80
+ }
56
81
  getVueValue(buildFileName) {
57
82
  let vueContent = fs.readFileSync(this.getVueContent(buildFileName), 'utf8');
58
83
  let vueData = vueContent + ""
@@ -249,7 +274,7 @@ class Builder {
249
274
  console.error(chalk.green(`Success!`));
250
275
  console.log();
251
276
  } else {
252
- console.error(chalk.red(`Fail: ${res.returnInfo}`));
277
+ console.error(chalk.red(`Publish Plugin Fail: ${res.returnInfo}`));
253
278
  console.log();
254
279
  }
255
280
  return res;
@@ -53,7 +53,7 @@ async function publish(argvs) {
53
53
  }
54
54
  } else {
55
55
  console.log();
56
- console.log(chalk.red('Fail:' + res.returnInfo));
56
+ console.log(chalk.red('Publish Client Scirpt Failed:' + res.returnInfo));
57
57
  console.log();
58
58
  }
59
59
  } else {
@@ -18,6 +18,10 @@ async function pull(argvs) {
18
18
  let devConsoleConfig = await getPackageJson()
19
19
  console.log(chalk.green('Pulling, please wait...'));
20
20
  let configContent = JSON.parse(fs.readFileSync(srcPath + "config.json", 'utf8'));
21
+ if (!configContent.id) {
22
+ console.log(chalk.red('Script ID is not exist, please publish first!'));
23
+ return;
24
+ }
21
25
  configContent = {
22
26
  "pageSize": 20,
23
27
  "pageNo": 1,
@@ -39,7 +43,7 @@ ${res.data.list[0].scriptContent}
39
43
  fs.writeFileSync(srcPath + `${name}.js`, newContent);
40
44
  } else {
41
45
  console.log();
42
- console.log(chalk.red('Fail:' + res.returnInfo));
46
+ console.log(chalk.red('Pull Client Scirpt Failed' + res.returnInfo));
43
47
  console.log();
44
48
  }
45
49
  } else {
@@ -40,7 +40,7 @@ async function publish(name) {
40
40
  fs.writeFileSync(path.join(timerPath, "config.json"), JSON.stringify(configContent))
41
41
  }
42
42
  } else {
43
- console.log(chalk.red('Fail:' + res.returnInfo));
43
+ console.log(chalk.red('Pull Schedule Failed' + res.returnInfo));
44
44
  }
45
45
  }
46
46
  }
package/src/timer/pull.js CHANGED
@@ -15,10 +15,11 @@ async function pull(name) {
15
15
  console.log(chalk.green('Pulling, please wait...'));
16
16
  console.log();
17
17
  const timerPath = path.join(process.cwd(), `schedule/${name}/`);
18
- let fullContent = fs.readFileSync(timerPath + `${name}.java`, 'utf8');
19
-
20
18
  let configContent = JSON.parse(fs.readFileSync(timerPath + "config.json", 'utf8'));
21
-
19
+ if (!configContent.id) {
20
+ console.log(chalk.red('Schedule ID is not exist, please publish first!'));
21
+ return;
22
+ }
22
23
  let body = {
23
24
  "id": configContent.id,
24
25
  }
@@ -42,7 +43,7 @@ async function pull(name) {
42
43
  fs.writeFileSync(timerPath + `${name}.java`, newContent, 'utf8');
43
44
 
44
45
  } else {
45
- console.log(chalk.red('Fail:' + res.returnInfo));
46
+ console.log(chalk.red('Pull Schedule Failed:' + res.returnInfo));
46
47
  }
47
48
  }
48
49
  }
@@ -45,7 +45,7 @@ async function publish(argvs) {
45
45
  fs.writeFileSync(path.join(triggersPath, "config.json"), JSON.stringify(configContent))
46
46
  }
47
47
  } else {
48
- console.log(chalk.red('Fail:' + res.returnInfo));
48
+ console.log(chalk.red('Publish Trigger Failed:' + res.returnInfo));
49
49
  }
50
50
  }
51
51
  }
@@ -15,7 +15,10 @@ async function pull(argvs) {
15
15
  console.log();
16
16
  const triggersPath = path.join(process.cwd(), `triggers/${namePath}/`);
17
17
  let configContent = JSON.parse(fs.readFileSync(triggersPath + "config.json", 'utf8'));
18
-
18
+ if (!configContent.id) {
19
+ console.log(chalk.red('Trigger ID is not exist, please publish first!'));
20
+ return;
21
+ }
19
22
  let body = {
20
23
  "id": configContent.id,
21
24
  }
@@ -39,7 +42,7 @@ async function pull(argvs) {
39
42
  fs.writeFileSync(triggersPath + `${name}.java`, newContent);
40
43
 
41
44
  } else {
42
- console.log(chalk.red('Fail:' + res.returnInfo));
45
+ console.log(chalk.red('Pull Trigger Failed:' + res.returnInfo));
43
46
  }
44
47
  }
45
48
  }