diff --git a/README.md b/README.md index 12a358f3..0fb291f6 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,22 @@ Netlify を使ってプレビュー環境デプロイを行っています。 npm run preview-build ``` -## add resource +## リソース情報の更新 + +コードの更新 + +```bash +EDITOR_VERSION="0.21.0" +RESOURCE_VERSION="0.21.0" +NEMO_VERSION="0.21.0" + +npm run updateVersion -- \ + --editor_version="$EDITOR_VERSION" \ + --resource_version="$RESOURCE_VERSION" \ + --nemo_version="$NEMO_VERSION" +``` + +リソースの更新 ```bash editor_tag="0.21.0" diff --git a/package.json b/package.json index f905af36..55be14fd 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1", "generateThumb": "tsx ./src/generateThumb.ts", "generateLatestDefaultEngineInfos": "tsx ./src/generateLatestDefaultEngineInfos.ts", + "updateVersion": "tsx ./src/updateVersion.ts", "deploy": "gatsby build && gh-pages -d public" }, "repository": { diff --git a/src/updateVersion.ts b/src/updateVersion.ts new file mode 100644 index 00000000..5848e341 --- /dev/null +++ b/src/updateVersion.ts @@ -0,0 +1,109 @@ +/** + * このブログからダウンロードするVOICEVOXのバージョンを更新するスクリプト。 + * 複数箇所に書かれているバージョンを書き換える必要があり、それを一括で行える。 + */ + +import yargs from "yargs" +import { hideBin } from "yargs/helpers" + +import fs from "fs" + +const argv = yargs(hideBin(process.argv)) + .option("editor_version", { + type: "string", + }) + .option("resource_version", { + type: "string", + }) + .option("nemo_version", { + type: "string", + }) + .help() + .parse() + +function updateFile(path: string, before: RegExp, after: string) { + if (!fs.existsSync(path)) { + throw new Error(`ファイルが存在しません: パス "${path}"`) + } + + const file = fs.readFileSync(path, "utf-8") + if (!before.test(file)) { + throw new Error( + `置き換え対象が存在しません: パス "${path}": 正規表現 "${before}"` + ) + } + + const updated = file.replace(before, after) + fs.writeFileSync(path, updated) +} + +async function main() { + const editorVersion = (await argv).editor_version + const resourceVersion = (await argv).resource_version + const nemoVersion = (await argv).nemo_version + + console.log(`editor_version: ${editorVersion}`) + console.log(`resource_version: ${resourceVersion}`) + console.log(`nemo_version: ${nemoVersion}`) + + // README.md + if (editorVersion != undefined) { + updateFile( + "./README.md", + /editor_tag=".*?"/, + `editor_tag="${editorVersion}"` + ) + } + if (resourceVersion != undefined) { + updateFile( + "./README.md", + /resource_tag=".*?"/, + `resource_tag="${resourceVersion}"` + ) + } + + // src/constants.ts + if (editorVersion != undefined) { + updateFile( + "./src/constants.ts", + /export const APP_VERSION = ".*?"/, + `export const APP_VERSION = "${editorVersion}"` + ) + } + if (nemoVersion != undefined) { + updateFile( + "./src/constants.ts", + /export const NEMO_VERSION = ".*?"/, + `export const NEMO_VERSION = "${nemoVersion}"` + ) + } + + // src/scripts/linuxInstallCpu.sh + if (editorVersion != undefined) { + updateFile( + "./src/scripts/linuxInstallCpu.sh", + /VOICEVOX\/voicevox\/.*?\//, + `VOICEVOX/voicevox/${editorVersion}/` + ) + updateFile( + "./src/scripts/linuxInstallCpu.sh", + /VERSION=.*?\s/, + `VERSION=${editorVersion} ` + ) + } + + // src/scripts/linuxInstallNvidia.sh + if (editorVersion != undefined) { + updateFile( + "./src/scripts/linuxInstallNvidia.sh", + /VOICEVOX\/voicevox\/.*?\//, + `VOICEVOX/voicevox/${editorVersion}/` + ) + updateFile( + "./src/scripts/linuxInstallNvidia.sh", + /VERSION=.*?\s/, + `VERSION=${editorVersion} ` + ) + } +} +main()