cloudcc-cli 1.5.7 → 1.5.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 +16 -0
- package/bin/cc.js +12 -6
- package/package.json +1 -2
- package/src/classes/create.js +1 -1
- package/src/classes/publish.js +2 -2
- package/src/plugin/create1.js +67 -0
- package/src/plugin/index.js +2 -2
- package/src/plugin/publish1.js +293 -0
- package/src/project/create1.js +95 -0
- package/src/project/index.js +7 -0
- package/src/timer/create.js +29 -0
- package/src/timer/index.js +8 -0
- package/src/timer/publish.js +47 -0
- package/src/triggers/create.js +35 -0
- package/src/triggers/index.js +8 -0
- package/src/triggers/publish.js +51 -0
- package/utils/utils.js +1 -2
package/README.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# ReleaseV1.5.9
|
|
2
|
+
#### 发布日期:2023-3-11
|
|
3
|
+
#### 发布范围:全量
|
|
4
|
+
#### 发布内容
|
|
5
|
+
* 修复
|
|
6
|
+
* 更改帮助文档地址
|
|
7
|
+
|
|
8
|
+
# ReleaseV1.5.8
|
|
9
|
+
#### 发布日期:2023-3-11
|
|
10
|
+
#### 发布范围:全量
|
|
11
|
+
#### 发布内容
|
|
12
|
+
* 迭代
|
|
13
|
+
* 添加创建类的命令。
|
|
14
|
+
* 添加创建触发器的命令。
|
|
15
|
+
* 添加创建定时器的命令。
|
|
16
|
+
|
|
1
17
|
# ReleaseV1.5.7
|
|
2
18
|
#### 发布日期:2024-2-22
|
|
3
19
|
#### 发布范围:全量
|
package/bin/cc.js
CHANGED
|
@@ -6,7 +6,7 @@ let argvs = process.argv.splice(2);
|
|
|
6
6
|
let action = argvs[0]
|
|
7
7
|
if (!action) {
|
|
8
8
|
console.log()
|
|
9
|
-
console.log(chalk.yellow("请查看帮助文档:https://
|
|
9
|
+
console.log(chalk.yellow("请查看帮助文档:https://cloudccone.feishu.cn/wiki/Q2AgwlxAtijmMJkjXXZcYgQVnmw?fromScene=spaceOverview"));
|
|
10
10
|
console.log()
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
@@ -15,7 +15,7 @@ if (!action) {
|
|
|
15
15
|
let type = argvs[1]
|
|
16
16
|
if (!type) {
|
|
17
17
|
console.log()
|
|
18
|
-
console.log(chalk.yellow("请查看帮助文档:https://
|
|
18
|
+
console.log(chalk.yellow("请查看帮助文档:https://cloudccone.feishu.cn/wiki/Q2AgwlxAtijmMJkjXXZcYgQVnmw?fromScene=spaceOverview"));
|
|
19
19
|
console.log()
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
@@ -24,21 +24,27 @@ if (!type) {
|
|
|
24
24
|
let name = argvs[2]
|
|
25
25
|
if (!name) {
|
|
26
26
|
console.log()
|
|
27
|
-
console.log(chalk.yellow("请查看帮助文档:https://
|
|
27
|
+
console.log(chalk.yellow("请查看帮助文档:https://cloudccone.feishu.cn/wiki/Q2AgwlxAtijmMJkjXXZcYgQVnmw?fromScene=spaceOverview"));
|
|
28
28
|
console.log()
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
const cc = {}
|
|
34
|
-
//
|
|
35
|
-
cc.
|
|
34
|
+
// 创建模板项目
|
|
35
|
+
cc.project = require("../src/project/index")
|
|
36
36
|
// 组件的管理
|
|
37
37
|
cc.plugin = require("../src/plugin/index")
|
|
38
|
+
// 类的管理
|
|
39
|
+
cc.classes = require("../src/classes/index")
|
|
40
|
+
// 定时器的管理
|
|
41
|
+
cc.timer = require("../src/timer/index")
|
|
42
|
+
// 触发器的管理
|
|
43
|
+
cc.triggers = require("../src/triggers/index")
|
|
38
44
|
try {
|
|
39
45
|
cc[type](action, name);
|
|
40
46
|
} catch (e) {
|
|
41
47
|
console.log()
|
|
42
|
-
console.log(chalk.yellow("请查看帮助文档:https://
|
|
48
|
+
console.log(chalk.yellow("请查看帮助文档:https://cloudccone.feishu.cn/wiki/Q2AgwlxAtijmMJkjXXZcYgQVnmw?fromScene=spaceOverview"), e);
|
|
43
49
|
console.log()
|
|
44
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudcc-cli",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.9",
|
|
4
4
|
"description": "cloudcc-cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudcc",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"marked": "^5.0.1",
|
|
30
30
|
"mem-fs": "^2.2.1",
|
|
31
31
|
"mem-fs-editor": "^9.0.1",
|
|
32
|
-
"node-localstorage": "^3.0.5",
|
|
33
32
|
"vue-custom-element": "^3.3.0",
|
|
34
33
|
"vue-template-compiler": "^2.6.14"
|
|
35
34
|
}
|
package/src/classes/create.js
CHANGED
|
@@ -11,7 +11,7 @@ async function create(name) {
|
|
|
11
11
|
if (!res) {
|
|
12
12
|
const classesPath = path.join(process.cwd(), "classes/" + name);
|
|
13
13
|
try {
|
|
14
|
-
fs.mkdirSync(classesPath)
|
|
14
|
+
fs.mkdirSync(classesPath, { recursive: true })
|
|
15
15
|
const javaTmp = `
|
|
16
16
|
public class ${name}{
|
|
17
17
|
private UserInfo userInfo;
|
package/src/classes/publish.js
CHANGED
|
@@ -29,14 +29,14 @@ async function publish(name) {
|
|
|
29
29
|
"folderId": "wgd"
|
|
30
30
|
}
|
|
31
31
|
let url = new URL(global.baseUrl).origin
|
|
32
|
-
let res = await postNormal(url + "/
|
|
32
|
+
let res = await postNormal(url + "/ccdomaingateway/setup/api/ccfag/save", body)
|
|
33
33
|
if (res.result) {
|
|
34
34
|
console.log(chalk.green('发布成功!'));
|
|
35
35
|
console.log();
|
|
36
36
|
// 组件发布成功后,判断下配置文件是否有id,如果没有,那么将id存储到配置中
|
|
37
37
|
if (!configContent.id) {
|
|
38
38
|
configContent.id = res.data
|
|
39
|
-
fs.writeFileSync(path.join(
|
|
39
|
+
fs.writeFileSync(path.join(classPath, "config.json"), JSON.stringify(configContent))
|
|
40
40
|
}
|
|
41
41
|
} else {
|
|
42
42
|
console.log(chalk.red('发布失败:' + res.returnInfo));
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// 检查cli版本更新功能
|
|
2
|
+
const { checkUpdate } = require("../../utils/checkVersion")
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path")
|
|
5
|
+
const chalk = require("chalk")
|
|
6
|
+
|
|
7
|
+
const temp = `<template>
|
|
8
|
+
<div class="cc-container">
|
|
9
|
+
<div>Hello CloudCC</div>
|
|
10
|
+
<div>
|
|
11
|
+
<a href="https://cloudccone.feishu.cn/wiki/JZ7CwcRfriU8taknCKCcwKEmncd">
|
|
12
|
+
开发者文档</a
|
|
13
|
+
>
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script>
|
|
19
|
+
export default {
|
|
20
|
+
data() {
|
|
21
|
+
return {
|
|
22
|
+
componentInfo: {
|
|
23
|
+
// 组件唯一标识,全局唯一
|
|
24
|
+
component: "cloudcc-demo-01",
|
|
25
|
+
// 组件名称,在页面编辑器显示的名字
|
|
26
|
+
compName: "cloudcc-demo-01",
|
|
27
|
+
// 组件描述信息
|
|
28
|
+
compDesc: "组件描述信息",
|
|
29
|
+
},
|
|
30
|
+
isLock: false,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
</script>
|
|
35
|
+
<style lang="scss" scoped>
|
|
36
|
+
.cc-container {
|
|
37
|
+
text-align: center;
|
|
38
|
+
padding: 8px;
|
|
39
|
+
background: goldenrod;
|
|
40
|
+
}
|
|
41
|
+
</style>`
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 创建文件
|
|
47
|
+
* @param {string} name 文件名称
|
|
48
|
+
*/
|
|
49
|
+
async function create(name) {
|
|
50
|
+
let res = await checkUpdate();
|
|
51
|
+
if (!res) {
|
|
52
|
+
const pluginPath = path.join(process.cwd(), "plugin/" + name);
|
|
53
|
+
try {
|
|
54
|
+
fs.mkdirSync(pluginPath, { recursive: true })
|
|
55
|
+
fs.writeFileSync(path.join(pluginPath, name + ".vue"), temp)
|
|
56
|
+
fs.writeFileSync(path.join(pluginPath, "config.json"), `{"name":"${name}"}`)
|
|
57
|
+
console.log()
|
|
58
|
+
console.log(chalk.green("创建成功:" + name))
|
|
59
|
+
console.log()
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.log()
|
|
62
|
+
console.log(chalk.red("创建失败:" + e))
|
|
63
|
+
console.log()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
module.exports = create;
|
package/src/plugin/index.js
CHANGED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
const { exec } = require('child_process');
|
|
2
|
+
const { post } = require('../../utils/http');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require("path")
|
|
5
|
+
const chalk = require("chalk")
|
|
6
|
+
const inquirer = require("inquirer")
|
|
7
|
+
// 检查cli版本更新功能
|
|
8
|
+
const { checkUpdate } = require("../../utils/checkVersion")
|
|
9
|
+
const BaseUrl = "https://developer.apis.cloudcc.cn"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 自定义组件,组件打包命令,将组件打包发布到服务器。
|
|
13
|
+
*/
|
|
14
|
+
class Builder {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.options = {
|
|
17
|
+
// 开发配置信息
|
|
18
|
+
devConsoleConfig: {
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
this.plugin = process.argv.splice(2)[0]
|
|
22
|
+
}
|
|
23
|
+
async publish(name) {
|
|
24
|
+
let res = await checkUpdate();
|
|
25
|
+
if (!res) {
|
|
26
|
+
this.options.devConsoleConfig = this.getPackageJson();
|
|
27
|
+
let config = this.options.devConsoleConfig
|
|
28
|
+
// 如果不是私有化部署,那么需要获取token
|
|
29
|
+
if ("private" != this.options.devConsoleConfig.version) { // private私有化
|
|
30
|
+
config = { "accessToken": await this.getToken(config) };
|
|
31
|
+
}
|
|
32
|
+
// 获得用户输入
|
|
33
|
+
let answers = { buildFileName: `${name}/${name}.vue` }
|
|
34
|
+
// 如果输入的是*.vue,那么表示编译全部文件
|
|
35
|
+
if ("*.vue" == answers.buildFileName) {
|
|
36
|
+
let dirs = fs.readdirSync("plugin")
|
|
37
|
+
for (let i = 0; i < dirs.length; i++) {
|
|
38
|
+
let item = dirs[i]
|
|
39
|
+
let obj = this.getVueValue(item);
|
|
40
|
+
this.initPluginFile(item, obj.component, "plginTemp" + i);
|
|
41
|
+
this.build(obj, config, "plginTemp" + i)
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
let obj = this.getVueValue(answers.buildFileName);
|
|
45
|
+
this.initPluginFile(answers.buildFileName, obj.component, "plginTemp");
|
|
46
|
+
this.build(obj, config, "plginTemp")
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 获得用户信息
|
|
52
|
+
* @returns 配置信息
|
|
53
|
+
*/
|
|
54
|
+
getPackageJson() {
|
|
55
|
+
const packageJson = JSON.parse(fs.readFileSync("package.json", 'utf8'));
|
|
56
|
+
return packageJson.devConsoleConfig; // cloudcc-plugin 中的 devConsoleConfig
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 请求用户token
|
|
60
|
+
* @param {用户信息} devConsoleConfig
|
|
61
|
+
* @returns token
|
|
62
|
+
*/
|
|
63
|
+
async getToken(devConsoleConfig) {
|
|
64
|
+
let res = await post(this.options.devConsoleConfig.baseUrl || BaseUrl + "/sysconfig/auth/pc/1.0/post/tokenInfo", devConsoleConfig);
|
|
65
|
+
if (res.returnCode == 200) {
|
|
66
|
+
return res.data.accessToken;
|
|
67
|
+
} else {
|
|
68
|
+
console.error(chalk.red(`登录失败`, JSON.stringify(res)));
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 获得Vue内容
|
|
75
|
+
*/
|
|
76
|
+
getVueValue(buildFileName) {
|
|
77
|
+
let vueContent = fs.readFileSync(this.getVueContent(buildFileName), 'utf8');
|
|
78
|
+
let vueData = vueContent + ""
|
|
79
|
+
// 添加scoped限制样式污染
|
|
80
|
+
if (!vueContent.includes("scoped")) {
|
|
81
|
+
// vueData = vueData.replace("<style", "<style scoped ")
|
|
82
|
+
console.log()
|
|
83
|
+
console.log(chalk.yellow("警告:style中缺少scoped属性,可能会造成样式全局污染,建议修复。"));
|
|
84
|
+
console.log()
|
|
85
|
+
}
|
|
86
|
+
// 去除空格
|
|
87
|
+
// vueData = vueData.replace(/\ +/g, "")
|
|
88
|
+
// 去除换行
|
|
89
|
+
// vueData =vueData.replace(/[\r\n]/g, "");
|
|
90
|
+
vueData = vueData.split("data()")[1].split("isLock:")[0] + "isLock:false,};}";
|
|
91
|
+
vueData = "function data()" + vueData;
|
|
92
|
+
const data = eval(`(${vueData})`)()
|
|
93
|
+
// 如果propObj不存在,那么初始一个空对象
|
|
94
|
+
if (!data.propObj) {
|
|
95
|
+
data.propObj = {};
|
|
96
|
+
data.propOption = {};
|
|
97
|
+
}
|
|
98
|
+
// 如果events不存在,那么初始一个空对象
|
|
99
|
+
if (!data.events) {
|
|
100
|
+
data.events = {};
|
|
101
|
+
data.eventsOption = {};
|
|
102
|
+
}
|
|
103
|
+
// 如果style不存在,那么初始一个空对象
|
|
104
|
+
if (!data.style) {
|
|
105
|
+
data.style = {
|
|
106
|
+
unit: "px",
|
|
107
|
+
width: 72,
|
|
108
|
+
height: 38,
|
|
109
|
+
top: 0,
|
|
110
|
+
left: 0,
|
|
111
|
+
rotate: 0,
|
|
112
|
+
opacity: 1,
|
|
113
|
+
};
|
|
114
|
+
data.styleOption = {
|
|
115
|
+
word: {
|
|
116
|
+
lable: "label.help",
|
|
117
|
+
type: "word",
|
|
118
|
+
link: "https://zucfl0psd6.feishu.cn/wiki/wikcnlXGFHfXw5LgAWbDcJXTFyd",
|
|
119
|
+
},
|
|
120
|
+
unit: {
|
|
121
|
+
lable: "label.custom.unit",
|
|
122
|
+
type: "option",
|
|
123
|
+
options: [
|
|
124
|
+
{
|
|
125
|
+
value: "px",
|
|
126
|
+
label: "label.custom.pixel",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
value: "%",
|
|
130
|
+
label: "label.percent",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
value: "hw",
|
|
134
|
+
label: "label.custom.viewport",
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
width: {
|
|
139
|
+
lable: "label.custom.width",
|
|
140
|
+
type: "input",
|
|
141
|
+
inputType: "number",
|
|
142
|
+
},
|
|
143
|
+
height: {
|
|
144
|
+
lable: "label.custom.height",
|
|
145
|
+
type: "input",
|
|
146
|
+
inputType: "number",
|
|
147
|
+
},
|
|
148
|
+
top: {
|
|
149
|
+
lable: "label.dev.y.coordinate",
|
|
150
|
+
type: "input",
|
|
151
|
+
inputType: "number",
|
|
152
|
+
},
|
|
153
|
+
left: {
|
|
154
|
+
lable: "label.dev.x.coordinate",
|
|
155
|
+
type: "input",
|
|
156
|
+
inputType: "number",
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
let component = data.componentInfo.component // 组件标识
|
|
161
|
+
let compName = data.componentInfo.compName // 组件名字
|
|
162
|
+
vueData = JSON.stringify(data);
|
|
163
|
+
let bizType = data.componentInfo.bizType // 组件类型
|
|
164
|
+
let compDesc = data.componentInfo.compDesc // 组件描述
|
|
165
|
+
let category = data.componentInfo.category // 组件状态
|
|
166
|
+
let loadModel = data.componentInfo.loadModel // 组件加载模式,按需加载(lazy),启动加载(start)。
|
|
167
|
+
return { compName, component, vueContent, vueData, bizType, compDesc, category, loadModel }
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
*
|
|
171
|
+
* @param {string} buildFileName 编译文件入口
|
|
172
|
+
* @param {string} component 编译后组件的名字
|
|
173
|
+
* @param {string} plginTemp 生成模板代码存储路径
|
|
174
|
+
*/
|
|
175
|
+
initPluginFile(buildFileName, component, plginTemp) {
|
|
176
|
+
this.initPluginFile1(buildFileName, component, plginTemp)
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* 生成依赖文件,vue-custom-element
|
|
180
|
+
* @param {编译的文件名称} buildFileName
|
|
181
|
+
* @param {编译后的组件名称} component
|
|
182
|
+
*/
|
|
183
|
+
initPluginFile1(buildFileName, component, plginTemp) {
|
|
184
|
+
let newContent =
|
|
185
|
+
`
|
|
186
|
+
import Vue from "vue"
|
|
187
|
+
import VueCustomElement from "vue-custom-element"
|
|
188
|
+
Vue.use(VueCustomElement);
|
|
189
|
+
|
|
190
|
+
import index from "./` + buildFileName + `"
|
|
191
|
+
Vue.customElement('`+ component + `', index,{ destroyTimeout: ${this.options.devConsoleConfig.destroyTimeout || 20 * 60 * 1000} });
|
|
192
|
+
`
|
|
193
|
+
|
|
194
|
+
fs.writeFileSync(`plugin/${plginTemp}.js`, newContent);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 生成依赖文件
|
|
199
|
+
* @param {编译的文件名称} buildFileName
|
|
200
|
+
* @param {编译后的组件名称} component
|
|
201
|
+
*/
|
|
202
|
+
initPluginFile2(buildFileName, component, plginTemp) {
|
|
203
|
+
let newContent =
|
|
204
|
+
`
|
|
205
|
+
import index from "./${buildFileName}"
|
|
206
|
+
function install(Vue) {
|
|
207
|
+
Vue.component('${component}', index);
|
|
208
|
+
}
|
|
209
|
+
export default install;
|
|
210
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
|
211
|
+
console.log("install装载",install)
|
|
212
|
+
window.Vue.use(install);
|
|
213
|
+
if (install.installed) {
|
|
214
|
+
install.installed = false;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
`
|
|
218
|
+
fs.writeFileSync(`plugin/${plginTemp}.js`, newContent);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 编译文件,将vue编译为js文件
|
|
223
|
+
* @param {编译对象信息} obj
|
|
224
|
+
*/
|
|
225
|
+
build(obj, config, plginTemp) {
|
|
226
|
+
console.log(chalk.green('编译中,请稍后...'));
|
|
227
|
+
exec('npx vue-cli-service build --target lib --name ' + obj.component + ` --dest build plugin/${plginTemp}.js`, async (error, stdout, stderr) => {
|
|
228
|
+
if (error) {
|
|
229
|
+
console.log('编译失败:', error);
|
|
230
|
+
console.log(chalk.red('编译失败:' + stdout));
|
|
231
|
+
return;
|
|
232
|
+
} else {
|
|
233
|
+
console.log(chalk.green('编译成功!'));
|
|
234
|
+
console.log();
|
|
235
|
+
await this.upload(obj, config)
|
|
236
|
+
fs.unlinkSync(`plugin/${plginTemp}.js`);
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* 将文件上传
|
|
242
|
+
*/
|
|
243
|
+
async upload(obj, header) {
|
|
244
|
+
console.log(chalk.green('发布中,请稍后...'));
|
|
245
|
+
let jsContent = "";
|
|
246
|
+
try {
|
|
247
|
+
jsContent = fs.readFileSync(path.join("build", obj.component + ".umd.min.js"), 'utf8')
|
|
248
|
+
} catch (err) {
|
|
249
|
+
console.error(err)
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
let body = {
|
|
253
|
+
"compLabel": obj.compName,
|
|
254
|
+
"compUniName": obj.component,
|
|
255
|
+
"compContentJs": jsContent,
|
|
256
|
+
"compContentVue": obj.vueContent,
|
|
257
|
+
"vueData": obj.vueData,
|
|
258
|
+
"bizType": obj.bizType,
|
|
259
|
+
"compDesc": obj.compDesc,
|
|
260
|
+
"category": obj.category,
|
|
261
|
+
"loadModel": obj.loadModel || "lazy",
|
|
262
|
+
"belongOrgFlag": this.options.devConsoleConfig.belongOrgFlag || "custom" //belongOrgFlag: 所属单位标识,std:官方的组件(神州云动);custom:第三方的组件
|
|
263
|
+
}
|
|
264
|
+
// 服务名
|
|
265
|
+
let devSvcDispatch = this.options.devConsoleConfig.devSvcDispatch || '/devconsole'
|
|
266
|
+
let res = await post(`${this.options.devConsoleConfig.baseUrl || BaseUrl}${devSvcDispatch}/custom/pc/1.0/post/insertCustomComp`,
|
|
267
|
+
body, header);
|
|
268
|
+
if (res.returnCode == 200) {
|
|
269
|
+
console.error(chalk.green(`发布成功!`));
|
|
270
|
+
console.log();
|
|
271
|
+
} else {
|
|
272
|
+
console.error(chalk.red(`发布失败: ${res.returnInfo}`));
|
|
273
|
+
console.log();
|
|
274
|
+
}
|
|
275
|
+
return res;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 过滤出min.js文件
|
|
280
|
+
* @returns 过滤结果
|
|
281
|
+
*/
|
|
282
|
+
getVueContent(buildFileName) {
|
|
283
|
+
const jsPath = "plugin";
|
|
284
|
+
return path.join(jsPath, buildFileName);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function publish(name) {
|
|
289
|
+
let p = new Builder()
|
|
290
|
+
p.publish(name)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
module.exports = publish;
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
|
|
95
|
+
module.exports = create;
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { postNormal } = require("../../utils/http")
|
|
7
|
+
|
|
8
|
+
const { getBusToken } = require("../../utils/utils")
|
|
9
|
+
/**
|
|
10
|
+
* 发布文件
|
|
11
|
+
* @param {string} name 文件名称
|
|
12
|
+
*/
|
|
13
|
+
async function publish(name) {
|
|
14
|
+
let res = await checkUpdate();
|
|
15
|
+
if (!res) {
|
|
16
|
+
console.log();
|
|
17
|
+
console.log(chalk.green('发布中,请稍后...'));
|
|
18
|
+
console.log();
|
|
19
|
+
const timerPath = path.join(process.cwd(), `timer/${name}/`);
|
|
20
|
+
let classContent = fs.readFileSync(timerPath + `${name}.java`, 'utf8');
|
|
21
|
+
let configContent = JSON.parse(fs.readFileSync(timerPath + "config.json", 'utf8'));
|
|
22
|
+
// 获取token成功后,发布内容
|
|
23
|
+
if (await getBusToken()) {
|
|
24
|
+
let body = {
|
|
25
|
+
"id": configContent.id,
|
|
26
|
+
"name": name,
|
|
27
|
+
"version": configContent.version,
|
|
28
|
+
"source": encodeURI(classContent),
|
|
29
|
+
"folderId": "wgd"
|
|
30
|
+
}
|
|
31
|
+
let url = new URL(global.baseUrl).origin
|
|
32
|
+
let res = await postNormal(url + "/ccdomaingateway/setup/api/ccPeak/save", body)
|
|
33
|
+
if (res.result) {
|
|
34
|
+
console.log(chalk.green('发布成功!'));
|
|
35
|
+
console.log();
|
|
36
|
+
// 组件发布成功后,判断下配置文件是否有id,如果没有,那么将id存储到配置中
|
|
37
|
+
if (!configContent.id) {
|
|
38
|
+
configContent.id = res.data
|
|
39
|
+
fs.writeFileSync(path.join(timerPath, "config.json"), JSON.stringify(configContent))
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
console.log(chalk.red('发布失败:' + res.returnInfo));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
module.exports = publish;
|
|
@@ -0,0 +1,35 @@
|
|
|
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 triggersPath = path.join(process.cwd(), "triggers/" + name);
|
|
13
|
+
try {
|
|
14
|
+
fs.mkdirSync(triggersPath, { recursive: true })
|
|
15
|
+
const javaTmp = `System.out.print("hello CloudCC");`
|
|
16
|
+
fs.writeFileSync(path.join(triggersPath, name + ".java"), javaTmp)
|
|
17
|
+
fs.writeFileSync(path.join(triggersPath, "config.json"),
|
|
18
|
+
`{
|
|
19
|
+
"isactive":false,
|
|
20
|
+
"targetObjectId":"account",
|
|
21
|
+
"triggerTime":"beforeInsert",
|
|
22
|
+
"version":"3"
|
|
23
|
+
}`)
|
|
24
|
+
console.log()
|
|
25
|
+
console.log(chalk.green("创建成功:" + name))
|
|
26
|
+
console.log()
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.log()
|
|
29
|
+
console.log(chalk.red("创建失败:" + e))
|
|
30
|
+
console.log()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = create;
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { postNormal } = require("../../utils/http")
|
|
7
|
+
const { getBusToken } = require("../../utils/utils")
|
|
8
|
+
/**
|
|
9
|
+
* 发布文件
|
|
10
|
+
* @param {string} name 文件名称
|
|
11
|
+
*/
|
|
12
|
+
async function publish(name) {
|
|
13
|
+
let res = await checkUpdate();
|
|
14
|
+
if (!res) {
|
|
15
|
+
console.log();
|
|
16
|
+
console.log(chalk.green('发布中,请稍后...'));
|
|
17
|
+
console.log();
|
|
18
|
+
const triggersPath = path.join(process.cwd(), `triggers/${name}/`);
|
|
19
|
+
let classContent = fs.readFileSync(triggersPath + `${name}.java`, 'utf8');
|
|
20
|
+
let configContent = JSON.parse(fs.readFileSync(triggersPath + "config.json", 'utf8'));
|
|
21
|
+
// 获取token成功后,发布内容
|
|
22
|
+
if (await getBusToken()) {
|
|
23
|
+
let body = {
|
|
24
|
+
"id": configContent.id,
|
|
25
|
+
"apiname": configContent.apiname,
|
|
26
|
+
"isactive": configContent.isactive,
|
|
27
|
+
"targetObjectId": configContent.targetObjectId,
|
|
28
|
+
"triggerTime": configContent.triggerTime,
|
|
29
|
+
"name": name,
|
|
30
|
+
"version": configContent.version,
|
|
31
|
+
"triggerSource": encodeURI(classContent),
|
|
32
|
+
"folderId": "wgd"
|
|
33
|
+
}
|
|
34
|
+
let url = new URL(global.baseUrl).origin
|
|
35
|
+
let res = await postNormal(url + "/ccdomaingateway/setup/api/triggerSetup/saveTrigger", body)
|
|
36
|
+
if (res.result) {
|
|
37
|
+
console.log(chalk.green('发布成功!'));
|
|
38
|
+
console.log();
|
|
39
|
+
// 组件发布成功后,判断下配置文件是否有id,如果没有,那么将id存储到配置中
|
|
40
|
+
if (!configContent.id) {
|
|
41
|
+
configContent.id = res.data.id
|
|
42
|
+
configContent.apiname = res.data.apiname
|
|
43
|
+
fs.writeFileSync(path.join(triggersPath, "config.json"), JSON.stringify(configContent))
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
console.log(chalk.red('发布失败:' + res.returnInfo));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
module.exports = publish;
|
package/utils/utils.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
const { getParams, postNormal } = require("./http")
|
|
2
|
-
const LocalStorage = require('node-localstorage').LocalStorage;
|
|
3
|
-
const localStorage = new LocalStorage('./cloudcc-cli');
|
|
4
2
|
const fs = require("fs");
|
|
5
3
|
const path = require("path")
|
|
6
4
|
|
|
@@ -33,6 +31,7 @@ async function getBusToken() {
|
|
|
33
31
|
orgId: devConfig.orgId
|
|
34
32
|
}
|
|
35
33
|
await getBaseUrl(devConfig.orgId)
|
|
34
|
+
|
|
36
35
|
let res = await postNormal(global.baseUrl + "/api/cauth/token", body)
|
|
37
36
|
if (res.result) {
|
|
38
37
|
global.accessToken = res.data.accessToken
|