|
1 |
| -/** |
2 |
| - * 发版规范: |
3 |
| - * 1. 版本号由产品经理统一规定,如 2.0.0 |
4 |
| - * 2. 开发在修复 bug 时,在版本号后增加修复版本号,如 2.0.0-1、2.0.0-2 |
5 |
| - * |
6 |
| - * 注意: |
7 |
| - * 1. 如果在 develop 执行 release.js,则会自动同步发版 SYNC_RELEASE_BRANCHES 中的分支 |
8 |
| - * 2. 如果在其他分支中执行 release.js,则只会在当前分支发版(遵循 git work flow 的 hot-fix 工作法) |
9 |
| - * 3. 可以在通过命令行参数指定要发版的分支(分支名称用英文逗号间隔),如: npm run release --syncbranch develop,master |
10 |
| - */ |
11 |
| - |
12 |
| -// 在 develop 分支执行发版操作时,同步发版的分支 |
13 |
| -const SYNC_RELEASE_BRANCHES = [ |
14 |
| - "test", |
15 |
| - // "master" |
16 |
| -]; |
17 |
| - |
18 | 1 | /* eslint-disable @typescript-eslint/no-var-requires */
|
19 | 2 | const args = require("minimist")(process.argv.slice(2));
|
20 | 3 | const fs = require("fs");
|
@@ -53,20 +36,6 @@ function getCurrentBranch() {
|
53 | 36 | return res.stdout;
|
54 | 37 | }
|
55 | 38 |
|
56 |
| -// 验证需要同步的分支是否存在于远程仓库中 |
57 |
| -const getSyncBranches = () => { |
58 |
| - if (!args.syncbranch) return SYNC_RELEASE_BRANCHES; |
59 |
| - const inputBranch = args.syncbranch.split(","); |
60 |
| - const allRemoteBranch = execa.commandSync("git branch -r").stdout; |
61 |
| - inputBranch.forEach((branch) => { |
62 |
| - if (!allRemoteBranch.includes(branch)) { |
63 |
| - throw new Error(`远程仓库中没有此分支: ${branch}`); |
64 |
| - } |
65 |
| - }); |
66 |
| - return inputBranch; |
67 |
| -}; |
68 |
| -const syncBranch = getSyncBranches(); |
69 |
| - |
70 | 39 | async function main() {
|
71 | 40 | let targetVersion = args._[0];
|
72 | 41 |
|
@@ -113,9 +82,6 @@ async function main() {
|
113 | 82 | step("\nUpdating cross dependencies...");
|
114 | 83 | updateVersions(targetVersion);
|
115 | 84 |
|
116 |
| - step("publish all packages..."); |
117 |
| - await run("pnpm", ["run", "publish"]); |
118 |
| - |
119 | 85 | // // build all packages with types
|
120 | 86 | // step("\nBuilding all packages...");
|
121 | 87 | // if (!skipBuild && !isDryRun) {
|
@@ -143,42 +109,33 @@ async function main() {
|
143 | 109 | // 推送当前分支代码
|
144 | 110 | step(`\n[Branch ${getCurrentBranch()}] Pushing to GitLab...`);
|
145 | 111 | await runIfNotDry("git", ["tag", `v${targetVersion}`]);
|
146 |
| - await runIfNotDry("git", ["push", "origin", `refs/tags/v${targetVersion}`]); |
147 |
| - await runIfNotDry("git", ["push"]); |
148 |
| - |
149 |
| - // 如果当前是 develop 分支,则同步发版到 SYNC_RELEASE_BRANCHES 中所有分支 |
150 |
| - if (getCurrentBranch() == "develop") { |
151 |
| - for (const branch of syncBranch) { |
152 |
| - step(`\n[Branch ${branch}] Pushing to GitLab...`); |
153 |
| - runIfNotDry("git", ["push", branch, `refs/tags/v${targetVersion}`]); |
154 |
| - await runIfNotDry("git", ["checkout", branch]); |
155 |
| - await runIfNotDry("git", ["merge", "develop"]); |
156 |
| - await runIfNotDry("git", ["push"]); |
157 |
| - } |
158 |
| - await runIfNotDry("git", ["checkout", "develop"]); |
159 |
| - } |
| 112 | + // await runIfNotDry("git", ["push", "origin", `refs/tags/v${targetVersion}`]); |
| 113 | + // await runIfNotDry("git", ["push"]); |
160 | 114 | };
|
161 | 115 |
|
162 | 116 | await syncPushCode();
|
163 | 117 |
|
| 118 | + step("publish all packages..."); |
| 119 | + await run("pnpm", ["run", "publish"]); |
| 120 | + |
164 | 121 | if (isDryRun) {
|
165 | 122 | console.log("\nDry run finished - run git diff to see package changes.");
|
166 | 123 | }
|
167 | 124 |
|
168 | 125 | console.log();
|
169 | 126 | }
|
170 | 127 |
|
171 |
| -function updateVersions(version) { |
172 |
| - updatePackage(path.resolve(__dirname, "../"), version); |
173 |
| -} |
174 |
| - |
175 | 128 | function updatePackage(pkgRoot, version) {
|
176 | 129 | const pkgPath = path.resolve(pkgRoot, "package.json");
|
177 | 130 | const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
178 | 131 | pkg.version = version;
|
179 | 132 | fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
180 | 133 | }
|
181 | 134 |
|
| 135 | +function updateVersions(version) { |
| 136 | + updatePackage(path.resolve(__dirname, "../"), version); |
| 137 | +} |
| 138 | + |
182 | 139 | main().catch((err) => {
|
183 | 140 | updateVersions(currentVersion);
|
184 | 141 | console.error(err);
|
|
0 commit comments