Skip to content

Commit

Permalink
chore: update release process
Browse files Browse the repository at this point in the history
  • Loading branch information
samrith-s committed Dec 10, 2023
1 parent aa9b818 commit cd3f27a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
8 changes: 7 additions & 1 deletion .release-it.json
Original file line number Diff line number Diff line change
@@ -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
Expand Down
49 changes: 29 additions & 20 deletions scripts/release.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,27 +19,35 @@ const pkgClone: Partial<typeof pkg> = {

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("")
);
}

0 comments on commit cd3f27a

Please sign in to comment.