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
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
const exec = require('child_process').execSync;
|
|
2
|
+
const chalk = require("chalk")
|
|
3
|
+
// 文件编辑对象
|
|
4
|
+
const fs = require("fs")
|
|
5
|
+
// 配置信息
|
|
6
|
+
const projectConfig = JSON.parse(fs.readFileSync('package.json', 'utf8'))
|
|
7
|
+
// 网页转换器
|
|
8
|
+
const { change } = require("../utils/md2html")
|
|
9
|
+
// 检查版本更新
|
|
10
|
+
const { checkUpdate } = require("../utils/checkVersion")
|
|
11
|
+
// 控制台交互
|
|
12
|
+
const { askType } = require("../utils/askTool")
|
|
13
|
+
// 提交代码,设置Tag
|
|
14
|
+
const { getNewVersionName, pushCodeAndTags } = require("../utils/pushCode")
|
|
15
|
+
// 触发构建器
|
|
16
|
+
const { jenkins } = require("../utils/trigger")
|
|
17
|
+
// 通知飞书
|
|
18
|
+
const { notifyFeishu } = require("../utils/notifyIM")
|
|
19
|
+
// 时间库
|
|
20
|
+
const dayjs = require("dayjs")
|
|
21
|
+
// 多语言更新脚本
|
|
22
|
+
const { updatei18n, askI18n } = require("../utils/updatei18n")
|
|
23
|
+
/**
|
|
24
|
+
* 项目打包发布脚本
|
|
25
|
+
*/
|
|
26
|
+
class Publish {
|
|
27
|
+
constructor() {
|
|
28
|
+
/**
|
|
29
|
+
* 控制台参数
|
|
30
|
+
* type:发布类型
|
|
31
|
+
* branch:使用的分支
|
|
32
|
+
*/
|
|
33
|
+
this.args = new Map();
|
|
34
|
+
this.arguments = process.argv.splice(2).map((item) => {
|
|
35
|
+
let arr = item.split("=");
|
|
36
|
+
this.args.set(arr[0].split("-")[1], arr[1]);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 初始化
|
|
41
|
+
*/
|
|
42
|
+
async init() {
|
|
43
|
+
// 检查cli版本,提示用户更新:false:不更新,true:更新
|
|
44
|
+
let update = await checkUpdate();
|
|
45
|
+
if (!update) {
|
|
46
|
+
// 1:版本发布信息,包含发布版本类型信息
|
|
47
|
+
let condition = {};
|
|
48
|
+
// 检查命令行是否输入了发布版本信息,如果没有包含,那么询问发布类型
|
|
49
|
+
if (this.args.get("type")) {
|
|
50
|
+
condition.type = this.args.get("type")
|
|
51
|
+
} else {
|
|
52
|
+
// 询问发布类型
|
|
53
|
+
condition = await askType();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 2:如果命令行包含了分支信息,那么git切换到命令行的分支
|
|
57
|
+
if (this.args.get("branch")) {
|
|
58
|
+
exec(`git checkout ${this.args.get("branch")}`);
|
|
59
|
+
console.log(chalk.green("切换分支:" + this.args.get("branch")))
|
|
60
|
+
console.log()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 3:获取新的发布版本号
|
|
64
|
+
let version = getNewVersionName([condition.type])
|
|
65
|
+
console.log();
|
|
66
|
+
console.log(chalk.green('待发布版本:' + version));
|
|
67
|
+
console.log();
|
|
68
|
+
|
|
69
|
+
// 4:如果存在多语言配置,则更新多语言
|
|
70
|
+
if (projectConfig.config && projectConfig.config["language-config"]) {
|
|
71
|
+
// 询问是否更新多语言
|
|
72
|
+
let i18n = await askI18n()
|
|
73
|
+
if (i18n.checked === '1') {
|
|
74
|
+
let laguage = projectConfig.config["language-config"]
|
|
75
|
+
// 执行更新多语言文件
|
|
76
|
+
await updatei18n(laguage)
|
|
77
|
+
console.log(chalk.blue("多语言文件更新完毕,准备开始打包"));
|
|
78
|
+
console.log();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 5:开始打包
|
|
83
|
+
if (await this.build()) {
|
|
84
|
+
// 6:将readme生成为html,并复制到dist中
|
|
85
|
+
let outPath = "dist"
|
|
86
|
+
// 读取配置,是否改变了输出路径
|
|
87
|
+
if (projectConfig.config && projectConfig.config["doc-path"]) {
|
|
88
|
+
outPath = projectConfig.config["doc-path"];
|
|
89
|
+
}
|
|
90
|
+
// lightning的Release禁止生成Readme文档
|
|
91
|
+
if (!(Object.is("CloudCC", projectConfig.name) && Object.is("Release", condition.type))) {
|
|
92
|
+
try {
|
|
93
|
+
// 设置readme文件位置
|
|
94
|
+
change("README", outPath);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.log(chalk.red("README写入异常:" + error))
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
// 7:写入版本信息
|
|
102
|
+
this.writeVersion(version);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.log(chalk.red("版本信息写入异常:" + error))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 8:发布代码并设置tags,触发发布,飞书提醒
|
|
108
|
+
if (pushCodeAndTags([condition.type])) {
|
|
109
|
+
if (projectConfig && projectConfig.config) {
|
|
110
|
+
jenkins(projectConfig.config["jenkins-" + condition.type])
|
|
111
|
+
}
|
|
112
|
+
notifyFeishu(condition.type, version, projectConfig)
|
|
113
|
+
console.log();
|
|
114
|
+
console.log(chalk.green('发布完成'));
|
|
115
|
+
console.log();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 编译代码
|
|
123
|
+
* @param {发布类型} types:Dev,uat,Release,GA,RC
|
|
124
|
+
* @param {发布版本} versions:Dev-V12.0.0
|
|
125
|
+
* @returns
|
|
126
|
+
*/
|
|
127
|
+
async build() {
|
|
128
|
+
console.log(chalk.green('开始编译,请稍后...'));
|
|
129
|
+
console.log();
|
|
130
|
+
// 打包命令
|
|
131
|
+
try {
|
|
132
|
+
exec('npm run build');
|
|
133
|
+
console.log(chalk.green('编译成功!'));
|
|
134
|
+
console.log();
|
|
135
|
+
return true;
|
|
136
|
+
} catch (error) {
|
|
137
|
+
try {
|
|
138
|
+
exec('npx vue-cli-service build');
|
|
139
|
+
console.log(chalk.green('编译成功!'));
|
|
140
|
+
console.log();
|
|
141
|
+
return true;
|
|
142
|
+
} catch (error) {
|
|
143
|
+
console.log(chalk.red('编译失败!' + error));
|
|
144
|
+
return false
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 将版本信息写入文件
|
|
151
|
+
* @param {版本信息} version
|
|
152
|
+
*/
|
|
153
|
+
writeVersion(version) {
|
|
154
|
+
try {
|
|
155
|
+
// 获得分支信息
|
|
156
|
+
let branch = exec('git rev-parse --abbrev-ref HEAD');
|
|
157
|
+
branch = branch.toString("utf8").trim();
|
|
158
|
+
// 获得提交版本信息
|
|
159
|
+
var gitHEAD = fs.readFileSync('.git/HEAD', 'utf-8').trim()
|
|
160
|
+
var ref = gitHEAD.split(': ')[1]
|
|
161
|
+
var develop = gitHEAD.split('/')[2]
|
|
162
|
+
var gitVersion = fs.readFileSync('.git/' + ref, 'utf-8').trim()
|
|
163
|
+
var gitCommitVersion = '"' + develop + ': ' + gitVersion + '"'
|
|
164
|
+
|
|
165
|
+
let versionInfo =
|
|
166
|
+
`
|
|
167
|
+
<!DOCTYPE html>
|
|
168
|
+
<html lang="en">
|
|
169
|
+
|
|
170
|
+
<head>
|
|
171
|
+
<meta charset="UTF-8">
|
|
172
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
173
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
174
|
+
<title>版本信息</title>
|
|
175
|
+
</head>
|
|
176
|
+
|
|
177
|
+
<body>
|
|
178
|
+
<div style="font-size: 20px">
|
|
179
|
+
<div>Lightning-Web:</div>
|
|
180
|
+
<div style="margin-left:48px">
|
|
181
|
+
<div>分支:${branch}</div>
|
|
182
|
+
<div>版本号:${version}</div>
|
|
183
|
+
<div>提交Hash:${gitCommitVersion}</div>
|
|
184
|
+
<div>发布时间:${dayjs().format('YYYY-MM-DD HH:mm:ss')}</div>
|
|
185
|
+
<div>发布人员:${exec("git config user.name").toString("utf8").trim()}</div>
|
|
186
|
+
</div>
|
|
187
|
+
</div>
|
|
188
|
+
</body>
|
|
189
|
+
|
|
190
|
+
</html>
|
|
191
|
+
`
|
|
192
|
+
fs.writeFileSync("dist/version.html", versionInfo, 'utf-8');
|
|
193
|
+
return true
|
|
194
|
+
} catch (error) {
|
|
195
|
+
return false
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
module.exports = Publish;
|
|
201
|
+
|
|
202
|
+
|
package/template/Appvue
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div id="app">
|
|
3
|
+
<cloudcc-input />
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
import CloudccInput from "../plugin/index.vue";
|
|
9
|
+
export default {
|
|
10
|
+
name: "App",
|
|
11
|
+
components: {
|
|
12
|
+
CloudccInput,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<style>
|
|
18
|
+
#app {
|
|
19
|
+
font-family: Avenir, Helvetica, Arial, sans-serif;
|
|
20
|
+
-webkit-font-smoothing: antialiased;
|
|
21
|
+
-moz-osx-font-smoothing: grayscale;
|
|
22
|
+
text-align: center;
|
|
23
|
+
color: #2c3e50;
|
|
24
|
+
margin-top: 60px;
|
|
25
|
+
}
|
|
26
|
+
</style>
|
package/template/httpjs
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import VueCookies from "vue-cookies";
|
|
2
|
+
import axios from 'axios'
|
|
3
|
+
import packageJson from '../package.json'
|
|
4
|
+
const service = axios.create({
|
|
5
|
+
timeout: 60000, // request timeout
|
|
6
|
+
headers: {
|
|
7
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
8
|
+
},
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
// request interceptor
|
|
12
|
+
service.interceptors.request.use(
|
|
13
|
+
config => {
|
|
14
|
+
config.headers.accessToken = VueCookies.get("JSESSIONID")
|
|
15
|
+
return config
|
|
16
|
+
},
|
|
17
|
+
error => {
|
|
18
|
+
// Do something with request error
|
|
19
|
+
Promise.reject(error)
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
// response interceptor
|
|
24
|
+
service.interceptors.response.use(
|
|
25
|
+
response => {
|
|
26
|
+
const code = response.data.code || 200
|
|
27
|
+
if (code !== 200) {
|
|
28
|
+
return Promise.reject(null == response.data.msg ? "未知异常" : response.data.msg)
|
|
29
|
+
} else {
|
|
30
|
+
return response.data
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
error => {
|
|
34
|
+
return Promise.reject(error)
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
const formateData = data => {
|
|
38
|
+
return {
|
|
39
|
+
head: {
|
|
40
|
+
appType: packageJson.name,
|
|
41
|
+
appVersion: packageJson.version,
|
|
42
|
+
accessToken: VueCookies.get("JSESSIONID")
|
|
43
|
+
},
|
|
44
|
+
body: {
|
|
45
|
+
...data
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export default {
|
|
50
|
+
get: (url, data = {}, responseType = '') => {
|
|
51
|
+
return service({
|
|
52
|
+
url: url,
|
|
53
|
+
method: 'get',
|
|
54
|
+
params: data,
|
|
55
|
+
responseType: responseType
|
|
56
|
+
})
|
|
57
|
+
},
|
|
58
|
+
getLight: (url, data = {}, responseType = '') => {
|
|
59
|
+
return service({
|
|
60
|
+
url: url,
|
|
61
|
+
method: 'get',
|
|
62
|
+
params: data,
|
|
63
|
+
responseType: responseType
|
|
64
|
+
})
|
|
65
|
+
},
|
|
66
|
+
postLight: (url, data = {}) => {
|
|
67
|
+
return service({
|
|
68
|
+
url: url,
|
|
69
|
+
method: 'post',
|
|
70
|
+
data: { ...data },
|
|
71
|
+
})
|
|
72
|
+
},
|
|
73
|
+
post: (url, data = {}, responseType = '') => {
|
|
74
|
+
return service({
|
|
75
|
+
url: url,
|
|
76
|
+
method: 'post',
|
|
77
|
+
data: formateData(data),
|
|
78
|
+
responseType: responseType
|
|
79
|
+
})
|
|
80
|
+
},
|
|
81
|
+
postParams: (url, data = {}) => {
|
|
82
|
+
return service({
|
|
83
|
+
url: url,
|
|
84
|
+
method: 'post',
|
|
85
|
+
params: data
|
|
86
|
+
})
|
|
87
|
+
},
|
|
88
|
+
patch: (url, data = {}) => {
|
|
89
|
+
return service({
|
|
90
|
+
url: url,
|
|
91
|
+
method: 'patch',
|
|
92
|
+
data: formateData(data)
|
|
93
|
+
})
|
|
94
|
+
},
|
|
95
|
+
delete: (url, data = {}) => {
|
|
96
|
+
return service({
|
|
97
|
+
url: url,
|
|
98
|
+
method: 'delete',
|
|
99
|
+
data: formateData(data)
|
|
100
|
+
})
|
|
101
|
+
},
|
|
102
|
+
put: (url, data = {}) => {
|
|
103
|
+
return service({
|
|
104
|
+
url: url,
|
|
105
|
+
method: 'put',
|
|
106
|
+
data: formateData(data)
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
}
|
package/template/index.js
CHANGED
|
@@ -9,23 +9,53 @@ module.exports = function (creator, options, callback) {
|
|
|
9
9
|
|
|
10
10
|
const projectPath = path.join(cwd, name);
|
|
11
11
|
const pluginPath = path.join(projectPath, "plugin");
|
|
12
|
+
const src = path.join(projectPath, "src");
|
|
13
|
+
const utils = path.join(projectPath, "utils");
|
|
14
|
+
const public = path.join(projectPath, "public");
|
|
12
15
|
|
|
13
16
|
//新建项目目录
|
|
14
17
|
//同步创建目录,以免文件目录不对齐
|
|
15
18
|
fs.mkdirSync(projectPath)
|
|
16
19
|
fs.mkdirSync(pluginPath)
|
|
20
|
+
fs.mkdirSync(src)
|
|
21
|
+
fs.mkdirSync(public)
|
|
17
22
|
|
|
18
23
|
creator.copyTpl('packagejson', path.join(projectPath, "package.json"), {
|
|
19
24
|
name, description
|
|
20
25
|
})
|
|
26
|
+
|
|
27
|
+
creator.copyTpl('vueconfigjs', path.join(projectPath, "vue.config.js"))
|
|
28
|
+
|
|
29
|
+
creator.copyTpl('babelconfigjs', path.join(projectPath, "babel.config.js"))
|
|
30
|
+
|
|
31
|
+
creator.copyTpl('mainjs', path.join(src, "main.js"))
|
|
32
|
+
|
|
33
|
+
creator.copyTpl('Appvue', path.join(src, "App.vue"))
|
|
34
|
+
|
|
35
|
+
creator.copyTpl('httpjs', path.join(utils, "http.js"))
|
|
36
|
+
|
|
37
|
+
creator.copyTpl('generateIDjs', path.join(utils, "generateID.js"))
|
|
38
|
+
|
|
21
39
|
creator.copyTpl('indexvue', path.join(pluginPath, "index.vue"))
|
|
22
40
|
|
|
41
|
+
creator.copyTpl('indexhtml', path.join(public, "index.html"))
|
|
42
|
+
|
|
23
43
|
creator.fs.commit(() => {
|
|
24
44
|
console.log();
|
|
25
45
|
console.log(`${chalk.grey(`创建项目: ${name}`)} ${chalk.green('✔ ')}`);
|
|
26
46
|
console.log(`${chalk.grey(`创建目录: ${name}/plugin`)} ${chalk.green('✔ ')}`);
|
|
27
47
|
console.log(`${chalk.grey(`创建文件: ${name}/plugin/index.vue`)} ${chalk.green('✔ ')}`);
|
|
48
|
+
|
|
49
|
+
console.log(`${chalk.grey(`创建目录: ${name}/public`)} ${chalk.green('✔ ')}`);
|
|
50
|
+
console.log(`${chalk.grey(`创建文件: ${name}/plugin/index.html`)} ${chalk.green('✔ ')}`);
|
|
51
|
+
|
|
52
|
+
console.log(`${chalk.grey(`创建目录: ${name}/src`)} ${chalk.green('✔ ')}`);
|
|
53
|
+
console.log(`${chalk.grey(`创建文件: ${name}/src/App.vue`)} ${chalk.green('✔ ')}`);
|
|
54
|
+
console.log(`${chalk.grey(`创建文件: ${name}/src/main.js`)} ${chalk.green('✔ ')}`);
|
|
55
|
+
|
|
56
|
+
console.log(`${chalk.grey(`创建文件: ${name}/babel.config.js`)} ${chalk.green('✔ ')}`);
|
|
28
57
|
console.log(`${chalk.grey(`创建文件: ${name}/package.json`)} ${chalk.green('✔ ')}`);
|
|
58
|
+
console.log(`${chalk.grey(`创建文件: ${name}/vue.config.js`)} ${chalk.green('✔ ')}`);
|
|
29
59
|
callback();
|
|
30
60
|
});
|
|
31
61
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
7
|
+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
8
|
+
<title>
|
|
9
|
+
Cloudcc Plugin Dev
|
|
10
|
+
</title>
|
|
11
|
+
</head>
|
|
12
|
+
|
|
13
|
+
<body>
|
|
14
|
+
<noscript>
|
|
15
|
+
<strong>We're sorry but Cloudcc Plugin Dev doesn't work properly without JavaScript enabled.
|
|
16
|
+
Please enable it to continue.</strong>
|
|
17
|
+
</noscript>
|
|
18
|
+
<div id="app"></div>
|
|
19
|
+
<!-- built files will be auto injected -->
|
|
20
|
+
</body>
|
|
21
|
+
|
|
22
|
+
</html>
|