|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import fs from "fs"; |
| 4 | +import { execSync } from "child_process"; |
| 5 | + |
| 6 | +// Helper function to run shell commands |
| 7 | +function runCommand(command) { |
| 8 | + try { |
| 9 | + execSync(command, { stdio: "inherit" }); |
| 10 | + } catch (error) { |
| 11 | + console.error(`❌ Error running command: ${command}`); |
| 12 | + process.exit(1); |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +// Read package.json and increment the alpha version |
| 17 | +async function getNextAlphaVersion() { |
| 18 | + const packageJsonPath = "./package.json"; |
| 19 | + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); |
| 20 | + |
| 21 | + let currentVersion = packageJson.version; |
| 22 | + const match = currentVersion.match(/^(\d+\.\d+\.\d+)(-alpha\.(\d+))?$/); |
| 23 | + |
| 24 | + if (!match) { |
| 25 | + console.error("❌ Invalid version format in package.json."); |
| 26 | + process.exit(1); |
| 27 | + } |
| 28 | + |
| 29 | + let baseVersion = match[1]; |
| 30 | + let alphaNumber = match[3] ? parseInt(match[3]) + 1 : 0; |
| 31 | + let newVersion = `${baseVersion}-alpha.${alphaNumber}`; |
| 32 | + |
| 33 | + // Update package.json with new version |
| 34 | + packageJson.version = newVersion; |
| 35 | + fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); |
| 36 | + |
| 37 | + console.log(`🔹 Updated package.json to version: ${newVersion}`); |
| 38 | + return newVersion; |
| 39 | +} |
| 40 | + |
| 41 | +// Main release process |
| 42 | +async function releaseAlpha() { |
| 43 | + console.log("🚀 Starting Alpha Release Process..."); |
| 44 | + |
| 45 | + // Ensure the working directory is clean |
| 46 | + runCommand("git status"); |
| 47 | + |
| 48 | + // Get next alpha version |
| 49 | + const newVersion = await getNextAlphaVersion(); |
| 50 | + |
| 51 | + // Commit changes |
| 52 | + runCommand("git add package.json"); |
| 53 | + runCommand(`git commit -m "Bump version to ${newVersion}"`); |
| 54 | + |
| 55 | + // Create a git tag |
| 56 | + runCommand(`git tag -a ${newVersion} -m "Alpha release for ${newVersion}"`); |
| 57 | + runCommand("git push origin --tags"); |
| 58 | + |
| 59 | + // Publish to npm with alpha tag |
| 60 | + runCommand("npm publish --tag alpha"); |
| 61 | + |
| 62 | + console.log(`✅ Alpha release ${newVersion} published successfully!`); |
| 63 | +} |
| 64 | + |
| 65 | +// Execute the release function |
| 66 | +releaseAlpha(); |
0 commit comments