cloudcc-cli 1.8.9 → 1.9.0

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,10 @@
1
+ # ReleaseV1.9.0
2
+ #### Release Date: 2025-2-10
3
+ #### Release Scope: Full
4
+ #### Release Content
5
+ * Optimization
6
+ * add pull code method
7
+
1
8
  # ReleaseV1.8.9
2
9
  #### Release Date: 2025-2-6
3
10
  #### Release Scope: Full
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudcc-cli",
3
- "version": "1.8.9",
3
+ "version": "1.9.0",
4
4
  "description": "cloudcc-cli",
5
5
  "keywords": [
6
6
  "cloudcc",
@@ -1,6 +1,7 @@
1
1
  const cc = {}
2
2
  cc.create = require("./create")
3
3
  cc.publish = require("./publish")
4
+ cc.pull = require("./pull")
4
5
  function Classes(action, argvs) {
5
6
  cc[action](argvs[2])
6
7
  }
@@ -15,7 +15,7 @@ async function publish(name) {
15
15
  const classPath = path.join(process.cwd(), `classes/${name}/`);
16
16
  let fullContent = fs.readFileSync(classPath + `${name}.java`, 'utf8');
17
17
 
18
- const sourceMatch = fullContent.match(/\/\/ @SOURCE_CONTENT_START\n([\s\S]*?)\n\/\/ @SOURCE_CONTENT_END/);
18
+ const sourceMatch = fullContent.match(/\/\/\s*@SOURCE_CONTENT_START\n([\s\S]*?)\n\/\/\s*@SOURCE_CONTENT_END/);
19
19
  let classContent = sourceMatch ? sourceMatch[1] : fullContent;
20
20
  let configContent = JSON.parse(fs.readFileSync(classPath + "config.json", 'utf8'));
21
21
 
@@ -23,7 +23,7 @@ async function publish(name) {
23
23
  let body = {
24
24
  "id": configContent.id,
25
25
  "name": name,
26
- "source": encodeURIComponent(classContent),
26
+ "source": encodeURIComponent(classContent.trim()),
27
27
  "version": configContent.version || "2",
28
28
  "folderId": "wgd"
29
29
  }
@@ -0,0 +1,46 @@
1
+ const { checkUpdate } = require("../../utils/checkVersion")
2
+ const fs = require("fs");
3
+ const path = require("path")
4
+ const chalk = require("chalk")
5
+ const { postNormal } = require("../../utils/http")
6
+
7
+ const { getBusToken } = require("../../utils/utils")
8
+
9
+ async function pull(name) {
10
+ let res = await checkUpdate();
11
+ if (!res) {
12
+ console.log();
13
+ console.log(chalk.green('Pulling, please wait...'));
14
+ console.log();
15
+ const classPath = path.join(process.cwd(), `classes/${name}/`);
16
+ 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) {
30
+ newContent = fullContent.replace(
31
+ /\/\/ @SOURCE_CONTENT_START\n[\s\S]*?\n\/\/ @SOURCE_CONTENT_END/,
32
+ `// @SOURCE_CONTENT_START\n${res.data.trigger.source}\n// @SOURCE_CONTENT_END`
33
+ );
34
+ } else {
35
+ newContent = res.data.trigger.source;
36
+ }
37
+
38
+ fs.writeFileSync(classPath + `${name}.java`, newContent, 'utf8');
39
+
40
+ } else {
41
+ console.log(chalk.red('Fail:' + res.returnInfo));
42
+ }
43
+ }
44
+ }
45
+ }
46
+ module.exports = pull;
package/src/object/get.js CHANGED
@@ -2,31 +2,44 @@ const { getBusToken } = require("../../utils/utils")
2
2
  const { postNormal } = require("../../utils/http")
3
3
 
4
4
 
