cloudcc-cli 1.9.9 → 2.0.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 +10 -0
- package/java/com/cloudcc/core/CCService.java +5 -5
- package/java/com/cloudcc/core/Tool.java +15 -238
- package/package.json +1 -1
- package/pom.xml +1 -1
- package/src/classes/create.js +1 -1
- package/src/classes/publish.js +22 -20
- package/src/classes/pull.js +25 -24
- package/src/config/get.js +3 -14
- package/src/object/get.js +67 -68
- package/src/plugin/publish.js +1 -1
- package/src/plugin/publish1.js +12 -37
- package/src/recordType/get.js +6 -8
- package/src/script/publish.js +1 -5
- package/src/script/pull.js +1 -9
- package/src/timer/create.js +1 -1
- package/src/timer/publish.js +21 -20
- package/src/timer/pull.js +25 -24
- package/src/triggers/create.js +1 -1
- package/src/triggers/publish.js +26 -25
- package/src/triggers/pull.js +24 -25
- package/template/lib/ccopenapi-0.0.2.jar +0 -0
- package/utils/checkVersion.js +55 -1
- package/utils/config.js +71 -8
- package/utils/http.js +25 -59
- package/utils/utils.js +140 -81
- package/template/lib/ccopenapi-0.0.1.jar +0 -0
package/src/plugin/publish.js
CHANGED
|
@@ -22,7 +22,7 @@ class Builder {
|
|
|
22
22
|
async init() {
|
|
23
23
|
let res = await checkUpdate();
|
|
24
24
|
if (!res) {
|
|
25
|
-
this.options.devConsoleConfig = getPackageJson();
|
|
25
|
+
this.options.devConsoleConfig = await getPackageJson();
|
|
26
26
|
let config = this.options.devConsoleConfig
|
|
27
27
|
|
|
28
28
|
if ("private" != this.options.devConsoleConfig.version) {
|
package/src/plugin/publish1.js
CHANGED
|
@@ -3,7 +3,6 @@ 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")
|
|
7
6
|
|
|
8
7
|
const { checkUpdate } = require("../../utils/checkVersion")
|
|
9
8
|
const BaseUrl = "https://developer.apis.cloudcc.cn"
|
|
@@ -24,17 +23,12 @@ class Builder {
|
|
|
24
23
|
async publish(name) {
|
|
25
24
|
let res = await checkUpdate();
|
|
26
25
|
if (!res) {
|
|
27
|
-
this.options.devConsoleConfig = getPackageJson();
|
|
26
|
+
this.options.devConsoleConfig = await getPackageJson();
|
|
28
27
|
this.options.pluginConfig = JSON.parse(fs.readFileSync(path.join(process.cwd(), `plugins/${name}/config.json`), 'utf8'));
|
|
29
28
|
let config = this.options.devConsoleConfig
|
|
30
29
|
|
|
31
30
|
if ("private" != this.options.devConsoleConfig.version) {
|
|
32
|
-
|
|
33
|
-
if (token) {
|
|
34
|
-
config = { "accessToken": token };
|
|
35
|
-
} else {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
31
|
+
config = { "accessToken": this.options.devConsoleConfig.pluginToken };
|
|
38
32
|
}
|
|
39
33
|
|
|
40
34
|
let answers = { buildFileName: `${name}/${name}.vue` }
|
|
@@ -59,33 +53,6 @@ class Builder {
|
|
|
59
53
|
}
|
|
60
54
|
}
|
|
61
55
|
|
|
62
|
-
async getToken(devConsoleConfig) {
|
|
63
|
-
const cache = readCache();
|
|
64
|
-
const cacheKey = `plugin_token_${devConsoleConfig.secretKey}`;
|
|
65
|
-
const now = Date.now();
|
|
66
|
-
const oneHour = 60 * 60 * 1000;
|
|
67
|
-
|
|
68
|
-
if (cache[cacheKey] &&
|
|
69
|
-
cache[cacheKey].token &&
|
|
70
|
-
cache[cacheKey].timestamp &&
|
|
71
|
-
(now - cache[cacheKey].timestamp) < oneHour) {
|
|
72
|
-
return cache[cacheKey].token;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
let res = await post((this.options.devConsoleConfig.baseUrl || BaseUrl) + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
|
|
76
|
-
if (res.returnCode == 200) {
|
|
77
|
-
cache[cacheKey] = {
|
|
78
|
-
token: res.data.accessToken,
|
|
79
|
-
timestamp: now
|
|
80
|
-
};
|
|
81
|
-
writeCache(process.cwd(), cache);
|
|
82
|
-
return res.data.accessToken;
|
|
83
|
-
} else {
|
|
84
|
-
console.error(chalk.red(`Login failed`, JSON.stringify(res)));
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
56
|
getVueValue(buildFileName) {
|
|
90
57
|
let vueContent = fs.readFileSync(this.getVueContent(buildFileName), 'utf8');
|
|
91
58
|
let vueData = vueContent + ""
|
|
@@ -96,8 +63,16 @@ class Builder {
|
|
|
96
63
|
}
|
|
97
64
|
vueData = vueData.split(/data\s*\(\s*\)/)[1].split(/isLock\s*:/)[0] + "isLock:false,};}";
|
|
98
65
|
vueData = "function data()" + vueData;
|
|
99
|
-
|
|
100
|
-
|
|
66
|
+
let data = {}
|
|
67
|
+
try {
|
|
68
|
+
data = eval(`(${vueData})`)()
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
console.log()
|
|
72
|
+
console.log(chalk.red("Error: The data function cannot contain reference variables."));
|
|
73
|
+
console.log()
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
101
76
|
if (!data.propObj) {
|
|
102
77
|
data.propObj = {};
|
|
103
78
|
data.propOption = {};
|
package/src/recordType/get.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
const {
|
|
2
|
-
const {
|
|
1
|
+
const { postClass } = require("../../utils/http")
|
|
2
|
+
const { getPackageJson } = require("../../utils/config")
|
|
3
3
|
|
|
4
4
|
async function get(path, prefix) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return res.data
|
|
10
|
-
}
|
|
5
|
+
let config = await getPackageJson();
|
|
6
|
+
let res = await postClass(config.apiSvc + "/api/batch/getRecordType", { prefix: prefix }, config.accessToken)
|
|
7
|
+
console.log(JSON.stringify(res.data.recordTypeList))
|
|
8
|
+
return res.data
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
module.exports = get;
|
package/src/script/publish.js
CHANGED
|
@@ -6,7 +6,6 @@ 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")
|
|
10
9
|
|
|
11
10
|
function checkMainFunctionExists(content) {
|
|
12
11
|
const mainFunctionPattern = /^function\s+main\s*\(\$CCDK,\s*obj\)\s*\{/m;
|
|
@@ -39,10 +38,7 @@ async function publish(argvs) {
|
|
|
39
38
|
let configContentOld = JSON.parse(JSON.stringify(configContent))
|
|
40
39
|
|
|
41
40
|
if (scriptContent) {
|
|
42
|
-
let devConsoleConfig = getPackageJson()
|
|
43
|
-
if ("private" != devConsoleConfig.version) {
|
|
44
|
-
devConsoleConfig.accessToken = await getBusToken();
|
|
45
|
-
}
|
|
41
|
+
let devConsoleConfig = await getPackageJson()
|
|
46
42
|
console.log(chalk.green('Posting, please wait...'));
|
|
47
43
|
configContent.scriptContent = scriptContent.trim()
|
|
48
44
|
let res = await post((devConsoleConfig.baseUrl || BaseUrl) + "/devconsole/script/saveClientScript", configContent, devConsoleConfig)
|
package/src/script/pull.js
CHANGED
|
@@ -6,12 +6,7 @@ const chalk = require("chalk")
|
|
|
6
6
|
const { post } = require("../../utils/http.js")
|
|
7
7
|
const { getPackageJson } = require("../../utils/config.js")
|
|
8
8
|
const BaseUrl = "https://developer.apis.cloudcc.cn"
|
|
9
|
-
const { getBusToken } = require("../../utils/utils.js")
|
|
10
9
|
|
|
11
|
-
function checkMainFunctionExists(content) {
|
|
12
|
-
const mainFunctionPattern = /^function\s+main\s*\(\$CCDK,\s*obj\)\s*\{/m;
|
|
13
|
-
return mainFunctionPattern.test(content);
|
|
14
|
-
}
|
|
15
10
|
|
|
16
11
|
async function pull(argvs) {
|
|
17
12
|
let namePath = argvs[2]
|
|
@@ -20,10 +15,7 @@ async function pull(argvs) {
|
|
|
20
15
|
if (!res) {
|
|
21
16
|
const srcPath = path.join(process.cwd(), `script/${namePath}/`);
|
|
22
17
|
|
|
23
|
-
let devConsoleConfig = getPackageJson()
|
|
24
|
-
if ("private" != devConsoleConfig.version) {
|
|
25
|
-
devConsoleConfig.accessToken = await getBusToken();
|
|
26
|
-
}
|
|
18
|
+
let devConsoleConfig = await getPackageJson()
|
|
27
19
|
console.log(chalk.green('Pulling, please wait...'));
|
|
28
20
|
let configContent = JSON.parse(fs.readFileSync(srcPath + "config.json", 'utf8'));
|
|
29
21
|
configContent = {
|
package/src/timer/create.js
CHANGED
|
@@ -24,7 +24,7 @@ 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":"${getPackageJson().extandVersion || '2'}"}`)
|
|
27
|
+
fs.writeFileSync(path.join(timerPath, "config.json"), `{"name":"${name}","version":"${await getPackageJson().extandVersion || '2'}"}`)
|
|
28
28
|
console.log()
|
|
29
29
|
console.log(chalk.green("Successfully Created:" + name))
|
|
30
30
|
console.log()
|
package/src/timer/publish.js
CHANGED
|
@@ -2,10 +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 {
|
|
6
|
+
const { javaContentRegular } = require("../../utils/utils")
|
|
8
7
|
|
|
8
|
+
const { getPackageJson } = require("../../utils/config")
|
|
9
|
+
const { postClass } = require("../../utils/http")
|
|
9
10
|
async function publish(name) {
|
|
10
11
|
let res = await checkUpdate();
|
|
11
12
|
if (!res) {
|
|
@@ -20,26 +21,26 @@ async function publish(name) {
|
|
|
20
21
|
|
|
21
22
|
let configContent = JSON.parse(fs.readFileSync(timerPath + "config.json", 'utf8'));
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
let body = {
|
|
25
|
+
"id": configContent.id,
|
|
26
|
+
"name": name,
|
|
27
|
+
"version": configContent.version || "2",
|
|
28
|
+
"source": encodeURIComponent(classContent.trim()),
|
|
29
|
+
"folderId": "wgd"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let config = await getPackageJson();
|
|
33
|
+
let res = await postClass(config.setupSvc + "/api/ccPeak/save", body, config.accessToken)
|
|
34
|
+
if (res.result) {
|
|
35
|
+
console.log(chalk.green('Success!'));
|
|
36
|
+
console.log();
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
console.log(chalk.red('Fail:' + res.returnInfo));
|
|
38
|
+
if (!configContent.id) {
|
|
39
|
+
configContent.id = res.data
|
|
40
|
+
fs.writeFileSync(path.join(timerPath, "config.json"), JSON.stringify(configContent))
|
|
42
41
|
}
|
|
42
|
+
} else {
|
|
43
|
+
console.log(chalk.red('Fail:' + res.returnInfo));
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
}
|
package/src/timer/pull.js
CHANGED
|
@@ -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 {
|
|
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();
|
|
@@ -17,31 +19,30 @@ async function pull(name) {
|
|
|
17
19
|
|
|
18
20
|
let configContent = JSON.parse(fs.readFileSync(timerPath + "config.json", 'utf8'));
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let newContent = '';
|
|
31
|
-
if (fullContent.includes("@SOURCE_CONTENT_START")) {
|
|
32
|
-
newContent = fullContent.replace(
|
|
33
|
-
javaContentRegular,
|
|
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');
|
|
22
|
+
let body = {
|
|
23
|
+
"id": configContent.id,
|
|
24
|
+
}
|
|
25
|
+
let config = await getPackageJson();
|
|
26
|
+
let res = await postClass(config.setupSvc + "/api/ccPeak/detail", body, config.accessToken)
|
|
27
|
+
if (res.result) {
|
|
28
|
+
console.log(chalk.green('Success!'));
|
|
29
|
+
console.log
|
|
30
|
+
let fullContent = fs.readFileSync(timerPath + `${name}.java`, 'utf8');
|
|
41
31
|
|
|
32
|
+
let newContent = '';
|
|
33
|
+
if (fullContent.includes("@SOURCE_CONTENT_START")) {
|
|
34
|
+
newContent = fullContent.replace(
|
|
35
|
+
javaContentRegular,
|
|
36
|
+
`// @SOURCE_CONTENT_START\n${res.data.trigger.source}\n// @SOURCE_CONTENT_END`
|
|
37
|
+
);
|
|
42
38
|
} else {
|
|
43
|
-
|
|
39
|
+
newContent = res.data.trigger.tsource;
|
|
44
40
|
}
|
|
41
|
+
|
|
42
|
+
fs.writeFileSync(timerPath + `${name}.java`, newContent, 'utf8');
|
|
43
|
+
|
|
44
|
+
} else {
|
|
45
|
+
console.log(chalk.red('Fail:' + res.returnInfo));
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
}
|
package/src/triggers/create.js
CHANGED
|
@@ -30,7 +30,7 @@ public class ${body.name} extends CCTrigger {
|
|
|
30
30
|
}`
|
|
31
31
|
|
|
32
32
|
fs.writeFileSync(path.join(triggersPath, body.name + ".java"), javaTmp);
|
|
33
|
-
body.version = getPackageJson().extandVersion || "2";
|
|
33
|
+
body.version =await getPackageJson().extandVersion || "2";
|
|
34
34
|
body.isactive = true;
|
|
35
35
|
fs.writeFileSync(path.join(triggersPath, "config.json"), JSON.stringify(body));
|
|
36
36
|
console.log();
|
package/src/triggers/publish.js
CHANGED
|
@@ -2,8 +2,9 @@ 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 {
|
|
6
|
-
const {
|
|
5
|
+
const { javaContentRegular } = require("../../utils/utils")
|
|
6
|
+
const { getPackageJson } = require("../../utils/config")
|
|
7
|
+
const { postClass } = require("../../utils/http")
|
|
7
8
|
|
|
8
9
|
async function publish(argvs) {
|
|
9
10
|
let namePath = argvs[2]
|
|
@@ -20,31 +21,31 @@ async function publish(argvs) {
|
|
|
20
21
|
let triggersContent = sourceMatch ? sourceMatch[1] : fullContent;
|
|
21
22
|
let configContent = JSON.parse(fs.readFileSync(triggersPath + "config.json", 'utf8'));
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
let body = {
|
|
25
|
+
"id": configContent.id,
|
|
26
|
+
"apiname": configContent.apiname,
|
|
27
|
+
"isactive": configContent.isactive,
|
|
28
|
+
"targetObjectId": configContent.targetObjectId,
|
|
29
|
+
"triggerTime": configContent.triggerTime,
|
|
30
|
+
"name": name,
|
|
31
|
+
"version": configContent.version || "2",
|
|
32
|
+
"triggerSource": encodeURIComponent(triggersContent.trim()),
|
|
33
|
+
"folderId": "wgd"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let config = await getPackageJson();
|
|
37
|
+
let res = await postClass(config.setupSvc + "/api/triggerSetup/saveTrigger", body, config.accessToken)
|
|
38
|
+
if (res.result) {
|
|
39
|
+
console.log(chalk.green('Success!'));
|
|
40
|
+
console.log();
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
console.log(chalk.red('Fail:' + res.returnInfo));
|
|
42
|
+
if (!configContent.id) {
|
|
43
|
+
configContent.id = res.data.id
|
|
44
|
+
configContent.apiname = res.data.apiname
|
|
45
|
+
fs.writeFileSync(path.join(triggersPath, "config.json"), JSON.stringify(configContent))
|
|
47
46
|
}
|
|
47
|
+
} else {
|
|
48
|
+
console.log(chalk.red('Fail:' + res.returnInfo));
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
}
|
package/src/triggers/pull.js
CHANGED
|
@@ -2,9 +2,9 @@ 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 {
|
|
6
|
-
const {
|
|
7
|
-
|
|
5
|
+
const { javaContentRegular } = require("../../utils/utils")
|
|
6
|
+
const { getPackageJson } = require("../../utils/config")
|
|
7
|
+
const { postClass } = require("../../utils/http")
|
|
8
8
|
async function pull(argvs) {
|
|
9
9
|
let namePath = argvs[2]
|
|
10
10
|
let name = namePath.split("/")[1]
|
|
@@ -16,31 +16,30 @@ async function pull(argvs) {
|
|
|
16
16
|
const triggersPath = path.join(process.cwd(), `triggers/${namePath}/`);
|
|
17
17
|
let configContent = JSON.parse(fs.readFileSync(triggersPath + "config.json", 'utf8'));
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
let fullContent = fs.readFileSync(triggersPath + `${name}.java`, 'utf8');
|
|
29
|
-
let newContent = '';
|
|
30
|
-
if (fullContent.includes("@SOURCE_CONTENT_START")) {
|
|
31
|
-
newContent = fullContent.replace(
|
|
32
|
-
javaContentRegular,
|
|
33
|
-
`// @SOURCE_CONTENT_START\n${res.data.trigger.triggerSource}\n// @SOURCE_CONTENT_END`
|
|
34
|
-
);
|
|
35
|
-
} else {
|
|
36
|
-
newContent = res.data.trigger.triggerSource;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
fs.writeFileSync(triggersPath + `${name}.java`, newContent);
|
|
19
|
+
let body = {
|
|
20
|
+
"id": configContent.id,
|
|
21
|
+
}
|
|
22
|
+
let config = await getPackageJson();
|
|
23
|
+
let res = await postClass(config.setupSvc + "/api/trigger/newobjtrigger", body, config.accessToken)
|
|
24
|
+
if (res.result) {
|
|
25
|
+
console.log(chalk.green('Success!'));
|
|
26
|
+
console.log();
|
|
40
27
|
|
|
28
|
+
let fullContent = fs.readFileSync(triggersPath + `${name}.java`, 'utf8');
|
|
29
|
+
let newContent = '';
|
|
30
|
+
if (fullContent.includes("@SOURCE_CONTENT_START")) {
|
|
31
|
+
newContent = fullContent.replace(
|
|
32
|
+
javaContentRegular,
|
|
33
|
+
`// @SOURCE_CONTENT_START\n${res.data.trigger.triggerSource}\n// @SOURCE_CONTENT_END`
|
|
34
|
+
);
|
|
41
35
|
} else {
|
|
42
|
-
|
|
36
|
+
newContent = res.data.trigger.triggerSource;
|
|
43
37
|
}
|
|
38
|
+
|
|
39
|
+
fs.writeFileSync(triggersPath + `${name}.java`, newContent);
|
|
40
|
+
|
|
41
|
+
} else {
|
|
42
|
+
console.log(chalk.red('Fail:' + res.returnInfo));
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
}
|
|
Binary file
|
package/utils/checkVersion.js
CHANGED
|
@@ -3,6 +3,8 @@ 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
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
6
8
|
|
|
7
9
|
function checkNpmVersion() {
|
|
8
10
|
let currentVersion = Number(config.version.replace(/\./g, ""));
|
|
@@ -77,6 +79,7 @@ async function checkUpdate(path = process.cwd()) {
|
|
|
77
79
|
|
|
78
80
|
let onlineVersion;
|
|
79
81
|
try {
|
|
82
|
+
checkAndReplaceJar();
|
|
80
83
|
onlineVersion = checkNpmVersion();
|
|
81
84
|
cache[cacheKey] = {
|
|
82
85
|
timestamp: now
|
|
@@ -99,4 +102,55 @@ async function checkUpdate(path = process.cwd()) {
|
|
|
99
102
|
return false
|
|
100
103
|
}
|
|
101
104
|
|
|
102
|
-
|
|
105
|
+
function checkAndReplaceJar(projectPath = process.cwd()) {
|
|
106
|
+
const projectLibPath = path.join(projectPath, 'lib');
|
|
107
|
+
const templateLibPath = path.join(__dirname, '../template/lib');
|
|
108
|
+
|
|
109
|
+
if (!fs.existsSync(projectLibPath)) {
|
|
110
|
+
console.log(chalk.red('Project lib folder does not exist.'));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const projectJar = fs.readdirSync(projectLibPath).find(file => file.startsWith('ccopenapi') && file.endsWith('.jar'));
|
|
115
|
+
if (!projectJar) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const projectVersion = projectJar.match(/ccopenapi-(\d+\.\d+\.\d+)/)?.[1];
|
|
120
|
+
if (!projectVersion) {
|
|
121
|
+
console.log(chalk.red('Failed to parse the version of the ccopenapi jar in the project.'));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const templateJar = fs.readdirSync(templateLibPath).find(file => file.startsWith('ccopenapi') && file.endsWith('.jar'));
|
|
126
|
+
if (!templateJar) {
|
|
127
|
+
console.log(chalk.yellow('No ccopenapi jar found in the template lib folder.'));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const templateVersion = templateJar.match(/ccopenapi-(\d+\.\d+\.\d+)/)?.[1];
|
|
132
|
+
if (!templateVersion) {
|
|
133
|
+
console.log(chalk.red('Failed to parse the version of the ccopenapi jar in the template.'));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const compareVersions = (v1, v2) => {
|
|
138
|
+
const [major1, minor1, patch1] = v1.split('.').map(Number);
|
|
139
|
+
const [major2, minor2, patch2] = v2.split('.').map(Number);
|
|
140
|
+
if (major1 !== major2) return major1 - major2;
|
|
141
|
+
if (minor1 !== minor2) return minor1 - minor2;
|
|
142
|
+
return patch1 - patch2;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
if (compareVersions(templateVersion, projectVersion) > 0) {
|
|
146
|
+
// Delete the old jar file
|
|
147
|
+
fs.unlinkSync(path.join(projectLibPath, projectJar));
|
|
148
|
+
// Copy the new jar file
|
|
149
|
+
fs.copyFileSync(
|
|
150
|
+
path.join(templateLibPath, templateJar),
|
|
151
|
+
path.join(projectLibPath, templateJar)
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
module.exports = { checkUpdate };
|
package/utils/config.js
CHANGED
|
@@ -1,18 +1,81 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
|
|
3
|
+
// 引入解密函数
|
|
4
|
+
const { getDevConsoleConfig, decryptCloudCCDevInfo } = require("./utils");
|
|
5
|
+
const { readCache } = require("./cache")
|
|
6
|
+
/**
|
|
7
|
+
* 1.0版本的配置文件
|
|
8
|
+
* @param {string} projectPath baseUrl
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
4
11
|
function getPackageJson_old(projectPath = process.cwd()) {
|
|
5
12
|
const packageJson = JSON.parse(fs.readFileSync(path.join(projectPath, "package.json")), 'utf8');
|
|
6
13
|
return packageJson.devConsoleConfig;
|
|
7
14
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
/**
|
|
16
|
+
* 2.0版本的配置文件
|
|
17
|
+
* 配置参数移入cloudcc-cli.config.js,最多需要配置9个参数
|
|
18
|
+
* @param {string} projectPath baseUrl
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
async function getPackageJson2(projectPath = process.cwd()) {
|
|
22
|
+
let config = require(path.join(projectPath, "cloudcc-cli.config.js"))
|
|
23
|
+
config = config[config.use]
|
|
24
|
+
if (config.baseUrl && !config.baseUrl.includes("ccdomaingateway")) {
|
|
25
|
+
config.baseUrl = config.baseUrl + "/ccdomaingateway"
|
|
14
26
|
}
|
|
27
|
+
config = await getDevConsoleConfig(projectPath, config)
|
|
15
28
|
return config
|
|
16
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* 3.0版本的配置文件
|
|
32
|
+
* 将多个参数压缩到一个参数重,方便配置
|
|
33
|
+
* @param {string} projectPath baseUrl
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
async function getPackageJson3(projectPath = process.cwd()) {
|
|
37
|
+
let config = require(path.join(projectPath, "cloudcc-cli.config.js"))
|
|
38
|
+
config = config[config.use]
|
|
39
|
+
// 检查并解密CloudCCDev信息
|
|
40
|
+
if (config && config.CloudCCDev) {
|
|
41
|
+
const decryptedInfo = decryptCloudCCDevInfo(config.CloudCCDev);
|
|
42
|
+
if (decryptedInfo) {
|
|
43
|
+
config = { ...decryptedInfo, ...config }
|
|
44
|
+
if (config.baseUrl && !config.baseUrl.includes("ccdomaingateway")) {
|
|
45
|
+
config.baseUrl = config.baseUrl + "/ccdomaingateway"
|
|
46
|
+
}
|
|
47
|
+
config = await getDevConsoleConfig(projectPath, config)
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
config = null;
|
|
51
|
+
}
|
|
52
|
+
return config;
|
|
53
|
+
}
|
|
17
54
|
|
|
18
|
-
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 从缓存读取
|
|
58
|
+
* @returns 配置参数
|
|
59
|
+
*/
|
|
60
|
+
async function getPackageJsonCache(projectPath = process.cwd()) {
|
|
61
|
+
let config = require(path.join(projectPath, "cloudcc-cli.config.js"));
|
|
62
|
+
const cacheData = readCache()[config[config.use].safetyMark || config[config.use].secretKey];
|
|
63
|
+
|
|
64
|
+
if (cacheData && cacheData.timestamp) {
|
|
65
|
+
const oneHour = 60 * 60 * 1000; // 1小时的毫秒数
|
|
66
|
+
const currentTime = Date.now();
|
|
67
|
+
if (currentTime - cacheData.timestamp > oneHour) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return cacheData;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function getPackageJson(projectPath = process.cwd()) {
|
|
75
|
+
return getPackageJson_old(projectPath) || await getPackageJsonCache(projectPath) || await getPackageJson3(projectPath) || await getPackageJson2(projectPath)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
module.exports = {
|
|
80
|
+
getPackageJson,
|
|
81
|
+
}
|