diff --git a/package.json b/package.json index 6a5e457..f38ad85 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "lint": "biome check .", "lint:fix": "biome check . --write", "prerelease": "turbo run build", - "release": "changeset publish", + "release": "node scripts/release-if-needed.mjs", "build-storybook": "turbo run build-storybook" }, "devDependencies": { diff --git a/scripts/release-if-needed.mjs b/scripts/release-if-needed.mjs new file mode 100644 index 0000000..0deaafa --- /dev/null +++ b/scripts/release-if-needed.mjs @@ -0,0 +1,27 @@ +import { execFileSync } from "node:child_process"; +import { readFileSync } from "node:fs"; + +const publishablePackages = ["packages/components/package.json"]; + +const unpublishedPackages = publishablePackages.filter((packagePath) => { + const localPackage = JSON.parse(readFileSync(packagePath, "utf8")); + + try { + const exactVersion = execFileSync( + "npm", + ["view", `${localPackage.name}@${localPackage.version}`, "version"], + { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }, + ).trim(); + + return exactVersion !== localPackage.version; + } catch { + return true; + } +}); + +if (unpublishedPackages.length === 0) { + console.log("All publishable package versions are already on npm."); + process.exit(0); +} + +execFileSync("yarn", ["changeset", "publish"], { stdio: "inherit" });