|
| 1 | +import fs from 'fs'; |
| 2 | +import path from 'path'; |
| 3 | + |
| 4 | +// ファイルパスの設定 |
| 5 | +const README_PATH = path.join(process.cwd(), 'themes/develop/README.md'); |
| 6 | +const PACKAGE_PATH = path.join(process.cwd(), 'themes/develop/package.json'); |
| 7 | + |
| 8 | +// バージョン番号を抽出する正規表現 |
| 9 | +const VERSION_REGEX = /Ver\.(\d+\.\d+\.\d+)/; |
| 10 | + |
| 11 | +// ファイルを読み込む関数 |
| 12 | +function readFile(filePath) { |
| 13 | + try { |
| 14 | + return fs.readFileSync(filePath, 'utf8'); |
| 15 | + } catch (error) { |
| 16 | + console.error(`Error reading file ${filePath}:`, error); |
| 17 | + process.exit(1); |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +// ファイルを書き込む関数 |
| 22 | +function writeFile(filePath, content) { |
| 23 | + try { |
| 24 | + fs.writeFileSync(filePath, content, 'utf8'); |
| 25 | + } catch (error) { |
| 26 | + console.error(`Error writing file ${filePath}:`, error); |
| 27 | + process.exit(1); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +// バージョン番号を更新する関数 |
| 32 | +function updateVersion() { |
| 33 | + // package.jsonからバージョン番号を取得 |
| 34 | + const packageContent = readFile(PACKAGE_PATH); |
| 35 | + const packageJson = JSON.parse(packageContent); |
| 36 | + const version = packageJson.version; |
| 37 | + console.log(`Found version ${version} in package.json`); |
| 38 | + |
| 39 | + // README.mdを読み込んで更新 |
| 40 | + const readmeContent = readFile(README_PATH); |
| 41 | + const currentVersionMatch = readmeContent.match(VERSION_REGEX); |
| 42 | + |
| 43 | + if (!currentVersionMatch) { |
| 44 | + console.error('Version number not found in README.md'); |
| 45 | + process.exit(1); |
| 46 | + } |
| 47 | + |
| 48 | + const currentVersion = currentVersionMatch[1]; |
| 49 | + if (currentVersion !== version) { |
| 50 | + // バージョン番号を更新 |
| 51 | + const updatedContent = readmeContent.replace(VERSION_REGEX, `Ver.${version}`); |
| 52 | + writeFile(README_PATH, updatedContent); |
| 53 | + console.log(`Updated README.md version to ${version}`); |
| 54 | + } else { |
| 55 | + console.log('Versions are already in sync'); |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +// スクリプトを実行 |
| 60 | +updateVersion(); |
0 commit comments