From a8e4b6e658ce89b050bb038e477f8a95adad2e17 Mon Sep 17 00:00:00 2001 From: Cho-P4 Date: Thu, 23 Jul 2026 01:29:04 +0800 Subject: [PATCH] fix(build): generate Suwayomi WebUI revision --- package.json | 3 ++- .../services/MaterialYouRevision.test.ts | 22 +++++++++++++++++++ .../theme/services/MaterialYouRevision.ts | 15 +++++++++++++ tools/scripts/writeWebUIRevision.ts | 16 ++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/features/theme/services/MaterialYouRevision.test.ts create mode 100644 src/features/theme/services/MaterialYouRevision.ts create mode 100644 tools/scripts/writeWebUIRevision.ts diff --git a/package.json b/package.json index e807f074..a01b1fab 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "setup": "pnpm i --frozen-lockfile && pnpm setup-env-files", "dev": "pnpm setup && vite", "preview": "pnpm setup && vite preview", - "build": "pnpm setup && vite build", + "build": "pnpm setup && vite build && pnpm build-revision", + "build-revision": "tsx tools/scripts/writeWebUIRevision.ts", "test": "pnpm test:material-you", "test:material-you": "tsx --test src/features/theme/services/*.test.ts", "build-md5": "find build -type f | sort | xargs md5sum | awk '{ print $1 }' | tr -d '\n' | md5sum| awk '{ print $1 }' > buildZip/md5sum ", diff --git a/src/features/theme/services/MaterialYouRevision.test.ts b/src/features/theme/services/MaterialYouRevision.test.ts new file mode 100644 index 00000000..6df6c5a1 --- /dev/null +++ b/src/features/theme/services/MaterialYouRevision.test.ts @@ -0,0 +1,22 @@ +/* + * Copyright (C) Contributors to the Suwayomi project + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +import assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; +import { formatWebUIRevision } from '@/features/theme/services/MaterialYouRevision.ts'; + +describe('formatWebUIRevision', () => { + it('matches the revision format required by Suwayomi custom WebUI builds', () => { + assert.equal(formatWebUIRevision(3356), 'r3356\n'); + }); + + it('rejects invalid git commit counts', () => { + assert.throws(() => formatWebUIRevision(0), /positive integer/); + assert.throws(() => formatWebUIRevision(4.5), /positive integer/); + }); +}); diff --git a/src/features/theme/services/MaterialYouRevision.ts b/src/features/theme/services/MaterialYouRevision.ts new file mode 100644 index 00000000..9ee1f67d --- /dev/null +++ b/src/features/theme/services/MaterialYouRevision.ts @@ -0,0 +1,15 @@ +/* + * Copyright (C) Contributors to the Suwayomi project + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +export const formatWebUIRevision = (commitCount: number): string => { + if (!Number.isInteger(commitCount) || commitCount < 1) { + throw new Error('WebUI revision commit count must be a positive integer'); + } + + return `r${commitCount}\n`; +}; diff --git a/tools/scripts/writeWebUIRevision.ts b/tools/scripts/writeWebUIRevision.ts new file mode 100644 index 00000000..3c949f67 --- /dev/null +++ b/tools/scripts/writeWebUIRevision.ts @@ -0,0 +1,16 @@ +/* + * Copyright (C) Contributors to the Suwayomi project + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +import { execFileSync } from 'node:child_process'; +import { writeFileSync } from 'node:fs'; +import { formatWebUIRevision } from '@/features/theme/services/MaterialYouRevision.ts'; + +const commitCount = Number(execFileSync('git', ['rev-list', 'HEAD', '--count'], { encoding: 'utf8' }).trim()); +const revisionPath = new URL('../../build/revision', import.meta.url); + +writeFileSync(revisionPath, formatWebUIRevision(commitCount), 'utf8');