@plugin-light/cli 1.0.16 → 1.0.19

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
@@ -5,8 +5,8 @@
5
5
  <img src="https://img.shields.io/npm/unpacked-size/@plugin-light/cli">
6
6
  <img src="https://img.shields.io/npm/v/@plugin-light/cli">
7
7
  <img src="https://img.shields.io/npm/l/@plugin-light/cli">
8
- <img src="https://img.shields.io/github/last-commit/novlan1/plugin-light">
9
- <img src="https://img.shields.io/github/created-at/novlan1/plugin-light">
8
+ <img src="https://img.shields.io/badge/TypeScript-strict-blue?logo=typescript&logoColor=white" alt="TypeScript strict">
9
+ <img src="https://img.shields.io/badge/created-2022--01-blue?logo=github&logoColor=white">
10
10
  </p>
11
11
 
12
12
  可以在 `nodejs` 或 `bash` 中使用。
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "@plugin-light/cli",
3
- "version": "1.0.16",
3
+ "version": "1.0.19",
4
+ "description": "本地发布",
5
+ "keywords": [
6
+ "plugin-light",
7
+ "plugin-light-cli"
8
+ ],
4
9
  "homepage": "https://novlan1.github.io/docs/plugin-light/zh/plugin-light-cli.html",
5
10
  "bugs": {
6
11
  "url": "https://github.com/novlan1/plugin-light/issues"
@@ -24,9 +29,9 @@
24
29
  "@tdesign/uniapp": "^0.7.3",
25
30
  "@tdesign/uniapp-chat": "^0.2.1",
26
31
  "axios": "^1.12.2",
27
- "t-comm": "^3.0.24",
28
- "@plugin-light/const": "^0.1.4",
29
- "@plugin-light/shared": "^1.0.24"
32
+ "t-comm": "latest",
33
+ "@plugin-light/const": "^0.1.6",
34
+ "@plugin-light/shared": "^1.0.25"
30
35
  },
