cloudcc-cli 1.7.4 → 1.7.6

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.6
2
+ #### 发布日期:2025-1-14
3
+ #### 发布范围:全量
4
+ #### 发布内容
5
+ * 优化
6
+ * 调整发布类获取token的逻辑。
7
+ * 调整发布组件截取data内容的逻辑。
8
+
9
+ # ReleaseV1.7.5
10
+ #### 发布日期:2025-1-13
11
+ #### 发布范围:全量
12
+ #### 发布内容
13
+ * 优化
14
+ * 调整查到data逻辑。
15
+ * 调整创建组件和发布组件获取配置信息的逻辑。
16
+ * 调整setup服务前缀名称。
17
+ * 增加token缓存策略。
18
+ * 调整忽略文件。
19
+ * 自定义类/timer/triggers添加源码标识:// @SOURCE_CONTENT_START // @SOURCE_CONTENT_END
20
+
1
21
  # ReleaseV1.7.4
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.4",
3
+ "version": "1.7.6",
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>Hello</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
- },
18
+ data() {
19
+ return {
28
20
  isLock: false,
29
- };
30
- },
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,28 @@ 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
94
  vueData = vueData.split(/data\s*\(\s*\)/)[1].split(/isLock\s*:/)[0] + "isLock:false,};}";
76
95
  vueData = "function data()" + vueData;
77
96
  const data = eval(`(${vueData})`)()
78
-
97
+
79
98
  if (!data.propObj) {
80
99
  data.propObj = {};
81
100
  data.propOption = {};
82
101
  }
83
-
102
+
84
103
  if (!data.events) {
85
104
  data.events = {};
86
105
  data.eventsOption = {};
87
106
  }
88
-
107
+
89
108
  if (!data.style) {
90
109
  data.style = {
91
110
  unit: "px",
@@ -142,20 +161,38 @@ class Builder {
142
161
  },
143
162
  };
144
163
  }
145
- let component = data.componentInfo.component
146
- let compName = data.componentInfo.compName
164
+ let component;
165
+ let compName;
166
+ let bizType;
167
+ let compDesc;
168
+ let category;
169
+ let loadModel = "lazy";
170
+ let belongOrgFlag = this.options.devConsoleConfig.belongOrgFlag || "custom"
171
+ if (data.componentInfo) {
172
+ component = data.componentInfo.component
173
+ compName = data.componentInfo.compName
174
+ bizType = data.componentInfo.bizType
175
+ compDesc = data.componentInfo.compDesc
176
+ category = data.componentInfo.category
177
+ loadModel = data.componentInfo.loadModel
178
+ belongOrgFlag = data.componentInfo.belongOrgFlag
179
+ } else {
180
+ component = this.options.pluginConfig.component
181
+ compName = this.options.pluginConfig.compName
182
+ bizType = this.options.pluginConfig.bizType
183
+ compDesc = this.options.pluginConfig.compDesc
184
+ category = this.options.pluginConfig.category
185
+ loadModel = this.options.pluginConfig.loadModel
186
+ belongOrgFlag = this.options.pluginConfig.belongOrgFlag
187
+ }
147
188
  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 }
189
+ return { compName, component, vueContent, vueData, bizType, compDesc, category, loadModel, belongOrgFlag }
153
190
  };
154
-
191
+
155
192
  initPluginFile(buildFileName, component, plginTemp) {
156
193
  this.initPluginFile1(buildFileName, component, plginTemp)
157
194
  }
158
-
195
+
159
196
  initPluginFile1(buildFileName, component, plginTemp) {
160
197
  let newContent =
161
198
  `
@@ -164,13 +201,12 @@ class Builder {
164
201
  Vue.use(VueCustomElement);
165
202
 
166
203
  import index from "./` + buildFileName + `"
167
- Vue.customElement('`+ component + `', index,{ destroyTimeout: ${this.options.devConsoleConfig.destroyTimeout || 20 * 60 * 1000} });
204
+ Vue.customElement('`+ component + `', index,{ destroyTimeout: ${this.options.pluginConfig.destroyTimeout || this.options.devConsoleConfig.destroyTimeout || 20 * 60 * 1000} });
168
205
  `
169
-
170
206
  fs.writeFileSync(`plugins/${plginTemp}.js`, newContent);
171
207
  }
