cloudcc-cli 2.2.4 → 2.2.5
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 +7 -0
- package/package.json +1 -1
- package/src/classes/create.js +66 -0
- package/src/classes/detail.js +78 -0
- package/src/classes/get.js +24 -0
- package/src/classes/index.js +12 -0
- package/src/classes/publish.js +51 -0
- package/src/classes/pull.js +55 -0
- package/src/classes/pullList.js +46 -0
- package/target/classes/com/cloudcc/core/CCObject.class +0 -0
- package/target/classes/com/cloudcc/core/CCSchedule.class +0 -0
- package/target/classes/com/cloudcc/core/CCService.class +0 -0
- package/target/classes/com/cloudcc/core/CCTrigger.class +0 -0
- package/target/classes/com/cloudcc/core/CCTriggerHandler.class +0 -0
- package/target/classes/com/cloudcc/core/DevLogger.class +0 -0
- package/target/classes/com/cloudcc/core/OperatationEnum.class +0 -0
- package/target/classes/com/cloudcc/core/PeakInterf.class +0 -0
- package/target/classes/com/cloudcc/core/SendEmail.class +0 -0
- package/target/classes/com/cloudcc/core/ServiceResult.class +0 -0
- package/target/classes/com/cloudcc/core/TimeUtil.class +0 -0
- package/target/classes/com/cloudcc/core/Tool$1.class +0 -0
- package/target/classes/com/cloudcc/core/Tool.class +0 -0
- package/target/classes/com/cloudcc/core/TriggerInvoker.class +0 -0
- package/target/classes/com/cloudcc/core/TriggerMethod.class +0 -0
- package/target/classes/com/cloudcc/core/TriggerTimeEnum.class +0 -0
- package/target/classes/com/cloudcc/core/UserInfo.class +0 -0
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const { checkUpdate } = require("../../utils/checkVersion")
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path")
|
|
4
|
+
const chalk = require("chalk")
|
|
5
|
+
const { getPackageJson } = require("../../utils/config.js")
|
|
6
|
+
|
|
7
|
+
async function create(name) {
|
|
8
|
+
let res = await checkUpdate();
|
|
9
|
+
if (!res) {
|
|
10
|
+
let config = await getPackageJson();
|
|
11
|
+
const classesPath = path.join(process.cwd(), "classes/" + name);
|
|
12
|
+
try {
|
|
13
|
+
fs.mkdirSync(classesPath, { recursive: true })
|
|
14
|
+
const javaTmp =
|
|
15
|
+
`package classes.${name};
|
|
16
|
+
|
|
17
|
+
import com.cloudcc.core.*;
|
|
18
|
+
// @SOURCE_CONTENT_START
|
|
19
|
+
public class ${name}{
|
|
20
|
+
private UserInfo userInfo;
|
|
21
|
+
private CCService cs;
|
|
22
|
+
|
|
23
|
+
public ${name}(UserInfo userInfo){
|
|
24
|
+
this(userInfo,new CCService(userInfo));
|
|
25
|
+
}
|
|
26
|
+
public ${name}(UserInfo userInfo,CCService cs){
|
|
27
|
+
this.userInfo = userInfo;
|
|
28
|
+
this.cs=cs;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public String getName(String str){
|
|
32
|
+
str = "demo";
|
|
33
|
+
return str;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// @SOURCE_CONTENT_END
|
|
37
|
+
`
|
|
38
|
+
const javaTestTmp =
|
|
39
|
+
`package classes.${name};
|
|
40
|
+
|
|
41
|
+
import com.cloudcc.core.*;
|
|
42
|
+
|
|
43
|
+
public class ${name}Test {
|
|
44
|
+
public static void main(String[] args) {
|
|
45
|
+
${name} obj = new ${name}(new UserInfo());
|
|
46
|
+
String name = obj.getName("test");
|
|
47
|
+
System.out.println("name:" + name);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`
|
|
51
|
+
fs.writeFileSync(path.join(classesPath, name + ".java"), javaTmp)
|
|
52
|
+
fs.writeFileSync(path.join(classesPath, name + "Test.java"), javaTestTmp)
|
|
53
|
+
fs.writeFileSync(path.join(classesPath, "config.json"), `{"name":"${name}","version":"${config.extandVersion || '2'}"}`)
|
|
54
|
+
console.error()
|
|
55
|
+
console.error(chalk.green("Successfully Created:" + name))
|
|
56
|
+
console.error()
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.error()
|
|
59
|
+
console.error(chalk.red("Creation Class Failed:" + e))
|
|
60
|
+
console.error()
|
|
61
|
+
throw new Error("Creation Class Failed: " + e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = create;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path")
|
|
3
|
+
|
|
4
|
+
const { getPackageJson } = require("../../utils/config")
|
|
5
|
+
const { postClass } = require("../../utils/http")
|
|
6
|
+
|
|
7
|
+
async function detail(name, id) {
|
|
8
|
+
// 如果有 name,优先查询本地
|
|
9
|
+
if (name && name !== '') {
|
|
10
|
+
const classPath = path.join(process.cwd(), `classes/${name}/`);
|
|
11
|
+
const configPath = classPath + "config.json";
|
|
12
|
+
const javaFilePath = classPath + `${name}.java`;
|
|
13
|
+
|
|
14
|
+
// 先尝试从本地文件获取详情
|
|
15
|
+
if (fs.existsSync(configPath) && fs.existsSync(javaFilePath)) {
|
|
16
|
+
let configContent = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
17
|
+
let javaContent = fs.readFileSync(javaFilePath, 'utf8');
|
|
18
|
+
return {
|
|
19
|
+
name: configContent.name,
|
|
20
|
+
version: configContent.version,
|
|
21
|
+
id: configContent.id || null,
|
|
22
|
+
source: javaContent,
|
|
23
|
+
published: !!configContent.id,
|
|
24
|
+
fromLocal: true
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 本地文件不完整,从服务器拉取
|
|
29
|
+
if (!fs.existsSync(configPath)) {
|
|
30
|
+
throw new Error('Class not found in local directory: ' + classPath);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let configContent = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
34
|
+
|
|
35
|
+
if (!configContent.id) {
|
|
36
|
+
throw new Error('Class has not been published. Please publish first to fetch details from server.');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 使用本地 config 中的 id 从服务器获取详细信息
|
|
40
|
+
let body = {
|
|
41
|
+
"id": configContent.id,
|
|
42
|
+
}
|
|
43
|
+
let config = await getPackageJson();
|
|
44
|
+
let res = await postClass(config.setupSvc + "/api/ccfag/detail", body, config.accessToken)
|
|
45
|
+
|
|
46
|
+
if (res.result) {
|
|
47
|
+
return {
|
|
48
|
+
...res.data.trigger,
|
|
49
|
+
fromLocal: false
|
|
50
|
+
};
|
|
51
|
+
} else {
|
|
52
|
+
throw new Error('Get Class Details Failed: ' + res.returnInfo);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 如果没有 name,用 id 从服务器查询
|
|
57
|
+
if (id && id !== '') {
|
|
58
|
+
let body = {
|
|
59
|
+
"id": id,
|
|
60
|
+
}
|
|
61
|
+
let config = await getPackageJson();
|
|
62
|
+
let res = await postClass(config.setupSvc + "/api/ccfag/detail", body, config.accessToken)
|
|
63
|
+
|
|
64
|
+
if (res.result) {
|
|
65
|
+
return {
|
|
66
|
+
...res.data.trigger,
|
|
67
|
+
fromLocal: false
|
|
68
|
+
};
|
|
69
|
+
} else {
|
|
70
|
+
throw new Error('Get Class Details Failed: ' + res.returnInfo);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 既没有 name 也没有 id,报错
|
|
75
|
+
throw new Error('Either class name or id must be provided');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = detail;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const { getPackageJson } = require("../../utils/config")
|
|
2
|
+
const { postClass } = require("../../utils/http")
|
|
3
|
+
|
|
4
|
+
async function get(arg, path, isMcp = false) {
|
|
5
|
+
let body = arg != null && arg != '' ? JSON.parse(decodeURI(arg)) : { shownum: "2000", showpage: "1", fid: "", sname: '', rptcond: '', rptorder: '' }
|
|
6
|
+
let config = await getPackageJson(path);
|
|
7
|
+
let res = await postClass(config.setupSvc + "/api/ccfag/list", body, config.accessToken)
|
|
8
|
+
if (res.result) {
|
|
9
|
+
const simpleList = (res.data.list || []).map(item => ({
|
|
10
|
+
apiname: item.apiname,
|
|
11
|
+
id: item.id,
|
|
12
|
+
name: item.name
|
|
13
|
+
}))
|
|
14
|
+
if (!isMcp) {
|
|
15
|
+
console.log(JSON.stringify(simpleList))
|
|
16
|
+
}
|
|
17
|
+
return res.data.list
|
|
18
|
+
} else {
|
|
19
|
+
console.error('error:', res.message);
|
|
20
|
+
throw new Error('Get Class Failed: ' + res.message);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = get;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const cc = {}
|
|
2
|
+
cc.create = require("./create")
|
|
3
|
+
cc.publish = require("./publish")
|
|
4
|
+
cc.pull = require("./pull")
|
|
5
|
+
cc.get = require("./get")
|
|
6
|
+
cc.pullList = require("./pullList")
|
|
7
|
+
cc.detail = require("./detail")
|
|
8
|
+
function Classes(action, argvs) {
|
|
9
|
+
cc[action](argvs[2], argvs[3])
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = Classes;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const { checkUpdate } = require("../../utils/checkVersion")
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path")
|
|
4
|
+
const chalk = require("chalk")
|
|
5
|
+
const { postClass } = require("../../utils/http")
|
|
6
|
+
|
|
7
|
+
const { javaContentRegular } = require("../../utils/utils")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const { getPackageJson } = require("../../utils/config")
|
|
11
|
+
|
|
12
|
+
async function publish(name) {
|
|
13
|
+
let res = await checkUpdate();
|
|
14
|
+
if (!res) {
|
|
15
|
+
console.error();
|
|
16
|
+
const now = new Date();
|
|
17
|
+
const timeStr = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0') + '-' + String(now.getDate()).padStart(2, '0') + ' ' + String(now.getHours()).padStart(2, '0') + ':' + String(now.getMinutes()).padStart(2, '0') + ':' + String(now.getSeconds()).padStart(2, '0');
|
|
18
|
+
console.error(chalk.green(timeStr));
|
|
19
|
+
console.error(chalk.green('Posting, please wait...'));
|
|
20
|
+
console.error();
|
|
21
|
+
const classPath = path.join(process.cwd(), `classes/${name}/`);
|
|
22
|
+
let fullContent = fs.readFileSync(classPath + `${name}.java`, 'utf8');
|
|
23
|
+
|
|
24
|
+
const sourceMatch = fullContent.match(javaContentRegular);
|
|
25
|
+
let classContent = sourceMatch ? sourceMatch[1] : fullContent;
|
|
26
|
+
let configContent = JSON.parse(fs.readFileSync(classPath + "config.json", 'utf8'));
|
|
27
|
+
|
|
28
|
+
let body = {
|
|
29
|
+
"id": configContent.id,
|
|
30
|
+
"name": name,
|
|
31
|
+
"source": encodeURIComponent(classContent.trim()),
|
|
32
|
+
"version": configContent.version || "2",
|
|
33
|
+
"folderId": "wgd"
|
|
34
|
+
}
|
|
35
|
+
let config = await getPackageJson();
|
|
36
|
+
let res = await postClass(config.setupSvc + "/api/ccfag/save", body, config.accessToken)
|
|
37
|
+
if (res.result) {
|
|
38
|
+
console.error(chalk.green('Success!'));
|
|
39
|
+
console.error();
|
|
40
|
+
|
|
41
|
+
if (!configContent.id) {
|
|
42
|
+
configContent.id = res.data
|
|
43
|
+
fs.writeFileSync(path.join(classPath, "config.json"), JSON.stringify(configContent))
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
console.error(chalk.red('Publish Class Failed:' + res.returnInfo));
|
|
47
|
+
throw new Error('Publish Class Failed: ' + res.returnInfo);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
module.exports = publish;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const { checkUpdate } = require("../../utils/checkVersion")
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path")
|
|
4
|
+
const chalk = require("chalk")
|
|
5
|
+
|
|
6
|
+
const { javaContentRegular } = require("../../utils/utils")
|
|
7
|
+
|
|
8
|
+
const { getPackageJson } = require("../../utils/config")
|
|
9
|
+
const { postClass } = require("../../utils/http")
|
|
10
|
+
|
|
11
|
+
async function pull(name) {
|
|
12
|
+
let res = await checkUpdate();
|
|
13
|
+
if (!res) {
|
|
14
|
+
console.error();
|
|
15
|
+
const now = new Date();
|
|
16
|
+
const timeStr = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0') + '-' + String(now.getDate()).padStart(2, '0') + ' ' + String(now.getHours()).padStart(2, '0') + ':' + String(now.getMinutes()).padStart(2, '0') + ':' + String(now.getSeconds()).padStart(2, '0');
|
|
17
|
+
console.error(chalk.green(timeStr));
|
|
18
|
+
console.error(chalk.green('Pulling, please wait...'));
|
|
19
|
+
console.error();
|
|
20
|
+
const classPath = path.join(process.cwd(), `classes/${name}/`);
|
|
21
|
+
let configContent = JSON.parse(fs.readFileSync(classPath + "config.json", 'utf8'));
|
|
22
|
+
if (!configContent.id) {
|
|
23
|
+
console.error(chalk.red('Class ID is not exist, please publish first!'));
|
|
24
|
+
throw new Error('Class ID is not exist, please publish first!');
|
|
25
|
+
}
|
|
26
|
+
let body = {
|
|
27
|
+
"id": configContent.id,
|
|
28
|
+
}
|
|
29
|
+
let config = await getPackageJson();
|
|
30
|
+
let res = await postClass(config.setupSvc + "/api/ccfag/detail", body, config.accessToken)
|
|
31
|
+
if (res.result) {
|
|
32
|
+
console.error(chalk.green('Success!'));
|
|
33
|
+
console.error();
|
|
34
|
+
|
|
35
|
+
let fullContent = fs.readFileSync(classPath + `${name}.java`, 'utf8');
|
|
36
|
+
|
|
37
|
+
let newContent = '';
|
|
38
|
+
if (fullContent.includes("@SOURCE_CONTENT_START")) {
|
|
39
|
+
newContent = fullContent.replace(
|
|
40
|
+
javaContentRegular,
|
|
41
|
+
`// @SOURCE_CONTENT_START\n${res.data.trigger.source}\n// @SOURCE_CONTENT_END`
|
|
42
|
+
);
|
|
43
|
+
} else {
|
|
44
|
+
newContent = res.data.trigger.source;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fs.writeFileSync(classPath + `${name}.java`, newContent, 'utf8');
|
|
48
|
+
|
|
49
|
+
} else {
|
|
50
|
+
console.error(chalk.red('Pull Class Failed:' + res.returnInfo));
|
|
51
|
+
throw new Error('Pull Class Failed: ' + res.returnInfo);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
module.exports = pull;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path")
|
|
3
|
+
const { getPackageJson } = require("../../utils/config");
|
|
4
|
+
const { postClass } = require("../../utils/http");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Batch pull class details and generate local files
|
|
8
|
+
* @param class id
|
|
9
|
+
*/
|
|
10
|
+
async function pullList(id, url, isMcp = false) {
|
|
11
|
+
let config = await getPackageJson(url);
|
|
12
|
+
const body = { id };
|
|
13
|
+
const res = await postClass(config.setupSvc + "/api/ccfag/detail", body, config.accessToken);
|
|
14
|
+
try {
|
|
15
|
+
const data = res.data;
|
|
16
|
+
const trigger = data.trigger;
|
|
17
|
+
const className = trigger.name;
|
|
18
|
+
const folderPath = path.join(url, `classes/${trigger.name}`);
|
|
19
|
+
// 3. Check and create folder
|
|
20
|
+
if (!fs.existsSync(folderPath)) {
|
|
21
|
+
fs.mkdirSync(folderPath, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
// 4. Create class file
|
|
24
|
+
const javaFile = path.join(folderPath, `${className}.java`);
|
|
25
|
+
const javaContent = `package classes.${className};\n\nimport com.cloudcc.core.*;\n// @SOURCE_CONTENT_START\n${trigger.source}\n// @SOURCE_CONTENT_END\n`;
|
|
26
|
+
fs.writeFileSync(javaFile, javaContent, "utf8");
|
|
27
|
+
// 5. Create config.json
|
|
28
|
+
const configJson = {
|
|
29
|
+
name: trigger.name,
|
|
30
|
+
version: "2",
|
|
31
|
+
id: trigger.id || id
|
|
32
|
+
};
|
|
33
|
+
fs.writeFileSync(path.join(folderPath, "config.json"), JSON.stringify(configJson, null, 4), "utf8");
|
|
34
|
+
// 6. Create test class
|
|
35
|
+
const testClassName = `${className}Test`;
|
|
36
|
+
const testContent = `package classes.${className};\n\nimport com.cloudcc.core.*;\n\npublic class ${testClassName} {\n public static void main(String[] args) {\n System.out.println(\"name:\");\n }\n}\n`;
|
|
37
|
+
fs.writeFileSync(path.join(folderPath, `${testClassName}.java`), testContent, "utf8");
|
|
38
|
+
if (!isMcp) {
|
|
39
|
+
console.log("true");
|
|
40
|
+
}
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.error(`Error occurred while processing class id: ${id}, message: ${e.message}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = pullList;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|