cloudcc-cli 1.9.9 → 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,22 @@
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
+
10
+ # ReleaseV2.0.0
11
+ #### Release Date: 2025-4-2
12
+ #### Release Scope: Full
13
+ #### Release Content
14
+ * Optimization
15
+ * Simplify developer information configuration
16
+ * Add component compilation error capture
17
+ * change http methods
18
+ * auto update ccopenapi.jar
19
+
1
20
  # ReleaseV1.9.9
2
21
  #### Release Date: 2025-3-12
3
22
  #### Release Scope: Full
@@ -24,15 +24,13 @@ public class CCService {
24
24
  public String URL;
25
25
  protected Map<String, Object> record_new;
26
26
  protected Map<String, Object> record_old;
27
- public Map<String, String> Config = Tool.getConfig();
27
+ public Map<String, String> Config = Tool.executeGetTokenCommand();
28
28
  public ServiceResult trigger = new ServiceResult();
29
29
  public String objectApiName;
30
- String orgId = Config.get("orgId");
31
30
 
32
31
  public CCService(UserInfo userInfo) {
33
- this.URL = Config.get("apiSvc");
34
- this.ACCESSTOKEN = Config.get("token");
35
- this.path = URL + "/openApi/common";
32
+ this.ACCESSTOKEN = Config.get("accessToken"); // 修复键名
33
+ this.path = Config.get("apiSvc") + "/openApi/common";
36
34
  }
37
35
 
38
36
  @SuppressWarnings("rawtypes")
@@ -87,6 +85,8 @@ public class CCService {
87
85
  }
88
86
  orst.add(co);
89
87
  }
88
+ } else {
89
+ System.err.println("cquery报错: " + relObj.getString("returnInfo"));
90
90
  }
91
91
  return orst;
92
92
  }
@@ -1,270 +1,47 @@
1
1
  package com.cloudcc.core;
2
2
 
3
3
  import java.io.BufferedReader;
4
- import java.io.File;
5
- import java.io.FileReader;
6
4
  import java.io.IOException;
7
5
  import java.io.InputStreamReader;
8
- import java.util.HashMap;
9
6
  import java.util.Map;
10
- import java.util.regex.Matcher;
11
- import java.util.regex.Pattern;
12
-
13
7
  import com.alibaba.fastjson.JSONObject;
14
8
 
