cloudcc-cli 1.7.9 → 1.8.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 +944 -928
- package/package.json +1 -1
- package/src/plugin/publish.js +6 -1
- package/src/plugin/publish1.js +7 -2
- package/src/script/create.js +8 -2
- package/src/script/publish.js +3 -2
- package/src/triggers/create.js +14 -7
- package/src/triggers/publish.js +3 -2
- package/utils/cache.js +7 -7
- package/utils/checkVersion.js +3 -3
- package/utils/utils.js +8 -6
package/package.json
CHANGED
package/src/plugin/publish.js
CHANGED
|
@@ -26,7 +26,12 @@ class Builder {
|
|
|
26
26
|
let config = this.options.devConsoleConfig
|
|
27
27
|
|
|
28
28
|
if ("private" != this.options.devConsoleConfig.version) {
|
|
29
|
-
|
|
29
|
+
let token = await this.getToken(config);
|
|
30
|
+
if (token) {
|
|
31
|
+
config = { "accessToken": token };
|
|
32
|
+
} else {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
let answers;
|
package/src/plugin/publish1.js
CHANGED
|
@@ -29,7 +29,12 @@ class Builder {
|
|
|
29
29
|
let config = this.options.devConsoleConfig
|
|
30
30
|
|
|
31
31
|
if ("private" != this.options.devConsoleConfig.version) {
|
|
32
|
-
|
|
32
|
+
let token = await this.getToken(config);
|
|
33
|
+
if (token) {
|
|
34
|
+
config = { "accessToken": token };
|
|
35
|
+
} else {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
let answers = { buildFileName: `${name}/${name}.vue` }
|
|
@@ -75,7 +80,7 @@ class Builder {
|
|
|
75
80
|
token: res.data.accessToken,
|
|
76
81
|
timestamp: now
|
|
77
82
|
};
|
|
78
|
-
writeCache(cache);
|
|
83
|
+
writeCache(process.cwd(), cache);
|
|
79
84
|
return res.data.accessToken;
|
|
80
85
|
} else {
|
|
81
86
|
console.error(chalk.red(`Login failed`, JSON.stringify(res)));
|
package/src/script/create.js
CHANGED
|
@@ -7,9 +7,15 @@ async function create(argvs) {
|
|
|
7
7
|
let res = await checkUpdate();
|
|
8
8
|
if (!res) {
|
|
9
9
|
let body = JSON.parse(decodeURI(argvs[2]))
|
|
10
|
-
const
|
|
10
|
+
const baseScriptPath = path.join(process.cwd(), "script");
|
|
11
|
+
const objectFolderPath = path.join(baseScriptPath, body.objId);
|
|
12
|
+
const filePath = path.join(objectFolderPath, body.scriptName);
|
|
13
|
+
|
|
11
14
|
try {
|
|
12
|
-
|
|
15
|
+
// 确保对象文件夹和脚本文件夹都存在
|
|
16
|
+
fs.mkdirSync(objectFolderPath, { recursive: true });
|
|
17
|
+
fs.mkdirSync(filePath, { recursive: true });
|
|
18
|
+
|
|
13
19
|
const fileTmp =
|
|
14
20
|
`function main($CCDK, obj){
|
|
15
21
|
console.log("hello World")
|
package/src/script/publish.js
CHANGED
|
@@ -9,10 +9,11 @@ const BaseUrl = "https://developer.apis.cloudcc.cn"
|
|
|
9
9
|
const { getBusToken } = require("../../utils/utils")
|
|
10
10
|
|
|
11
11
|
async function publish(argvs) {
|
|
12
|
-
let
|
|
12
|
+
let namePath = argvs[2]
|
|
13
|
+
let name = namePath.split("/")[1]
|
|
13
14
|
let res = await checkUpdate();
|
|
14
15
|
if (!res) {
|
|
15
|
-
const srcPath = path.join(process.cwd(), `script/${
|
|
16
|
+
const srcPath = path.join(process.cwd(), `script/${namePath}/`);
|
|
16
17
|
let classContent = fs.readFileSync(srcPath + `${name}.js`, 'utf8').replace(/\s+/g, '').replace(/\n/g, '').match(/\{([\s\S]*?)\}/)[1];
|
|
17
18
|
let configContent = JSON.parse(fs.readFileSync(srcPath + "config.json", 'utf8'));
|
|
18
19
|
let configContentOld = JSON.parse(JSON.stringify(configContent))
|
package/src/triggers/create.js
CHANGED
|
@@ -7,17 +7,24 @@ async function create(argvs) {
|
|
|
7
7
|
let res = await checkUpdate();
|
|
8
8
|
if (!res) {
|
|
9
9
|
let body = JSON.parse(decodeURI(argvs[2]))
|
|
10
|
-
const
|
|
10
|
+
const baseTriggersPath = path.join(process.cwd(), "triggers");
|
|
11
|
+
const objectFolderPath = path.join(baseTriggersPath, body.targetObjectId);
|
|
12
|
+
const triggersPath = path.join(objectFolderPath, body.name);
|
|
13
|
+
|
|
11
14
|
try {
|
|
12
|
-
|
|
15
|
+
// 确保对象文件夹和触发器文件夹都存在
|
|
16
|
+
fs.mkdirSync(objectFolderPath, { recursive: true });
|
|
17
|
+
fs.mkdirSync(triggersPath, { recursive: true });
|
|
18
|
+
|
|
13
19
|
const javaTmp = `// @SOURCE_CONTENT_START
|
|
14
20
|
System.out.print("hello World");
|
|
15
21
|
// @SOURCE_CONTENT_END`
|
|
16
|
-
|
|
17
|
-
fs.writeFileSync(path.join(triggersPath, "
|
|
18
|
-
|
|
19
|
-
console.log(
|
|
20
|
-
console.log()
|
|
22
|
+
|
|
23
|
+
fs.writeFileSync(path.join(triggersPath, body.name + ".java"), javaTmp);
|
|
24
|
+
fs.writeFileSync(path.join(triggersPath, "config.json"), JSON.stringify(body));
|
|
25
|
+
console.log();
|
|
26
|
+
console.log(chalk.green("Successfully Created:" + body.name));
|
|
27
|
+
console.log();
|
|
21
28
|
} catch (e) {
|
|
22
29
|
console.log()
|
|
23
30
|
console.log(chalk.red("Creation Failed:" + e))
|
package/src/triggers/publish.js
CHANGED
|
@@ -6,13 +6,14 @@ const { postNormal } = require("../../utils/http")
|
|
|
6
6
|
const { getBusToken } = require("../../utils/utils")
|
|
7
7
|
|
|
8
8
|
async function publish(argvs) {
|
|
9
|
-
let
|
|
9
|
+
let namePath = argvs[2]
|
|
10
|
+
let name = namePath.split("/")[1]
|
|
10
11
|
let res = await checkUpdate();
|
|
11
12
|
if (!res) {
|
|
12
13
|
console.log();
|
|
13
14
|
console.log(chalk.green('Posting, please wait...'));
|
|
14
15
|
console.log();
|
|
15
|
-
const triggersPath = path.join(process.cwd(), `triggers/${
|
|
16
|
+
const triggersPath = path.join(process.cwd(), `triggers/${namePath}/`);
|
|
16
17
|
let fullContent = fs.readFileSync(triggersPath + `${name}.java`, 'utf8');
|
|
17
18
|
|
|
18
19
|
// 提取标记之间的内容
|
package/utils/cache.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
-
const
|
|
2
|
+
const pathpath = require('path');
|
|
3
3
|
|
|
4
|
-
function getCachePath() {
|
|
5
|
-
return
|
|
4
|
+
function getCachePath(path = process.cwd()) {
|
|
5
|
+
return pathpath.join(path, '.cloudcc-cache.json');
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
function readCache() {
|
|
8
|
+
function readCache(path = process.cwd()) {
|
|
9
9
|
try {
|
|
10
|
-
const cachePath = getCachePath();
|
|
10
|
+
const cachePath = getCachePath(path);
|
|
11
11
|
if (!fs.existsSync(cachePath)) {
|
|
12
12
|
fs.writeFileSync(cachePath, JSON.stringify({}, null, 2));
|
|
13
13
|
return {};
|
|
@@ -19,9 +19,9 @@ function readCache() {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
function writeCache(data) {
|
|
22
|
+
function writeCache(path = process.cwd(), data) {
|
|
23
23
|
try {
|
|
24
|
-
const cachePath = getCachePath();
|
|
24
|
+
const cachePath = getCachePath(path);
|
|
25
25
|
fs.writeFileSync(cachePath, JSON.stringify(data, null, 2));
|
|
26
26
|
} catch (error) {
|
|
27
27
|
console.error('Failed to write cache:', error);
|
package/utils/checkVersion.js
CHANGED
|
@@ -65,9 +65,9 @@ function update(onlineVersion) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
async function checkUpdate() {
|
|
68
|
+
async function checkUpdate(path = process.cwd()) {
|
|
69
69
|
// 检查缓存
|
|
70
|
-
const cache = readCache();
|
|
70
|
+
const cache = readCache(path);
|
|
71
71
|
const cacheKey = 'version_check';
|
|
72
72
|
const now = Date.now();
|
|
73
73
|
const oneHour = 60 * 60 * 1000;
|
|
@@ -86,7 +86,7 @@ async function checkUpdate() {
|
|
|
86
86
|
cache[cacheKey] = {
|
|
87
87
|
timestamp: now
|
|
88
88
|
};
|
|
89
|
-
writeCache(cache);
|
|
89
|
+
writeCache(path, cache);
|
|
90
90
|
} catch (error) {
|
|
91
91
|
console.log("error", error)
|
|
92
92
|
onlineVersion = false;
|
package/utils/utils.js
CHANGED
|
@@ -3,8 +3,8 @@ const chalk = require("chalk")
|
|
|
3
3
|
const { getPackageJson } = require("./config")
|
|
4
4
|
const { readCache, writeCache } = require("./cache")
|
|
5
5
|
|
|
6
|
-
async function getBaseUrl(devConfig) {
|
|
7
|
-
const cache = readCache();
|
|
6
|
+
async function getBaseUrl(path, devConfig) {
|
|
7
|
+
const cache = readCache(path);
|
|
8
8
|
const cacheKey = devConfig.secretKey;
|
|
9
9
|
const now = Date.now();
|
|
10
10
|
const oneHour = 60 * 60 * 1000;
|
|
@@ -37,7 +37,7 @@ async function getBaseUrl(devConfig) {
|
|
|
37
37
|
setupSvc: global.setupSvc,
|
|
38
38
|
timestamp: now
|
|
39
39
|
};
|
|
40
|
-
writeCache(cache);
|
|
40
|
+
writeCache(path, cache);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
async function getBusToken(path = process.cwd()) {
|
|
@@ -48,7 +48,7 @@ async function getBusToken(path = process.cwd()) {
|
|
|
48
48
|
return false;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
const cache = readCache();
|
|
51
|
+
const cache = readCache(path);
|
|
52
52
|
const cacheKey = devConfig.secretKey;
|
|
53
53
|
const now = Date.now();
|
|
54
54
|
const oneHour = 60 * 60 * 1000;
|
|
@@ -72,7 +72,8 @@ async function getBusToken(path = process.cwd()) {
|
|
|
72
72
|
secretKey: devConfig.openSecretKey,
|
|
73
73
|
orgId: devConfig.orgId
|
|
74
74
|
}
|
|
75
|
-
await getBaseUrl(devConfig)
|
|
75
|
+
await getBaseUrl(path, devConfig)
|
|
76
|
+
// return path
|
|
76
77
|
let res = await postNormal(global.apiSvc + "/api/cauth/token", body)
|
|
77
78
|
if (res.result) {
|
|
78
79
|
global.accessToken = res.data.accessToken;
|
|
@@ -83,7 +84,8 @@ async function getBusToken(path = process.cwd()) {
|
|
|
83
84
|
setupSvc: global.setupSvc,
|
|
84
85
|
timestamp: now
|
|
85
86
|
};
|
|
86
|
-
|
|
87
|
+
|
|
88
|
+
writeCache(path, cache);
|
|
87
89
|
return res.data.accessToken;
|
|
88
90
|
} else {
|
|
89
91
|
console.log(chalk.red(res.returnInfo));
|