From db02de97210969f5d721607aa6a824def56e45fe Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Wed, 23 Oct 2024 01:37:46 +0900 Subject: [PATCH] =?UTF-8?q?add:=20=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E6=9B=B4=E6=96=B0=E7=94=A8=E3=81=AE=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=82=92=E8=A8=AD=E7=BD=AE=20(#227)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 17 ++++++- package.json | 1 + src/updateVersion.ts | 109 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 src/updateVersion.ts 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()