15
9
  public class Tool {
16
- /**
17
- * 读取cloudcc-cli.config.js文件内容,解析use属性,获取对应内容
18
- *
19
- * @return Map包含currentEnv和对应的配置信息
20
- */
21
- public static Map<String, String> getConfig() {
22
- Map<String, String> result = new HashMap<>();
23
- try {
24
- // 获取配置文件路径
25
- String configPath = new File("").getAbsolutePath() + "/cloudcc-cli.config.js";
26
- File configFile = new File(configPath);
27
-
28
- if (!configFile.exists()) {
29
- System.err.println("配置文件不存在: " + configPath);
30
- return null;
31
- }
32
-
33
- // 读取文件内容
34
- StringBuilder content = new StringBuilder();
35
- try (BufferedReader reader = new BufferedReader(new FileReader(configFile))) {
36
- String line;
37
- while ((line = reader.readLine()) != null) {
38
- // 跳过注释行
39
- if (line.trim().startsWith("//")) {
40
- continue;
41
- }
42
- content.append(line).append("\n");
43
- }
44
- }
45
-
46
- String fileContent = content.toString();
47
-
48
- // 替换 'module.exports = ' 为空字符串,并移除注释
49
- String jsonStr = fileContent.replaceFirst("module\\.exports\\s*=\\s*", "")
50
- .replaceAll("//[^\\n]*", ""); // 移除单行注释
51
-
52
- // 使用正则表达式提取配置对象,处理最后可能有多余的分号
53
- Pattern configPattern = Pattern.compile("\\{([\\s\\S]*)\\}\\s*;?\\s*$");
54
- Matcher configMatcher = configPattern.matcher(jsonStr);
55
- if (configMatcher.find()) {
56
- jsonStr = "{" + configMatcher.group(1) + "}";
57
- }
58
-
59
- // 使用正则表达式提取use值
60
- Pattern usePattern = Pattern.compile("\"use\"\\s*:\\s*\"([^\"]*)\"");
61
- Matcher useMatcher = usePattern.matcher(jsonStr);
62
-
63
- if (!useMatcher.find()) {
64
- System.err.println("无法找到use属性");
65
- return null;
66
- }
67
-
68
- String currentEnv = useMatcher.group(1);
69
- result.put("currentEnv", currentEnv);
70
-
71
- // 创建更精确的正则表达式来匹配环境配置块
72
- Pattern envPattern = Pattern.compile(
73
- "\"" + Pattern.quote(currentEnv) + "\"\\s*:\\s*\\{([^\\{\\}]*(\\{[^\\{\\}]*\\})*[^\\{\\}]*)\\}");
74
- Matcher envMatcher = envPattern.matcher(jsonStr);
75
-
76
- if (envMatcher.find()) {
77
- String envConfig = envMatcher.group(1);
78
- // 解析配置项(考虑到键和值可能包含更复杂的内容)
79
- Pattern itemPattern = Pattern.compile("\"([^\"]+)\"\\s*:\\s*\"([^\"]*)\"");
80
- Matcher itemMatcher = itemPattern.matcher(envConfig);
81
- while (itemMatcher.find()) {
82
- result.put(itemMatcher.group(1), itemMatcher.group(2));
83
- }
84
-
85
- // 获取secretKey
86
- String secretKey = result.get("secretKey");
87
- if (secretKey != null) {
88
- // 从缓存文件中读取相关信息
89
- Map<String, Object> cacheData = readCache(secretKey);
90
- if (cacheData != null) {
91
- // 将缓存信息添加到结果中
92
- for (Map.Entry<String, Object> entry : cacheData.entrySet()) {
93
- result.put(entry.getKey(), String.valueOf(entry.getValue()));
94
- }
95
- }
96
- }
97
- } else {
98
- System.err.println("无法找到环境配置: " + currentEnv);
99
- }
100
-
101
- return result;
102
- } catch (IOException e) {
103
- System.err.println("读取配置文件失败: " + e.getMessage());
104
- e.printStackTrace();
105
- return null;
106
- }
107
- }
108
-
109
- /**
110
- * 读取.cloudcc-cache.json缓存文件并根据secretKey获取相关信息
111
- *
112
- * @param secretKey 密钥
113
- * @return 包含缓存信息的Map
114
- */
115
- private static Map<String, Object> readCache(String secretKey) {
116
- try {
117
- // 获取缓存文件路径
118
- String cachePath = new File("").getAbsolutePath() + "/.cloudcc-cache.json";
119
- File cacheFile = new File(cachePath);
120
-
121
- // 如果缓存文件不存在,执行刷新token命令
122
- if (!cacheFile.exists()) {
123
- boolean refreshed = executeGetTokenCommand();
124
- if (refreshed) {
125
- // 重新检查缓存文件是否存在
126
- if (cacheFile.exists()) {
127
- return readCacheAfterRefresh(secretKey);
128
- } else {
129
- System.err.println("获取token失败");
130
- return null;
131
- }
132
- } else {
133
- System.err.println("获取token失败");
134
- return null;
135
- }
136
- }
137
-
138
- // 读取文件内容
139
- StringBuilder content = new StringBuilder();
140
- try (BufferedReader reader = new BufferedReader(new FileReader(cacheFile))) {
141
- String line;
142
- while ((line = reader.readLine()) != null) {
143
- content.append(line).append("\n");
144
- }
145
- }
146
-
147
- String jsonContent = content.toString();
148
- // 使用Fastjson解析JSON内容
149
- JSONObject jsonObject = JSONObject.parseObject(jsonContent);
150
-
151
- // 检查secretKey是否存在,如果不存在,执行刷新token命令
152
- if (!jsonObject.containsKey(secretKey)) {
153
- System.out.println("缓存文件中不存在该secretKey: " + secretKey + ",正在获取新的token...");
154
- boolean refreshed = executeGetTokenCommand();
155
- if (refreshed) {
156
- return readCacheAfterRefresh(secretKey);
157
- } else {
158
- System.err.println("获取token失败");
159
- return null;
160
- }
161
- }
162
-
163
- // 获取secretKey对应的数据
164
- JSONObject secretKeyData = jsonObject.getJSONObject(secretKey);
165
-
166
- // 检查时间戳是否过期(大于1小时)或者不存在
167
- if (!secretKeyData.containsKey("timestamp") ||
168
- (System.currentTimeMillis() - secretKeyData.getLongValue("timestamp") > 60 * 60 * 1000)) {
169
- boolean refreshed = executeGetTokenCommand();
170
- if (refreshed) {
171
- // 重新读取缓存文件
172
- return readCacheAfterRefresh(secretKey);
173
- } else {
174
- System.err.println("刷新Token失败");
175
- }
176
- }
177
-
178
- // 将JSON对象转换为Map
179
- Map<String, Object> resultMap = new HashMap<>();
180
- for (String key : secretKeyData.keySet()) {
181
- resultMap.put(key, secretKeyData.get(key));
182
- }
183
- return resultMap;
184
- } catch (IOException e) {
185
- System.err.println("读取缓存文件失败: " + e.getMessage());
186
- e.printStackTrace();
187
- // 发生IO异常时,尝试获取新的token
188
- boolean refreshed = executeGetTokenCommand();
189
- if (refreshed) {
190
- return readCacheAfterRefresh(secretKey);
191
- }
192
- return null;
193
- } catch (Exception e) {
194
- System.err.println("解析缓存文件失败: " + e.getMessage());
195
- e.printStackTrace();
196
- return null;
197
- }
198
- }
199
10
 
200
11
  /**
201
12
  * 执行命令 cc get token 刷新token
202
13
  *
203
14
  * @return 执行是否成功
204
15
  */
205
- private static boolean executeGetTokenCommand() {
16
+ public static Map<String, String> executeGetTokenCommand() {
206
17
  try {
207
- ProcessBuilder processBuilder = new ProcessBuilder("cc", "get", "token");
18
+ ProcessBuilder processBuilder = new ProcessBuilder("cc", "get", "config");
208
19
  processBuilder.redirectErrorStream(true);
209
20
  Process process = processBuilder.start();
210
21
 
211
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
212
- // consume the stream if necessary
213
- }
214
-
22
+ // 等待命令执行完成
215
23
  int exitCode = process.waitFor();
216
- return exitCode == 0;
217
- } catch (IOException | InterruptedException e) {
218
- System.err.println("执行命令失败: " + e.getMessage());
219
- e.printStackTrace();
220
- return false;
221
- }
222
- }
223
-
224
- /**
225
- * 在刷新token后重新读取缓存文件
226
- *
227
- * @param secretKey 密钥
228
- * @return 包含缓存信息的Map
229
- */
230
- private static Map<String, Object> readCacheAfterRefresh(String secretKey) {
231
- try {
232
- // 获取缓存文件路径
233
- String cachePath = new File("").getAbsolutePath() + "/.cloudcc-cache.json";
234
- File cacheFile = new File(cachePath);
235
-
236
- if (!cacheFile.exists()) {
237
- System.err.println("缓存文件不存在: " + cachePath);
24
+ if (exitCode != 0) {
25
+ System.err.println("命令执行失败,退出码: " + exitCode);
238
26
  return null;
239
27
  }
240
28
 
241
- // 读取文件内容
242
- StringBuilder content = new StringBuilder();
243
- try (BufferedReader reader = new BufferedReader(new FileReader(cacheFile))) {
29
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
30
+ StringBuilder output = new StringBuilder();
244
31
  String line;
245
32
  while ((line = reader.readLine()) != null) {
246
- content.append(line).append("\n");
33
+ output.append(line);
247
34
  }
35
+ // 使用 fastjson 将 JSON 数据转换为 Map
36
+ return JSONObject.parseObject(output.toString(),
37
+ new com.alibaba.fastjson.TypeReference<Map<String, String>>() {
38
+ });
248
39
  }
249
40
 
250
- String jsonContent = content.toString();
251
- JSONObject jsonObject = JSONObject.parseObject(jsonContent);
252
-
253
- if (!jsonObject.containsKey(secretKey)) {
254
- System.err.println("缓存文件中不存在该secretKey: " + secretKey);
255
- return null;
256
- }
257
-
258
- JSONObject secretKeyData = jsonObject.getJSONObject(secretKey);
259
- Map<String, Object> resultMap = new HashMap<>();
260
- for (String key : secretKeyData.keySet()) {
261
- resultMap.put(key, secretKeyData.get(key));
262
- }
263
- return resultMap;
264
- } catch (Exception e) {
265
- System.err.println("刷新后读取缓存失败: " + e.getMessage());
41
+ } catch (IOException | InterruptedException e) {
42
+ System.err.println("执行命令失败: " + e.getMessage());
266
43
  e.printStackTrace();
267
- return null;
44
+ return null; // 返回一个空的Map
268
45
  }
269
46
  }
270
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudcc-cli",
3
- "version": "1.9.9",
3
+ "version": "2.0.1",
4
4
  "description": "cloudcc-cli",
5
5
  "keywords": [
6
6
  "cloudcc",
package/pom.xml CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  <groupId>com.cloudcc.core</groupId>
6
6
  <artifactId>ccopenapi</artifactId>
7
- <version>0.0.1</version>
7
+ <version>0.0.2</version>
8
8
  <packaging>jar</packaging>
9
9
  <name>ccopenapi</name>
10
10
  <dependencies>
@@ -49,7 +49,7 @@ 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":"${getPackageJson().extandVersion || '2'}"}`)
52
+ fs.writeFileSync(path.join(classesPath, "config.json"), `{"name":"${name}","version":"${await getPackageJson().extandVersion || '2'}"}`)
53
53
  console.log()
54
54
  console.log(chalk.green("Successfully Created:" + name))
55
55
  console.log()
@@ -2,9 +2,12 @@ const { checkUpdate } = require("../../utils/checkVersion")
2
2
  const fs = require("fs");
3
3
  const path = require("path")
4
4
  const chalk = require("chalk")
5
- const { postNormal } = require("../../utils/http")
5
+ const { postClass } = require("../../utils/http")
6
6
 
7
- const { getBusToken, javaContentRegular } = require("../../utils/utils")
7
+ const { javaContentRegular } = require("../../utils/utils")
8
+
9
+
10
+ const { getPackageJson } = require("../../utils/config")
8
11
 
9
12
  async function publish(name) {
10
13
  let res = await checkUpdate();
@@ -19,26 +22,25 @@ async function publish(name) {
19
22
  let classContent = sourceMatch ? sourceMatch[1] : fullContent;
20
23
  let configContent = JSON.parse(fs.readFileSync(classPath + "config.json", 'utf8'));
21
24
 
22
- if (await getBusToken()) {
23
- let body = {
24
- "id": configContent.id,
25
- "name": name,
26
- "source": encodeURIComponent(classContent.trim()),
27
- "version": configContent.version || "2",
28
- "folderId": "wgd"
29
- }
30
- let res = await postNormal(global.setupSvc + "/api/ccfag/save", body)
31
- if (res.result) {
32
- console.log(chalk.green('Success!'));
33
- console.log();
25
+ let body = {
26
+ "id": configContent.id,
27
+ "name": name,
28
+ "source": encodeURIComponent(classContent.trim()),
29
+ "version": configContent.version || "2",
30
+ "folderId": "wgd"
31
+ }
32
+ let config = await getPackageJson();
33
+ let res = await postClass(config.setupSvc + "/api/ccfag/save", body, config.accessToken)
34
+ if (res.result) {
35
+ console.log(chalk.green('Success!'));
36
+ console.log();
34
37
 
35
- if (!configContent.id) {
36
- configContent.id = res.data
37
- fs.writeFileSync(path.join(classPath, "config.json"), JSON.stringify(configContent))
38
- }
39
- } else {
40
- console.log(chalk.red('Fail:' + res.returnInfo));
38
+ if (!configContent.id) {
39
+ configContent.id = res.data
40
+ fs.writeFileSync(path.join(classPath, "config.json"), JSON.stringify(configContent))
41
41
  }
42
+ } else {
43
+ console.log(chalk.red('Failed:' + res.returnInfo));
42
44
  }
43
45
  }
44
46
  }
@@ -2,9 +2,11 @@ const { checkUpdate } = require("../../utils/checkVersion")
2
2
  const fs = require("fs");
3
3
  const path = require("path")
4
4
  const chalk = require("chalk")
5
- const { postNormal } = require("../../utils/http")
6
5
 
7
- const { getBusToken, javaContentRegular } = require("../../utils/utils")
6
+ const { javaContentRegular } = require("../../utils/utils")
7
+
8
+ const { getPackageJson } = require("../../utils/config")
9
+ const { postClass } = require("../../utils/http")
8
10
 
9
11
  async function pull(name) {
10
12
  let res = await checkUpdate();
@@ -14,32 +16,35 @@ async function pull(name) {
14
16
  console.log();
15
17
  const classPath = path.join(process.cwd(), `classes/${name}/`);
16
18
  let configContent = JSON.parse(fs.readFileSync(classPath + "config.json", 'utf8'));
17
- if (await getBusToken()) {
18
- let body = {
19
- "id": configContent.id,
20
- }
21
- let res = await postNormal(global.setupSvc + "/api/ccfag/detail", body)
22
- if (res.result) {
23
- console.log(chalk.green('Success!'));
24
- console.log();
25
-
26
- let fullContent = fs.readFileSync(classPath + `${name}.java`, 'utf8');
27
-
28
- let newContent = '';
29
- if (fullContent.includes("@SOURCE_CONTENT_START")) {
30
- newContent = fullContent.replace(
31
- javaContentRegular,
32
- `// @SOURCE_CONTENT_START\n${res.data.trigger.source}\n// @SOURCE_CONTENT_END`
33
- );
34
- } else {
35
- newContent = res.data.trigger.source;
36
- }
19
+ if (!configContent.id) {
20
+ console.log(chalk.red('Class ID is not exist, please publish first!'));
21
+ return;
22
+ }
23
+ let body = {
24
+ "id": configContent.id,
25
+ }
26
+ let config = await getPackageJson();
27
+ let res = await postClass(config.setupSvc + "/api/ccfag/detail", body, config.accessToken)
28
+ if (res.result) {
29
+ console.log(chalk.green('Success!'));
30
+ console.log();
37
31
 
38
- fs.writeFileSync(classPath + `${name}.java`, newContent, 'utf8');
32
+ let fullContent = fs.readFileSync(classPath + `${name}.java`, 'utf8');
39
33
 
34
+ let newContent = '';
35
+ if (fullContent.includes("@SOURCE_CONTENT_START")) {
36
+ newContent = fullContent.replace(
37
+ javaContentRegular,
38
+ `// @SOURCE_CONTENT_START\n${res.data.trigger.source}\n// @SOURCE_CONTENT_END`
39
+ );
40
40
  } else {
41
- console.log(chalk.red('Fail:' + res.returnInfo));
41
+ newContent = res.data.trigger.source;
42
42
  }
43
+
44
+ fs.writeFileSync(classPath + `${name}.java`, newContent, 'utf8');
45
+
46
+ } else {
47
+ console.log(chalk.red('Pull Fail:' + res.returnInfo));
43
48
  }
44
49
  }
45
50
  }
package/src/config/get.js CHANGED
@@ -1,20 +1,9 @@
1
1
 
2
- const chalk = require("chalk")
3
- const path = require("path")
2
+ const { getPackageJson } = require("../../utils/config.js")
4
3
 
5
4
  async function get(projectPath = process.cwd()) {
6
- let config = require(path.join(projectPath, "cloudcc-cli.config.js"))
7
- if (config) {
8
- console.log();
9
- Object.keys(config).map((item) => {
10
- if (item == config.use) {
11
- console.log(chalk.green(`*${item}`));
12
- } else if ("use" != item) {
13
- console.log(item);
14
- }
15
- })
16
- console.log();
17
- }
5
+ const config = await getPackageJson();
6
+ console.log(config);
18
7
  }
19
8
 
20
9
  module.exports = get;