cloudcc-cli 1.5.3 → 1.5.5

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 CHANGED
@@ -1,3 +1,17 @@
1
+ # ReleaseV1.5.5
2
+ #### 发布日期:2023-12-26
3
+ #### 发布范围:全量
4
+ #### 发布内容
5
+ * 修复
6
+ * 普通命令打包。
7
+
8
+ # ReleaseV1.5.4
9
+ #### 发布日期:2023-12-25
10
+ #### 发布范围:全量
11
+ #### 发布内容
12
+ * 迭代
13
+ * 添加build2命令。
14
+
1
15
  # ReleaseV1.5.3
2
16
  #### 发布日期:2023-11-21
3
17
  #### 发布范围:全量
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+
3
+ const Publish = require("../src/publishProjectBuild.js");
4
+
5
+ const publish = new Publish();
6
+
7
+ publish.init();
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+
3
+ const Publish = require("../src/publishProjectH5Build.js");
4
+
5
+ const publish = new Publish();
6
+
7
+ publish.init();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudcc-cli",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "description": "cloudcc-cli",
5
5
  "keywords": [
6
6
  "cloudcc",
@@ -14,7 +14,9 @@
14
14
  "cloudccBuild": "bin/build.js",
15
15
  "cloudccCreatePlugin": "bin/createPlugin.js",
16
16
  "cloudccPublic": "bin/publish.js",
17
+ "cloudccPublicBuild": "bin/publishBuild.js",
17
18
  "cloudccPublicH5": "bin/publishh5.js",
19
+ "cloudccPublicH5Build": "bin/publishh5Build.js",
18
20
  "cloudccBuildCCSDK": "bin/buildccsdk.js",
19
21
  "cloudccBuildCCBaseSDK": "bin/buildccbasesdk.js",
20
22
  "cloudccBuildTag": "bin/buildtag.js"
@@ -29,6 +31,7 @@
29
31
  "chalk": "^2.4.2",
30
32
  "crypto-js": "^4.1.1",
31
33
  "dayjs": "^1.10.7",
34
+ "fs-extra": "^11.2.0",
32
35
  "inquirer": "^8.1.0",
33
36
  "marked": "^5.0.1",
34
37
  "mem-fs": "^2.2.1",
@@ -13,7 +13,7 @@ const { askType, askTypeOther } = require("../utils/askTool")
13
13
  // 提交代码,设置Tag
14
14
  const { getNewVersionName, pushCodeAndTags } = require("../utils/pushCode")
15
15
  // 通知飞书
16
- const { notifyFeishu,notifyDingDing } = require("../utils/NotifyIM")
16
+ const { notifyDingDing } = require("../utils/NotifyIM")
17
17
  // 网络请求
18
18
  const { postParams } = require("../utils/http")
19
19
  /**
@@ -33,7 +33,7 @@ class Builder {
33
33
  if (condition && condition.type) {
34
34
  if (this.buildpush2npm(version[0].split("V")[1])) {
35
35
  pushCodeAndTags([condition.type])
36
- notifyFeishu(condition.type, version, projectConfig);
36
+ // notifyFeishu(condition.type, version, projectConfig);
37
37
  notifyDingDing(condition.type, version, projectConfig);
38
38
  console.log(chalk.green('发布完成'));
39
39
  }
@@ -1,5 +1,3 @@
1
- const { exec } = require('child_process');
2
- const { post } = require('../utils/http');
3
1
  const fs = require('fs');
4
2
  const path = require("path")
5
3
  const chalk = require("chalk")
@@ -186,11 +186,20 @@ class Builder {
186
186
  return { compName, component, vueContent, vueData, bizType, compDesc, category, loadModel }
187
187
  };
188
188
  /**
189
- * 生成依赖文件
189
+ *
190
+ * @param {string} buildFileName 编译文件入口
191
+ * @param {string} component 编译后组件的名字
192
+ * @param {string} plginTemp 生成模板代码存储路径
193
+ */
194
+ initPluginFile(buildFileName, component, plginTemp) {
195
+ this.initPluginFile2(buildFileName, component, plginTemp)
196
+ }
197
+ /**
198
+ * 生成依赖文件,vue-custom-element
190
199
  * @param {编译的文件名称} buildFileName
191
200
  * @param {编译后的组件名称} component
192
201
  */
193
- initPluginFile(buildFileName, component, plginTemp) {
202
+ initPluginFile1(buildFileName, component, plginTemp) {
194
203
  let newContent =
195
204
  `
196
205
  import Vue from "vue"
@@ -203,6 +212,31 @@ class Builder {
203
212
 
204
213
  fs.writeFileSync(`plugin/${plginTemp}.js`, newContent);
205
214
  }
215
+
216
+ /**
217
+ * 生成依赖文件
218
+ * @param {编译的文件名称} buildFileName
219
+ * @param {编译后的组件名称} component
220
+ */
221
+ initPluginFile2(buildFileName, component, plginTemp) {
222
+ let newContent =
223
+ `
224
+ import index from "./${buildFileName}"
225
+ function install(Vue) {
226
+ Vue.component('${component}', index);
227
+ }
228
+ export default install;
229
+ if (typeof window !== 'undefined' && window.Vue) {
230
+ console.log("install装载",install)
231
+ window.Vue.use(install);
232
+ if (install.installed) {
233
+ install.installed = false;
234
+ }
235
+ }
236
+ `
237
+ fs.writeFileSync(`plugin/${plginTemp}.js`, newContent);
238
+ }
239
+
206
240
  /**
207
241
  * 编译文件,将vue编译为js文件
208
242
  * @param {编译对象信息} obj
@@ -15,7 +15,7 @@ const { getNewVersionName, pushCodeAndTags } = require("../utils/pushCode")
15
15
  // 触发构建器
16
16
  const { jenkins } = require("../utils/trigger")
17
17
  // 通知飞书
18
- const { notifyFeishu, notifyDingDing } = require("../utils/notifyIM")
18
+ const { notifyDingDing } = require("../utils/notifyIM")
19
19
  // 时间库
20
20
  const dayjs = require("dayjs")
21
21
  // 多语言更新脚本
@@ -103,15 +103,12 @@ class Publish {
103
103
  }
104
104
  // 4:开始打包
105
105
  this.build(condition)
106
-
107
- // 7:写入版本信息
108
- // writeVersion("sdf", condition.type, projectConfig, this.user);
109
106
  }
110
107
  }
111
108
 
112
109
  /**
113
110
  * 编译代码
114
- * @param {发布类型} types:Dev,uat,Release,GA,RC
111
+ * @param {发布类型} types:Dev,uat,RC
115
112
  * @returns
116
113
  */
117
114
  build(condition) {
@@ -210,7 +207,7 @@ class Publish {
210
207
  if (projectConfig && projectConfig.config) {
211
208
  jenkins(projectConfig.config["jenkins-" + condition.type])
212
209
  }
213
- notifyFeishu(condition.type, version, projectConfig, this.user)
210
+ // notifyFeishu(condition.type, version, projectConfig, this.user)
214
211
  notifyDingDing(condition.type, version, projectConfig, this.user)
215
212
  console.log();
216
213
  console.log(chalk.green('发布完成'));
@@ -0,0 +1,223 @@
1
+ const { execSync, exec } = require('child_process');
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, askTypeOther, askBuildType } = require("../utils/askTool")
13
+ // 提交代码,设置Tag
14
+ const { getNewVersionName, pushCodeAndTags } = require("../utils/pushCode")
15
+ // 触发构建器
16
+ const { yunxiao } = require("../utils/trigger")
17
+ // 通知飞书
18
+ const { notifyDingDing } = require("../utils/notifyIM")
19
+ // 时间库
20
+ const dayjs = require("dayjs")
21
+ // 多语言更新脚本
22
+ const { updatei18n, askI18n } = require("../utils/updatei18n")
23
+ // 部署脚本
24
+ const { deploy } = require("../utils/deploy")
25
+ // 创建版本信息
26
+ const { writeVersion } = require("../utils/writeVersion")
27
+ /**
28
+ * 项目打包发布脚本
29
+ */
30
+ class Publish {
31
+ constructor() {
32
+ /**
33
+ * 控制台参数:key=value
34
+ * type:发布的tag
35
+ * branch:使用的分支
36
+ * language:是否更新多语言,'1'更新,'0'不更新
37
+ * buildType:打包方式,online-云打包,local-本地打包
38
+ * user:打包用户
39
+ * update:代码不同步的时候,是否强制更新代码
40
+ */
41
+ this.args = new Map();
42
+ this.arguments = process.argv.splice(2).map((item) => {
43
+ let arr = item.split("=");
44
+ this.args.set(arr[0], arr[1]);
45
+ });
46
+ this.user = this.args.get("user") || execSync("git config user.name").toString("utf8").trim();
47
+ }
48
+ /**
49
+ * 初始化
50
+ */
51
+ async init() {
52
+ // 检查cli版本,提示用户更新:false:不更新,true:更新
53
+ let update = await checkUpdate();
54
+ if (!update) {
55
+ // 1:版本发布信息,包含发布版本类型信息
56
+ let condition = {};
57
+ // 检查命令行是否输入了发布版本信息,如果没有包含,那么询问发布类型
58
+ if (this.args.get("type")) {
59
+ condition.type = this.args.get("type")
60
+ } else {
61
+ // 询问发布类型
62
+ condition = await askType();
63
+ if ("other" == condition.type) {
64
+ condition = await askTypeOther();
65
+ }
66
+ }
67
+
68
+ // 1.1:询问打包方式
69
+ let buildType = null;
70
+ if (this.args.get("buildType")) {
71
+ buildType = this.args.get("buildType")
72
+ } else {
73
+ buildType = await askBuildType();
74
+ }
75
+ if ("online" == buildType.buildType) {
76
+ deploy(projectConfig.config["deploy-" + condition.type] + "," + encodeURI(this.user))
77
+ console.log(chalk.green("云发布已开始,请稍后查看通知"))
78
+ return
79
+ }
80
+ // 2:如果命令行包含了分支信息,那么git切换到命令行的分支
81
+ if (this.args.get("branch")) {
82
+ execSync(`git checkout ${this.args.get("branch")}`);
83
+ console.log(chalk.green("切换分支:" + this.args.get("branch")))
84
+ console.log()
85
+ }
86
+
87
+ // 3:如果存在多语言配置,则更新多语言
88
+ if (projectConfig.config && projectConfig.config["language-config"]) {
89
+ // 获得命令行多语言参数
90
+ let i18n = this.args.get("language")
91
+ // 如果存在命令行参数,那么获取,否则询问
92
+ if (!i18n) {
93
+ i18n = await askI18n()
94
+ }
95
+ // 如果选择为1,那么下载多语言
96
+ if ('1' === i18n || '1' === i18n.checked) {
97
+ let laguage = projectConfig.config["language-config"]
98
+ // 执行更新多语言文件
99
+ await updatei18n(laguage)
100
+ console.log(chalk.blue("多语言文件更新完毕,准备开始打包"));
101
+ console.log();
102
+ }
103
+ }
104
+ // 4:开始打包
105
+ this.build(condition)
106
+ }
107
+ }
108
+
109
+ /**
110
+ * 编译代码
111
+ * @param {发布类型} types:Stable/Latest/GA
112
+ * @returns
113
+ */
114
+ build(condition) {
115
+ console.log(chalk.green('开始编译,请稍后...'));
116
+ console.log();
117
+ // 5:获取新的发布版本号
118
+ let version = getNewVersionName([condition.type])
119
+ // 5.1:将版本信息写入env文件中,公其他业务使用
120
+ try {
121
+ fs.writeFileSync(".env.production", "VUE_APP_OUT_PUT_DIR = build \nVUE_APP_PROJECT_VERSION = " + condition.type + "-" + version, 'utf-8')
122
+ } catch (error) {
123
+ }
124
+ let that = this;
125
+ // 打包命令
126
+ exec('npm run build', (error, stdout, stderr) => {
127
+ if (error) {
128
+ exec('npx vue-cli-service build', (error, stdout, stderr) => {
129
+ if (error) {
130
+ console.log('编译失败:', error);
131
+ console.log(chalk.red('编译失败:' + stdout));
132
+ } else {
133
+ console.log(chalk.green('编译成功!'));
134
+ console.log();
135
+ that.buildSucess(condition, version);
136
+ }
137
+ })
138
+ } else {
139
+ console.log(chalk.green('编译成功!'));
140
+ console.log();
141
+ that.buildSucess(condition, version);
142
+ }
143
+ })
144
+
145
+ }
146
+
147
+
148
+ /**
149
+ * 编译成功回调
150
+ */
151
+ buildSucess(condition, version) {
152
+ // 5.2:更新日志文档添加发布日期
153
+ // 获得分支信息
154
+ let branch = execSync('git branch --show-current');
155
+ branch = branch.toString("utf8").trim();
156
+ const datas = fs.readFileSync("README.md", 'utf-8').split("\n")
157
+ let data = ""
158
+ datas.map((item, index) => {
159
+ if (0 == index) {
160
+ data = data + `#### 发布版本:${version}` + "\n"
161
+ data = data + `#### 发布时间:${dayjs().format('YYYY-MM-DD HH:mm:ss')}` + "\n"
162
+ data = data + `#### 发布人员:${this.user}` + "\n"
163
+ data = data + `#### 发布分支:${branch}` + "\n"
164
+ data = data + `#### 发布标签:${condition.type}` + "\n"
165
+ if (!item.startsWith("#### 发布版本")) {
166
+ data = data + item + "\n"
167
+ }
168
+ } else if (1 == index) {
169
+ if (!item.startsWith("#### 发布时间")) {
170
+ data = data + item + "\n"
171
+ }
172
+ } else if (2 == index) {
173
+ if (!item.startsWith("#### 发布人员")) {
174
+ data = data + item + "\n"
175
+ }
176
+ } else if (3 == index) {
177
+ if (!item.startsWith("#### 发布分支")) {
178
+ data = data + item + "\n"
179
+ }
180
+ } else if (4 == index) {
181
+ if (!item.startsWith("#### 发布标签")) {
182
+ data = data + item + "\n"
183
+ }
184
+ } else {
185
+ data = data + item + "\n"
186
+ }
187
+ })
188
+ fs.writeFileSync("README.md", data)
189
+ // 6:将readme生成为html,并复制到dist中
190
+ let outPath = "build/dist"
191
+ // 读取配置,是否改变了输出路径
192
+ if (projectConfig.config && projectConfig.config["doc-path"]) {
193
+ outPath = projectConfig.config["doc-path"];
194
+ }
195
+ try {
196
+ // 设置readme文件位置
197
+ change("README", outPath, "README");
198
+ } catch (error) {
199
+ console.log(chalk.red("README写入异常:" + error))
200
+ }
201
+ try {
202
+ // 7:写入版本信息
203
+ writeVersion(version, condition.type, projectConfig, this.user, branch, "build/dist");
204
+ } catch (error) {
205
+ console.log(chalk.red("版本信息写入异常:" + error))
206
+ }
207
+ // 8:发布代码并设置tags,触发发布,飞书提醒
208
+ if (pushCodeAndTags(version, [condition.type], this.args.get("update"), "build")) {
209
+ if (projectConfig && projectConfig.config) {
210
+ yunxiao(projectConfig.config["jenkins-" + condition.type])
211
+ }
212
+ // notifyFeishu(condition.type, version, projectConfig, this.user)
213
+ notifyDingDing(condition.type, version, projectConfig, this.user)
214
+ console.log();
215
+ console.log(chalk.green('发布完成'));
216
+ console.log();
217
+ }
218
+ }
219
+ }
220
+
221
+ module.exports = Publish;
222
+
223
+
@@ -0,0 +1,224 @@
1
+ const { execSync, exec } = require('child_process');
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, askTypeOther, askBuildType } = require("../utils/askTool")
13
+ // 提交代码,设置Tag
14
+ const { getNewVersionName, pushCodeAndTags } = require("../utils/pushCode")
15
+ // 触发构建器
16
+ const { yunxiao } = require("../utils/trigger")
17
+ // 通知飞书
18
+ const { notifyDingDing } = require("../utils/notifyIM")
19
+ // 时间库
20
+ const dayjs = require("dayjs")
21
+ // 文件夹操作工具
22
+ const fsex = require('fs-extra')
23
+ /**
24
+ * H5项目打包发布脚本
25
+ */
26
+ class Publish {
27
+ constructor() {
28
+ /**
29
+ * 控制台参数:key=value
30
+ * type:发布的tag
31
+ * branch:使用的分支
32
+ * language:是否更新多语言,'1'更新,'0'不更新
33
+ * buildType:打包方式,online-云打包,local-本地打包
34
+ * user:打包用户
35
+ * update:代码不同步的时候,是否强制更新代码
36
+ */
37
+ this.args = new Map();
38
+ this.arguments = process.argv.splice(2).map((item) => {
39
+ let arr = item.split("=");
40
+ this.args.set(arr[0], arr[1]);
41
+ });
42
+ this.user = this.args.get("user") || execSync("git config user.name").toString("utf8").trim();
43
+ }
44
+ /**
45
+ * 初始化
46
+ */
47
+ async init() {
48
+ // 检查cli版本,提示用户更新:false:不更新,true:更新
49
+ let update = await checkUpdate();
50
+ if (!update) {
51
+ // 1:版本发布信息,包含发布版本类型信息
52
+ let condition = {};
53
+ // 2:检查命令行是否输入了发布版本信息,如果没有包含,那么询问发布类型
54
+ if (this.args.get("type")) {
55
+ condition.type = this.args.get("type")
56
+ } else {
57
+ // 询问发布类型
58
+ condition = await askType();
59
+ if ("other" == condition.type) {
60
+ condition = await askTypeOther();
61
+ }
62
+ }
63
+ // 3:获取新的发布版本号
64
+ let version = getNewVersionName([condition.type])
65
+ console.log();
66
+ console.log(chalk.green('待发布版本:' + version));
67
+ console.log();
68
+ // 4:开始打包
69
+ this.build(condition, version)
70
+ }
71
+ }
72
+ /**
73
+ * 编译代码
74
+ * @param {发布类型} types:Dev,uat,Release,GA,RC
75
+ * @param {发布版本} versions:V12.0.0
76
+ * @returns
77
+ */
78
+ build(condition, version) {
79
+ // 删除多余文件夹
80
+ fsex.removeSync("./build/dist")
81
+ console.log(chalk.green('开始编译,请稍后...'));
82
+ console.log();
83
+ let that = this;
84
+ // 当时mac系统时使用mac路径命令,当时window系统时,使用window命令路径
85
+ let path = "cli.exe"
86
+ if (process.platform === 'darwin') {
87
+ path = "/Applications/HBuilderX.app/Contents/MacOS/cli"
88
+ }
89
+ exec(`${path} publish --platform h5 --project ` + projectConfig.name, (error, stdout, stderr) => {
90
+ if (error) {
91
+ console.log('编译失败:', error);
92
+ console.log(chalk.red('编译失败:' + stdout));
93
+ } else {
94
+ console.log(chalk.green('编译成功!'));
95
+ console.log();
96
+ that.buildSucess(condition, version);
97
+ }
98
+ })
99
+ }
100
+ /**
101
+ * 编译成功
102
+ */
103
+ buildSucess(condition, version) {
104
+ // 更新日志文档添加发布日期
105
+ // 获得分支信息
106
+ let branch = execSync('git branch --show-current');
107
+ branch = branch.toString("utf8").trim();
108
+ const datas = fs.readFileSync("README.md", 'utf-8').split("\n")
109
+ let data = ""
110
+ datas.map((item, index) => {
111
+ if (0 == index) {
112
+ data = data + `#### 发布版本:${version}` + "\n"
113
+ data = data + `#### 发布时间:${dayjs().format('YYYY-MM-DD HH:mm:ss')}` + "\n"
114
+ data = data + `#### 发布人员:${this.user}` + "\n"
115
+ data = data + `#### 发布分支:${branch}` + "\n"
116
+ data = data + `#### 发布标签:${condition.type}` + "\n"
117
+ if (!item.startsWith("#### 发布版本")) {
118
+ data = data + item + "\n"
119
+ }
120
+ } else if (1 == index) {
121
+ if (!item.startsWith("#### 发布时间")) {
122
+ data = data + item + "\n"
123
+ }
124
+ } else if (2 == index) {
125
+ if (!item.startsWith("#### 发布人员")) {
126
+ data = data + item + "\n"
127
+ }
128
+ } else if (3 == index) {
129
+ if (!item.startsWith("#### 发布分支")) {
130
+ data = data + item + "\n"
131
+ }
132
+ } else if (4 == index) {
133
+ if (!item.startsWith("#### 发布标签")) {
134
+ data = data + item + "\n"
135
+ }
136
+ } else {
137
+ data = data + item + "\n"
138
+ }
139
+ })
140
+ fs.writeFileSync("README.md", data)
141
+ // 5:将readme生成为html,并复制到dist中
142
+ let outPath = "dist"
143
+ // 读取配置,是否改变了输出路径
144
+ if (projectConfig.config && projectConfig.config["doc-path"]) {
145
+ outPath = projectConfig.config["doc-path"];
146
+ }
147
+ try {
148
+ // 设置readme文件位置
149
+ change("README", outPath);
150
+ } catch (error) {
151
+ console.log(chalk.red("README写入异常:" + error))
152
+ }
153
+
154
+ try {
155
+ // 6:写入版本信息
156
+ this.writeVersion(version, outPath, condition.type, branch);
157
+ } catch (error) {
158
+ console.log(chalk.red("版本信息写入异常:" + error))
159
+ }
160
+ // 移动打包文件
161
+ fsex.copySync('./unpackage/dist/build/h5/', './build/dist');
162
+ // 删除多余文件夹
163
+ fsex.removeSync("unpackage")
164
+
165
+ // 7:发布代码并设置tags,触发发布,飞书提醒
166
+ if (pushCodeAndTags(version, [condition.type], this.args.get("update"), "build")) {
167
+ if (projectConfig && projectConfig.config) {
168
+ yunxiao(projectConfig.config["jenkins-" + condition.type])
169
+ }
170
+ notifyDingDing(condition.type, version, projectConfig, this.user)
171
+ console.log();
172
+ console.log(chalk.green('发布完成'));
173
+ console.log();
174
+ }
175
+ }
176
+ /**
177
+ * 将版本信息写入文件
178
+ * @param {版本信息} version
179
+ * @param {输出路径} outPath
180
+ */
181
+ writeVersion(version, outPath, type, branch) {
182
+ try {
183
+ // 获得分支信息
184
+ let versionInfo =
185
+ `
186
+ <!DOCTYPE html>
187
+ <html lang="en">
188
+
189
+ <head>
190
+ <meta charset="UTF-8">
191
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
192
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
193
+ <title>版本信息</title>
194
+ </head>
195
+
196
+ <body>
197
+ <div style="font-size: 20px">
198
+ <div>${projectConfig.name}</div>
199
+ <div style="margin-left:48px">
200
+ <div>版本:${version}</div>
201
+ <div>时间:${dayjs().format('YYYY-MM-DD HH:mm:ss')}</div>
202
+ <div>人员:${this.user}</div>
203
+ <div>分支:${branch}</div>
204
+ <div>标签:${type}</div>
205
+ </div>
206
+ </div>
207
+ </body>
208
+
209
+ </html>
210
+ `
211
+ fs.writeFileSync(outPath + "/version.html", versionInfo, 'utf-8');
212
+
213
+ let versionInfoJson =
214
+ `{"projectName":"${projectConfig.name}","版本":"${version}","时间":"${dayjs().format('YYYY-MM-DD HH:mm:ss')}","人员":"${user}","分支":"${branch}","标签":"${type}"}`
215
+ fs.writeFileSync(outPath + "/version.json", versionInfoJson, 'utf-8');
216
+
217
+ return true
218
+ } catch (error) {
219
+ return false
220
+ }
221
+ };
222
+ }
223
+
224
+ module.exports = Publish;
package/utils/http.js CHANGED
@@ -68,6 +68,13 @@ module.exports = {
68
68
  params: data
69
69
  })
