From cd3f27a748643a29a4c22240718ea90c84a91292 Mon Sep 17 00:00:00 2001 From: Samrith Shankar Date: Sun, 10 Dec 2023 19:29:09 +0530 Subject: [PATCH] chore: update release process --- .release-it.json | 8 +++++++- scripts/release.ts | 49 +++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/.release-it.json b/.release-it.json index f7a9f1d..bf75aef 100644 --- a/.release-it.json +++ b/.release-it.json @@ -1,6 +1,12 @@ { "git": { - "commitMessage": "release: v${version}" + "commitMessage": "release: v${version}", + "commitArgs": ["--no-verify"], + "requireCleanWorkingDir": false, + "push": false + }, + "npm": { + "release": true }, "github": { "release": true diff --git a/scripts/release.ts b/scripts/release.ts index 769469d..f12f006 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -1,13 +1,14 @@ /* eslint-disable @typescript-eslint/no-var-requires */ import { spawnSync } from "child_process"; -// import fs from "fs"; -// import path from "path"; +import fs from "fs"; +import path from "path"; import pkg from "../package.json"; const argv = process.argv.slice(2); -// const ROOT = path.resolve(__dirname, ".."); +const ROOT = path.resolve(__dirname, ".."); +const PKG_JSON_PATH = path.resolve(ROOT, "package.json"); /** * Clean up package.json @@ -18,27 +19,35 @@ const pkgClone: Partial = { delete pkgClone.dependencies; delete pkgClone.devDependencies; -delete pkgClone.files; delete pkgClone.scripts; delete pkgClone["lint-staged"]; -delete pkgClone.publishConfig; -// fs.writeFileSync( -// path.resolve(ROOT, "package.json"), -// JSON.stringify(pkgClone, null, 2) -// ); +fs.writeFileSync( + PKG_JSON_PATH, + [JSON.stringify(pkgClone, null, 2), "\n"].join("") +); /** * Execute release */ -spawnSync("yarn", ["release-it", ...argv], { - stdio: "inherit", -}); - -/** - * Restore package.json - */ -// fs.writeFileSync( -// path.resolve(ROOT, "package.json"), -// JSON.stringify(pkg, null, 2) -// ); +try { + spawnSync("yarn", ["release-it", ...argv], { + stdio: "inherit", + }); + + spawnSync("git", ["reset", "--soft", "HEAD~1"], { + stdio: "inherit", + }); + spawnSync("git", ["restore", "--staged", PKG_JSON_PATH], { + stdio: "inherit", + }); + spawnSync("git", ["commit", "-c", "ORIG_HEAD"], { + stdio: "inherit", + }); +} catch (e) { + console.error(e); + fs.writeFileSync( + PKG_JSON_PATH, + [JSON.stringify(pkg, null, 2), "\n"].join("") + ); +}