Skip to content
This repository was archived by the owner on Jul 24, 2025. It is now read-only.

Commit 29df332

Browse files
committed
chore: release script
1 parent eacb4ae commit 29df332

File tree

6 files changed

+84
-11
lines changed

6 files changed

+84
-11
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,3 @@ jobs:
2727
path: ~/.cache/ms-playwright
2828
- run: pnpm playwright install chromium
2929
- run: pnpm ci
30-
- uses: ArnaudBarre/[email protected]
31-
if: ${{ contains(github.event.head_commit.message, '[publish]') && github.ref == 'refs/heads/main' }}
32-
with:
33-
working-directory: dist
34-
npm-token: ${{ secrets.NPM_TOKEN }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Publish changelog
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
ci:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: ArnaudBarre/github-release@v1

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
2-
"name": "@vitejs/plugin-react-swc",
2+
"name": "@vitejs/plugin-react-swc-monorepo",
33
"version": "3.0.0",
4-
"license": "MIT",
4+
"private": true,
55
"scripts": {
66
"dev": "scripts/bundle.ts --dev",
77
"build": "scripts/bundle.ts",
88
"test": "playwright test",
99
"prettier": "pnpm prettier-ci --write",
1010
"prettier-ci": "prettier --cache --ignore-path=.gitignore --check '**/*.{js,jsx,ts,tsx,html,css,json,md,yml}'",
11-
"ci": "tsc && pnpm prettier-ci && pnpm build && cd playground && tsc && cd .. && pnpm test"
11+
"ci": "tsc && pnpm prettier-ci && pnpm build && cd playground && tsc && cd .. && pnpm test",
12+
"release": "scripts/release.ts"
1213
},
1314
"prettier": {
1415
"trailingComma": "all"
@@ -17,7 +18,7 @@
1718
"@swc/core": "^1.3.22"
1819
},
1920
"peerDependencies": {
20-
"vite": "^4.0.0"
21+
"vite": "^4"
2122
},
2223
"devDependencies": {
2324
"@nabla/tnode": "^0.8.0",
@@ -26,6 +27,7 @@
2627
"@types/node": "^18.11.13",
2728
"esbuild": "^0.16.4",
2829
"fs-extra": "^11.1.0",
30+
"picocolors": "^1.0.0",
2931
"prettier": "^2.8.1",
3032
"typescript": "^4.9.4",
3133
"vite": "^4.0.0"

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/bundle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ module.exports.default = react;`,
5959
"dist/package.json",
6060
JSON.stringify(
6161
{
62-
name: packageJSON.name,
62+
name: "@vitejs/plugin-react-swc",
6363
description: "Speed up your Vite dev server with SWC",
6464
version: packageJSON.version,
6565
author: "Arnaud Barré (https://github.com/ArnaudBarre)",
66-
license: packageJSON.license,
66+
license: "MIT",
6767
repository: "github:vitejs/vite-plugin-react-swc",
6868
main: "index.cjs",
6969
types: "index.d.ts",

scripts/release.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env tnode
2+
import { readFileSync, writeFileSync } from "node:fs";
3+
import {
4+
execSync,
5+
ExecSyncOptionsWithBufferEncoding,
6+
} from "node:child_process";
7+
import { stdin, stdout } from "node:process";
8+
import { createInterface } from "node:readline";
9+
import * as colors from "picocolors";
10+
11+
async function main(): Promise<void> {
12+
run("pnpm i --loglevel error");
13+
const packageJSON = JSON.parse(readFileSync("package.json", "utf-8")) as {
14+
version: string;
15+
};
16+
const changelog = readFileSync("CHANGELOG.md", "utf-8");
17+
if (!changelog.includes("## Unreleased")) {
18+
throw new Error("Can't find '## Unreleased' section in CHANGELOG.md");
19+
}
20+
21+
console.log(colors.cyan("Changelog:"));
22+
const index = changelog.indexOf("## Unreleased") + 13;
23+
console.log(
24+
colors.dim(changelog.slice(index, changelog.indexOf("## ", index)).trim()),
25+
);
26+
27+
console.log(
28+
colors.cyan("Current version: ") + colors.magenta(packageJSON.version),
29+
);
30+
const newVersion = (await ask(colors.cyan(`New version: `))).trim();
31+
if (!newVersion) throw new Error("No version provided");
32+
33+
console.log(colors.dim("Write package.json & CHANGELOG.md"));
34+
packageJSON.version = newVersion;
35+
writeFileSync("package.json", JSON.stringify(packageJSON, null, 2) + "\n");
36+
writeFileSync(
37+
"CHANGELOG.md",
38+
changelog.replace("## Unreleased", `## Unreleased\n\n## ${newVersion}`),
39+
);
40+
41+
run(`git commit -am "release: v${newVersion}"`);
42+
run(`git tag v${newVersion}`);
43+
run("pnpm build");
44+
run("npm publish", { cwd: "dist" });
45+
run("git push --tags");
46+
}
47+
48+
const ask = (question: string) =>
49+
new Promise<string>((res) =>
50+
createInterface({ input: stdin, output: stdout }).question(question, res),
51+
);
52+
53+
const run = (cmd: string, opts?: ExecSyncOptionsWithBufferEncoding) => {
54+
console.log(colors.dim(`$ ${cmd}`));
55+
execSync(cmd, { stdio: "inherit", ...opts });
56+
};
57+
58+
main().catch((err) => {
59+
console.error(err);
60+
process.exit(1);
61+
});

0 commit comments

Comments
 (0)