diff --git a/package.json b/package.json index 2fccdb1..7a68dc6 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "dev": "tauri --config src/backend/tauri.conf.json dev", "build": "tauri --config src/backend/tauri.conf.json build", "tauri": "tauri --config src/backend/tauri.conf.json", + "release": "node scripts/release.js", "test:watch": "bun test --watch test/**/*.test.js" }, "devDependencies": { diff --git a/scripts/release.js b/scripts/release.js new file mode 100644 index 0000000..a6cf51a --- /dev/null +++ b/scripts/release.js @@ -0,0 +1,69 @@ +import { execSync } from 'child_process'; +import fs from 'fs'; +import path from 'path'; + +/** + * リリース自動化スクリプト + * 1. バージョンのバリデーション + * 2. リリースブランチの作成 (release/vX.Y.Z) + * 3. 各設定ファイルのバージョン更新 + * 4. コミット + */ + +const newVersion = process.argv[2]; + +if (!newVersion || !/^\d+\.\d+\.\d+$/.test(newVersion)) { + console.error('❌ Error: 有効なバージョン番号を指定してください (例: 0.2.0)'); + process.exit(1); +} + +const projectRoot = process.cwd(); +const branchName = `release/v${newVersion}`; + +console.log(`🚀 Starting release process for v${newVersion}...`); + +try { + // 1. ブランチ作成 + console.log(`\n--- Creating branch: ${branchName} ---`); + execSync(`git checkout -b ${branchName}`, { stdio: 'inherit' }); + + // 2. package.json の更新 + console.log('\n--- Updating package.json ---'); + const pkgPath = path.join(projectRoot, 'package.json'); + const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')); + pkg.version = newVersion; + fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n'); + console.log('✅ Updated package.json'); + + // 3. src/backend/tauri.conf.json の更新 + console.log('\n--- Updating tauri.conf.json ---'); + const tauriPath = path.join(projectRoot, 'src', 'backend', 'tauri.conf.json'); + const tauri = JSON.parse(fs.readFileSync(tauriPath, 'utf-8')); + tauri.version = newVersion; + fs.writeFileSync(tauriPath, JSON.stringify(tauri, null, 2) + '\n'); + console.log('✅ Updated tauri.conf.json'); + + // 4. src/backend/Cargo.toml の更新 (regex で置換) + console.log('\n--- Updating Cargo.toml ---'); + const cargoPath = path.join(projectRoot, 'src', 'backend', 'Cargo.toml'); + let cargo = fs.readFileSync(cargoPath, 'utf-8'); + cargo = cargo.replace(/^version = ".*?"/m, `version = "${newVersion}"`); + fs.writeFileSync(cargoPath, cargo); + console.log('✅ Updated Cargo.toml'); + + // 5. コミット + console.log('\n--- Committing changes ---'); + execSync('git add .', { stdio: 'inherit' }); + execSync(`git commit -m "chore: release v${newVersion}"`, { stdio: 'inherit' }); + console.log(`✅ Committed: chore: release v${newVersion}`); + + console.log(`\n✨ Success! Release branch ${branchName} is ready.`); + console.log('Next steps:'); + console.log(` 1. インストーラーをビルドして最終確認: bun run build`); + console.log(` 2. マスターブランチにマージ: git checkout master && git merge ${branchName}`); + console.log(` 3. リリースタグを打つ: git tag -a v${newVersion} -m "Release v${newVersion}"`); + +} catch (err) { + console.error('\n❌ Failed to process release:', err.message); + process.exit(1); +}