31
36
  "publishConfig": {
32
37
  "access": "public",
@@ -48,20 +48,30 @@ function toPublish({
48
48
  doCommand('pnpm run init');
49
49
  }
50
50
 
51
- releaseCore({
52
- version: versionType,
53
- pwd,
54
-
55
- needVersionTip,
56
- ignoreBuild,
57
- ignorePublish,
58
- });
51
+ let releaseOk = false;
52
+ try {
53
+ releaseCore({
54
+ version: versionType,
55
+ pwd,
56
+
57
+ needVersionTip,
58
+ ignoreBuild,
59
+ ignorePublish,
60
+ });
61
+ releaseOk = true;
62
+ } catch (e) {
63
+ console.error('🚀 [release] releaseCore failed:', (e && e.message) || e);
64
+ // 保守策略:发布过程任何阶段失败 → 不 push commit、不 push tag,由人工介入
65
+ process.exitCode = 1;
66
+ }
59
67
 
60
- if (!ignorePushOrigin) {
68
+ if (!ignorePushOrigin && releaseOk) {
61
69
  doCommand('git remote remove origin');
62
70
  doCommand(`git remote add origin git@git.a.com:${repo}.git`);
63
71
  doCommand(`git push origin ${branch}`);
64
72
  doCommand('git push origin --tags');
73
+ } else if (!releaseOk) {
74
+ console.error('🚀 [release] release failed, skip git push (both commit and tag).');
65
75
  }
66
76
  }
67
77
 
@@ -4,6 +4,7 @@
4
4
  // pnpm --filter="pixui-runtime" release beta --ignoreBuild --ignorePublish
5
5
  // pnpm --filter="pixui-runtime" release beta --ignoreBuild --ignorePublish --needVersionTip
6
6
 
7
+ const { execSync } = require('child_process');
7
8
  const path = require('path');
8
9
 
9
10
  const { execCommand, readFileSync, writeFileSync, getNextVersion } = require('t-comm');
@@ -16,6 +17,39 @@ function log(...args) {
16
17
  console.log('🚀 [release] ', ...args);
17
18
  }
18
19
 
20
+ /**
21
+ * 检测 tag 是否存在(同时检测本地与远程 origin)
22
+ * 任一存在即视为存在
23
+ */
24
+ function tagExists(tag) {
25
+ // 1) 本地 tag
26
+ try {
27
+ const localOut = execSync(`git tag -l ${tag}`, { encoding: 'utf8' }).trim();
28
+ if (localOut === tag) {
29
+ return true;
30
+ }
31
+ } catch (e) {
32
+ // 本地命令失败不阻塞,继续判断远程
33
+ log(`[tagExists] local check error: ${e.message}`);
34
+ }
35
+
36
+ // 2) 远程 tag
37
+ try {
38
+ const remoteOut = execSync(`git ls-remote --tags origin refs/tags/${tag}`, {
39
+ encoding: 'utf8',
40
+ stdio: ['ignore', 'pipe', 'ignore'],
41
+ }).trim();
42
+ if (remoteOut.includes(`refs/tags/${tag}`)) {
43
+ return true;
44
+ }
45
+ } catch (e) {
46
+ // 远程不可达时保守认为不存在,让后续 git tag 自己报错
47
+ log(`[tagExists] remote check error: ${e.message}`);
48
+ }
49
+
50
+ return false;
51
+ }
52
+
19
53
 
20
54
  function packageBuild(pkgName) {
21
55
  log(`build ${pkgName}`);
@@ -27,11 +61,20 @@ function packageBuild(pkgName) {
27
61
  function bumpVersion({
28
62
  pwd,
29
63
  pkgName,
64
+ purePkgName,
30
65
  version,
31
66
  }) {
32
67
  log(`origin version is ${version}`);
33
68
 
34
- const newVersion = getNextVersion(pkgName, version);
69
+ const newVersion = getNextVersion(pkgName, version, {
70
+ checkTagExists: (v) => {
71
+ const exists = tagExists(`${purePkgName}@${v}`);
72
+ if (exists) {
73
+ log(`⚠️ tag ${purePkgName}@${v} already exists, will bump again`);
74
+ }
75
+ return exists;
76
+ },
77
+ });
35
78
  log(`new version is ${newVersion}`);
36
79
 
37
80
  const jsonFile = path.resolve(pwd, './package.json');
@@ -58,8 +101,15 @@ function doChangeLog(pwd, pkgName) {
58
101
 
59
102
 
60
103
  function genTag(purePkgName, newVersion) {
61
- log('new version is ', newVersion);
62
- execCommand(`git tag ${purePkgName}@${newVersion}`, process.cwd(), 'inherit');
104
+ const tag = `${purePkgName}@${newVersion}`;
105
+ log('new tag is ', tag);
106
+
107
+ // 双保险:bumpVersion 已经做了避让,这里再校验一次,避免极端竞态
108
+ if (tagExists(tag)) {
109
+ throw new Error(`tag ${tag} 已存在,发布中断(请检查 npm dist-tag 与 git tag 是否一致)`);
110
+ }
111
+
112
+ execCommand(`git tag ${tag}`, process.cwd(), 'inherit');
63
113
  }
64
114
 
65
115
 
@@ -84,7 +134,9 @@ function getPublishTag(version) {
84
134
  function publish({ pkgName, version }) {
85
135
  const tag = getPublishTag(version);
86
136
  log(`publish tag is ${tag}`);
87
- execCommand(`pnpm --filter=${pkgName} publish ${tag ? `--tag ${tag}` : ''} --no-git-checks`, process.cwd(), 'inherit');
137
+ execCommand(`pnpm --filter=${pkgName} publish ${tag ? `--tag ${tag}` : ''} --no-git-checks`, process.cwd(), 'inherit', {
138
+ throwError: true,
139
+ });
88
140
  }
89
141
 
90
142
  /**
@@ -127,6 +179,7 @@ function releaseCore({
127
179
  const newVersion = bumpVersion({
128
180
  pwd,
129
181
  pkgName,
182
+ purePkgName,
130
183
  version,
131
184
  });
132
185
 
@@ -139,6 +192,8 @@ function releaseCore({
139
192
  pwd,
140
193
  });
141
194
 
195
+ // genTag 失败会直接抛错,下方 publish/sendVersionTip 不会执行;
196
+ // 调用方(pipeline-release)应在 catch 中跳过 push commit / push tag
142
197
  genTag(purePkgName, newVersion);
143
198
 
144
199
  if (!ignorePublish) {
@@ -151,6 +206,12 @@ function releaseCore({
151
206
  if (needVersionTip) {
152
207
  sendVersionTip(pwd);
153
208
  }
209
+
210
+ return {
211
+ pkgName,
212
+ purePkgName,
213
+ newVersion,
214
+ };
154
215
  }
155
216
 
156
217
  module.exports = {
@@ -1,11 +1,17 @@
1
- const { batchSendWxRobotMarkdown, genVersionTip } = require('t-comm');
1
+ const {
2
+ batchSendWxRobotMarkdown,
3
+ genVersionTip,
4
+ resolveNpmLink,
5
+ collectPackageSize,
6
+ } = require('t-comm');
2
7
 
3
8
 
4
- function sendVersionTip({
9
+ async function sendVersionTip({
5
10
  readmeFilePath,
6
11
  appInfo,
7
12
  publisher,
8
13
  webhookUrl,
14
+ registry,
9
15
  }) {
10
16
  console.log('[webhookUrl]: ', webhookUrl);
11
17
  if (!webhookUrl) {
@@ -13,11 +19,16 @@ function sendVersionTip({
13
19
  return;
14
20
  }
15
21
 
22
+ const packageSize = await collectPackageSize(appInfo, { registry });
23
+
16
24
  const content = genVersionTip({
17
25
  appInfo,
18
- showNpmLink: false,
26
+ showNpmLink: true,
19
27
  readmeFilePath,
20
28
  publisher: publisher || process.env.creator || '',
29
+ pipelineUrl: process.env.BK_CI_BUILD_URL || '',
30
+ packageSize,
31
+ npmLink: resolveNpmLink(appInfo.name),
21
32
  });
22
33
 
23
34
  console.log('content:\n', content);
@@ -32,4 +43,3 @@ function sendVersionTip({
32
43
  module.exports = {
33
44
  sendVersionTip,
34
45
  };
35
-