cloudcc-cli 1.6.0 → 1.6.2

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.
Files changed (50) hide show
  1. package/README.md +1147 -1128
  2. package/bin/cc.js +48 -48
  3. package/bin/plugin.js +5 -5
  4. package/bin/project.js +5 -5
  5. package/package.json +34 -34
  6. package/src/classes/create.js +43 -43
  7. package/src/classes/index.js +8 -8
  8. package/src/classes/publish.js +48 -47
  9. package/src/config/get.js +22 -0
  10. package/src/config/index.js +8 -0
  11. package/src/config/use.js +16 -0
  12. package/src/object/get.js +16 -0
  13. package/src/object/index.js +7 -0
  14. package/src/plugin/create.js +80 -80
  15. package/src/plugin/create1.js +66 -67
  16. package/src/plugin/index.js +8 -8
  17. package/src/plugin/publish.js +298 -305
  18. package/src/plugin/publish1.js +286 -293
  19. package/src/project/create.js +89 -89
  20. package/src/project/create1.js +111 -94
  21. package/src/project/index.js +7 -7
  22. package/src/recordType/get.js +16 -0
  23. package/src/recordType/index.js +7 -0
  24. package/src/script/create.js +33 -0
  25. package/src/script/index.js +8 -0
  26. package/src/script/publish.js +69 -0
  27. package/src/timer/create.js +29 -29
  28. package/src/timer/index.js +8 -8
  29. package/src/timer/publish.js +47 -47
  30. package/src/token/get.js +13 -0
  31. package/src/token/index.js +7 -0
  32. package/src/triggers/create.js +35 -35
  33. package/src/triggers/index.js +8 -8
  34. package/src/triggers/publish.js +51 -51
  35. package/template/Appvue +29 -29
  36. package/template/babelconfigjs +5 -5
  37. package/template/cloudcc-cli.configjs +1 -0
  38. package/template/demojava +14 -14
  39. package/template/gitignore +11 -0
  40. package/template/index.js +57 -52
  41. package/template/indexhtml +21 -21
  42. package/template/indexvue +34 -34
  43. package/template/javaconfigjson +2 -2
  44. package/template/mainjs +13 -13
  45. package/template/package-lockjson +12115 -12115
  46. package/template/packagejson +42 -46
  47. package/template/vueconfigjs +26 -26
  48. package/utils/checkVersion.js +105 -105
  49. package/utils/http.js +122 -122
  50. package/utils/utils.js +54 -44
