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);
}