70
70
  },
71
+ postNormal: (url, data = {}) => {
72
+ return service({
73
+ url: url,
74
+ method: 'post',
75
+ data: data
76
+ })
77
+ },
71
78
  patch: (url, data = {}) => {
72
79
  return service({
73
80
  url: url,
package/utils/pushCode.js CHANGED
@@ -11,6 +11,7 @@ const changeVersion = require("../utils/changeVersion")
11
11
  function getNewVersionName(types) {
12
12
  exec("git fetch --tags -f")
13
13
  return types.map((item) => {
14
+
14
15
  // 更新本地tag
15
16
  let version = exec(`git tag --sort=-committerdate`)
16
17
  version = version.toString("utf8").trim();
@@ -44,17 +45,23 @@ function getNewVersionName(types) {
44
45
  * @param {update} 是否强制更新:1强制更新,0不强制更新
45
46
  * @returns true 成功,false 失败
46
47
  */
47
- function push(version, update = "0") {
48
+ function push(version, update = "0", path) {
48
49
  try {
49
50
  // 添加改变文件
50
- exec("git add .")
51
+ exec(`git -C ${path} add .`)
52
+ if ("." != path) {
53
+ exec(`git add .`)
54
+ }
51
55
  } catch (error) {
52
56
  return false;
53
57
  }
54
58
 
55
59
  try {
56
60
  // 提交到本地
57
- exec("git commit -m " + version)
61
+ exec(`git -C ${path} commit -m ` + version)
62
+ if ("." != path) {
63
+ exec(`git commit -m ` + version)
64
+ }
58
65
  } catch (error) {
59
66
  return false;
60
67
  }
@@ -63,13 +70,19 @@ function push(version, update = "0") {
63
70
  console.log(chalk.green('代码开始推送,请稍后...'));
64
71
  try {
65
72
  // 推送到服务器
66
- exec("git push")
73
+ exec(`git -C ${path} push`)
74
+ if ("." != path) {
75
+ exec(`git push`)
76
+ }
67
77
  console.log();
68
78
  console.log(chalk.green('代码推送成功!'));
69
79
  } catch (error) {
70
80
  console.log("update", update);
71
81
  if ("1" == update) {
72
- exec(`git fetch --tags -f && git pull --force && git push`)
82
+ exec(`git -C ${path} fetch --tags -f && git -C ${path} pull --force && git -C ${path} push`)
83
+ if ("." != path) {
84
+ exec(`git fetch --tags -f && git pull --force && git push`)
85
+ }
73
86
  console.log(chalk.green('代码推送成功!'));
74
87
  } else {
75
88
  console.log(chalk.red('代码推送失败,本地代码与线上不同步,请先 git pull 同步!'));
@@ -84,53 +97,54 @@ function push(version, update = "0") {
84
97
  * @param {types} 发布版本类型,如Dev,uat,GA,Release
85
98
  * @param {versions} 版本tag信息,如Dev-V12.0.1
86
99
  */
87
- function setTag(types, versions) {
100
+ function setTag(types, versions, path) {
88
101
  console.log(chalk.green('开始同步Tag设置,请稍后...'));
89
102
  try {
90
103
  // 更新tag
91
- exec("git fetch --tags -f")
104
+ exec(`git fetch --tags -f`)
92
105
  } catch (error) {
93
106
  return false;
94
107
  }
95
- // 删除本地版本Tag
108
+ // 删除本地版本版本Tag
96
109
  versions.map((version) => {
97
110
  try {
98
- exec("git tag -d " + version)
111
+ exec(`git tag -d ` + version)
99
112
  } catch (error) {
100
113
  }
101
114
  })
102
115
  types.map((type) => {
103
116
  try {
104
117
  // 删除本地发布Tag
105
- exec("git tag -d " + type)
118
+ exec(`git -C ${path} tag -d ` + type)
106
119
  } catch (error) {
107
120
  }
108
121
  })
109
122
  versions.map((version) => {
110
123
  try {
111
124
  // 删除远程Tag
112
- exec("git push origin :refs/tags/" + version)
125
+ exec(`git push origin :refs/tags/` + version)
113
126
  } catch (error) {
114
127
  }
115
128
  })
116
129
  types.map((type) => {
117
130
  try {
118
131
  // 删除远程发布Tag
119
- exec("git push origin :refs/tags/" + type)
132
+ exec(`git -C ${path} push origin :refs/tags/` + type)
120
133
  } catch (error) {
121
134
  }
122
135
  })
123
136
 
124
- // 添加tag
137
+ // 添加版本tag
125
138
  versions.map((version) => {
126
- exec("git tag " + version + " -f")
139
+ exec(`git tag ` + version + " -f")
127
140
  })
128
141
 
129
142
  types.map((type) => {
130
- exec("git tag " + type + " -f")
143
+ exec(`git -C ${path} tag ` + type + " -f")
131
144
  })
132
145
  // 推送tag
133
- exec("git push --tags")
146
+ exec(`git -C ${path} push --tags`)
147
+ exec(`git push --tags`)
134
148
 
135
149
  console.log(chalk.green('Tag设置成功!'));
136
150
  console.log();
@@ -140,37 +154,36 @@ function setTag(types, versions) {
140
154
  * 删除dist文件夹
141
155
  * @returns true 成功,false 失败
142
156
  */
143
- function deleteDist() {
144
-
157
+ function deleteDist(version, path) {
145
158
  try {
146
159
  // 删除dist文件夹
147
- exec("git rm -r dist")
160
+ exec(`git -C ${path} rm -r dist`)
148
161
  } catch (error) {
149
162
 
150
163
  }
151
164
 
152
165
  try {
153
166
  // 删除unpackage文件夹
154
- exec("git rm -r unpackage")
167
+ exec(`git -C ${path} rm -r unpackage`)
155
168
  } catch (error) {
156
169
 
157
170
  }
158
171
 
159
172
  try {
160
173
  // 添加改变文件
161
- exec("git add .")
174
+ exec(`git -C ${path} add .`)
162
175
  } catch (error) {
163
176
 
164
177
  }
165
178
 
166
179
  try {
167
180
  // 提交到本地
168
- exec("git commit -m clear-dist")
181
+ exec(`git -C ${path} commit -m clear-dist`)
169
182
  } catch (error) {
170
183
  }
171
184
  try {
172
185
  // 推送到服务器
173
- exec("git push")
186
+ exec(`git -C ${path} push`)
174
187
  } catch (error) {
175
188
 
176
189
  }
@@ -178,10 +191,12 @@ function deleteDist() {
178
191
  }
179
192
  /**
180
193
  * 发布代码同时设置Tags
194
+ * @param {versions} 版本信息
181
195
  * @param {types} 版本集合
182
196
  * @param {update} 是否强制更新
197
+ * @param {path} git运行目录
183
198
  */
184
- function pushCodeAndTags(versions, types = [], update = "0") {
185
- return push(versions[0], update) && setTag(types, versions) && deleteDist(versions[0]);
199
+ function pushCodeAndTags(versions, types = [], update = "0", path = ".") {
200
+ return push(versions[0], update, path) && setTag(types, versions, path) && deleteDist(versions[0], path);
186
201
  }
187
202
  module.exports = { pushCodeAndTags, push, getNewVersionName, setTag }
package/utils/trigger.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * 版本构建触发器
3
3
  */
4
4
 
5
- const { get } = require('../utils/http');
5
+ const { get, postNormal } = require('../utils/http');
6
6
 
7
7
  async function jenkins(url) {
8
8
  try {
@@ -12,4 +12,12 @@ async function jenkins(url) {
12
12
  return true
13
13
  }
14
14
 
15
- module.exports = { jenkins }
15
+ async function yunxiao(url) {
16
+ try {
17
+ await postNormal(url)
18
+ } catch (error) {
19
+ }
20
+ return true
21
+ }
22
+
23
+ module.exports = { jenkins, yunxiao }
@@ -8,11 +8,13 @@ const { execSync } = require('child_process');
8
8
  * @param {版本信息} version
9
9
  */
10
10
  module.exports = {
11
- writeVersion(version, type, projectConfig, user) {
11
+ writeVersion(version, type, projectConfig, user, branch, path = "dist") {
12
12
  try {
13
13
  // 获得分支信息
14
- let branch = execSync('git branch --show-current');
15
- branch = branch.toString("utf8").trim();
14
+ if (!branch) {
15
+ branch = execSync('git branch --show-current');
16
+ branch = branch.toString("utf8").trim();
17
+ }
16
18
  let versionInfo =
17
19
  `
18
20
  <!DOCTYPE html>
@@ -40,12 +42,11 @@ module.exports = {
40
42
 
41
43
  </html>
42
44
  `
43
- fs.writeFileSync("dist/version.html", versionInfo, 'utf-8');
44
-
45
+ fs.writeFileSync(path + "/version.html", versionInfo, 'utf-8');
45
46
  let versionInfoJson =
46
47
  `{"serviceName":"${projectConfig.name}","status":"OK","codeVersion":"${projectConfig.codeVersion + version}","serviceType":"${projectConfig.serviceType}"}`
47
- fs.mkdirSync("dist/ccmonitor", { recursive: true });
48
- fs.writeFileSync("dist/ccmonitor/sck", versionInfoJson, 'utf-8');
48
+ fs.mkdirSync(path + "/ccmonitor", { recursive: true });
49
+ fs.writeFileSync(path + "/ccmonitor/sck", versionInfoJson, 'utf-8');
49
50
  return true
50
51
  } catch (error) {
51
52
  console.log(error)
package/utils/test.js DELETED
@@ -1,2 +0,0 @@
1
- const fs = require('fs')
2
- const exec = require('child_process').execSync;