@@ -1,90 +1,90 @@
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 { checkUpdate } = require("../../utils/checkVersion")
8
- /**
9
- * 创建自定组件开发模板项目
10
- */
11
- class Creator {
12
- constructor() {
13
- this.fs = memFsEditor.create(memFs.create());
14
- this.options = {
15
- name: "",
16
- description: ""
17
- }
18
- // 当前目录
19
- this.rootPath = path.resolve(__dirname, "../../");
20
- // 模板目录
21
- this.tplDirPath = path.join(this.rootPath, "template");
22
- }
23
- // 初始化
24
- async init(name) {
25
- let res = await checkUpdate();
26
- if (!res) {
27
- console.log()
28
- console.log(chalk.green('欢迎使用CloudCC-CLI'));
29
- console.log()
30
- if (!name) {
31
- this.ask().then(answers => {
32
- this.options = Object.assign({}, this.options, answers);
33
- console.log(this.options);
34
- this.write();
35
- })
36
- } else {
37
- this.options = { name }
38
- this.write();
39
- }
40
- }
41
- }
42
- // 命令行交互
43
- ask() {
44
- const prompt = [];
45
-
46
- prompt.push({
47
- type: "input",
48
- name: "name",
49
- message: "请输入项目名称",
50
- validate(input) {
51
- if (!input) {
52
- return "请输入项目名称"
53
- }
54
-
55
- if (fs.existsSync(input)) {
56
- return "项目名已存在"
57
- }
58
-
59
- return true;
60
- }
61
- });
62
- return inquirer.prompt(prompt)
63
- }
64
- // 拷贝和写数据
65
- write() {
66
- console.log();
67
- console.log(chalk.green("开始构建,请稍后"));
68
- const tplBuilder = require("../../template/index");
69
- tplBuilder(this, this.options, () => {
70
- console.log();
71
- console.log(chalk.green('构建完成,运行前请安装依赖'))
72
- console.log();
73
- })
74
- }
75
-
76
- getTplPath(file) {
77
- return path.join(this.tplDirPath, file);
78
- }
79
-
80
- copyTpl(file, to, data = {}) {
81
- const tplPath = this.getTplPath(file);
82
- this.fs.copyTpl(tplPath, to, data);
83
- }
84
-
85
- copy(file, to) {
86
- const tplPath = this.getTplPath(file);
87
- this.fs.copy(tplPath, to)
88
- }
89
- }
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 { checkUpdate } = require("../../utils/checkVersion")
8
+ /**
9
+ * 创建自定组件开发模板项目
10
+ */
11
+ class Creator {
12
+ constructor() {
13
+ this.fs = memFsEditor.create(memFs.create());
14
+ this.options = {
15
+ name: "",
16
+ description: ""
17
+ }
18
+ // 当前目录
19
+ this.rootPath = path.resolve(__dirname, "../../");
20
+ // 模板目录
21
+ this.tplDirPath = path.join(this.rootPath, "template");
22
+ }
23
+ // 初始化
24
+ async init(name) {
25
+ let res = await checkUpdate();
26
+ if (!res) {
27
+ console.log()
28
+ console.log(chalk.green('欢迎使用CloudCC-CLI'));
29
+ console.log()
30
+ if (!name) {
31
+ this.ask().then(answers => {
32
+ this.options = Object.assign({}, this.options, answers);
33
+ console.log(this.options);
34
+ this.write();
35
+ })
36
+ } else {
37
+ this.options = { name }
38
+ this.write();
39
+ }
40
+ }
41
+ }
42
+ // 命令行交互
43
+ ask() {
44
+ const prompt = [];
45
+
46
+ prompt.push({
47
+ type: "input",
48
+ name: "name",
49
+ message: "请输入项目名称",
50
+ validate(input) {
51
+ if (!input) {
52
+ return "请输入项目名称"
53
+ }
54
+
55
+ if (fs.existsSync(input)) {
56
+ return "项目名已存在"
57
+ }
58
+
59
+ return true;
60
+ }
61
+ });
62
+ return inquirer.prompt(prompt)
63
+ }
64
+ // 拷贝和写数据
65
+ write() {
66
+ console.log();
67
+ console.log(chalk.green("开始构建,请稍后"));
68
+ const tplBuilder = require("../../template/index");
69
+ tplBuilder(this, this.options, () => {
70
+ console.log();
71
+ console.log(chalk.green('构建完成,运行前请安装依赖'))
72
+ console.log();
73
+ })
74
+ }
75
+
76
+ getTplPath(file) {
77
+ return path.join(this.tplDirPath, file);
78
+ }
79
+
80
+ copyTpl(file, to, data = {}) {
81
+ const tplPath = this.getTplPath(file);
82
+ this.fs.copyTpl(tplPath, to, data);
83
+ }
84
+
85
+ copy(file, to) {
86
+ const tplPath = this.getTplPath(file);
87
+ this.fs.copy(tplPath, to)
88
+ }
89
+ }
90
90
  module.exports = Creator;
