cloudcc-cli 2.0.0 → 2.0.2

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,19 @@
1
+ # ReleaseV2.0.2
2
+ #### Release Date: 2025-4-2
3
+ #### Release Scope: Full
4
+ #### Release Content
5
+ * Optimization
6
+ * Fix baseUrl Prefix
7
+
8
+ # ReleaseV2.0.1
9
+ #### Release Date: 2025-4-2
10
+ #### Release Scope: Full
11
+ #### Release Content
12
+ * Optimization
13
+ * update error message
14
+ * Add verification to the pull method
15
+ * publish plugin change http
16
+
1
17
  # ReleaseV2.0.0
2
18
  #### Release Date: 2025-4-2
3
19
  #### 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.2",
4
4
  "description": "cloudcc-cli",
5
5
  "keywords": [
6
6
  "cloudcc",
@@ -49,13 +49,14 @@ public class ${name}Test {
49
49
  `
50
50
  fs.writeFileSync(path.join(classesPath, name + ".java"), javaTmp)
51
51
  fs.writeFileSync(path.join(classesPath, name + "Test.java"), javaTestTmp)
52
- fs.writeFileSync(path.join(classesPath, "config.json"), `{"name":"${name}","version":"${await getPackageJson().extandVersion || '2'}"}`)
52
+ let config = await getPackageJson();
53
+ fs.writeFileSync(path.join(classesPath, "config.json"), `{"name":"${name}","version":"${config.extandVersion || '2'}"}`)
53
54
  console.log()
54
55
  console.log(chalk.green("Successfully Created:" + name))
55
56
  console.log()
56
57
  } catch (e) {
57
58
  console.log()
58
- console.log(chalk.red("Creation Failed:" + e))
59
+ console.log(chalk.red("Creation Class Failed:" + e))
59
60
  console.log()
60
61
  }
61
62
  }
@@ -40,7 +40,7 @@ async function publish(name) {
40
40
  fs.writeFileSync(path.join(classPath, "config.json"), JSON.stringify(configContent))
41
41
  }
42
42
  } else {
43
- console.log(chalk.red('Failed:' + res.returnInfo));
43
+ console.log(chalk.red('Publish Class Failed:' + res.returnInfo));
44
44
  }
45
45
  }
46
46
  }
@@ -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 Class Failed:' + res.returnInfo));
44
48
  }
45
49
  }
46
50
  }
package/src/config/get.js CHANGED
@@ -2,7 +2,7 @@
2
2
  const { getPackageJson } = require("../../utils/config.js")
3
3
 
4
4
  async function get(projectPath = process.cwd()) {
5
- const config = await getPackageJson();
5
+ const config = await getPackageJson(projectPath);
6
6
  console.log(config);
7
7
  }
8
8
 
@@ -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;
@@ -26,7 +26,7 @@ async function create(argvs) {
26
26
  console.log()
27
27
  } catch (e) {
28
28
  console.log()
29
- console.log(chalk.red("Creation Failed:" + e))
29
+ console.log(chalk.red("Creation Client Script Failed:" + e))
30
30
  console.log()
31
31
  }
32
32
  }
@@ -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 {
@@ -24,13 +24,14 @@ public class ${name} extends CCSchedule {
24
24
  }
25
25
  }`
26
26
  fs.writeFileSync(path.join(timerPath, name + ".java"), javaTmp)
27
- fs.writeFileSync(path.join(timerPath, "config.json"), `{"name":"${name}","version":"${await getPackageJson().extandVersion || '2'}"}`)
27
+ let config = await getPackageJson();
28
+ fs.writeFileSync(path.join(timerPath, "config.json"), `{"name":"${name}","version":"${config.extandVersion || '2'}"}`)
28
29
  console.log()
29
30
  console.log(chalk.green("Successfully Created:" + name))
30
31
  console.log()
31
32
  } catch (e) {
32
33
  console.log()
33
- console.log(chalk.red("Creation Failed:" + e))
34
+ console.log(chalk.red("Creation Schedule Failed:" + e))
34
35
  console.log()
35
36
  }
36
37
  }
@@ -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
  }