5
- async function get(path) {
5
+ async function get(path, type) {
6
6
  if (await getBusToken(path)) {
7
7
  let res = [];
8
- //get standar object
9
- let standardObjList = await postNormal(global.setupSvc + "/api/customObject/standardObjList")
10
- standardObjList.data.forEach((item) => {
11
- res.push({
12
- id: item.id,
13
- label: item.objname,
14
- objname: item.label,
15
- objprefix: item.objprefix,
16
- schemetableName: item.label
8
+ if ("trigger" === type) {
9
+ //get trigger object
10
+ let triggerObjList = await postNormal(global.setupSvc + "/api/trigger/newobjtrigger")
11
+ triggerObjList.data.targetObjList.map((item) => {
12
+ res.push({
13
+ id: item.id,
14
+ label: item.label,
15
+ objname: item.schemetable_name,
16
+ schemetableName: item.schemetableName
17
+ })
17
18
  })
18
- })
19
- //get custom object
20
- let customObjList = await postNormal(global.setupSvc + "/api/customObject/list")
21
- customObjList.data.objList.map((item) => {
22
- res.push({
23
- id: item.id,
24
- label: item.objLabel,
25
- objname: item.schemetable_name,
26
- objprefix: item.prefix,
27
- schemetableName: item.schemetableName
19
+ } else {
20
+ //get standar object
21
+ let standardObjList = await postNormal(global.setupSvc + "/api/customObject/standardObjList")
22
+ standardObjList.data.forEach((item) => {
23
+ res.push({
24
+ id: item.id,
25
+ label: item.objname,
26
+ objname: item.label,
27
+ objprefix: item.objprefix,
28
+ schemetableName: item.label
29
+ })
28
30
  })
29
- })
31
+ //get custom object
32
+ let customObjList = await postNormal(global.setupSvc + "/api/customObject/list")
33
+ customObjList.data.objList.map((item) => {
34
+ res.push({
35
+ id: item.id,
36
+ label: item.objLabel,
37
+ objname: item.schemetable_name,
38
+ objprefix: item.prefix,
39
+ schemetableName: item.schemetableName
40
+ })
41
+ })
42
+ }
30
43
  console.log(JSON.stringify(res))
31
44
  return res
32
45
  }
@@ -1,7 +1,7 @@
1
1
  const cc = {}
2
2
  cc.get = require("./get")
3
3
  function main(action, argvs) {
4
- cc[action](argvs[2])
4
+ cc[action](argvs[2], argvs[3])
5
5
  }
6
6
 
7
7
  module.exports = main;
@@ -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 { readCache, writeCache } = require("../../utils/cache") // 添加缓存模块引入
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"
@@ -61,11 +61,10 @@ class Builder {
61
61
 
62
62
  async getToken(devConsoleConfig) {
63
63
  const cache = readCache();
64
- const cacheKey = `plugin_token_${devConsoleConfig.secretKey}`; // 使用orgId确保唯一性
64
+ const cacheKey = `plugin_token_${devConsoleConfig.secretKey}`;
65
65
  const now = Date.now();
66
66
  const oneHour = 60 * 60 * 1000;
67
67
 
68
- // 检查缓存是否有效
69
68
  if (cache[cacheKey] &&
70
69
  cache[cacheKey].token &&
71
70
  cache[cacheKey].timestamp &&
@@ -75,7 +74,6 @@ class Builder {
75
74
 
76
75
  let res = await post((this.options.devConsoleConfig.baseUrl || BaseUrl) + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
77
76
  if (res.returnCode == 200) {
78
- // 更新缓存
79
77
  cache[cacheKey] = {
80
78
  token: res.data.accessToken,
81
79
  timestamp: now
@@ -12,7 +12,6 @@ async function create(argvs) {
12
12
  const filePath = path.join(objectFolderPath, body.scriptName);
13
13
 
14
14
  try {
15
- // 确保对象文件夹和脚本文件夹都存在
16
15
  fs.mkdirSync(objectFolderPath, { recursive: true });
17
16
  fs.mkdirSync(filePath, { recursive: true });
18
17
 
@@ -1,6 +1,7 @@
1
1
  const cc = {}
2
2
  cc.create = require("./create")
3
3
  cc.publish = require("./publish")
4
+ cc.pull = require("./pull")
4
5
  function main(action, argvs) {
5
6
  cc[action](argvs)
6
7
  }
@@ -44,7 +44,7 @@ async function publish(argvs) {
44
44
  devConsoleConfig.accessToken = await getBusToken();
45
45
  }
46
46
  console.log(chalk.green('Posting, please wait...'));
47
- configContent.scriptContent = scriptContent
47
+ configContent.scriptContent = scriptContent.trim()
48
48
  let res = await post((devConsoleConfig.baseUrl || BaseUrl) + "/devconsole/script/saveClientScript", configContent, devConsoleConfig)
49
49
  if (res.result) {
50
50
  console.log();
@@ -0,0 +1,60 @@
1
+
2
+ const { checkUpdate } = require("../../utils/checkVersion.js")
3
+ const fs = require("fs");
4
+ const path = require("path")
5
+ const chalk = require("chalk")
6
+ const { post } = require("../../utils/http.js")
7
+ const { getPackageJson } = require("../../utils/config.js")
8
+ const BaseUrl = "https://developer.apis.cloudcc.cn"
9
+ const { getBusToken } = require("../../utils/utils.js")
10
+
11
+ function checkMainFunctionExists(content) {
12
+ const mainFunctionPattern = /^function\s+main\s*\(\$CCDK,\s*obj\)\s*\{/m;
13
+ return mainFunctionPattern.test(content);
14
+ }
15
+
16
+ async function pull(argvs) {
17
+ let namePath = argvs[2]
18
+ let name = namePath.split("/")[1]
19
+ let res = await checkUpdate();
20
+ if (!res) {
21
+ const srcPath = path.join(process.cwd(), `script/${namePath}/`);
22
+
23
+ let devConsoleConfig = getPackageJson()
24
+ if ("private" != devConsoleConfig.version) {
25
+ devConsoleConfig.accessToken = await getBusToken();
26
+ }
27
+ console.log(chalk.green('Pulling, please wait...'));
28
+ let configContent = JSON.parse(fs.readFileSync(srcPath + "config.json", 'utf8'));
29
+ configContent = {
30
+ "pageSize": 20,
31
+ "pageNo": 1,
32
+ "condition": {
33
+ "id": configContent.id,
34
+ "pageLabel": "",
35
+ "objName": ""
36
+ }
37
+ }
38
+ let res = await post((devConsoleConfig.baseUrl || BaseUrl) + "/devconsoleone/script/pageClientScript", configContent, devConsoleConfig)
39
+ if (res.result) {
40
+ console.log();
41
+ console.log(chalk.green('Success!'));
42
+ console.log();
43
+
44
+ let newContent = `function main($CCDK, obj){
45
+ ${res.data.list[0].scriptContent}
46
+ }`
47
+ fs.writeFileSync(srcPath + `${name}.js`, newContent);
48
+ } else {
49
+ console.log();
50
+ console.log(chalk.red('Fail:' + res.returnInfo));
51
+ console.log();
52
+ }
53
+ } else {
54
+ console.log();
55
+ console.log(chalk.red('Invalid Script Content'));
56
+ console.log();
57
+ }
58
+ }
59
+
60
+ module.exports = pull;
@@ -10,9 +10,14 @@ async function create(name) {
10
10
  const timerPath = path.join(process.cwd(), "schedule/" + name);
11
11
  try {
12
12
  fs.mkdirSync(timerPath, { recursive: true })
13
- const javaTmp = `// @SOURCE_CONTENT_START
14
- System.out.print("hello World");
15
- // @SOURCE_CONTENT_END`
13
+
14
+ const javaTmp = `public class ${name} extends CCSchedule {
15
+ public ${name}(){
16
+ // @SOURCE_CONTENT_START
17
+ System.out.print("hello World");
18
+ // @SOURCE_CONTENT_END
19
+ }
20
+ }`
16
21
  fs.writeFileSync(path.join(timerPath, name + ".java"), javaTmp)
17
22
  fs.writeFileSync(path.join(timerPath, "config.json"), `{"name":"${name}","version":"${getPackageJson().extandVersion || '2'}"}`)
18
23
  console.log()
@@ -1,6 +1,7 @@
1
1
  const cc = {}
2
2
  cc.create = require("./create")
3
3
  cc.publish = require("./publish")
4
+ cc.pull = require("./pull")
4
5
  function Timer(action, argvs) {
5
6
  cc[action](argvs[2])
6
7
  }
@@ -15,8 +15,7 @@ async function publish(name) {
15
15
  const timerPath = path.join(process.cwd(), `schedule/${name}/`);
16
16
  let fullContent = fs.readFileSync(timerPath + `${name}.java`, 'utf8');
17
17
 
18
- // 提取标记之间的内容
19
- const sourceMatch = fullContent.match(/\/\/ @SOURCE_CONTENT_START\n([\s\S]*?)\n\/\/ @SOURCE_CONTENT_END/);
18
+ const sourceMatch = fullContent.match(/\/\/\s*@SOURCE_CONTENT_START([\s\S]*?)\/\/\s*@SOURCE_CONTENT_END/);
20
19
  let classContent = sourceMatch ? sourceMatch[1] : fullContent;
21
20
 
22
21
  let configContent = JSON.parse(fs.readFileSync(timerPath + "config.json", 'utf8'));
@@ -26,7 +25,7 @@ async function publish(name) {
26
25
  "id": configContent.id,
27
26
  "name": name,
28
27
  "version": configContent.version || "2",
29
- "source": encodeURIComponent(classContent),
28
+ "source": encodeURIComponent(classContent.trim()),
30
29
  "folderId": "wgd"
31
30
  }
32
31
  let res = await postNormal(global.setupSvc + "/api/ccPeak/save", body)
@@ -0,0 +1,48 @@
1
+ const { checkUpdate } = require("../../utils/checkVersion")
2
+ const fs = require("fs");
3
+ const path = require("path")
4
+ const chalk = require("chalk")
5
+ const { postNormal } = require("../../utils/http")
6
+
7
+ const { getBusToken } = require("../../utils/utils")
8
+
9
+ async function pull(name) {
10
+ let res = await checkUpdate();
11
+ if (!res) {
12
+ console.log();
13
+ console.log(chalk.green('Pulling, please wait...'));
14
+ console.log();
15
+ const timerPath = path.join(process.cwd(), `schedule/${name}/`);
16
+ let fullContent = fs.readFileSync(timerPath + `${name}.java`, 'utf8');
17
+
18
+ let configContent = JSON.parse(fs.readFileSync(timerPath + "config.json", 'utf8'));
19
+
20
+ if (await getBusToken()) {
21
+ let body = {
22
+ "id": configContent.id,
23
+ }
24
+ let res = await postNormal(global.setupSvc + "/api/ccPeak/detail", body)
25
+ if (res.result) {
26
+ console.log(chalk.green('Success!'));
27
+ console.log
28
+ let fullContent = fs.readFileSync(timerPath + `${name}.java`, 'utf8');
29
+
30
+ let newContent = '';
31
+ if (fullContent) {
32
+ newContent = fullContent.replace(
33
+ /\/\/\s*@SOURCE_CONTENT_START[\s\S]*?\/\/\s*@SOURCE_CONTENT_END/,
34
+ `// @SOURCE_CONTENT_START\n${res.data.trigger.source}\n// @SOURCE_CONTENT_END`
35
+ );
36
+ } else {
37
+ newContent = res.data.trigger.tsource;
38
+ }
39
+
40
+ fs.writeFileSync(timerPath + `${name}.java`, newContent, 'utf8');
41
+
42
+ } else {
43
+ console.log(chalk.red('Fail:' + res.returnInfo));
44
+ }
45
+ }
46
+ }
47
+ }
48
+ module.exports = pull;
@@ -13,13 +13,16 @@ async function create(argvs) {
13
13
  const triggersPath = path.join(objectFolderPath, body.name);
14
14
 
15
15
  try {
16
- // 确保对象文件夹和触发器文件夹都存在
17
16
  fs.mkdirSync(objectFolderPath, { recursive: true });
18
17
  fs.mkdirSync(triggersPath, { recursive: true });
19
18
 
20
- const javaTmp = `// @SOURCE_CONTENT_START
21
- System.out.print("hello World");
22
- // @SOURCE_CONTENT_END`
19
+ const javaTmp = `public class ${body.name} extends CCTrigger {
20
+ public ${body.name}(){
21
+ // @SOURCE_CONTENT_START
22
+ System.out.print("hello World");
23
+ // @SOURCE_CONTENT_END
24
+ }
25
+ }`
23
26
 
24
27
  fs.writeFileSync(path.join(triggersPath, body.name + ".java"), javaTmp);
25
28
  body.version = getPackageJson().extandVersion || "2";
@@ -1,6 +1,7 @@
1
1
  const cc = {}
2
2
  cc.create = require("./create")
3
3
  cc.publish = require("./publish")
4
+ cc.pull = require("./pull")
4
5
  function Classes(action, argvs) {
5
6
  cc[action](argvs)
6
7
  }
@@ -16,10 +16,8 @@ async function publish(argvs) {
16
16
  const triggersPath = path.join(process.cwd(), `triggers/${namePath}/`);
17
17
  let fullContent = fs.readFileSync(triggersPath + `${name}.java`, 'utf8');
18
18
 
19
- // 提取标记之间的内容
20
- const sourceMatch = fullContent.match(/\/\/ @SOURCE_CONTENT_START\n([\s\S]*?)\n\/\/ @SOURCE_CONTENT_END/);
21
- let classContent = sourceMatch ? sourceMatch[1] : fullContent;
22
-
19
+ const sourceMatch = fullContent.match(/\/\/\s*@SOURCE_CONTENT_START([\s\S]*?)\/\/\s*@SOURCE_CONTENT_END/);
20
+ let triggersContent = sourceMatch ? sourceMatch[1] : fullContent;
23
21
  let configContent = JSON.parse(fs.readFileSync(triggersPath + "config.json", 'utf8'));
24
22
 
25
23
  if (await getBusToken()) {
@@ -31,7 +29,7 @@ async function publish(argvs) {
31
29
  "triggerTime": configContent.triggerTime,
32
30
  "name": name,
33
31
  "version": configContent.version || "2",
34
- "triggerSource": encodeURIComponent(classContent),
32
+ "triggerSource": encodeURIComponent(triggersContent.trim()),
35
33
  "folderId": "wgd"
36
34
  }
37
35
  let res = await postNormal(global.setupSvc + "/api/triggerSetup/saveTrigger", body)
@@ -0,0 +1,48 @@
1
+ const { checkUpdate } = require("../../utils/checkVersion")
2
+ const fs = require("fs");
3
+ const path = require("path")
4
+ const chalk = require("chalk")
5
+ const { postNormal } = require("../../utils/http")
6
+ const { getBusToken } = require("../../utils/utils")
7
+
8
+ async function pull(argvs) {
9
+ let namePath = argvs[2]
10
+ let name = namePath.split("/")[1]
11
+ let res = await checkUpdate();
12
+ if (!res) {
13
+ console.log();
14
+ console.log(chalk.green('Pulling, please wait...'));
15
+ console.log();
16
+ const triggersPath = path.join(process.cwd(), `triggers/${namePath}/`);
17
+ let configContent = JSON.parse(fs.readFileSync(triggersPath + "config.json", 'utf8'));
18
+
19
+ if (await getBusToken()) {
20
+ let body = {
21
+ "id": configContent.id,
22
+ }
23
+ let res = await postNormal(global.setupSvc + "/api/trigger/newobjtrigger", body)
24
+ if (res.result) {
25
+ console.log(chalk.green('Success!'));
26
+ console.log();
27
+
28
+ let fullContent = fs.readFileSync(triggersPath + `${name}.java`, 'utf8');
29
+ let newContent = '';
30
+
31
+ if (fullContent) {
32
+ newContent = fullContent.replace(
33
+ /\/\/\s*@SOURCE_CONTENT_START([\s\S]*?)\/\/\s*@SOURCE_CONTENT_END/,
34
+ `// @SOURCE_CONTENT_START\n${res.data.trigger.triggerSource}\n// @SOURCE_CONTENT_END`
35
+ );
36
+ } else {
37
+ newContent = res.data.trigger.triggerSource;
38
+ }
39
+
40
+ fs.writeFileSync(triggersPath + `${name}.java`, newContent);
41
+
42
+ } else {
43
+ console.log(chalk.red('Fail:' + res.returnInfo));
44
+ }
45
+ }
46
+ }
47
+ }
48
+ module.exports = pull;
@@ -9,11 +9,9 @@ function checkNpmVersion() {
9
9
  let onlineVersionNum
10
10
  let onlineVersion = '0.0.1'
11
11
 
12
- // 获取在线版本
13
12
  onlineVersion = exec(`npm view cloudcc-cli version --registry http://registry.npmmirror.com`)
14
13
  onlineVersion = onlineVersion.toString("utf8").trim();
15
14
 
16
- // 获取发布时间信息
17
15
  const timeInfo = exec(`npm view cloudcc-cli time --json --registry http://registry.npmmirror.com`)
18
16
  const timeData = JSON.parse(timeInfo.toString().trim());
19
17
  const formattedTime = new Date(timeData[onlineVersion]).toLocaleString('zh-CN', {
@@ -66,13 +64,11 @@ function update(onlineVersion) {
66
64
 
67
65
 
68
66
  async function checkUpdate(path = process.cwd()) {
69
- // 检查缓存
70
67
  const cache = readCache(path);
71
68
  const cacheKey = 'version_check';
72
69
  const now = Date.now();
73
70
  const oneHour = 60 * 60 * 1000;
74
71
 
75
- // 如果缓存有效,跳过版本检查
76
72
  if (cache[cacheKey] &&
77
73
  cache[cacheKey].timestamp &&
78
74
  (now - cache[cacheKey].timestamp) < oneHour) {
@@ -82,7 +78,6 @@ async function checkUpdate(path = process.cwd()) {
82
78
  let onlineVersion;
83
79
  try {
84
80
  onlineVersion = checkNpmVersion();
85
- // 更新缓存
86
81
  cache[cacheKey] = {
87
82
  timestamp: now
88
83
  };