feat(commands): add release script customizability (#12)

This commit is contained in:
2023-12-16 15:22:43 +02:00
parent c80d763259
commit f4a7a0d2bc
4 changed files with 75 additions and 15 deletions

View File

@@ -424,24 +424,40 @@ program
const config = await GetConfig();
const sign = config?.autoSignReleases || options.sign ? true : false;
const version = string.replace("v", "");
const packageFile = JSON.parse(
(
await fs.promises.readFile(path.join(process.cwd(), "package.json"))
).toString()
);
if (!packageFile) {
console.log("[rcz]: this directory does not have a package.json file");
const onReleaseFile = (
await fs.promises.readFile(
path.join(process.cwd(), ".rczrc.onrelease.js")
)
).toString();
if (onReleaseFile) {
const releaseScript = `
const __NEW_VERSION__ = "${version}";
const __IS_SIGNED__ = ${sign};
${onReleaseFile}`;
eval(releaseScript);
} else {
const packageFile = JSON.parse(
(
await fs.promises.readFile(path.join(process.cwd(), "package.json"))
).toString()
);
if (!packageFile) {
console.log("[rcz]: this directory does not have a package.json file");
}
packageFile.version = version;
await fs.promises.writeFile(
path.join(process.cwd(), "package.json"),
JSON.stringify(packageFile, null, 4)
);
}
packageFile.version = version;
await fs.promises.writeFile(
path.join(process.cwd(), "package.json"),
JSON.stringify(packageFile, null, 4)
);
await simpleGit()
.add(".")
.commit(`chore(release): v${version}`, sign ? ["-S"] : [])