@@ -17,7 +17,7 @@ async function create(argvs) {
17
17
  fs.mkdirSync(triggersPath, { recursive: true });
18
18
 
19
19
  const javaTmp =
20
- `package triggers.${body.schemetableName.toLowerCase()}.${body.name};
20
+ `package triggers.${body.schemetableName.toLowerCase()}.${body.name};
21
21
 
22
22
  import com.cloudcc.core.*;
23
23
 
@@ -30,7 +30,8 @@ public class ${body.name} extends CCTrigger {
30
30
  }`
31
31
 
32
32
  fs.writeFileSync(path.join(triggersPath, body.name + ".java"), javaTmp);
33
- body.version =await getPackageJson().extandVersion || "2";
33
+ let config = await getPackageJson();
34
+ body.version = config.extandVersion || "2";
34
35
  body.isactive = true;
35
36
  fs.writeFileSync(path.join(triggersPath, "config.json"), JSON.stringify(body));
36
37
  console.log();
@@ -38,7 +39,7 @@ public class ${body.name} extends CCTrigger {
38
39
  console.log();
39
40
  } catch (e) {
40
41
  console.log()
41
- console.log(chalk.red("Creation Failed:" + e))
42
+ console.log(chalk.red("Creation Trigger Failed:" + e))
42
43
  console.log()
43
44
  }
44
45
  }
@@ -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
  }
@@ -107,7 +107,6 @@ function checkAndReplaceJar(projectPath = process.cwd()) {
107
107
  const templateLibPath = path.join(__dirname, '../template/lib');
108
108
 
109
109
  if (!fs.existsSync(projectLibPath)) {
110
- console.log(chalk.red('Project lib folder does not exist.'));
111
110
  return;
112
111
  }
113
112
 
package/utils/config.js CHANGED
@@ -21,9 +21,9 @@ function getPackageJson_old(projectPath = process.cwd()) {
21
21
  async function getPackageJson2(projectPath = process.cwd()) {
22
22
  let config = require(path.join(projectPath, "cloudcc-cli.config.js"))
23
23
  config = config[config.use]
24
- if (config.baseUrl && !config.baseUrl.includes("ccdomaingateway")) {
25
- config.baseUrl = config.baseUrl + "/ccdomaingateway"
26
- }
24
+ // if (config.baseUrl && !config.baseUrl.includes("ccdomaingateway")) {
25
+ // config.baseUrl = config.baseUrl + "/ccdomaingateway"
26
+ // }
27
27
  config = await getDevConsoleConfig(projectPath, config)
28
28
  return config
29
29
  }
@@ -41,9 +41,9 @@ async function getPackageJson3(projectPath = process.cwd()) {
41
41
  const decryptedInfo = decryptCloudCCDevInfo(config.CloudCCDev);
42
42
  if (decryptedInfo) {
43
43
  config = { ...decryptedInfo, ...config }
44
- if (config.baseUrl && !config.baseUrl.includes("ccdomaingateway")) {
45
- config.baseUrl = config.baseUrl + "/ccdomaingateway"
46
- }
44
+ // if (config.baseUrl && !config.baseUrl.includes("ccdomaingateway")) {
45
+ // config.baseUrl = config.baseUrl + "/ccdomaingateway"
46
+ // }
47
47
  config = await getDevConsoleConfig(projectPath, config)
48
48
  }
49
49
  } else {
package/utils/utils.js CHANGED
@@ -72,19 +72,23 @@ async function getBusToken(config) {
72
72
  secretKey: config.openSecretKey,
73
73
  orgId: config.orgId
74
74
  }
75
-
76
- const res = await axios({
77
- method: 'post',
78
- url: config.apiSvc + "/api/cauth/token",
79
- headers: {
80
- 'Content-Type': 'application/json; charset=utf-8',
81
- },
82
- data: body
83
- });
84
- if (res.data.result) {
85
- config.accessToken = res.data.data.accessToken;
86
- } else {
87
- console.error(chalk.red(`Get OpenAPI Token Failed:`, res.data.returnInfo));
75
+ try {
76
+ const res = await axios({
77
+ method: 'post',
78
+ url: config.apiSvc + "/api/cauth/token",
79
+ headers: {
80
+ 'Content-Type': 'application/json; charset=utf-8',
81
+ },
82
+ data: body
83
+ });
84
+ if (res.data.result) {
85
+ config.accessToken = res.data.data.accessToken;
86
+ } else {
87
+ console.error(chalk.red(`Get OpenAPI Token Failed:`, res.data.returnInfo));
88
+ process.exit(1)
89
+ }
90
+ } catch (error) {
91
+ console.error(chalk.red(`Get OpenAPI Token Failed:`, error.message));
88
92
  process.exit(1)
89
93
  }
90
94
  }