mayurankv_Obsidian-Code-Styler/version-bump.mjs

34 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2023-01-25 20:38:33 +00:00
import { readFileSync, writeFileSync } from "fs";
2023-08-12 15:48:22 +00:00
import { exec } from "child_process";
2023-01-25 20:38:33 +00:00
2023-08-12 15:48:22 +00:00
// Get new version
const newVersion = process.env.npm_package_version;
2023-01-25 20:38:33 +00:00
2023-08-12 15:48:22 +00:00
// Read minAppVersion from manifest.json and bump version to target version
2023-01-25 20:38:33 +00:00
let manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
const { minAppVersion } = manifest;
2023-08-12 15:48:22 +00:00
manifest.version = newVersion;
2023-01-25 20:38:33 +00:00
writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t"));
2023-08-12 15:48:22 +00:00
// Update versions.json with target version and minAppVersion from manifest.json
2023-01-25 20:38:33 +00:00
let versions = JSON.parse(readFileSync("versions.json", "utf8"));
2023-08-12 15:48:22 +00:00
versions[newVersion] = minAppVersion;
2023-01-25 20:38:33 +00:00
writeFileSync("versions.json", JSON.stringify(versions, null, "\t"));
2023-08-12 15:48:22 +00:00
// Update CHANGELOG.md
2023-08-20 17:29:40 +00:00
let changelogText = readFileSync("CHANGELOG.md", "utf8");
const lastVersion = /\[Unreleased\]: \/..\/..\/compare\/(\d+.\d+.\d+)...HEAD/.exec(changelogText)?.[1] ?? "0.0.0";
process.env.release_notes = /(?<=## \[Unreleased\])[\s\S]*?\n(?=## )/.exec(changelogText)[0].trim();
writeFileSync("CHANGELOG.md",changelogText.replace(/## \[Unreleased\]/,`## [Unreleased]\n\n## [${newVersion}] - ${new Date().toISOString().slice(0, 10)}`).replace(/(?<=\[Unreleased\]: \/..\/..\/compare\/)(\d+.\d+.\d+)...HEAD/,`${newVersion}...HEAD\n[${newVersion}]: /../../compare/${lastVersion}...${newVersion}`));
2023-08-12 15:48:22 +00:00
2023-08-24 20:15:24 +00:00
// Update settings
let settingsText = readFileSync("src/settings.ts", "utf8");
const settingsUpdaterText = /const settingsUpdaters: Record<string,\(settings: CodeStylerSettings\)=>CodeStylerSettings> = {[\s\S]*?\n(?=})/.exec(settingsText)?.[0];
2024-02-23 13:31:54 +00:00
writeFileSync("src/settings.ts",settingsText.replace(/(?<=export const DEFAULT_SETTINGS: CodeStylerSettings = {[\s\S]*?version: ")(.*)(?="[\s\S]*?})/,newVersion).replace(settingsUpdaterText,settingsUpdaterText+(settingsUpdaterText.split("\n").some(line=>line.trim().startsWith(`"${lastVersion}"`))?"":`\t"${lastVersion}": settingsPreserve,\n`)));
2023-08-24 20:15:24 +00:00
2023-08-12 15:48:22 +00:00
// Push to origin
2023-08-30 19:34:56 +00:00
exec(`git add . && git commit -m 'Ready release ${newVersion}' && git push && git tag -a $npm_package_version -F- <<EOF && git push origin $npm_package_version
2023-08-12 15:48:22 +00:00
$release_notes
2023-08-15 12:57:35 +00:00
EOF`,(error)=>console.log(error));