@@ -1,95 +1,112 @@
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 { checkUpdate } = require("../../utils/checkVersion")
8
- /**
9
- * 创建自定组件开发模板项目
10
- */
11
- class Creator {
12
- constructor() {
13
- this.fs = memFsEditor.create(memFs.create());
14
- this.options = {
15
- name: "",
16
- description: ""
17
- }
18
- // 当前目录
19
- this.rootPath = path.resolve(__dirname, "../../");
20
- // 模板目录
21
- this.tplDirPath = path.join(this.rootPath, "template");
22
- }
23
- // 初始化
24
- async init(name) {
25
- let res = await checkUpdate();
26
- if (!res) {
27
- console.log()
28
- console.log(chalk.green('欢迎使用CloudCC-CLI'));
29
- console.log()
30
- if (!name) {
31
- this.ask().then(answers => {
32
- this.options = Object.assign({}, this.options, answers);
33
- console.log(this.options);
34
- this.write();
35
- })
36
- } else {
37
- this.options = { name }
38
- this.write();
39
- }
40
- }
41
- }
42
- // 命令行交互
43
- ask() {
44
- const prompt = [];
45
-
46
- prompt.push({
47
- type: "input",
48
- name: "name",
49
- message: "请输入项目名称",
50
- validate(input) {
51
- if (!input) {
52
- return "请输入项目名称"
53
- }
54
-
55
- if (fs.existsSync(input)) {
56
- return "项目名已存在"
57
- }
58
-
59
- return true;
60
- }
61
- });
62
- return inquirer.prompt(prompt)
63
- }
64
- // 拷贝和写数据
65
- write() {
66
- console.log();
67
- console.log(chalk.green("开始构建,请稍后"));
68
- const tplBuilder = require("../../template/index");
69
- tplBuilder(this, this.options, () => {
70
- console.log();
71
- console.log(chalk.green('构建完成,运行前请安装依赖'))
72
- console.log();
73
- })
74
- }
75
-
76
- getTplPath(file) {
77
- return path.join(this.tplDirPath, file);
78
- }
79
-
80
- copyTpl(file, to, data = {}) {
81
- const tplPath = this.getTplPath(file);
82
- this.fs.copyTpl(tplPath, to, data);
83
- }
84
-
85
- copy(file, to) {
86
- const tplPath = this.getTplPath(file);
87
- this.fs.copy(tplPath, to)
88
- }
89
- }
90
- function create(name) {
91
- let c = new Creator();
92
- c.init(name)
93
- }
94
-
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 { checkUpdate } = require("../../utils/checkVersion")
8
+ const tplBuilder = require("../../template/index");
9
+ const execSync = require('child_process').execSync;
10
+ /**
11
+ * 创建自定组件开发模板项目
12
+ */
13
+ class Creator {
14
+ constructor() {
15
+ this.fs = memFsEditor.create(memFs.create());
16
+ this.options = {
17
+ name: "",
18
+ description: ""
19
+ }
20
+ // 当前目录
21
+ this.rootPath = path.resolve(__dirname, "../../");
22
+ // 模板目录
23
+ this.tplDirPath = path.join(this.rootPath, "template");
24
+ }
25
+ // 初始化
26
+ async init(name) {
27
+ let res = await checkUpdate();
28
+ if (!res) {
29
+ console.log()
30
+ console.log(chalk.green('欢迎使用CloudCC-CLI'));
31
+ console.log()
32
+ if (!name) {
33
+ this.ask().then(answers => {
34
+ this.options = Object.assign({}, this.options, answers);
35
+ console.log(this.options);
36
+ this.write();
37
+ })
38
+ } else {
39
+ this.options = { name }
40
+ this.write();
41
+ }
42
+ }
43
+ }
44
+ // 命令行交互
45
+ ask() {
46
+ const prompt = [];
47
+
48
+ prompt.push({
49
+ type: "input",
50
+ name: "name",
51
+ message: "请输入项目名称",
52
+ validate(input) {
53
+ if (!input) {
54
+ return "请输入项目名称"
55
+ }
56
+
57
+ if (fs.existsSync(input)) {
58
+ return "项目名已存在"
59
+ }
60
+
61
+ return true;
62
+ }
63
+ });
64
+ return inquirer.prompt(prompt)
65
+ }
66
+ // 拷贝和写数据
67
+ write() {
68
+ console.log();
69
+ console.log(chalk.green("开始构建,请稍后"));
70
+ tplBuilder(this, this.options, () => {
71
+ console.log();
72
+ this.initGit(path.join(process.cwd(), this.options.name))
73
+ console.log(chalk.green('构建完成,运行前请安装依赖'))
74
+ console.log();
75
+ })
76
+ }
77
+
78
+ getTplPath(file) {
79
+ return path.join(this.tplDirPath, file);
80
+ }
81
+
82
+ copyTpl(file, to, data = {}) {
83
+ const tplPath = this.getTplPath(file);
84
+ this.fs.copyTpl(tplPath, to, data);
85
+ }
86
+
87
+ copy(file, to) {
88
+ const tplPath = this.getTplPath(file);
89
+ this.fs.copy(tplPath, to)
90
+ }
91
+
92
+ initGit(path) {
93
+ try {
94
+ execSync(`git -C ${path} init`)
95
+ execSync(`git -C ${path} add .`)
96
+ execSync(`git -C ${path} commit -m 'init'`)
97
+ console.log(`${chalk.grey(`Git仓库初始化完成`)} ${chalk.green('✔ ')}`);
98
+ console.log();
99
+ console.log(`${chalk.yellow(`请设置仓库地址:git remote add origin [远程仓库地址]`)}`);
100
+ console.log();
101
+ } catch (error) {
102
+ console.log();
103
+ console.log(chalk.red('git仓库初始化异常'))
104
+ console.log();
105
+ }
106
+ }
107
+ }
108
+ function create(argvs) {
109
+ let c = new Creator();
110
+ c.init(argvs[2])
111
+ }
95
112
  module.exports = create;
