Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into 指定されているVVPPがなかったら確認…
Browse files Browse the repository at this point in the history
…後にインストールし、使えるようにするようにする
  • Loading branch information
Hiroshiba committed Nov 7, 2024
2 parents b74cce6 + 4689cf8 commit b2434d6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/backend/electron/engineAndVvppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
EngineSettingType,
} from "@/type/preload";
import {
EnginePackage,
EngineVariant,
fetchLatestDefaultEngineInfo,
getSuitablePackage,
getSuitableVariant,
} from "@/domain/defaultEngine/latetDefaultEngine";
import {
EnvEngineInfoType,
Expand Down Expand Up @@ -148,7 +148,7 @@ export class EngineAndVvppController {
async fetchEngineAndPackageInfosToInstall(): Promise<
{
envEngineInfo: EnvEngineInfoType;
packageInfo: EnginePackage;
packageInfo: EngineVariant;
}[]
> {
// .envのデフォルトエンジン情報のうち、downloadVvppなものを集める
Expand All @@ -168,7 +168,7 @@ export class EngineAndVvppController {
continue;
}

const packageInfo = getSuitablePackage(latestInfo);
const packageInfo = getSuitableVariant(latestInfo);
log.info(`Latest default engine version: ${packageInfo.version}`);

// インストール済みだった場合はスキップ
Expand All @@ -190,7 +190,7 @@ export class EngineAndVvppController {
/** VVPPパッケージをダウンロードし、インストールする */
async downloadAndInstallVvppEngine(
downloadDir: string,
packageInfo: EnginePackage,
packageInfo: EngineVariant,
) {
// ダウンロード
const downloadedPaths = new Array<string>(packageInfo.packages.length);
Expand Down
24 changes: 12 additions & 12 deletions src/domain/defaultEngine/latetDefaultEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { z } from "zod";

/** パッケージ情報のスキーマ */
const enginePackageSchema = z.object({
const engineVariantSchema = z.object({
version: z.string(),
packages: z
.object({
Expand All @@ -16,34 +16,34 @@ const enginePackageSchema = z.object({
})
.array(),
});
export type EnginePackage = z.infer<typeof enginePackageSchema>;
export type EngineVariant = z.infer<typeof engineVariantSchema>;

/** デフォルトエンジンの更新情報のスキーマ */
/** デフォルトエンジンの最新情報のスキーマ */
const latestDefaultEngineInfoSchema = z.object({
formatVersion: z.number(),
windows: z.object({
x64: z.object({
CPU: enginePackageSchema,
"GPU/CPU": enginePackageSchema,
CPU: engineVariantSchema,
"GPU/CPU": engineVariantSchema,
}),
}),
macos: z.object({
x64: z.object({
CPU: enginePackageSchema,
CPU: engineVariantSchema,
}),
arm64: z.object({
CPU: enginePackageSchema,
CPU: engineVariantSchema,
}),
}),
linux: z.object({
x64: z.object({
CPU: enginePackageSchema,
"GPU/CPU": enginePackageSchema,
CPU: engineVariantSchema,
"GPU/CPU": engineVariantSchema,
}),
}),
});

/** デフォルトエンジンの更新情報を取得する */
/** デフォルトエンジンの最新情報を取得する */
export const fetchLatestDefaultEngineInfo = async (url: string) => {
const response = await fetch(url);
return latestDefaultEngineInfoSchema.parse(await response.json());
Expand All @@ -53,9 +53,9 @@ export const fetchLatestDefaultEngineInfo = async (url: string) => {
* 実行環境に合うパッケージを取得する。GPU版があればGPU版を返す。
* FIXME: どのデバイス版にするかはユーザーが選べるようにするべき。
*/
export const getSuitablePackage = (
export const getSuitableVariant = (
updateInfo: z.infer<typeof latestDefaultEngineInfoSchema>,
): EnginePackage => {
): EngineVariant => {
const platform = process.platform;
const arch = process.arch;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
// テスト用のファイルを読み込むのでNode環境で実行する

import path from "path";
import fs from "fs";
import latestDefaultEngineInfos from "./latestDefaultEngineInfos.json";
import { fetchLatestDefaultEngineInfo } from "@/domain/defaultEngine/latetDefaultEngine";

const currentDir = "tests/unit/domain/defaultEngine";

test("fetchLatestDefaultEngineInfo", async () => {
// テスト用のjsonファイルでfetchをモックする
// 元ファイルは https://raw.githubusercontent.com/VOICEVOX/voicevox_blog/master/src/generateLatestDefaultEngineInfos.ts
const p = path.resolve(currentDir, "latestDefaultEngineInfos.json");
const json = fs.readFileSync(p, "utf-8");
const spy = vi.spyOn(global, "fetch").mockResolvedValue(new Response(json));
const spy = vi
.spyOn(global, "fetch")
.mockResolvedValue(new Response(JSON.stringify(latestDefaultEngineInfos)));

// 読み込めることを確認
const infos = await fetchLatestDefaultEngineInfo("https://example.com/");
Expand Down

0 comments on commit b2434d6

Please sign in to comment.