172
208
 
173
-
209
+
174
210
  initPluginFile2(buildFileName, component, plginTemp) {
175
211
  let newContent =
176
212
  `
@@ -189,7 +225,7 @@ class Builder {
189
225
  fs.writeFileSync(`plugins/${plginTemp}.js`, newContent);
190
226
  }
191
227
 
192
-
228
+
193
229
  build(obj, config, plginTemp) {
194
230
  console.log(chalk.green('Compiling, Please Wait...'));
195
231
  exec('npx vue-cli-service build --target lib --name ' + obj.component + ` --dest build plugins/${plginTemp}.js`, async (error, stdout, stderr) => {
@@ -205,7 +241,7 @@ class Builder {
205
241
  }
206
242
  })
207
243
  }
208
-
244
+
209
245
  async upload(obj, header) {
210
246
  console.log(chalk.green('Posting, please wait...'));
211
247
  let jsContent = "";
@@ -224,10 +260,10 @@ class Builder {
224
260
  "bizType": obj.bizType,
225
261
  "compDesc": obj.compDesc,
226
262
  "category": obj.category,
227
- "loadModel": obj.loadModel || "lazy",
228
- "belongOrgFlag": this.options.devConsoleConfig.belongOrgFlag || "custom"
263
+ "loadModel": obj.loadModel,
264
+ "belongOrgFlag": obj.belongOrgFlag
229
265
  }
230
-
266
+
231
267
  let devSvcDispatch = this.options.devConsoleConfig.devSvcDispatch || '/devconsole'
232
268
  let res = await post(`${this.options.devConsoleConfig.baseUrl || BaseUrl}${devSvcDispatch}/custom/pc/1.0/post/insertCustomComp`,
233
269
  body, header);
@@ -241,7 +277,7 @@ class Builder {
241
277
  return res;
242
278
  }
243
279
 
244
-
280
+
245
281
  getVueContent(buildFileName) {
246
282
  const jsPath = "plugins";
247
283
  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 };
@@ -2,7 +2,7 @@ const config = require("../package.json")
2
2
  const inquirer = require("inquirer")
3
3
  const exec = require('child_process').execSync;
4
4
  const chalk = require("chalk")
5
-
5
+ const { readCache, writeCache } = require("./cache")
6
6
 
7
7
  function checkNpmVersion() {
8
8
  let currentVersion = Number(config.version.replace(/\./g, ""));
@@ -66,13 +66,32 @@ function update(onlineVersion) {
66
66
 
67
67
 
68
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
+
69
82
  let onlineVersion;
70
83
  try {
71
84
  onlineVersion = checkNpmVersion();
85
+ // 更新缓存
86
+ cache[cacheKey] = {
87
+ timestamp: now
88
+ };
89
+ writeCache(cache);
72
90
  } catch (error) {
73
91
  console.log("error", error)
74
92
  onlineVersion = false;
75
93
  }
94
+
76
95
  if (onlineVersion) {
77
96
  let res = await askUpdate()
78
97
  if ("Yes" == res.update) {
@@ -80,11 +99,9 @@ async function checkUpdate() {
80
99
  return true;
81
100
  } else {
82
101
  return false
83
-
84
102
  }
85
103
  }
86
104
  return false
87
105
  }
88
106
 
89
-
90
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) {
6
- if ('private' == devConfig.version) {
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
+
23
+ if (devConfig.baseUrl) {
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,20 @@ 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;
89
+ } else {
90
+ console.log(chalk.red(res.returnInfo));
36
91
  }
37
- return false
92
+ return false;
38
93
  }
39
94
 
40
95
  module.exports = { getBusToken }