diff --git a/package.json b/package.json index c47e430..a979222 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,9 @@ "generate": "nuxt generate", "postinstall": "nuxt prepare", "preview": "nuxt preview", + "release:patch": "node scripts/release.js patch", + "release:minor": "node scripts/release.js minor", + "release:major": "node scripts/release.js major", "tauri:build:debug": "tauri build --debug", "tauri": "tauri" }, diff --git a/scripts/release.js b/scripts/release.js new file mode 100755 index 0000000..22e50fe --- /dev/null +++ b/scripts/release.js @@ -0,0 +1,91 @@ +#!/usr/bin/env node + +import { readFileSync, writeFileSync } from 'fs'; +import { execSync } from 'child_process'; +import { fileURLToPath } from 'url'; +import { dirname, join } from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +const rootDir = join(__dirname, '..'); + +const versionType = process.argv[2]; + +if (!['patch', 'minor', 'major'].includes(versionType)) { + console.error('Usage: pnpm release '); + process.exit(1); +} + +// Read current package.json +const packageJsonPath = join(rootDir, 'package.json'); +const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); +const currentVersion = packageJson.version; + +if (!currentVersion) { + console.error('No version found in package.json'); + process.exit(1); +} + +// Parse version +const [major, minor, patch] = currentVersion.split('.').map(Number); + +// Calculate new version +let newVersion; +switch (versionType) { + case 'major': + newVersion = `${major + 1}.0.0`; + break; + case 'minor': + newVersion = `${major}.${minor + 1}.0`; + break; + case 'patch': + newVersion = `${major}.${minor}.${patch + 1}`; + break; +} + +console.log(`šŸ“¦ Bumping version from ${currentVersion} to ${newVersion}`); + +// Update package.json +packageJson.version = newVersion; +writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n'); +console.log('āœ… Updated package.json'); + +// Git operations +try { + // Check if there are uncommitted changes + const status = execSync('git status --porcelain', { encoding: 'utf8' }); + const hasOtherChanges = status + .split('\n') + .filter(line => line && !line.includes('package.json')) + .length > 0; + + if (hasOtherChanges) { + console.error('āŒ There are uncommitted changes besides package.json. Please commit or stash them first.'); + process.exit(1); + } + + // Add and commit package.json + execSync('git add package.json', { stdio: 'inherit' }); + execSync(`git commit -m "Bump version to ${newVersion}"`, { stdio: 'inherit' }); + console.log('āœ… Committed version bump'); + + // Create tag + execSync(`git tag v${newVersion}`, { stdio: 'inherit' }); + console.log(`āœ… Created tag v${newVersion}`); + + // Push changes and tag + console.log('šŸ“¤ Pushing to remote...'); + execSync('git push', { stdio: 'inherit' }); + execSync(`git push origin v${newVersion}`, { stdio: 'inherit' }); + console.log('āœ… Pushed changes and tag'); + + console.log('\nšŸŽ‰ Release v' + newVersion + ' created successfully!'); + console.log('šŸ“‹ GitHub Actions will now build and publish the release.'); +} catch (error) { + console.error('āŒ Git operation failed:', error.message); + // Rollback package.json changes + packageJson.version = currentVersion; + writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n'); + console.log('ā†©ļø Rolled back package.json changes'); + process.exit(1); +}