@taole/deploy-helper 0.7.4-beta.4 → 0.7.4-beta.6
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/lib/tagRelease.mjs +42 -13
- package/package.json +1 -1
package/lib/tagRelease.mjs
CHANGED
|
@@ -12,16 +12,34 @@ async function getTag(workDir, mode) {
|
|
|
12
12
|
);
|
|
13
13
|
const prefix = getTagNamePrefix(packageJson, mode);
|
|
14
14
|
const git = simpleGit(workDir);
|
|
15
|
-
|
|
15
|
+
let tags = await git.tags(["-n", "--sort=-creatordate"]); // 按照创建时间排序,最新的在前
|
|
16
16
|
// console.log(`tags: ${JSON.stringify(tags)}`);
|
|
17
|
-
|
|
17
|
+
tags = tags.all
|
|
18
|
+
.filter((tag) => tag.startsWith(prefix))
|
|
19
|
+
.slice(0, 15) // 最多显示15个tag
|
|
20
|
+
.map((tag) => {
|
|
21
|
+
// tag是一个字符串, 从左到右找到第一个空格, 这个空格以前的内容就是tag的名称, 以后的如有, 取出来当作commit信息,并考虑tag无空格的情况
|
|
22
|
+
const spaceIndex = tag.indexOf(" ");
|
|
23
|
+
let commitInfo = "";
|
|
24
|
+
let tagName = tag;
|
|
25
|
+
if (spaceIndex !== -1) {
|
|
26
|
+
commitInfo = (tag.slice(spaceIndex + 1) || "").trim();
|
|
27
|
+
tagName = tag.slice(0, spaceIndex);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
name: tagName,
|
|
31
|
+
commitInfo: commitInfo,
|
|
32
|
+
rawTag: tag,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
// console.log(`formated tags: ${JSON.stringify(tags)}`);
|
|
18
36
|
let tag = null;
|
|
19
|
-
if (
|
|
37
|
+
if (tags.length > 0) {
|
|
20
38
|
const propmtConfig = {
|
|
21
39
|
message: "请选择要回滚的tag版本: ",
|
|
22
|
-
choices:
|
|
23
|
-
name: item,
|
|
24
|
-
value: item,
|
|
40
|
+
choices: tags.map((item) => ({
|
|
41
|
+
name: item.rawTag,
|
|
42
|
+
value: item.name,
|
|
25
43
|
})),
|
|
26
44
|
};
|
|
27
45
|
try {
|
|
@@ -44,19 +62,25 @@ function getTagNamePrefix(packageJson, mode) {
|
|
|
44
62
|
|
|
45
63
|
function getTagName(packageJson, commitId, mode) {
|
|
46
64
|
const prefix = getTagNamePrefix(packageJson, mode);
|
|
65
|
+
let tagName = prefix;
|
|
47
66
|
const date = new Date();
|
|
48
67
|
const timeStr =
|
|
68
|
+
date.getFullYear() +
|
|
69
|
+
"-" +
|
|
49
70
|
date.getMonth() +
|
|
50
71
|
1 +
|
|
51
|
-
"
|
|
72
|
+
"-" +
|
|
52
73
|
date.getDate() +
|
|
53
|
-
"
|
|
74
|
+
"-" +
|
|
54
75
|
date.getHours() +
|
|
55
|
-
"
|
|
76
|
+
"-" +
|
|
56
77
|
date.getMinutes() +
|
|
57
|
-
"
|
|
78
|
+
"-" +
|
|
58
79
|
date.getSeconds();
|
|
59
|
-
|
|
80
|
+
// tagName += `@${packageJson.version}`;
|
|
81
|
+
tagName += `_${commitId.slice(0, 8)}`;
|
|
82
|
+
tagName += `_${timeStr}`;
|
|
83
|
+
return tagName;
|
|
60
84
|
}
|
|
61
85
|
|
|
62
86
|
/**
|
|
@@ -164,6 +188,10 @@ async function createRelease(workDir, config, mode) {
|
|
|
164
188
|
|
|
165
189
|
const git = simpleGit(workDir);
|
|
166
190
|
const commitId = await git.revparse("HEAD");
|
|
191
|
+
const commitMessage = (
|
|
192
|
+
await git.raw(["log", "-1", "--format=%s", commitId])
|
|
193
|
+
).trim();
|
|
194
|
+
|
|
167
195
|
log(`commitId: ${commitId}`);
|
|
168
196
|
|
|
169
197
|
const cleanfunc = async () => {
|
|
@@ -183,7 +211,7 @@ async function createRelease(workDir, config, mode) {
|
|
|
183
211
|
Object.keys(entryFiles).forEach((key) => {
|
|
184
212
|
const file = key;
|
|
185
213
|
const htmlFilePath = path.join(workDir, file);
|
|
186
|
-
log(`htmlFilePath: ${htmlFilePath}`);
|
|
214
|
+
// log(`htmlFilePath: ${htmlFilePath}`);
|
|
187
215
|
if (fs.existsSync(htmlFilePath)) {
|
|
188
216
|
const destFile = `_${file}`;
|
|
189
217
|
fs.cpSync(htmlFilePath, path.join(releaseDir, destFile), {
|
|
@@ -198,7 +226,8 @@ async function createRelease(workDir, config, mode) {
|
|
|
198
226
|
);
|
|
199
227
|
|
|
200
228
|
await git.add(releaseDir);
|
|
201
|
-
await git.commit("-#DH-2
|
|
229
|
+
// await git.commit("-#DH-2 --> ${commitMessage}");
|
|
230
|
+
await git.commit(commitMessage || `-#DH-2 ${commitId.slice(0, 8)}`);
|
|
202
231
|
// log(`commitResult: ${JSON.stringify(commitResult)}`);
|
|
203
232
|
|
|
204
233
|
const packageJson = JSON.parse(
|