cloudcc-cli 1.0.0 → 1.0.3
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 +707 -0
- package/bin/build.js +2 -2
- package/bin/buildccbasesdk.js +7 -0
- package/bin/buildccsdk.js +7 -0
- package/bin/create.js +6 -6
- package/bin/publish.js +7 -0
- package/package.json +35 -21
- package/src/builderBaseSDK.js +86 -0
- package/src/builderPlugin.js +201 -0
- package/src/builderSDK.js +161 -0
- package/src/{creator.js → creatorTemProject.js} +21 -12
- package/src/publishProject.js +202 -0
- package/template/Appvue +26 -0
- package/template/babelconfigjs +5 -0
- package/template/generateIDjs +4 -0
- package/template/httpjs +109 -0
- package/template/index.js +30 -0
- package/template/indexhtml +22 -0
- package/template/indexvue +289 -5
- package/template/mainjs +13 -0
- package/template/packagejson +48 -7
- package/template/vueconfigjs +7 -0
- package/test/index.html +15 -0
- package/test/test.js +6 -0
- package/utils/askTool.js +29 -0
- package/utils/changeVersion copy.js +75 -0
- package/utils/changeVersion.js +27 -0
- package/utils/checkVersion.js +74 -0
- package/utils/encryption.js +20 -0
- package/utils/github-markdown.min.css +2 -0
- package/utils/http.js +11 -5
- package/utils/md2html.js +89 -0
- package/utils/notifyIM.js +56 -0
- package/utils/pushCode.js +171 -0
- package/utils/test.js +4 -0
- package/utils/trigger.js +15 -0
- package/utils/updatei18n.js +127 -0
- package/bin/serve.js +0 -7
- package/src/builder.js +0 -70
- package/src/serve.js +0 -7
package/utils/http.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const axios = require("axios")
|
|
2
|
+
const encry = require("./encryption")
|
|
2
3
|
const service = axios.create({
|
|
3
4
|
timeout: 60000, // request timeout
|
|
4
5
|
headers: {
|
|
@@ -9,6 +10,7 @@ const service = axios.create({
|
|
|
9
10
|
// request interceptor
|
|
10
11
|
service.interceptors.request.use(
|
|
11
12
|
config => {
|
|
13
|
+
// config.data = encry.en(JSON.stringify(config.data))
|
|
12
14
|
return config
|
|
13
15
|
},
|
|
14
16
|
error => {
|
|
@@ -24,17 +26,21 @@ service.interceptors.response.use(
|
|
|
24
26
|
if (code !== 200) {
|
|
25
27
|
return Promise.reject(null == response.data.msg ? "未知异常" : response.data.msg)
|
|
26
28
|
} else {
|
|
27
|
-
|
|
29
|
+
// response.data= JSON.parse(encry.de(response.data));
|
|
30
|
+
return response.data;
|
|
28
31
|
}
|
|
29
32
|
},
|
|
30
33
|
error => {
|
|
31
34
|
return Promise.reject(error)
|
|
32
35
|
}
|
|
33
36
|
)
|
|
34
|
-
const formateData = data => {
|
|
37
|
+
const formateData = (data, header) => {
|
|
38
|
+
if (header) {
|
|
39
|
+
Object.assign(header, { source: "cloudcc_cli" })
|
|
40
|
+
}
|
|
35
41
|
return {
|
|
36
42
|
head: {
|
|
37
|
-
|
|
43
|
+
...header
|
|
38
44
|
},
|
|
39
45
|
body: {
|
|
40
46
|
...data
|
|
@@ -50,11 +56,11 @@ module.exports = {
|
|
|
50
56
|
responseType: responseType
|
|
51
57
|
})
|
|
52
58
|
},
|
|
53
|
-
post: (url, data = {}, responseType = '') => {
|
|
59
|
+
post: (url, data = {}, header = { appVersion: "1.0.0" }, responseType = '') => {
|
|
54
60
|
return service({
|
|
55
61
|
url: url,
|
|
56
62
|
method: 'post',
|
|
57
|
-
data: formateData(data),
|
|
63
|
+
data: formateData(data, header),
|
|
58
64
|
responseType: responseType
|
|
59
65
|
})
|
|
60
66
|
},
|
package/utils/md2html.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将md编译为html,并复制到dist/plu
|
|
3
|
+
*/
|
|
4
|
+
const fs = require('fs'); //文件模块
|
|
5
|
+
const path = require('path'); //路径模块
|
|
6
|
+
const marked = require('marked'); //md转html模块
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 检测文件改动
|
|
10
|
+
*/
|
|
11
|
+
function watchFile(target) {
|
|
12
|
+
fs.watchFile(target, {
|
|
13
|
+
persistent: true, //是否持续监听
|
|
14
|
+
interval: 200, //刷新间隔
|
|
15
|
+
}, (curr, prev) => {
|
|
16
|
+
if (curr.mtime == prev.mtime) { //比较修改时间,判断保存后内容是否真的发生了变化
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
change()
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 转换
|
|
24
|
+
* @param {target} 编译文件名称
|
|
25
|
+
* @param {outPath} 保存路径
|
|
26
|
+
*/
|
|
27
|
+
function change(target = "README", outPath = "dist") {
|
|
28
|
+
//读取文件
|
|
29
|
+
const data = fs.readFileSync(target + ".md", 'utf-8')
|
|
30
|
+
const html = marked(data); //将md内容转为html内容
|
|
31
|
+
let template = createTemplate();
|
|
32
|
+
template = template.replace('{{{content}}}', html); //替换html内容占位标记
|
|
33
|
+
|
|
34
|
+
let css = fs.readFileSync(path.join(__dirname) + '/github-markdown.min.css', 'utf8')
|
|
35
|
+
template = template.replace('{{{style}}}', css); //替换css内容占位标记
|
|
36
|
+
createFile(template, target, outPath);
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 创建页面模板
|
|
41
|
+
* @returns {string} 页面骨架字符串
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
function createTemplate() {
|
|
45
|
+
const template = `<!DOCTYPE html>
|
|
46
|
+
<html>
|
|
47
|
+
<head>
|
|
48
|
+
<meta charset="utf-8" >
|
|
49
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
50
|
+
<title>开发日志</title>
|
|
51
|
+
<style>
|
|
52
|
+
.markdown-body {
|
|
53
|
+
box-sizing: border-box;
|
|
54
|
+
min-width: 200px;
|
|
55
|
+
max-width: 980px;
|
|
56
|
+
margin: 0 auto;
|
|
57
|
+
padding: 45px;
|
|
58
|
+
}
|
|
59
|
+
@media (max-width: 767px) {
|
|
60
|
+
.markdown-body {
|
|
61
|
+
padding: 15px;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
{{{style}}}
|
|
65
|
+
</style>
|
|
66
|
+
</head>
|
|
67
|
+
<body>
|
|
68
|
+
<article class="markdown-body">
|
|
69
|
+
{{{content}}}
|
|
70
|
+
</article>
|
|
71
|
+
</body>
|
|
72
|
+
</html>`;
|
|
73
|
+
return template;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 创建html文件
|
|
78
|
+
* @param {string} content 写入html的文件内容
|
|
79
|
+
*/
|
|
80
|
+
function createFile(content, fileName, outPath = "public") {
|
|
81
|
+
const suffix = 'html'; //文件格式
|
|
82
|
+
const fullName = fileName + '.' + suffix; //文件全名
|
|
83
|
+
const file = path.join(outPath, fullName); //文件地址
|
|
84
|
+
fs.writeFileSync(file, content, 'utf-8')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = {
|
|
88
|
+
createFile, createTemplate, change, watchFile
|
|
89
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 调用IM机器人进行群通知
|
|
3
|
+
*/
|
|
4
|
+
const { postParams } = require('../utils/http');
|
|
5
|
+
// 同步执行exe命令
|
|
6
|
+
const exec = require('child_process').execSync;
|
|
7
|
+
// 控制台样式
|
|
8
|
+
const chalk = require("chalk")
|
|
9
|
+
module.exports = {
|
|
10
|
+
/**
|
|
11
|
+
* 通知飞书群
|
|
12
|
+
*/
|
|
13
|
+
notifyFeishu: (type, version, projectConfig) => {
|
|
14
|
+
if (projectConfig && projectConfig.config) {
|
|
15
|
+
let body = {
|
|
16
|
+
"msg_type": "interactive",
|
|
17
|
+
"card": {
|
|
18
|
+
"config": {
|
|
19
|
+
"wide_screen_mode": true,
|
|
20
|
+
"enable_forward": true
|
|
21
|
+
},
|
|
22
|
+
"elements": [{
|
|
23
|
+
"tag": "markdown",
|
|
24
|
+
"content": "项目名称:" + projectConfig.name + "\n分支:" + exec("git rev-parse --abbrev-ref HEAD").toString("utf8").trim() + "\nTag:" + type + "\n版本号:" + version + "\n发布者:" + exec("git config user.name").toString("utf8").trim()
|
|
25
|
+
}, {
|
|
26
|
+
"actions": [{
|
|
27
|
+
"tag": "button",
|
|
28
|
+
"text": {
|
|
29
|
+
"content": "更新日志",
|
|
30
|
+
"tag": "lark_md"
|
|
31
|
+
},
|
|
32
|
+
"url": projectConfig.config["doc-" + type],
|
|
33
|
+
"type": "default",
|
|
34
|
+
"value": {}
|
|
35
|
+
}],
|
|
36
|
+
"tag": "action"
|
|
37
|
+
}],
|
|
38
|
+
"header": {
|
|
39
|
+
"title": {
|
|
40
|
+
"content": `${projectConfig.name}项目发布通知`,
|
|
41
|
+
"tag": "plain_text"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// 获取飞书推送地址
|
|
47
|
+
let triggers = projectConfig.config["feishu-" + type];
|
|
48
|
+
if (triggers) {
|
|
49
|
+
triggers.map((trigger) => {
|
|
50
|
+
postParams(trigger, body);
|
|
51
|
+
})
|
|
52
|
+
console.log(chalk.green('已通知飞书群,请查看。'));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将代码提交到gitlab,并设置tag
|
|
3
|
+
*/
|
|
4
|
+
const exec = require('child_process').execSync;
|
|
5
|
+
const chalk = require("chalk")
|
|
6
|
+
const changeVersion = require("../utils/changeVersion")
|
|
7
|
+
/**
|
|
8
|
+
* 更改版本version
|
|
9
|
+
* @param {types} 版本类型,如Dev、uat,GA,Release
|
|
10
|
+
*/
|
|
11
|
+
function getNewVersionName(types) {
|
|
12
|
+
exec("git fetch --tags -f")
|
|
13
|
+
return types.map((item) => {
|
|
14
|
+
// 更新本地tag
|
|
15
|
+
let version = exec(`git tag --sort=-committerdate`)
|
|
16
|
+
version = version.toString("utf8").trim();
|
|
17
|
+
if (version) {
|
|
18
|
+
// 使用换行分隔下
|
|
19
|
+
let versions = version.split("\n");
|
|
20
|
+
// 取出第一个包含-V的版本号
|
|
21
|
+
version = versions.find((item) => {
|
|
22
|
+
return item.includes("-V");
|
|
23
|
+
})
|
|
24
|
+
if (version) {
|
|
25
|
+
// 取版本号
|
|
26
|
+
version = version.split("-V")[1]
|
|
27
|
+
// 改变版本号
|
|
28
|
+
version = changeVersion.change(version, item)
|
|
29
|
+
// 生成最后的版本号
|
|
30
|
+
item = item + "-V" + version
|
|
31
|
+
} else {
|
|
32
|
+
item = item + "-V0.0.1"
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
item = item + "-V0.0.1"
|
|
36
|
+
}
|
|
37
|
+
return item;
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 将代码推送至gitlab
|
|
43
|
+
*/
|
|
44
|
+
function push(version) {
|
|
45
|
+
try {
|
|
46
|
+
// 添加改变文件
|
|
47
|
+
exec("git add .")
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
// 提交到本地
|
|
54
|
+
exec("git commit -m " + version)
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
console.log();
|
|
60
|
+
console.log(chalk.green('代码开始推送,请稍后...'));
|
|
61
|
+
try {
|
|
62
|
+
// 推送到服务器
|
|
63
|
+
exec("git push")
|
|
64
|
+
console.log();
|
|
65
|
+
console.log(chalk.green('代码推送成功!'));
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.log(chalk.red('代码推送失败,本地代码与线上不同步,请先 git pull 同步!'));
|
|
68
|
+
console.log();
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return true
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 设置Tags
|
|
75
|
+
* @param {types} 发布版本类型,如Dev,uat,GA,Release
|
|
76
|
+
* @param {versions} 版本tag信息,如Dev-V12.0.1
|
|
77
|
+
*/
|
|
78
|
+
function setTag(types, versions) {
|
|
79
|
+
console.log(chalk.green('开始同步Tag设置,请稍后...'));
|
|
80
|
+
try {
|
|
81
|
+
// 更新tag
|
|
82
|
+
exec("git fetch --tags -f")
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
// 删除本地版本Tag
|
|
87
|
+
versions.map((version) => {
|
|
88
|
+
try {
|
|
89
|
+
exec("git tag -d " + version)
|
|
90
|
+
} catch (error) {
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
types.map((type) => {
|
|
94
|
+
try {
|
|
95
|
+
// 删除本地发布Tag
|
|
96
|
+
exec("git tag -d " + type)
|
|
97
|
+
} catch (error) {
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
versions.map((version) => {
|
|
101
|
+
try {
|
|
102
|
+
// 删除远程Tag
|
|
103
|
+
exec("git push origin :refs/tags/" + version)
|
|
104
|
+
} catch (error) {
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
types.map((type) => {
|
|
108
|
+
try {
|
|
109
|
+
// 删除远程发布Tag
|
|
110
|
+
exec("git push origin :refs/tags/" + type)
|
|
111
|
+
} catch (error) {
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
// 添加tag
|
|
116
|
+
versions.map((version) => {
|
|
117
|
+
exec("git tag " + version + " -f")
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
types.map((type) => {
|
|
121
|
+
exec("git tag " + type + " -f")
|
|
122
|
+
})
|
|
123
|
+
// 推送tag
|
|
124
|
+
exec("git push --tags")
|
|
125
|
+
|
|
126
|
+
console.log(chalk.green('Tag设置成功!'));
|
|
127
|
+
console.log();
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 删除dist文件夹
|
|
132
|
+
* @returns true 成功,false 失败
|
|
133
|
+
*/
|
|
134
|
+
function deleteDist() {
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
// 删除dist文件夹
|
|
138
|
+
exec("git rm -r dist")
|
|
139
|
+
} catch (error) {
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
// 添加改变文件
|
|
145
|
+
exec("git add .")
|
|
146
|
+
} catch (error) {
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
// 提交到本地
|
|
152
|
+
exec("git commit -m clear-dist")
|
|
153
|
+
} catch (error) {
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
// 推送到服务器
|
|
157
|
+
exec("git push")
|
|
158
|
+
} catch (error) {
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* 发布代码同时设置Tags
|
|
165
|
+
* @param {types} 版本集合
|
|
166
|
+
*/
|
|
167
|
+
function pushCodeAndTags(types = []) {
|
|
168
|
+
let versions = getNewVersionName(types);
|
|
169
|
+
return push(versions[0]) && setTag(types, versions) && deleteDist(versions[0]);
|
|
170
|
+
}
|
|
171
|
+
module.exports = { pushCodeAndTags, push, getNewVersionName, setTag }
|
package/utils/test.js
ADDED
package/utils/trigger.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
//文件下载
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const axios = require('axios');
|
|
5
|
+
const chalk = require("chalk")
|
|
6
|
+
const inquirer = require("inquirer")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
// 创建文件夹目录
|
|
11
|
+
const filepath = "src/utils/i18n";
|
|
12
|
+
let dirCache = {};
|
|
13
|
+
/**
|
|
14
|
+
* 创建文件夹
|
|
15
|
+
*/
|
|
16
|
+
function mkdir(filepath) {
|
|
17
|
+
const arr = filepath.split('/');
|
|
18
|
+
let dir = arr[0];
|
|
19
|
+
for (let i = 1; i <= arr.length; i++) {
|
|
20
|
+
if (!dirCache[dir] && !fs.existsSync(dir)) {
|
|
21
|
+
dirCache[dir] = true;
|
|
22
|
+
console.log("创建", dir);
|
|
23
|
+
fs.mkdirSync(dir);
|
|
24
|
+
} else {
|
|
25
|
+
// console.log("文件夹" + dir + "已存在");
|
|
26
|
+
}
|
|
27
|
+
dir = dir + '/' + arr[i];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
mkdir(filepath)
|
|
31
|
+
/**
|
|
32
|
+
* 检查多语言文件是否需要更新,如果需要更新,返回要更新的语种集合,否则返回空。
|
|
33
|
+
*/
|
|
34
|
+
function checkVersion() {
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 选择要更新的文件集合
|
|
39
|
+
*/
|
|
40
|
+
function selectUpdateFiles() {
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param {fileUrl} 文件源地址
|
|
47
|
+
* @param {localPath} 保存的地址
|
|
48
|
+
* @param {fileName} 文件名
|
|
49
|
+
*/
|
|
50
|
+
function down2save(fileUrl, localPath, fileName) {
|
|
51
|
+
const mypath = path.resolve(localPath, fileName);
|
|
52
|
+
const writer = fs.createWriteStream(mypath);
|
|
53
|
+
console.log(fileName + " 开始下载");
|
|
54
|
+
return axios({
|
|
55
|
+
method: 'get',
|
|
56
|
+
url: fileUrl,
|
|
57
|
+
responseType: 'stream',
|
|
58
|
+
}).then(response => {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
response.data.pipe(writer);
|
|
61
|
+
let error = null;
|
|
62
|
+
writer.on('error', err => {
|
|
63
|
+
console.log(fileName + " 下载失败", err);
|
|
64
|
+
error = err;
|
|
65
|
+
writer.close();
|
|
66
|
+
reject(err);
|
|
67
|
+
});
|
|
68
|
+
writer.on('close', () => {
|
|
69
|
+
if (!error) {
|
|
70
|
+
resolve(true);
|
|
71
|
+
console.log(chalk.blue(fileName + " 下载成功"));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 获取文件名
|
|
80
|
+
* @param {fileUrl} 文件地址
|
|
81
|
+
* @returns 文件名
|
|
82
|
+
*/
|
|
83
|
+
function getFileName(fileUrl) {
|
|
84
|
+
const arr = fileUrl.split('/');
|
|
85
|
+
return arr[arr.length - 1];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 更新多语言
|
|
90
|
+
* @returns 结果
|
|
91
|
+
*/
|
|
92
|
+
async function updatei18n(languageList) {
|
|
93
|
+
let promiseArr = []
|
|
94
|
+
languageList.forEach(item => {
|
|
95
|
+
promiseArr.push((async (item) => {
|
|
96
|
+
let fileName = getFileName(item);
|
|
97
|
+
await down2save(item, filepath, fileName)
|
|
98
|
+
})(item))
|
|
99
|
+
})
|
|
100
|
+
return Promise.all(promiseArr).then(function (result) {
|
|
101
|
+
console.log()
|
|
102
|
+
console.log(chalk.blue("所有语言下载完成"));
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 是否更新多语言词库
|
|
108
|
+
* @returns 结果
|
|
109
|
+
*/
|
|
110
|
+
function askI18n() {
|
|
111
|
+
const prompt = [{
|
|
112
|
+
type: 'list',
|
|
113
|
+
message: '是否更新多语言词库:',
|
|
114
|
+
name: 'checked',
|
|
115
|
+
choices: [
|
|
116
|
+
{ name: "否", value: "0" },
|
|
117
|
+
{ name: "是", value: "1" },
|
|
118
|
+
],
|
|
119
|
+
}
|
|
120
|
+
];
|
|
121
|
+
return inquirer.prompt(prompt)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
module.exports = {
|
|
126
|
+
updatei18n, askI18n
|
|
127
|
+
}
|
package/bin/serve.js
DELETED
package/src/builder.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
class Builder {
|
|
7
|
-
init() {
|
|
8
|
-
this.build();
|
|
9
|
-
// this.upload();
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* 编译文件,将vue编译为js文件
|
|
13
|
-
*/
|
|
14
|
-
build() {
|
|
15
|
-
console.log(chalk.green('编译中,请稍后...'));
|
|
16
|
-
exec('vue build -t wc -n cloud-cc -d build plugin/index.vue', (error, stdout, stderr) => {
|
|
17
|
-
if (error) {
|
|
18
|
-
console.error(chalk.red(`编译失败: ${error}`));
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
console.log(chalk.green('编译成功'));
|
|
22
|
-
this.upload()
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* 将文件上传
|
|
27
|
-
*/
|
|
28
|
-
upload() {
|
|
29
|
-
console.log(chalk.green('发布中,请稍后...'));
|
|
30
|
-
let jsFile = this.filterFile()[0];
|
|
31
|
-
let data = "";
|
|
32
|
-
try {
|
|
33
|
-
data = fs.readFileSync(jsFile, 'utf8')
|
|
34
|
-
} catch (err) {
|
|
35
|
-
console.error(err)
|
|
36
|
-
}
|
|
37
|
-
let body = {
|
|
38
|
-
"compName": "test1",
|
|
39
|
-
"compContent": data,
|
|
40
|
-
"version": "1.0.0",
|
|
41
|
-
"orgId": "100"
|
|
42
|
-
}
|
|
43
|
-
post("http://172.18.62.124:9000/devconsole/custom/pc/1.0/post/insertCustomComp",
|
|
44
|
-
body).then((res) => {
|
|
45
|
-
if (res.returnCode == 200) {
|
|
46
|
-
console.error(chalk.green(`发布成功`));
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
(err) => {
|
|
50
|
-
console.error(chalk.red(`发布失败: ${err}`));
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* 过滤出min.js文件
|
|
55
|
-
* @returns 过滤结果
|
|
56
|
-
*/
|
|
57
|
-
filterFile() {
|
|
58
|
-
const jsPath = path.join(__dirname, "..", "build");
|
|
59
|
-
let jsPaths = [];
|
|
60
|
-
if (jsPath) {
|
|
61
|
-
jsPaths = fs.readdirSync(jsPath).filter((f) => {
|
|
62
|
-
return f.endsWith('.min.js');
|
|
63
|
-
}).map((item) => {
|
|
64
|
-
return path.join(jsPath, item);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return jsPaths;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
module.exports = Builder;
|