Skip to content

Commit

Permalink
バージョン更新用のコードを設置
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba committed Oct 22, 2024
1 parent 792eec6 commit 7f13eb7
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
109 changes: 109 additions & 0 deletions src/updateVersion.ts
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 7f13eb7

Please sign in to comment.