@@ -1,7 +1,7 @@
1
- const cc = {}
2
- cc.create = require("./create1")
3
- function Plugin(action, name) {
4
- cc[action](name)
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;
@@ -0,0 +1,16 @@
1
+ const { getBusToken } = require("../../utils/utils")
2
+ const { postNormal } = require("../../utils/http")
3
+ /**
4
+ * 获取对象的记录类型
5
+ */
6
+ async function get(path, prefix) {
7
+ // 获取token成功后,发布内容
8
+ if (await getBusToken(path)) {
9
+ let url = new URL(global.baseUrl).origin
10
+ let res = await postNormal(url + "/apisvc/api/batch/getRecordType", { prefix: prefix })
11
+ console.log(JSON.stringify(res.data.recordTypeList))
12
+ return res.data
13
+ }
14
+ }
15
+
16
+ module.exports = get;
@@ -0,0 +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;
@@ -0,0 +1,33 @@
1
+ const { checkUpdate } = require("../../utils/checkVersion")
2
+ const fs = require("fs");
3
+ const path = require("path")
4
+ const chalk = require("chalk")
5
+ /**
6
+ * 创建文件
7
+ * @param {string} name 文件名称
8
+ */
9
+ async function create(argvs) {
10
+ let res = await checkUpdate();
11
+ if (!res) {
12
+ let body = JSON.parse(decodeURI(argvs[2]))
13
+ const filePath = path.join(process.cwd(), "script/" + body.scriptName);
14
+ try {
15
+ fs.mkdirSync(filePath, { recursive: true })
16
+ const fileTmp =
17
+ `function main($CCDK, obj){
18
+ console.log("Hello CloudCC")
19
+ }`
20
+ fs.writeFileSync(path.join(filePath, body.scriptName + ".js"), fileTmp)
21
+ fs.writeFileSync(path.join(filePath, "config.json"), JSON.stringify(body))
22
+ console.log()
23
+ console.log(chalk.green("创建成功:" + body.scriptName))
24
+ console.log()
25
+ } catch (e) {
26
+ console.log()
27
+ console.log(chalk.red("创建失败:" + e))
28
+ console.log()
29
+ }
30
+ }
31
+ }
32
+
33
+ module.exports = create;
@@ -0,0 +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;
@@ -0,0 +1,69 @@
1
+ // 检查cli版本更新功能
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/utils")
8
+ const BaseUrl = "https://developer.apis.cloudcc.cn"
9
+ /**
10
+ * 发布脚本
11
+ * @param {string} argvs 参数
12
+ */
13
+ async function publish(argvs) {
14
+ let name = argvs[2]
15
+ let res = await checkUpdate();
16
+ if (!res) {
17
+ const srcPath = path.join(process.cwd(), `script/${name}/`);
18
+ let classContent = fs.readFileSync(srcPath + `${name}.js`, 'utf8').replace(/\s+/g, '').replace(/\n/g, '').match(/\{([\s\S]*?)\}/)[1];
19
+ let configContent = JSON.parse(fs.readFileSync(srcPath + "config.json", 'utf8'));
20
+ let configContentOld = JSON.parse(JSON.stringify(configContent))
21
+
22
+ if (classContent) {
23
+ let devConsoleConfig = getPackageJson()
24
+ // 如果不是私有化部署,那么需要获取token
25
+ if ("private" != devConsoleConfig.version) {
26
+ devConsoleConfig = { "accessToken": await getToken(devConsoleConfig) };
27
+ }
28
+ console.log(chalk.green('发布中,请稍后...'));
29
+ configContent.scriptContent = classContent
30
+ let res = await post((devConsoleConfig.baseUrl || BaseUrl) + "/devconsole/script/saveClientScript", configContent, devConsoleConfig)
31
+ if (res.result) {
32
+ console.log();
33
+ console.log(chalk.green('发布成功!'));
34
+ console.log();
35
+ // 组件发布成功后,判断下配置文件是否有id,如果没有,那么将id存储到配置中
36
+ if (!configContentOld.id) {
37
+ configContentOld.id = res.data
38
+ fs.writeFileSync(path.join(srcPath, "config.json"), JSON.stringify(configContentOld))
39
+ }
40
+ } else {
41
+ console.log();
42
+ console.log(chalk.red('发布失败:' + res.returnInfo));
43
+ console.log();
44
+ }
45
+ } else {
46
+ console.log();
47
+ console.log(chalk.red('脚本内容无效'));
48
+ console.log();
49
+ }
50
+ }
51
+ }
52
+
53
+
54
+ /**
55
+ * 请求用户token
56
+ * @param {用户信息} devConsoleConfig
57
+ * @returns token
58
+ */
59
+ async function getToken(devConsoleConfig) {
60
+ let res = await post(devConsoleConfig.baseUrl || BaseUrl + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
61
+ if (res.returnCode == 200) {
62
+ return res.data.accessToken;
63
+ } else {
64
+ console.error(chalk.red(`登录失败`, JSON.stringify(res)));
65
+ return null;
66
+ }
67
+ }
68
+
69
+ module.exports = publish;
@@ -1,29 +1,29 @@
1
- const { checkUpdate } = require("../../utils/checkVersion")
2
- const fs = require("fs");
3
- const path = require("path")
4
- const chalk = require("chalk")
5
- /**
6
- * 创建文件
7
- * @param {string} name 文件名称
8
- */
9
- async function create(name) {
10
- let res = await checkUpdate();
11
- if (!res) {
12
- const timerPath = path.join(process.cwd(), "timer/" + name);
13
- try {
14
- fs.mkdirSync(timerPath, { recursive: true })
15
- const javaTmp = `System.out.print("hello CloudCC");`
16
- fs.writeFileSync(path.join(timerPath, name + ".java"), javaTmp)
17
- fs.writeFileSync(path.join(timerPath, "config.json"), `{"name":"${name}","version":"3"}`)
18
- console.log()
19
- console.log(chalk.green("创建成功:" + name))
20
- console.log()
21
- } catch (e) {
22
- console.log()
23
- console.log(chalk.red("创建失败:" + e))
24
- console.log()
25
- }
26
- }
27
- }
28
-
29
- module.exports = create;
1
+ const { checkUpdate } = require("../../utils/checkVersion")
2
+ const fs = require("fs");
3
+ const path = require("path")
4
+ const chalk = require("chalk")
5
+ /**
6
+ * 创建文件
7
+ * @param {string} name 文件名称
8
+ */
9
+ async function create(name) {
10
+ let res = await checkUpdate();
11
+ if (!res) {
12
+ const timerPath = path.join(process.cwd(), "timer/" + name);
13
+ try {
14
+ fs.mkdirSync(timerPath, { recursive: true })
15
+ const javaTmp = `System.out.print("hello CloudCC");`
16
+ fs.writeFileSync(path.join(timerPath, name + ".java"), javaTmp)
17
+ fs.writeFileSync(path.join(timerPath, "config.json"), `{"name":"${name}","version":"3"}`)
18
+ console.log()
19
+ console.log(chalk.green("创建成功:" + name))
20
+ console.log()
21
+ } catch (e) {
22
+ console.log()
23
+ console.log(chalk.red("创建失败:" + e))
24
+ console.log()
25
+ }
26
+ }
27
+ }
28
+
29
+ module.exports = create;
@@ -1,8 +1,8 @@
1
- const cc = {}
2
- cc.create = require("./create")
3
- cc.publish = require("./publish")
4
- function Timer(action, name) {
5
- cc[action](name)
6
- }
7
-
8
- module.exports = Timer;
1
+ const cc = {}
2
+ cc.create = require("./create")
3
+ cc.publish = require("./publish")
4
+ function Timer(action, argvs) {
5
+ cc[action](argvs[2])
6
+ }
7
+
8
+ module.exports = Timer;