cloudcc-cli 1.7.3 → 1.7.5

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,23 @@
1
+ # ReleaseV1.7.5
2
+ #### 发布日期:2025-1-13
3
+ #### 发布范围:全量
4
+ #### 发布内容
5
+ * 优化
6
+ * 调整查到data逻辑。
7
+ * 调整创建组件和发布组件获取配置信息的逻辑。
8
+ * 调整setup服务前缀名称。
9
+ * 增加token缓存策略。
10
+ * 调整忽略文件。
11
+ * 自定义类/timer/triggers添加源码标识:// @SOURCE_CONTENT_START // @SOURCE_CONTENT_END
12
+
13
+ # ReleaseV1.7.4
14
+ #### 发布日期:2025-1-7
15
+ #### 发布范围:全量
16
+ #### 发布内容
17
+ * 优化
18
+ * 调整日期时间格式
19
+
20
+
1
21
  # ReleaseV1.7.3
2
22
  #### 发布日期:2025-1-7
3
23
  #### 发布范围:全量
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudcc-cli",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "description": "cloudcc-cli",
5
5
  "keywords": [
6
6
  "cloudcc",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "scripts": {
18
18
  "cc-pull": "git fetch --tags -f && git pull",
19
- "publish-lib": "npm --proxy http://127.0.0.1:33210/ publish --registry https://registry.npmjs.org && curl https://npmmirror.com/sync/cloudcc-cli"
19
+ "publish-lib": "npm --proxy http://127.0.0.1:33210/ publish --registry https://registry.npmjs.org && git add . && git commit -m '发布新版' && git push && curl https://npmmirror.com/sync/cloudcc-cli"
20
20
  },
21
21
  "dependencies": {
22
22
  "axios": "^0.21.4",
@@ -10,7 +10,8 @@ async function create(name) {
10
10
  try {
11
11
  fs.mkdirSync(classesPath, { recursive: true })
12
12
  const javaTmp =
13
- `public class ${name}{
13
+ `// @SOURCE_CONTENT_START
14
+ public class ${name}{
14
15
  private UserInfo userInfo;
15
16
 
16
17
  public ${name}(UserInfo userInfo){
@@ -23,6 +24,7 @@ async function create(name) {
23
24
  return str;
24
25
  }
25
26
  }
27
+ // @SOURCE_CONTENT_END
26
28
  `
27
29
  fs.writeFileSync(path.join(classesPath, name + ".java"), javaTmp)
28
30
  fs.writeFileSync(path.join(classesPath, "config.json"), `{"name":"${name}","version":"3"}`)
@@ -1,4 +1,3 @@
1
-
2
1
  const { checkUpdate } = require("../../utils/checkVersion")
3
2
  const fs = require("fs");
4
3
  const path = require("path")
@@ -14,22 +13,25 @@ async function publish(name) {
14
13
  console.log(chalk.green('Posting, please wait...'));
15
14
  console.log();
16
15
  const classPath = path.join(process.cwd(), `classes/${name}/`);
17
- let classContent = fs.readFileSync(classPath + `${name}.java`, 'utf8');
16
+ let fullContent = fs.readFileSync(classPath + `${name}.java`, 'utf8');
17
+
18
+ const sourceMatch = fullContent.match(/\/\/ @SOURCE_CONTENT_START\n([\s\S]*?)\n\/\/ @SOURCE_CONTENT_END/);
19
+ let classContent = sourceMatch ? sourceMatch[1] : fullContent;
18
20
  let configContent = JSON.parse(fs.readFileSync(classPath + "config.json", 'utf8'));
19
-
21
+
20
22
  if (await getBusToken()) {
21
23
  let body = {
22
24
  "id": configContent.id,
23
25
  "name": name,
24
- "version": configContent.version,
25
26
  "source": encodeURI(classContent),
27
+ "version": configContent.version,
26
28
  "folderId": "wgd"
27
29
  }
28
30
  let res = await postNormal(global.setupSvc + "/api/ccfag/save", body)
29
31
  if (res.result) {
30
32
  console.log(chalk.green('Success!'));
31
33
  console.log();
32
-
34
+
33
35
  if (!configContent.id) {
34
36
  configContent.id = res.data
35
37
  fs.writeFileSync(path.join(classPath, "config.json"), JSON.stringify(configContent))
package/src/object/get.js CHANGED
@@ -3,7 +3,7 @@ const { postNormal } = require("../../utils/http")
3
3
 
4
4
 
5
5
  async function get(path = process.cwd()) {
6
-
6
+
7
7
  if (await getBusToken(path)) {
8
8
  let res = await postNormal(global.setupSvc + "/api/customObject/standardObjList")
9
9
  console.log(JSON.stringify(res.data))
@@ -8,33 +8,25 @@ const chalk = require("chalk")
8
8
 
9
9
  async function create(name) {
10
10
  const temp = `<template>
11
- <div class="cc-container">
12
- <div>Hello CloudCC</div>
13
- </div>
11
+ <div class="cc-container">
12
+ <div>{{ CloudCC }}</div>
13
+ </div>
14
14
  </template>
15
15
 
16
16
  <script>
17
17
  export default {
18
- data() {
19
- return {
20
- componentInfo: {
21
-
22
- component: "${name}",
23
-
24
- compName: "${name}",
25
-
26
- compDesc: "Component description information",
27
- },
28
- isLock: false,
29
- };
30
- },
18
+ data() {
19
+ return {
20
+ CloudCC: "Hello CloudCC",
21
+ };
22
+ },
31
23
  };
32
24
  </script>
33
25
  <style lang="scss" scoped>
34
26
  .cc-container {
35
- text-align: center;
36
- padding: 8px;
37
- background: goldenrod;
27
+ text-align: center;
28
+ padding: 8px;
29
+ background: goldenrod;
38
30
  }
39
31
  </style>`
40
32
  let res = await checkUpdate();
@@ -44,7 +36,7 @@ background: goldenrod;
44
36
  try {
45
37
  fs.mkdirSync(pluginPath, { recursive: true })
46
38
  fs.writeFileSync(path.join(pluginPath, name + ".vue"), temp)
47
- fs.writeFileSync(path.join(pluginPath, "config.json"), `{"name":"${name}"}`)
39
+ fs.writeFileSync(path.join(pluginPath, "config.json"), `{"component":"${name}","compName":"${name}","compDesc":"Description"}`)
48
40
  console.log()
49
41
  console.log(chalk.green("Successfully Created:" + name))
50
42
  console.log()
@@ -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
- const inquirer = require("inquirer")
6
+ const { readCache, writeCache } = require("../../utils/cache") // 添加缓存模块引入
7
7
 
8
8
  const { checkUpdate } = require("../../utils/checkVersion")
9
9
  const BaseUrl = "https://developer.apis.cloudcc.cn"
@@ -13,9 +13,11 @@ const { getPackageJson } = require("../../utils/config.js")
13
13
  class Builder {
14
14
  constructor() {
15
15
  this.options = {
16
-
17
16
  devConsoleConfig: {
18
17
  },
18
+ pluginConfig: {
19
+
20
+ }
19
21
  }
20
22
  this.plugin = process.argv.splice(2)[0]
21
23
  }
@@ -23,33 +25,57 @@ class Builder {
23
25
  let res = await checkUpdate();
24
26
  if (!res) {
25
27
  this.options.devConsoleConfig = getPackageJson();
28
+ this.options.pluginConfig = JSON.parse(fs.readFileSync(path.join(process.cwd(), `plugins/${name}/config.json`), 'utf8'));
26
29
  let config = this.options.devConsoleConfig
27
-
28
- if ("private" != this.options.devConsoleConfig.version) {
30
+
31
+ if ("private" != this.options.devConsoleConfig.version) {
29
32
  config = { "accessToken": await this.getToken(config) };
30
33
  }
31
-
34
+
32
35
  let answers = { buildFileName: `${name}/${name}.vue` }
33
-
36
+
34
37
  if ("*.vue" == answers.buildFileName) {
35
38
  let dirs = fs.readdirSync("plugins")
36
39
  for (let i = 0; i < dirs.length; i++) {
37
40
  let item = dirs[i]
38
41
  let obj = this.getVueValue(item);
39
- this.initPluginFile(item, obj.component, "plginTemp" + i);
40
- this.build(obj, config, "plginTemp" + i)
42
+ if (obj) {
43
+ this.initPluginFile(item, obj.component, "plginTemp" + i);
44
+ this.build(obj, config, "plginTemp" + i)
45
+ }
41
46
  }
42
47
  } else {
43
48
  let obj = this.getVueValue(answers.buildFileName);
44
- this.initPluginFile(answers.buildFileName, obj.component, "plginTemp");
45
- this.build(obj, config, "plginTemp")
49
+ if (obj) {
50
+ this.initPluginFile(answers.buildFileName, obj.component, "plginTemp");
51
+ this.build(obj, config, "plginTemp")
52
+ }
46
53
  }
47
54
  }
48
55
  }
49
-
56
+
50
57
  async getToken(devConsoleConfig) {
58
+ const cache = readCache();
59
+ const cacheKey = `plugin_token_${devConsoleConfig.secretKey}`; // 使用orgId确保唯一性
60
+ const now = Date.now();
61
+ const oneHour = 60 * 60 * 1000;
62
+
63
+ // 检查缓存是否有效
64
+ if (cache[cacheKey] &&
65
+ cache[cacheKey].token &&
66
+ cache[cacheKey].timestamp &&
67
+ (now - cache[cacheKey].timestamp) < oneHour) {
68
+ return cache[cacheKey].token;
69
+ }
70
+
51
71
  let res = await post((this.options.devConsoleConfig.baseUrl || BaseUrl) + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
52
72
  if (res.returnCode == 200) {
73
+ // 更新缓存
74
+ cache[cacheKey] = {
75
+ token: res.data.accessToken,
76
+ timestamp: now
77
+ };
78
+ writeCache(cache);
53
79
  return res.data.accessToken;
54
80
  } else {
55
81
  console.error(chalk.red(`Login failed`, JSON.stringify(res)));
@@ -57,35 +83,43 @@ class Builder {
57
83
  }
58
84
  }
59
85
 
60
-
61
86
  getVueValue(buildFileName) {
62
87
  let vueContent = fs.readFileSync(this.getVueContent(buildFileName), 'utf8');
63
88
  let vueData = vueContent + ""
64
-
65
89
  if (!vueContent.includes("scoped")) {
66
-
67
90
  console.log()
68
91
  console.log(chalk.yellow("Warning: The scoped attribute is missing in style, which may cause global style pollution. It is recommended to fix it。"));
69
92
  console.log()
70
93
  }
71
-
72
-
73
-
74
-
75
- vueData = vueData.split(/data\s*\(\s*\)/)[1].split(/isLock\s*:/)[0] + "isLock:false,};}";
76
- vueData = "function data()" + vueData;
77
- const data = eval(`(${vueData})`)()
78
-
94
+ vueData = vueData.match(/data\s*\(\s*\)\s*{\s*return\s*({[\s\S]*?})\s*;?\s*}/);
95
+ if (vueData && vueData.length > 0) {
96
+ vueData = vueData[1]
97
+ }
98
+ let data = {};
99
+
100
+ try {
101
+ data = eval(`(${vueData})`) || {};
102
+ } catch (err) {
103
+ console.log();
104
+ console.log(chalk.red(
105
+ "Error: Failed to parse data() in component. \n" +
106
+ "Please check if there are any reference type variable in your data(). \n" +
107
+ "Suggestion: Initialize external variables in created() lifecycle hook instead."
108
+ ));
109
+ console.log();
110
+ return;
111
+ }
112
+
79
113
  if (!data.propObj) {
80
114
  data.propObj = {};
81
115
  data.propOption = {};
82
116
  }
83
-
117
+
84
118
  if (!data.events) {
85
119
  data.events = {};
86
120
  data.eventsOption = {};
87
121
  }
88
-
122
+
89
123
  if (!data.style) {
90
124
  data.style = {
91
125
  unit: "px",
@@ -142,20 +176,38 @@ class Builder {
142
176
  },
143
177
  };
144
178
  }
145
- let component = data.componentInfo.component
146
- let compName = data.componentInfo.compName
179
+ let component;
180
+ let compName;
181
+ let bizType;
182
+ let compDesc;
183
+ let category;
184
+ let loadModel = "lazy";
185
+ let belongOrgFlag = this.options.devConsoleConfig.belongOrgFlag || "custom"
186
+ if (data.componentInfo) {
187
+ component = data.componentInfo.component
188
+ compName = data.componentInfo.compName
189
+ bizType = data.componentInfo.bizType
190
+ compDesc = data.componentInfo.compDesc
191
+ category = data.componentInfo.category
192
+ loadModel = data.componentInfo.loadModel
193
+ belongOrgFlag = data.componentInfo.belongOrgFlag
194
+ } else {
195
+ component = this.options.pluginConfig.component
196
+ compName = this.options.pluginConfig.compName
197
+ bizType = this.options.pluginConfig.bizType
198
+ compDesc = this.options.pluginConfig.compDesc
199
+ category = this.options.pluginConfig.category
200
+ loadModel = this.options.pluginConfig.loadModel
201
+ belongOrgFlag = this.options.pluginConfig.belongOrgFlag
202
+ }
147
203
  vueData = JSON.stringify(data);
148
- let bizType = data.componentInfo.bizType
149
- let compDesc = data.componentInfo.compDesc
150
- let category = data.componentInfo.category
151
- let loadModel = data.componentInfo.loadModel
152
- return { compName, component, vueContent, vueData, bizType, compDesc, category, loadModel }
204
+ return { compName, component, vueContent, vueData, bizType, compDesc, category, loadModel, belongOrgFlag }
153
205
  };
154
-
206
+
155
207
  initPluginFile(buildFileName, component, plginTemp) {
156
208
  this.initPluginFile1(buildFileName, component, plginTemp)
157
209
  }
158
-
210
+
159
211
  initPluginFile1(buildFileName, component, plginTemp) {
160
212
  let newContent =
161
213
  `
@@ -164,13 +216,12 @@ class Builder {
164
216
  Vue.use(VueCustomElement);
165
217
 
166
218
  import index from "./` + buildFileName + `"
167
- Vue.customElement('`+ component + `', index,{ destroyTimeout: ${this.options.devConsoleConfig.destroyTimeout || 20 * 60 * 1000} });
219
+ Vue.customElement('`+ component + `', index,{ destroyTimeout: ${this.options.pluginConfig.destroyTimeout || this.options.devConsoleConfig.destroyTimeout || 20 * 60 * 1000} });
168
220
  `
169
-
170
221
  fs.writeFileSync(`plugins/${plginTemp}.js`, newContent);
171
222
  }
172
223
 
173
-
224
+
174
225
  initPluginFile2(buildFileName, component, plginTemp) {
175
226
  let newContent =
176
227
  `
@@ -189,7 +240,7 @@ class Builder {
189
240
  fs.writeFileSync(`plugins/${plginTemp}.js`, newContent);
190
241
  }
191
242
 
192
-
243
+
193
244
  build(obj, config, plginTemp) {
194
245
  console.log(chalk.green('Compiling, Please Wait...'));
195
246
  exec('npx vue-cli-service build --target lib --name ' + obj.component + ` --dest build plugins/${plginTemp}.js`, async (error, stdout, stderr) => {
@@ -205,7 +256,7 @@ class Builder {
205
256
  }
206
257
  })
207
258
  }
208
-
259
+
209
260
  async upload(obj, header) {
210
261
  console.log(chalk.green('Posting, please wait...'));
211
262
  let jsContent = "";
@@ -224,10 +275,10 @@ class Builder {
224
275
  "bizType": obj.bizType,
225
276
  "compDesc": obj.compDesc,
226
277
  "category": obj.category,
227
- "loadModel": obj.loadModel || "lazy",
228
- "belongOrgFlag": this.options.devConsoleConfig.belongOrgFlag || "custom"
278
+ "loadModel": obj.loadModel,
279
+ "belongOrgFlag": obj.belongOrgFlag
229
280
  }
230
-
281
+
231
282
  let devSvcDispatch = this.options.devConsoleConfig.devSvcDispatch || '/devconsole'
232
283
  let res = await post(`${this.options.devConsoleConfig.baseUrl || BaseUrl}${devSvcDispatch}/custom/pc/1.0/post/insertCustomComp`,
233
284
  body, header);
@@ -241,7 +292,7 @@ class Builder {
241
292
  return res;
242
293
  }
243
294
 
244
-
295
+
245
296
  getVueContent(buildFileName) {
246
297
  const jsPath = "plugins";
247
298
  return path.join(jsPath, buildFileName);
@@ -0,0 +1,7 @@
1
+ ## 原始命令
2
+ * create
3
+ * publish
4
+
5
+ ## 1.0命令
6
+ * create1
7
+ * publish1
@@ -6,6 +6,7 @@ const chalk = require("chalk")
6
6
  const { post } = require("../../utils/http")
7
7
  const { getPackageJson } = require("../../utils/config.js")
8
8
  const BaseUrl = "https://developer.apis.cloudcc.cn"
9
+ const { getBusToken } = require("../../utils/utils")
9
10
 
10
11
  async function publish(argvs) {
11
12
  let name = argvs[2]
@@ -18,9 +19,9 @@ async function publish(argvs) {
18
19
 
19
20
  if (classContent) {
20
21
  let devConsoleConfig = getPackageJson()
21
-
22
+
22
23
  if ("private" != devConsoleConfig.version) {
23
- devConsoleConfig = { "accessToken": await getToken(devConsoleConfig) };
24
+ devConsoleConfig = { "accessToken": await getBusToken() };
24
25
  }
25
26
  console.log(chalk.green('Posting, please wait...'));
26
27
  configContent.scriptContent = classContent
@@ -29,7 +30,7 @@ async function publish(argvs) {
29
30
  console.log();
30
31
  console.log(chalk.green('Success!'));
31
32
  console.log();
32
-
33
+
33
34
  if (!configContentOld.id) {
34
35
  configContentOld.id = res.data
35
36
  fs.writeFileSync(path.join(srcPath, "config.json"), JSON.stringify(configContentOld))
@@ -47,16 +48,4 @@ async function publish(argvs) {
47
48
  }
48
49
  }
49
50
 
50
-
51
-
52
- async function getToken(devConsoleConfig) {
53
- let res = await post(devConsoleConfig.baseUrl || BaseUrl + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
54
- if (res.returnCode == 200) {
55
- return res.data.accessToken;
56
- } else {
57
- console.error(chalk.red(`Login failed`, JSON.stringify(res)));
58
- return null;
59
- }
60
- }
61
-
62
51
  module.exports = publish;
@@ -9,7 +9,9 @@ async function create(name) {
9
9
  const timerPath = path.join(process.cwd(), "timer/" + name);
10
10
  try {
11
11
  fs.mkdirSync(timerPath, { recursive: true })
12
- const javaTmp = `System.out.print("hello CloudCC");`
12
+ const javaTmp = `// @SOURCE_CONTENT_START
13
+ System.out.print("hello CloudCC");
14
+ // @SOURCE_CONTENT_END`
13
15
  fs.writeFileSync(path.join(timerPath, name + ".java"), javaTmp)
14
16
  fs.writeFileSync(path.join(timerPath, "config.json"), `{"name":"${name}","version":"3"}`)
15
17
  console.log()
@@ -1,4 +1,3 @@
1
-
2
1
  const { checkUpdate } = require("../../utils/checkVersion")
3
2
  const fs = require("fs");
4
3
  const path = require("path")
@@ -14,9 +13,14 @@ async function publish(name) {
14
13
  console.log(chalk.green('Posting, please wait...'));
15
14
  console.log();
16
15
  const timerPath = path.join(process.cwd(), `timer/${name}/`);
17
- let classContent = fs.readFileSync(timerPath + `${name}.java`, 'utf8');
16
+ let fullContent = fs.readFileSync(timerPath + `${name}.java`, 'utf8');
17
+
18
+ // 提取标记之间的内容
19
+ const sourceMatch = fullContent.match(/\/\/ @SOURCE_CONTENT_START\n([\s\S]*?)\n\/\/ @SOURCE_CONTENT_END/);
20
+ let classContent = sourceMatch ? sourceMatch[1] : fullContent;
21
+
18
22
  let configContent = JSON.parse(fs.readFileSync(timerPath + "config.json", 'utf8'));
19
-
23
+
20
24
  if (await getBusToken()) {
21
25
  let body = {
22
26
  "id": configContent.id,
@@ -29,7 +33,7 @@ async function publish(name) {
29
33
  if (res.result) {
30
34
  console.log(chalk.green('Success!'));
31
35
  console.log();
32
-
36
+
33
37
  if (!configContent.id) {
34
38
  configContent.id = res.data
35
39
  fs.writeFileSync(path.join(timerPath, "config.json"), JSON.stringify(configContent))
@@ -10,7 +10,9 @@ async function create(argvs) {
10
10
  const triggersPath = path.join(process.cwd(), "triggers/" + body.name);
11
11
  try {
12
12
  fs.mkdirSync(triggersPath, { recursive: true })
13
- const javaTmp = `System.out.print("hello CloudCC");`
13
+ const javaTmp = `// @SOURCE_CONTENT_START
14
+ System.out.print("hello CloudCC");
15
+ // @SOURCE_CONTENT_END`
14
16
  fs.writeFileSync(path.join(triggersPath, body.name + ".java"), javaTmp)
15
17
  fs.writeFileSync(path.join(triggersPath, "config.json"), JSON.stringify(body))
16
18
  console.log()
@@ -1,4 +1,3 @@
1
-
2
1
  const { checkUpdate } = require("../../utils/checkVersion")
3
2
  const fs = require("fs");
4
3
  const path = require("path")
@@ -14,9 +13,14 @@ async function publish(argvs) {
14
13
  console.log(chalk.green('Posting, please wait...'));
15
14
  console.log();
16
15
  const triggersPath = path.join(process.cwd(), `triggers/${name}/`);
17
- let classContent = fs.readFileSync(triggersPath + `${name}.java`, 'utf8');
16
+ let fullContent = fs.readFileSync(triggersPath + `${name}.java`, 'utf8');
17
+
18
+ // 提取标记之间的内容
19
+ const sourceMatch = fullContent.match(/\/\/ @SOURCE_CONTENT_START\n([\s\S]*?)\n\/\/ @SOURCE_CONTENT_END/);
20
+ let classContent = sourceMatch ? sourceMatch[1] : fullContent;
21
+
18
22
  let configContent = JSON.parse(fs.readFileSync(triggersPath + "config.json", 'utf8'));
19
-
23
+
20
24
  if (await getBusToken()) {
21
25
  let body = {
22
26
  "id": configContent.id,
@@ -33,7 +37,7 @@ async function publish(argvs) {
33
37
  if (res.result) {
34
38
  console.log(chalk.green('Success!'));
35
39
  console.log();
36
-
40
+
37
41
  if (!configContent.id) {
38
42
  configContent.id = res.data.id
39
43
  configContent.apiname = res.data.apiname
@@ -1,7 +1,3 @@
1
- .DS_Store
2
- node_modules/
3
- build
4
-
5
1
  # Editor directories and files
6
2
  .idea
7
3
  .vscode
@@ -9,3 +5,10 @@ build
9
5
  *.ntvs*
10
6
  *.njsproj
11
7
  *.sln
8
+ .cloudcc-cache.json
9
+ .temp
10
+ .cache
11
+ .idea
12
+ ./build
13
+ .DS_Store
14
+ node_modules/
package/utils/cache.js ADDED
@@ -0,0 +1,31 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ function getCachePath() {
5
+ return path.join(process.cwd(), '.cloudcc-cache.json');
6
+ }
7
+
8
+ function readCache() {
9
+ try {
10
+ const cachePath = getCachePath();
11
+ if (!fs.existsSync(cachePath)) {
12
+ fs.writeFileSync(cachePath, JSON.stringify({}, null, 2));
13
+ return {};
14
+ }
15
+ const cacheContent = fs.readFileSync(cachePath, 'utf8');
16
+ return JSON.parse(cacheContent);
17
+ } catch (error) {
18
+ return {};
19
+ }
20
+ }
21
+
22
+ function writeCache(data) {
23
+ try {
24
+ const cachePath = getCachePath();
25
+ fs.writeFileSync(cachePath, JSON.stringify(data, null, 2));
26
+ } catch (error) {
27
+ console.error('Failed to write cache:', error);
28
+ }
29
+ }
30
+
31
+ module.exports = { readCache, writeCache };
@@ -1,42 +1,37 @@
1
-
2
1
  const config = require("../package.json")
3
2
  const inquirer = require("inquirer")
4
3
  const exec = require('child_process').execSync;
5
4
  const chalk = require("chalk")
6
-
5
+ const { readCache, writeCache } = require("./cache")
7
6
 
8
7
  function checkNpmVersion() {
9
8
  let currentVersion = Number(config.version.replace(/\./g, ""));
10
9
  let onlineVersionNum
11
10
  let onlineVersion = '0.0.1'
12
11
 
13
-
12
+ // 获取在线版本
14
13
  onlineVersion = exec(`npm view cloudcc-cli version --registry http://registry.npmmirror.com`)
15
14
  onlineVersion = onlineVersion.toString("utf8").trim();
16
15
 
17
-
18
-
19
-
20
-
21
-
22
-
16
+ // 获取发布时间信息
17
+ const timeInfo = exec(`npm view cloudcc-cli time --json --registry http://registry.npmmirror.com`)
18
+ const timeData = JSON.parse(timeInfo.toString().trim());
19
+ const formattedTime = new Date(timeData[onlineVersion]).toLocaleString('zh-CN', {
20
+ year: 'numeric',
21
+ month: '2-digit',
22
+ day: '2-digit'
23
+ });
24
+
23
25
  onlineVersionNum = Number(onlineVersion.replace(/\./g, ""));
24
26
 
25
- console.log(chalk.green(
26
- `
27
- ********************************************************************************
28
- * *
29
- * CloudCC CLI *
30
- * *
31
- * Current Version:V${config.version} *
32
- * Latest Version:V${onlineVersion} *
33
- * *
34
- * *
35
- ********************************************************************************
36
- `
37
- ))
38
-
39
-
27
+ console.log('\n');
28
+ console.log(chalk.bold.cyan(' CloudCC CLI Version\n'));
29
+ console.log(' ' + chalk.gray('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'));
30
+ console.log(' ' + chalk.green('★') + ' Current Version : ' + chalk.bold.green('v' + config.version));
31
+ console.log(' ' + chalk.blue('★') + ' Latest Version : ' + chalk.bold.blue('v' + onlineVersion));
32
+ console.log(' ' + chalk.yellow('★') + ' Published At : ' + chalk.gray(formattedTime));
33
+ console.log(' ' + chalk.gray('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
34
+
40
35
  if (onlineVersionNum - currentVersion > 0) {
41
36
  return onlineVersion;
42
37
  }
@@ -71,13 +66,32 @@ function update(onlineVersion) {
71
66
 
72
67
 
73
68
  async function checkUpdate() {
69
+ // 检查缓存
70
+ const cache = readCache();
71
+ const cacheKey = 'version_check';
72
+ const now = Date.now();
73
+ const oneHour = 60 * 60 * 1000;
74
+
75
+ // 如果缓存有效,跳过版本检查
76
+ if (cache[cacheKey] &&
77
+ cache[cacheKey].timestamp &&
78
+ (now - cache[cacheKey].timestamp) < oneHour) {
79
+ return false;
80
+ }
81
+
74
82
  let onlineVersion;
75
83
  try {
76
84
  onlineVersion = checkNpmVersion();
85
+ // 更新缓存
86
+ cache[cacheKey] = {
87
+ timestamp: now
88
+ };
89
+ writeCache(cache);
77
90
  } catch (error) {
78
91
  console.log("error", error)
79
92
  onlineVersion = false;
80
93
  }
94
+
81
95
  if (onlineVersion) {
82
96
  let res = await askUpdate()
83
97
  if ("Yes" == res.update) {
@@ -90,5 +104,4 @@ async function checkUpdate() {
90
104
  return false
91
105
  }
92
106
 
93
-
94
107
  module.exports = { checkUpdate }
package/utils/utils.js CHANGED
@@ -1,26 +1,71 @@
1
1
  const { getParams, postNormal } = require("./http")
2
2
  const chalk = require("chalk")
3
3
  const { getPackageJson } = require("./config")
4
+ const { readCache, writeCache } = require("./cache")
4
5
 
5
6
  async function getBaseUrl(devConfig) {
7
+ const cache = readCache();
8
+ const cacheKey = devConfig.secretKey;
9
+ const now = Date.now();
10
+ const oneHour = 60 * 60 * 1000;
11
+
12
+ // Check if cache is valid
13
+ if (cache[cacheKey] &&
14
+ cache[cacheKey].apiSvc &&
15
+ cache[cacheKey].setupSvc &&
16
+ cache[cacheKey].timestamp &&
17
+ (now - cache[cacheKey].timestamp) < oneHour) {
18
+ global.apiSvc = cache[cacheKey].apiSvc;
19
+ global.setupSvc = cache[cacheKey].setupSvc;
20
+ return;
21
+ }
22
+
6
23
  if ('private' == devConfig.version) {
7
24
  global.apiSvc = devConfig.baseUrl + (devConfig.apiSvcPrefix || "/apitfs")
8
- global.setupSvc = devConfig.baseUrl + (devConfig.setupSvcPrefix || "/ccsetup")
25
+ global.setupSvc = devConfig.baseUrl + (devConfig.setupSvcPrefix || "/setup")
9
26
  } else {
10
27
  let u = "https://developer.apis.cloudcc.cn/oauth/apidomain?scope=cloudccCRM&orgId=" + devConfig.orgId
11
28
  let res = await getParams(u)
12
29
  global.apiSvc = res.orgapi_address
13
- global.setupSvc = new URL(res.orgapi_address).origin + (devConfig.setupSvcPrefix || "/ccsetup")
30
+ global.setupSvc = new URL(res.orgapi_address).origin + (devConfig.setupSvcPrefix || "/setup")
14
31
  }
32
+
33
+ // Update cache with apiSvc and setupSvc
34
+ cache[cacheKey] = {
35
+ ...(cache[cacheKey] || {}),
36
+ apiSvc: global.apiSvc,
37
+ setupSvc: global.setupSvc,
38
+ timestamp: now
39
+ };
40
+ writeCache(cache);
15
41
  }
16
42
 
17
- async function getBusToken(path) {
43
+ async function getBusToken(path = process.cwd()) {
18
44
  let devConfig = getPackageJson(path);
19
45
  if (!devConfig.username || !devConfig.safetyMark || !devConfig.clientId || !devConfig.openSecretKey || !devConfig.orgId) {
20
46
  console.log(chalk.red('The security tag configuration is incorrect. Please check the documentation for configuration.'));
21
47
  console.log();
22
48
  return false;
23
49
  }
50
+
51
+ const cache = readCache();
52
+ const cacheKey = devConfig.secretKey;
53
+ const now = Date.now();
54
+ const oneHour = 60 * 60 * 1000;
55
+
56
+ // Check if cache is valid
57
+ if (cache[cacheKey] &&
58
+ cache[cacheKey].token &&
59
+ cache[cacheKey].apiSvc &&
60
+ cache[cacheKey].setupSvc &&
61
+ cache[cacheKey].timestamp &&
62
+ (now - cache[cacheKey].timestamp) < oneHour) {
63
+ global.accessToken = cache[cacheKey].token;
64
+ global.apiSvc = cache[cacheKey].apiSvc;
65
+ global.setupSvc = cache[cacheKey].setupSvc;
66
+ return cache[cacheKey].token;
67
+ }
68
+
24
69
  let body = {
25
70
  username: devConfig.username,
26
71
  safetyMark: devConfig.safetyMark,
@@ -31,10 +76,18 @@ async function getBusToken(path) {
31
76
  await getBaseUrl(devConfig)
32
77
  let res = await postNormal(global.apiSvc + "/api/cauth/token", body)
33
78
  if (res.result) {
34
- global.accessToken = res.data.accessToken
79
+ global.accessToken = res.data.accessToken;
80
+ // Update cache
81
+ cache[cacheKey] = {
82
+ token: res.data.accessToken,
83
+ apiSvc: global.apiSvc,
84
+ setupSvc: global.setupSvc,
85
+ timestamp: now
86
+ };
87
+ writeCache(cache);
35
88
  return res.data.accessToken;
36
89
  }
37
- return false
90
+ return false;
38
91
  }
39
92
 
40
93
  module.exports = { getBusToken }