cloudcc-cli 1.8.7 → 1.8.9
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 +1326 -1312
- package/bin/cc.js +49 -49
- package/bin/plugin.js +5 -5
- package/bin/project.js +5 -5
- package/core/core/ServiceResult.java +35 -35
- package/core/core/UserInfo.java +45 -45
- package/package.json +34 -34
- package/src/classes/create.js +43 -43
- package/src/classes/index.js +8 -8
- package/src/classes/publish.js +45 -45
- package/src/config/get.js +20 -20
- package/src/config/index.js +8 -8
- package/src/config/use.js +14 -14
- package/src/object/get.js +35 -35
- package/src/object/index.js +7 -7
- package/src/plugin/create.js +70 -70
- package/src/plugin/create1.js +58 -58
- package/src/plugin/index.js +8 -8
- package/src/plugin/publish.js +267 -267
- package/src/plugin/publish1.js +297 -297
- package/src/plugin/readme.md +6 -6
- package/src/project/create.js +83 -83
- package/src/project/create1.js +105 -105
- package/src/project/index.js +7 -7
- package/src/recordType/get.js +13 -13
- package/src/recordType/index.js +7 -7
- package/src/script/create.js +35 -35
- package/src/script/index.js +8 -8
- package/src/script/publish.js +71 -51
- package/src/timer/create.js +29 -29
- package/src/timer/index.js +8 -8
- package/src/timer/publish.js +47 -47
- package/src/token/get.js +11 -11
- package/src/token/index.js +7 -7
- package/src/triggers/create.js +39 -39
- package/src/triggers/index.js +8 -8
- package/src/triggers/publish.js +53 -53
- package/template/Appvue +24 -24
- package/template/babelconfigjs +5 -5
- package/template/demojava +14 -14
- package/template/gitignore +13 -13
- package/template/index.js +57 -57
- package/template/indexhtml +21 -21
- package/template/indexvue +29 -29
- package/template/javaconfigjson +2 -2
- package/template/mainjs +13 -13
- package/template/package-lockjson +13952 -13952
- package/template/packagejson +42 -42
- package/template/vueconfigjs +21 -21
- package/tool/branch/index.js +25 -25
- package/tool/checkLange/checkLang.js +68 -68
- package/tool/checkLange/clearLang.js +85 -85
- package/utils/cache.js +31 -31
- package/utils/checkVersion.js +107 -107
- package/utils/config.js +18 -18
- package/utils/http.js +123 -123
- package/utils/utils.js +95 -95
package/src/project/create.js
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
const chalk = require("chalk")
|
|
2
|
-
const inquirer = require("inquirer")
|
|
3
|
-
const memFs = require("mem-fs")
|
|
4
|
-
const memFsEditor = require("mem-fs-editor")
|
|
5
|
-
const fs = require("fs")
|
|
6
|
-
const path = require("path")
|
|
7
|
-
|
|
8
|
-
class Creator {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.fs = memFsEditor.create(memFs.create());
|
|
11
|
-
this.options = {
|
|
12
|
-
name: "",
|
|
13
|
-
description: ""
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
this.rootPath = path.resolve(__dirname, "../../");
|
|
17
|
-
|
|
18
|
-
this.tplDirPath = path.join(this.rootPath, "template");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async init(name) {
|
|
22
|
-
console.log()
|
|
23
|
-
console.log(chalk.green('Welcome CloudCC-CLI'));
|
|
24
|
-
console.log()
|
|
25
|
-
if (!name) {
|
|
26
|
-
this.ask().then(answers => {
|
|
27
|
-
this.options = Object.assign({}, this.options, answers);
|
|
28
|
-
console.log(this.options);
|
|
29
|
-
this.write();
|
|
30
|
-
})
|
|
31
|
-
} else {
|
|
32
|
-
this.options = { name }
|
|
33
|
-
this.write();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
ask() {
|
|
38
|
-
const prompt = [];
|
|
39
|
-
|
|
40
|
-
prompt.push({
|
|
41
|
-
type: "input",
|
|
42
|
-
name: "name",
|
|
43
|
-
message: "Please enter the project name",
|
|
44
|
-
validate(input) {
|
|
45
|
-
if (!input) {
|
|
46
|
-
return "Please enter the project name"
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (fs.existsSync(input)) {
|
|
50
|
-
return "Project name already exists"
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
return inquirer.prompt(prompt)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
write() {
|
|
60
|
-
console.log();
|
|
61
|
-
console.log(chalk.green("Starting construction, please wait"));
|
|
62
|
-
const tplBuilder = require("../../template/index");
|
|
63
|
-
tplBuilder(this, this.options, () => {
|
|
64
|
-
console.log();
|
|
65
|
-
console.log(chalk.green('Build completed, please install dependencies before running'))
|
|
66
|
-
console.log();
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
getTplPath(file) {
|
|
71
|
-
return path.join(this.tplDirPath, file);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
copyTpl(file, to, data = {}) {
|
|
75
|
-
const tplPath = this.getTplPath(file);
|
|
76
|
-
this.fs.copyTpl(tplPath, to, data);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
copy(file, to) {
|
|
80
|
-
const tplPath = this.getTplPath(file);
|
|
81
|
-
this.fs.copy(tplPath, to)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
1
|
+
const chalk = require("chalk")
|
|
2
|
+
const inquirer = require("inquirer")
|
|
3
|
+
const memFs = require("mem-fs")
|
|
4
|
+
const memFsEditor = require("mem-fs-editor")
|
|
5
|
+
const fs = require("fs")
|
|
6
|
+
const path = require("path")
|
|
7
|
+
|
|
8
|
+
class Creator {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.fs = memFsEditor.create(memFs.create());
|
|
11
|
+
this.options = {
|
|
12
|
+
name: "",
|
|
13
|
+
description: ""
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
this.rootPath = path.resolve(__dirname, "../../");
|
|
17
|
+
|
|
18
|
+
this.tplDirPath = path.join(this.rootPath, "template");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async init(name) {
|
|
22
|
+
console.log()
|
|
23
|
+
console.log(chalk.green('Welcome CloudCC-CLI'));
|
|
24
|
+
console.log()
|
|
25
|
+
if (!name) {
|
|
26
|
+
this.ask().then(answers => {
|
|
27
|
+
this.options = Object.assign({}, this.options, answers);
|
|
28
|
+
console.log(this.options);
|
|
29
|
+
this.write();
|
|
30
|
+
})
|
|
31
|
+
} else {
|
|
32
|
+
this.options = { name }
|
|
33
|
+
this.write();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
ask() {
|
|
38
|
+
const prompt = [];
|
|
39
|
+
|
|
40
|
+
prompt.push({
|
|
41
|
+
type: "input",
|
|
42
|
+
name: "name",
|
|
43
|
+
message: "Please enter the project name",
|
|
44
|
+
validate(input) {
|
|
45
|
+
if (!input) {
|
|
46
|
+
return "Please enter the project name"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (fs.existsSync(input)) {
|
|
50
|
+
return "Project name already exists"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return inquirer.prompt(prompt)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
write() {
|
|
60
|
+
console.log();
|
|
61
|
+
console.log(chalk.green("Starting construction, please wait"));
|
|
62
|
+
const tplBuilder = require("../../template/index");
|
|
63
|
+
tplBuilder(this, this.options, () => {
|
|
64
|
+
console.log();
|
|
65
|
+
console.log(chalk.green('Build completed, please install dependencies before running'))
|
|
66
|
+
console.log();
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getTplPath(file) {
|
|
71
|
+
return path.join(this.tplDirPath, file);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
copyTpl(file, to, data = {}) {
|
|
75
|
+
const tplPath = this.getTplPath(file);
|
|
76
|
+
this.fs.copyTpl(tplPath, to, data);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
copy(file, to) {
|
|
80
|
+
const tplPath = this.getTplPath(file);
|
|
81
|
+
this.fs.copy(tplPath, to)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
84
|
module.exports = Creator;
|
package/src/project/create1.js
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
const chalk = require("chalk")
|
|
2
|
-
const inquirer = require("inquirer")
|
|
3
|
-
const memFs = require("mem-fs")
|
|
4
|
-
const memFsEditor = require("mem-fs-editor")
|
|
5
|
-
const fs = require("fs")
|
|
6
|
-
const path = require("path")
|
|
7
|
-
const tplBuilder = require("../../template/index");
|
|
8
|
-
const execSync = require('child_process').execSync;
|
|
9
|
-
|
|
10
|
-
class Creator {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.fs = memFsEditor.create(memFs.create());
|
|
13
|
-
this.options = {
|
|
14
|
-
name: "",
|
|
15
|
-
description: ""
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
this.rootPath = path.resolve(__dirname, "../../");
|
|
19
|
-
|
|
20
|
-
this.tplDirPath = path.join(this.rootPath, "template");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async init(name) {
|
|
24
|
-
console.log()
|
|
25
|
-
console.log(chalk.green('Welcome CloudCC-CLI'));
|
|
26
|
-
console.log()
|
|
27
|
-
if (!name) {
|
|
28
|
-
this.ask().then(answers => {
|
|
29
|
-
this.options = Object.assign({}, this.options, answers);
|
|
30
|
-
console.log(this.options);
|
|
31
|
-
this.write();
|
|
32
|
-
})
|
|
33
|
-
} else {
|
|
34
|
-
this.options = { name }
|
|
35
|
-
this.write();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
ask() {
|
|
40
|
-
const prompt = [];
|
|
41
|
-
|
|
42
|
-
prompt.push({
|
|
43
|
-
type: "input",
|
|
44
|
-
name: "name",
|
|
45
|
-
message: "Please enter the project name",
|
|
46
|
-
validate(input) {
|
|
47
|
-
if (!input) {
|
|
48
|
-
return "Please enter the project name"
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (fs.existsSync(input)) {
|
|
52
|
-
return "Project name already exists"
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return inquirer.prompt(prompt)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
write() {
|
|
62
|
-
console.log();
|
|
63
|
-
console.log(chalk.green("Starting construction, please wait"));
|
|
64
|
-
tplBuilder(this, this.options, () => {
|
|
65
|
-
console.log();
|
|
66
|
-
this.initGit(path.join(process.cwd(), this.options.name))
|
|
67
|
-
console.log(chalk.green('Build completed, please install dependencies before running'))
|
|
68
|
-
console.log();
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
getTplPath(file) {
|
|
73
|
-
return path.join(this.tplDirPath, file);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
copyTpl(file, to, data = {}) {
|
|
77
|
-
const tplPath = this.getTplPath(file);
|
|
78
|
-
this.fs.copyTpl(tplPath, to, data);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
copy(file, to) {
|
|
82
|
-
const tplPath = this.getTplPath(file);
|
|
83
|
-
this.fs.copy(tplPath, to)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
initGit(path) {
|
|
87
|
-
try {
|
|
88
|
-
execSync(`git -C ${path} init`)
|
|
89
|
-
execSync(`git -C ${path} add .`)
|
|
90
|
-
execSync(`git -C ${path} commit -m 'init'`)
|
|
91
|
-
console.log(`${chalk.grey(`Git repository initialization completed`)} ${chalk.green('✔ ')}`);
|
|
92
|
-
console.log();
|
|
93
|
-
console.log(`${chalk.yellow(`Please set the warehouse address: git remote add origin [remote repository address]`)}`);
|
|
94
|
-
console.log();
|
|
95
|
-
} catch (error) {
|
|
96
|
-
console.log();
|
|
97
|
-
console.log(chalk.red('git repository initialization exception'))
|
|
98
|
-
console.log();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function create(argvs) {
|
|
103
|
-
let c = new Creator();
|
|
104
|
-
c.init(argvs[2])
|
|
105
|
-
}
|
|
1
|
+
const chalk = require("chalk")
|
|
2
|
+
const inquirer = require("inquirer")
|
|
3
|
+
const memFs = require("mem-fs")
|
|
4
|
+
const memFsEditor = require("mem-fs-editor")
|
|
5
|
+
const fs = require("fs")
|
|
6
|
+
const path = require("path")
|
|
7
|
+
const tplBuilder = require("../../template/index");
|
|
8
|
+
const execSync = require('child_process').execSync;
|
|
9
|
+
|
|
10
|
+
class Creator {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.fs = memFsEditor.create(memFs.create());
|
|
13
|
+
this.options = {
|
|
14
|
+
name: "",
|
|
15
|
+
description: ""
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this.rootPath = path.resolve(__dirname, "../../");
|
|
19
|
+
|
|
20
|
+
this.tplDirPath = path.join(this.rootPath, "template");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async init(name) {
|
|
24
|
+
console.log()
|
|
25
|
+
console.log(chalk.green('Welcome CloudCC-CLI'));
|
|
26
|
+
console.log()
|
|
27
|
+
if (!name) {
|
|
28
|
+
this.ask().then(answers => {
|
|
29
|
+
this.options = Object.assign({}, this.options, answers);
|
|
30
|
+
console.log(this.options);
|
|
31
|
+
this.write();
|
|
32
|
+
})
|
|
33
|
+
} else {
|
|
34
|
+
this.options = { name }
|
|
35
|
+
this.write();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
ask() {
|
|
40
|
+
const prompt = [];
|
|
41
|
+
|
|
42
|
+
prompt.push({
|
|
43
|
+
type: "input",
|
|
44
|
+
name: "name",
|
|
45
|
+
message: "Please enter the project name",
|
|
46
|
+
validate(input) {
|
|
47
|
+
if (!input) {
|
|
48
|
+
return "Please enter the project name"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (fs.existsSync(input)) {
|
|
52
|
+
return "Project name already exists"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return inquirer.prompt(prompt)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
write() {
|
|
62
|
+
console.log();
|
|
63
|
+
console.log(chalk.green("Starting construction, please wait"));
|
|
64
|
+
tplBuilder(this, this.options, () => {
|
|
65
|
+
console.log();
|
|
66
|
+
this.initGit(path.join(process.cwd(), this.options.name))
|
|
67
|
+
console.log(chalk.green('Build completed, please install dependencies before running'))
|
|
68
|
+
console.log();
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getTplPath(file) {
|
|
73
|
+
return path.join(this.tplDirPath, file);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
copyTpl(file, to, data = {}) {
|
|
77
|
+
const tplPath = this.getTplPath(file);
|
|
78
|
+
this.fs.copyTpl(tplPath, to, data);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
copy(file, to) {
|
|
82
|
+
const tplPath = this.getTplPath(file);
|
|
83
|
+
this.fs.copy(tplPath, to)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
initGit(path) {
|
|
87
|
+
try {
|
|
88
|
+
execSync(`git -C ${path} init`)
|
|
89
|
+
execSync(`git -C ${path} add .`)
|
|
90
|
+
execSync(`git -C ${path} commit -m 'init'`)
|
|
91
|
+
console.log(`${chalk.grey(`Git repository initialization completed`)} ${chalk.green('✔ ')}`);
|
|
92
|
+
console.log();
|
|
93
|
+
console.log(`${chalk.yellow(`Please set the warehouse address: git remote add origin [remote repository address]`)}`);
|
|
94
|
+
console.log();
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.log();
|
|
97
|
+
console.log(chalk.red('git repository initialization exception'))
|
|
98
|
+
console.log();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function create(argvs) {
|
|
103
|
+
let c = new Creator();
|
|
104
|
+
c.init(argvs[2])
|
|
105
|
+
}
|
|
106
106
|
module.exports = create;
|
package/src/project/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const cc = {}
|
|
2
|
-
cc.create = require("./create1")
|
|
3
|
-
function Plugin(action, argvs) {
|
|
4
|
-
cc[action](argvs)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
module.exports = Plugin;
|
|
1
|
+
const cc = {}
|
|
2
|
+
cc.create = require("./create1")
|
|
3
|
+
function Plugin(action, argvs) {
|
|
4
|
+
cc[action](argvs)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
module.exports = Plugin;
|
package/src/recordType/get.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const { getBusToken } = require("../../utils/utils")
|
|
2
|
-
const { postNormal } = require("../../utils/http")
|
|
3
|
-
|
|
4
|
-
async function get(path, prefix) {
|
|
5
|
-
|
|
6
|
-
if (await getBusToken(path)) {
|
|
7
|
-
let res = await postNormal(global.apiSvc + "/api/batch/getRecordType", { prefix: prefix })
|
|
8
|
-
console.log(JSON.stringify(res.data.recordTypeList))
|
|
9
|
-
return res.data
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
module.exports = get;
|
|
1
|
+
const { getBusToken } = require("../../utils/utils")
|
|
2
|
+
const { postNormal } = require("../../utils/http")
|
|
3
|
+
|
|
4
|
+
async function get(path, prefix) {
|
|
5
|
+
|
|
6
|
+
if (await getBusToken(path)) {
|
|
7
|
+
let res = await postNormal(global.apiSvc + "/api/batch/getRecordType", { prefix: prefix })
|
|
8
|
+
console.log(JSON.stringify(res.data.recordTypeList))
|
|
9
|
+
return res.data
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = get;
|
package/src/recordType/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const cc = {}
|
|
2
|
-
cc.get = require("./get")
|
|
3
|
-
function main(action, argvs) {
|
|
4
|
-
cc[action](argvs[2],argvs[3])
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
module.exports = main;
|
|
1
|
+
const cc = {}
|
|
2
|
+
cc.get = require("./get")
|
|
3
|
+
function main(action, argvs) {
|
|
4
|
+
cc[action](argvs[2],argvs[3])
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
module.exports = main;
|
package/src/script/create.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
const { checkUpdate } = require("../../utils/checkVersion")
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
const path = require("path")
|
|
4
|
-
const chalk = require("chalk")
|
|
5
|
-
|
|
6
|
-
async function create(argvs) {
|
|
7
|
-
let res = await checkUpdate();
|
|
8
|
-
if (!res) {
|
|
9
|
-
let body = JSON.parse(decodeURI(argvs[2]))
|
|
10
|
-
const baseScriptPath = path.join(process.cwd(), "script");
|
|
11
|
-
const objectFolderPath = path.join(baseScriptPath, body.schemetableName.toLowerCase());
|
|
12
|
-
const filePath = path.join(objectFolderPath, body.scriptName);
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
// 确保对象文件夹和脚本文件夹都存在
|
|
16
|
-
fs.mkdirSync(objectFolderPath, { recursive: true });
|
|
17
|
-
fs.mkdirSync(filePath, { recursive: true });
|
|
18
|
-
|
|
19
|
-
const fileTmp =
|
|
20
|
-
`function main($CCDK, obj){
|
|
21
|
-
console.log("hello World")
|
|
22
|
-
}`
|
|
23
|
-
fs.writeFileSync(path.join(filePath, body.scriptName + ".js"), fileTmp)
|
|
24
|
-
fs.writeFileSync(path.join(filePath, "config.json"), JSON.stringify(body))
|
|
25
|
-
console.log()
|
|
26
|
-
console.log(chalk.green("Successfully Created:" + body.scriptName))
|
|
27
|
-
console.log()
|
|
28
|
-
} catch (e) {
|
|
29
|
-
console.log()
|
|
30
|
-
console.log(chalk.red("Creation Failed:" + e))
|
|
31
|
-
console.log()
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
1
|
+
const { checkUpdate } = require("../../utils/checkVersion")
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path")
|
|
4
|
+
const chalk = require("chalk")
|
|
5
|
+
|
|
6
|
+
async function create(argvs) {
|
|
7
|
+
let res = await checkUpdate();
|
|
8
|
+
if (!res) {
|
|
9
|
+
let body = JSON.parse(decodeURI(argvs[2]))
|
|
10
|
+
const baseScriptPath = path.join(process.cwd(), "script");
|
|
11
|
+
const objectFolderPath = path.join(baseScriptPath, body.schemetableName.toLowerCase());
|
|
12
|
+
const filePath = path.join(objectFolderPath, body.scriptName);
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
// 确保对象文件夹和脚本文件夹都存在
|
|
16
|
+
fs.mkdirSync(objectFolderPath, { recursive: true });
|
|
17
|
+
fs.mkdirSync(filePath, { recursive: true });
|
|
18
|
+
|
|
19
|
+
const fileTmp =
|
|
20
|
+
`function main($CCDK, obj){
|
|
21
|
+
console.log("hello World")
|
|
22
|
+
}`
|
|
23
|
+
fs.writeFileSync(path.join(filePath, body.scriptName + ".js"), fileTmp)
|
|
24
|
+
fs.writeFileSync(path.join(filePath, "config.json"), JSON.stringify(body))
|
|
25
|
+
console.log()
|
|
26
|
+
console.log(chalk.green("Successfully Created:" + body.scriptName))
|
|
27
|
+
console.log()
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.log()
|
|
30
|
+
console.log(chalk.red("Creation Failed:" + e))
|
|
31
|
+
console.log()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
36
|
module.exports = create;
|
package/src/script/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const cc = {}
|
|
2
|
-
cc.create = require("./create")
|
|
3
|
-
cc.publish = require("./publish")
|
|
4
|
-
function main(action, argvs) {
|
|
5
|
-
cc[action](argvs)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
module.exports = main;
|
|
1
|
+
const cc = {}
|
|
2
|
+
cc.create = require("./create")
|
|
3
|
+
cc.publish = require("./publish")
|
|
4
|
+
function main(action, argvs) {
|
|
5
|
+
cc[action](argvs)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
module.exports = main;
|
package/src/script/publish.js
CHANGED
|
@@ -1,51 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
const { checkUpdate } = require("../../utils/checkVersion")
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path")
|
|
5
|
-
const chalk = require("chalk")
|
|
6
|
-
const { post } = require("../../utils/http")
|
|
7
|
-
const { getPackageJson } = require("../../utils/config.js")
|
|
8
|
-
const BaseUrl = "https://developer.apis.cloudcc.cn"
|
|
9
|
-
const { getBusToken } = require("../../utils/utils")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
console.log(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
console.log();
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
|
|
2
|
+
const { checkUpdate } = require("../../utils/checkVersion")
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path")
|
|
5
|
+
const chalk = require("chalk")
|
|
6
|
+
const { post } = require("../../utils/http")
|
|
7
|
+
const { getPackageJson } = require("../../utils/config.js")
|
|
8
|
+
const BaseUrl = "https://developer.apis.cloudcc.cn"
|
|
9
|
+
const { getBusToken } = require("../../utils/utils")
|
|
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 publish(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
|
+
let scriptContent = fs.readFileSync(srcPath + `${name}.js`, 'utf8');
|
|
23
|
+
if (!checkMainFunctionExists(scriptContent)) {
|
|
24
|
+
console.log();
|
|
25
|
+
console.log(chalk.red('Warning: No valid main function definition found in file'));
|
|
26
|
+
console.log();
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const executableCode = `
|
|
30
|
+
${scriptContent}
|
|
31
|
+
main.toString();
|
|
32
|
+
`;
|
|
33
|
+
const functionStr = eval(executableCode);
|
|
34
|
+
const bodyStart = functionStr.indexOf('{') + 1;
|
|
35
|
+
const bodyEnd = functionStr.lastIndexOf('}');
|
|
36
|
+
|
|
37
|
+
scriptContent = functionStr.substring(bodyStart, bodyEnd);
|
|
38
|
+
let configContent = JSON.parse(fs.readFileSync(srcPath + "config.json", 'utf8'));
|
|
39
|
+
let configContentOld = JSON.parse(JSON.stringify(configContent))
|
|
40
|
+
|
|
41
|
+
if (scriptContent) {
|
|
42
|
+
let devConsoleConfig = getPackageJson()
|
|
43
|
+
if ("private" != devConsoleConfig.version) {
|
|
44
|
+
devConsoleConfig.accessToken = await getBusToken();
|
|
45
|
+
}
|
|
46
|
+
console.log(chalk.green('Posting, please wait...'));
|
|
47
|
+
configContent.scriptContent = scriptContent
|
|
48
|
+
let res = await post((devConsoleConfig.baseUrl || BaseUrl) + "/devconsole/script/saveClientScript", configContent, devConsoleConfig)
|
|
49
|
+
if (res.result) {
|
|
50
|
+
console.log();
|
|
51
|
+
console.log(chalk.green('Success!'));
|
|
52
|
+
console.log();
|
|
53
|
+
|
|
54
|
+
if (!configContentOld.id) {
|
|
55
|
+
configContentOld.id = res.data
|
|
56
|
+
fs.writeFileSync(path.join(srcPath, "config.json"), JSON.stringify(configContentOld))
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
console.log();
|
|
60
|
+
console.log(chalk.red('Fail:' + res.returnInfo));
|
|
61
|
+
console.log();
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
console.log();
|
|
65
|
+
console.log(chalk.red('Invalid Script Content'));
|
|
66
|
+
console.log();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = publish;
|