check-beta-mode.js
1 #!/usr/bin/env node 2 3 /** 4 * Check if we're in beta mode and exit if needed for stable releases 5 */ 6 7 const fs = require("node:fs"); 8 const path = require("node:path"); 9 const { execSync } = require("node:child_process"); 10 11 const preJsonPath = path.join(__dirname, "..", ".changeset", "pre.json"); 12 13 function isInBetaMode() { 14 return fs.existsSync(preJsonPath); 15 } 16 17 function exitBetaMode() { 18 console.log("⚠️ Detected beta mode. Exiting beta mode for stable release..."); 19 try { 20 execSync("bun run changeset:exit-beta", { 21 stdio: "inherit", 22 cwd: path.join(__dirname, ".."), 23 }); 24 console.log("✅ Successfully exited beta mode"); 25 return true; 26 } catch (error) { 27 console.error("❌ Failed to exit beta mode:", error.message); 28 return false; 29 } 30 } 31 32 if (require.main === module) { 33 const mode = process.argv[2]; 34 35 if (mode === "check") { 36 if (isInBetaMode()) { 37 console.log("⚠️ Warning: Currently in beta mode!"); 38 console.log( 39 " To create a stable release, beta mode will be exited first.", 40 ); 41 console.log( 42 " If you want to create a beta release instead, use: bun run release:beta", 43 ); 44 process.exit(1); 45 } else { 46 console.log("✅ Not in beta mode - ready for stable release"); 47 process.exit(0); 48 } 49 } else if (mode === "exit-if-beta") { 50 if (isInBetaMode()) { 51 const success = exitBetaMode(); 52 if (!success) { 53 process.exit(1); 54 } 55 } else { 56 console.log("✅ Not in beta mode - proceeding with stable release"); 57 } 58 } else { 59 console.log("Usage: node check-beta-mode.js [check|exit-if-beta]"); 60 process.exit(1); 61 } 62 } 63 64 module.exports = { isInBetaMode, exitBetaMode };