Skip to content

Commit

Permalink
chore: release script
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Dec 15, 2022
1 parent eacb4ae commit 29df332
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 11 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,3 @@ jobs:
path: ~/.cache/ms-playwright
- run: pnpm playwright install chromium
- run: pnpm ci
- uses: ArnaudBarre/[email protected]
if: ${{ contains(github.event.head_commit.message, '[publish]') && github.ref == 'refs/heads/main' }}
with:
working-directory: dist
npm-token: ${{ secrets.NPM_TOKEN }}
13 changes: 13 additions & 0 deletions .github/workflows/publish-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Publish changelog

on:
push:
tags:
- "v*"

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ArnaudBarre/github-release@v1
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "@vitejs/plugin-react-swc",
"name": "@vitejs/plugin-react-swc-monorepo",
"version": "3.0.0",
"license": "MIT",
"private": true,
"scripts": {
"dev": "scripts/bundle.ts --dev",
"build": "scripts/bundle.ts",
"test": "playwright test",
"prettier": "pnpm prettier-ci --write",
"prettier-ci": "prettier --cache --ignore-path=.gitignore --check '**/*.{js,jsx,ts,tsx,html,css,json,md,yml}'",
"ci": "tsc && pnpm prettier-ci && pnpm build && cd playground && tsc && cd .. && pnpm test"
"ci": "tsc && pnpm prettier-ci && pnpm build && cd playground && tsc && cd .. && pnpm test",
"release": "scripts/release.ts"
},
"prettier": {
"trailingComma": "all"
Expand All @@ -17,7 +18,7 @@
"@swc/core": "^1.3.22"
},
"peerDependencies": {
"vite": "^4.0.0"
"vite": "^4"
},
"devDependencies": {
"@nabla/tnode": "^0.8.0",
Expand All @@ -26,6 +27,7 @@
"@types/node": "^18.11.13",
"esbuild": "^0.16.4",
"fs-extra": "^11.1.0",
"picocolors": "^1.0.0",
"prettier": "^2.8.1",
"typescript": "^4.9.4",
"vite": "^4.0.0"
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scripts/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ module.exports.default = react;`,
"dist/package.json",
JSON.stringify(
{
name: packageJSON.name,
name: "@vitejs/plugin-react-swc",
description: "Speed up your Vite dev server with SWC",
version: packageJSON.version,
author: "Arnaud Barré (https://github.com/ArnaudBarre)",
license: packageJSON.license,
license: "MIT",
repository: "github:vitejs/vite-plugin-react-swc",
main: "index.cjs",
types: "index.d.ts",
Expand Down
61 changes: 61 additions & 0 deletions scripts/release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env tnode
import { readFileSync, writeFileSync } from "node:fs";
import {
execSync,
ExecSyncOptionsWithBufferEncoding,
} from "node:child_process";
import { stdin, stdout } from "node:process";
import { createInterface } from "node:readline";
import * as colors from "picocolors";

async function main(): Promise<void> {
run("pnpm i --loglevel error");
const packageJSON = JSON.parse(readFileSync("package.json", "utf-8")) as {
version: string;
};
const changelog = readFileSync("CHANGELOG.md", "utf-8");
if (!changelog.includes("## Unreleased")) {
throw new Error("Can't find '## Unreleased' section in CHANGELOG.md");
}

console.log(colors.cyan("Changelog:"));
const index = changelog.indexOf("## Unreleased") + 13;
console.log(
colors.dim(changelog.slice(index, changelog.indexOf("## ", index)).trim()),
);

console.log(
colors.cyan("Current version: ") + colors.magenta(packageJSON.version),
);
const newVersion = (await ask(colors.cyan(`New version: `))).trim();
if (!newVersion) throw new Error("No version provided");

console.log(colors.dim("Write package.json & CHANGELOG.md"));
packageJSON.version = newVersion;
writeFileSync("package.json", JSON.stringify(packageJSON, null, 2) + "\n");
writeFileSync(
"CHANGELOG.md",
changelog.replace("## Unreleased", `## Unreleased\n\n## ${newVersion}`),
);

run(`git commit -am "release: v${newVersion}"`);
run(`git tag v${newVersion}`);
run("pnpm build");
run("npm publish", { cwd: "dist" });
run("git push --tags");
}

const ask = (question: string) =>
new Promise<string>((res) =>
createInterface({ input: stdin, output: stdout }).question(question, res),
);

const run = (cmd: string, opts?: ExecSyncOptionsWithBufferEncoding) => {
console.log(colors.dim(`$ ${cmd}`));
execSync(cmd, { stdio: "inherit", ...opts });
};

main().catch((err) => {
console.error(err);
process.exit(1);
});

0 comments on commit 29df332

Please sign in to comment.