cloudcc-cli 1.3.2 → 1.3.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/utils/notifyIM.js CHANGED
@@ -1,87 +1,87 @@
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
- // 网络请求
10
- const axios = require("axios")
11
- module.exports = {
12
- /**
13
- * 通知钉钉群
14
- */
15
- notifyDingDing: (type, version, projectConfig, user) => {
16
- if (projectConfig && projectConfig.config) {
17
- let body = {
18
- "msgtype": "actionCard",
19
- "actionCard": {
20
- "title": `${projectConfig.name}项目发布通知`,
21
- "text": `${projectConfig.name}项目发布通知` + "\n\n 项  目  名:" + projectConfig.name + "\n\n分  支  名:" + exec("git rev-parse --abbrev-ref HEAD").toString("utf8").trim() + "\n\nTag        :" + type + "\n\n版  本  号:" + version + "\n\n发  布  者:" + user,
22
- "btnOrientation": "1",
23
- "btns": [
24
- {
25
- "title": "迭代日志",
26
- "actionURL": projectConfig.config["doc-" + type]
27
- }
28
- ]
29
- }
30
- }
31
- // 获取钉钉推送地址
32
- let triggers = projectConfig.config["dingding-" + type];
33
- if (triggers) {
34
- triggers.map((trigger) => {
35
- axios.post(trigger, body);
36
- })
37
- console.log(chalk.green('已通知钉钉群,请查看。'));
38
- }
39
- }
40
- },
41
- /**
42
- * 通知飞书群
43
- */
44
- notifyFeishu: (type, version, projectConfig, user) => {
45
- if (projectConfig && projectConfig.config) {
46
- let body = {
47
- "msg_type": "interactive",
48
- "card": {
49
- "config": {
50
- "wide_screen_mode": true,
51
- "enable_forward": true
52
- },
53
- "elements": [{
54
- "tag": "markdown",
55
- "content": "项目名称:" + projectConfig.name + "\n分支:" + exec("git rev-parse --abbrev-ref HEAD").toString("utf8").trim() + "\nTag:" + type + "\n版本号:" + version + "\n发布者:" + user
56
- }, {
57
- "actions": [{
58
- "tag": "button",
59
- "text": {
60
- "content": "更新日志",
61
- "tag": "lark_md"
62
- },
63
- "url": projectConfig.config["doc-" + type],
64
- "type": "default",
65
- "value": {}
66
- }],
67
- "tag": "action"
68
- }],
69
- "header": {
70
- "title": {
71
- "content": `${projectConfig.name}项目发布通知`,
72
- "tag": "plain_text"
73
- }
74
- }
75
- }
76
- }
77
- // 获取飞书推送地址
78
- let triggers = projectConfig.config["feishu-" + type];
79
- if (triggers) {
80
- triggers.map((trigger) => {
81
- postParams(trigger, body);
82
- })
83
- console.log(chalk.green('已通知飞书群,请查看。'));
84
- }
85
- }
86
- }
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
+ // 网络请求
10
+ const axios = require("axios")
11
+ module.exports = {
12
+ /**
13
+ * 通知钉钉群
14
+ */
15
+ notifyDingDing: (type, version, projectConfig, user) => {
16
+ if (projectConfig && projectConfig.config) {
17
+ let body = {
18
+ "msgtype": "actionCard",
19
+ "actionCard": {
20
+ "title": `${projectConfig.name}项目发布通知`,
21
+ "text": `${projectConfig.name}项目发布通知` + "\n\n 项  目  名:" + projectConfig.name + "\n\n分  支  名:" + exec("git rev-parse --abbrev-ref HEAD").toString("utf8").trim() + "\n\nTag        :" + type + "\n\n版  本  号:" + version + "\n\n发  布  者:" + user,
22
+ "btnOrientation": "1",
23
+ "btns": [
24
+ {
25
+ "title": "迭代日志",
26
+ "actionURL": projectConfig.config["doc-" + type]
27
+ }
28
+ ]
29
+ }
30
+ }
31
+ // 获取钉钉推送地址
32
+ let triggers = projectConfig.config["dingding-" + type];
33
+ if (triggers) {
34
+ triggers.map((trigger) => {
35
+ axios.post(trigger, body);
36
+ })
37
+ console.log(chalk.green('已通知钉钉群,请查看。'));
38
+ }
39
+ }
40
+ },
41
+ /**
42
+ * 通知飞书群
43
+ */
44
+ notifyFeishu: (type, version, projectConfig, user) => {
45
+ if (projectConfig && projectConfig.config) {
46
+ let body = {
47
+ "msg_type": "interactive",
48
+ "card": {
49
+ "config": {
50
+ "wide_screen_mode": true,
51
+ "enable_forward": true
52
+ },
53
+ "elements": [{
54
+ "tag": "markdown",
55
+ "content": "项目名称:" + projectConfig.name + "\n分支:" + exec("git rev-parse --abbrev-ref HEAD").toString("utf8").trim() + "\nTag:" + type + "\n版本号:" + version + "\n发布者:" + user
56
+ }, {
57
+ "actions": [{
58
+ "tag": "button",
59
+ "text": {
60
+ "content": "更新日志",
61
+ "tag": "lark_md"
62
+ },
63
+ "url": projectConfig.config["doc-" + type],
64
+ "type": "default",
65
+ "value": {}
66
+ }],
67
+ "tag": "action"
68
+ }],
69
+ "header": {
70
+ "title": {
71
+ "content": `${projectConfig.name}项目发布通知`,
72
+ "tag": "plain_text"
73
+ }
74
+ }
75
+ }
76
+ }
77
+ // 获取飞书推送地址
78
+ let triggers = projectConfig.config["feishu-" + type];
79
+ if (triggers) {
80
+ triggers.map((trigger) => {
81
+ postParams(trigger, body);
82
+ })
83
+ console.log(chalk.green('已通知飞书群,请查看。'));
84
+ }
85
+ }
86
+ }
87
87
  }
package/utils/pushCode.js CHANGED
@@ -1,187 +1,187 @@
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 = "V" + version
31
- } else {
32
- item = "V0.0.1"
33
- }
34
- } else {
35
- item = "V0.0.1"
36
- }
37
- return item;
38
- })
39
- }
40
-
41
- /**
42
- * 将代码推送至gitlab
43
- * @param {version} 版本号
44
- * @param {update} 是否强制更新:1强制更新,0不强制更新
45
- * @returns true 成功,false 失败
46
- */
47
- function push(version, update = "0") {
48
- try {
49
- // 添加改变文件
50
- exec("git add .")
51
- } catch (error) {
52
- return false;
53
- }
54
-
55
- try {
56
- // 提交到本地
57
- exec("git commit -m " + version)
58
- } catch (error) {
59
- return false;
60
- }
61
-
62
- console.log();
63
- console.log(chalk.green('代码开始推送,请稍后...'));
64
- try {
65
- // 推送到服务器
66
- exec("git push")
67
- console.log();
68
- console.log(chalk.green('代码推送成功!'));
69
- } catch (error) {
70
- console.log("update", update);
71
- if ("1" == update) {
72
- exec(`git fetch --tags -f && git pull --force`)
73
- } else {
74
- console.log(chalk.red('代码推送失败,本地代码与线上不同步,请先 git pull 同步!'));
75
- console.log();
76
- return false;
77
- }
78
- }
79
- return true
80
- }
81
- /**
82
- * 设置Tags
83
- * @param {types} 发布版本类型,如Dev,uat,GA,Release
84
- * @param {versions} 版本tag信息,如Dev-V12.0.1
85
- */
86
- function setTag(types, versions) {
87
- console.log(chalk.green('开始同步Tag设置,请稍后...'));
88
- try {
89
- // 更新tag
90
- exec("git fetch --tags -f")
91
- } catch (error) {
92
- return false;
93
- }
94
- // 删除本地版本Tag
95
- versions.map((version) => {
96
- try {
97
- exec("git tag -d " + version)
98
- } catch (error) {
99
- }
100
- })
101
- types.map((type) => {
102
- try {
103
- // 删除本地发布Tag
104
- exec("git tag -d " + type)
105
- } catch (error) {
106
- }
107
- })
108
- versions.map((version) => {
109
- try {
110
- // 删除远程Tag
111
- exec("git push origin :refs/tags/" + version)
112
- } catch (error) {
113
- }
114
- })
115
- types.map((type) => {
116
- try {
117
- // 删除远程发布Tag
118
- exec("git push origin :refs/tags/" + type)
119
- } catch (error) {
120
- }
121
- })
122
-
123
- // 添加tag
124
- versions.map((version) => {
125
- exec("git tag " + version + " -f")
126
- })
127
-
128
- types.map((type) => {
129
- exec("git tag " + type + " -f")
130
- })
131
- // 推送tag
132
- exec("git push --tags")
133
-
134
- console.log(chalk.green('Tag设置成功!'));
135
- console.log();
136
- return true;
137
- }
138
- /**
139
- * 删除dist文件夹
140
- * @returns true 成功,false 失败
141
- */
142
- function deleteDist() {
143
-
144
- try {
145
- // 删除dist文件夹
146
- exec("git rm -r dist")
147
- } catch (error) {
148
-
149
- }
150
-
151
- try {
152
- // 删除unpackage文件夹
153
- exec("git rm -r unpackage")
154
- } catch (error) {
155
-
156
- }
157
-
158
- try {
159
- // 添加改变文件
160
- exec("git add .")
161
- } catch (error) {
162
-
163
- }
164
-
165
- try {
166
- // 提交到本地
167
- exec("git commit -m clear-dist")
168
- } catch (error) {
169
- }
170
- try {
171
- // 推送到服务器
172
- exec("git push")
173
- } catch (error) {
174
-
175
- }
176
- return true;
177
- }
178
- /**
179
- * 发布代码同时设置Tags
180
- * @param {types} 版本集合
181
- * @param {update} 是否强制更新
182
- */
183
- function pushCodeAndTags(types = [], update = "0") {
184
- let versions = getNewVersionName(types);
185
- return push(versions[0], update) && setTag(types, versions) && deleteDist(versions[0]);
186
- }
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 = "V" + version
31
+ } else {
32
+ item = "V0.0.1"
33
+ }
34
+ } else {
35
+ item = "V0.0.1"
36
+ }
37
+ return item;
38
+ })
39
+ }
40
+
41
+ /**
42
+ * 将代码推送至gitlab
43
+ * @param {version} 版本号
44
+ * @param {update} 是否强制更新:1强制更新,0不强制更新
45
+ * @returns true 成功,false 失败
46
+ */
47
+ function push(version, update = "0") {
48
+ try {
49
+ // 添加改变文件
50
+ exec("git add .")
51
+ } catch (error) {
52
+ return false;
53
+ }
54
+
55
+ try {
56
+ // 提交到本地
57
+ exec("git commit -m " + version)
58
+ } catch (error) {
59
+ return false;
60
+ }
61
+
62
+ console.log();
63
+ console.log(chalk.green('代码开始推送,请稍后...'));
64
+ try {
65
+ // 推送到服务器
66
+ exec("git push")
67
+ console.log();
68
+ console.log(chalk.green('代码推送成功!'));
69
+ } catch (error) {
70
+ console.log("update", update);
71
+ if ("1" == update) {
72
+ exec(`git fetch --tags -f && git pull --force`)
73
+ } else {
74
+ console.log(chalk.red('代码推送失败,本地代码与线上不同步,请先 git pull 同步!'));
75
+ console.log();
76
+ return false;
77
+ }
78
+ }
79
+ return true
80
+ }
81
+ /**
82
+ * 设置Tags
83
+ * @param {types} 发布版本类型,如Dev,uat,GA,Release
84
+ * @param {versions} 版本tag信息,如Dev-V12.0.1
85
+ */
86
+ function setTag(types, versions) {
87
+ console.log(chalk.green('开始同步Tag设置,请稍后...'));
88
+ try {
89
+ // 更新tag
90
+ exec("git fetch --tags -f")
91
+ } catch (error) {
92
+ return false;
93
+ }
94
+ // 删除本地版本Tag
95
+ versions.map((version) => {
96
+ try {
97
+ exec("git tag -d " + version)
98
+ } catch (error) {
99
+ }
100
+ })
101
+ types.map((type) => {
102
+ try {
103
+ // 删除本地发布Tag
104
+ exec("git tag -d " + type)
105
+ } catch (error) {
106
+ }
107
+ })
108
+ versions.map((version) => {
109
+ try {
110
+ // 删除远程Tag
111
+ exec("git push origin :refs/tags/" + version)
112
+ } catch (error) {
113
+ }
114
+ })
115
+ types.map((type) => {
116
+ try {
117
+ // 删除远程发布Tag
118
+ exec("git push origin :refs/tags/" + type)
119
+ } catch (error) {
120
+ }
121
+ })
122
+
123
+ // 添加tag
124
+ versions.map((version) => {
125
+ exec("git tag " + version + " -f")
126
+ })
127
+
128
+ types.map((type) => {
129
+ exec("git tag " + type + " -f")
130
+ })
131
+ // 推送tag
132
+ exec("git push --tags")
133
+
134
+ console.log(chalk.green('Tag设置成功!'));
135
+ console.log();
136
+ return true;
137
+ }
138
+ /**
139
+ * 删除dist文件夹
140
+ * @returns true 成功,false 失败
141
+ */
142
+ function deleteDist() {
143
+
144
+ try {
145
+ // 删除dist文件夹
146
+ exec("git rm -r dist")
147
+ } catch (error) {
148
+
149
+ }
150
+
151
+ try {
152
+ // 删除unpackage文件夹
153
+ exec("git rm -r unpackage")
154
+ } catch (error) {
155
+
156
+ }
157
+
158
+ try {
159
+ // 添加改变文件
160
+ exec("git add .")
161
+ } catch (error) {
162
+
163
+ }
164
+
165
+ try {
166
+ // 提交到本地
167
+ exec("git commit -m clear-dist")
168
+ } catch (error) {
169
+ }
170
+ try {
171
+ // 推送到服务器
172
+ exec("git push")
173
+ } catch (error) {
174
+
175
+ }
176
+ return true;
177
+ }
178
+ /**
179
+ * 发布代码同时设置Tags
180
+ * @param {types} 版本集合
181
+ * @param {update} 是否强制更新
182
+ */
183
+ function pushCodeAndTags(types = [], update = "0") {
184
+ let versions = getNewVersionName(types);
185
+ return push(versions[0], update) && setTag(types, versions) && deleteDist(versions[0]);
186
+ }
187
187
  module.exports = { pushCodeAndTags, push, getNewVersionName, setTag }
package/utils/test.js CHANGED
@@ -1,2 +1,2 @@
1
- const fs = require('fs')
1
+ const fs = require('fs')
2
2
  const exec = require('child_process').execSync;
package/utils/trigger.js CHANGED
@@ -1,15 +1,15 @@
1
- /**
2
- * 版本构建触发器
3
- */
4
-
5
- const { get } = require('../utils/http');
6
-
7
- async function jenkins(url) {
8
- try {
9
- await get(url)
10
- } catch (error) {
11
- }
12
- return true
13
- }
14
-
15
- module.exports = { jenkins }
1
+ /**
2
+ * 版本构建触发器
3
+ */
4
+
5
+ const { get } = require('../utils/http');
6
+
7
+ async function jenkins(url) {
8
+ try {
9
+ await get(url)
10
+ } catch (error) {
11
+ }
12
+ return true
13
+ }
14
+
15
+ module.exports = { jenkins }