From 228557b866be0e555b5d9541ea1232e493324f90 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Wed, 15 Oct 2025 16:31:09 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=90=8C=E6=AD=A5=20template=20?= =?UTF-8?q?=E5=AF=B9=20script/=20=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/build-game.ts | 7 +++-- script/build-resource.ts | 6 ++--- script/pack-template.ts | 55 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 script/pack-template.ts diff --git a/script/build-game.ts b/script/build-game.ts index 2fc0c92..5afc8f7 100644 --- a/script/build-game.ts +++ b/script/build-game.ts @@ -13,6 +13,8 @@ import { RequiredData, RequiredIconsData, ResourceType } from './types'; import { splitResource, SplittedResource } from './build-resource'; import { formatSize } from './utils'; +const DEBUG_REPLAY = false; + const ansi = { clear: '\x1b[2J\x1b[0f' }; @@ -92,7 +94,8 @@ async function buildData(outDir: string, entry: string) { name: 'ProcessData', fileName: 'data', formats: ['iife'] - } + }, + minify: !DEBUG_REPLAY } } satisfies UserConfig); @@ -648,7 +651,7 @@ async function buildGame() { `⚠️ 压缩包大于 100M,可能导致发塔困难,请考虑降低塔的大小\r\n` ); const suggections: string[] = []; - if (dataObject.main.bgms.some(v => !v.endsWith('opuw'))) { + if (dataObject.main.bgms.some(v => !v.endsWith('opus'))) { suggections.push(`将 BGM 和音效换用 opus 格式`); } if (dataObject.main.images.some(v => !v.endsWith('webp'))) { diff --git a/script/build-resource.ts b/script/build-resource.ts index d39a300..70bcfd4 100644 --- a/script/build-resource.ts +++ b/script/build-resource.ts @@ -166,20 +166,20 @@ export async function splitResource( while (index < files.length) { let total = 0; const start = index; - for (let i = index; i < files.length; i++) { + let i = index; + for (; i < files.length; i++) { const file = files[i]; if (file.exceed) { if (i === index) i = index + 1; - index = i; break; } else { total += file.stats.size; } if (total > limit) { - index = i; break; } } + index = i; const toZip = files.slice(start, index); result.push(await compressFiles(toZip)); } diff --git a/script/pack-template.ts b/script/pack-template.ts new file mode 100644 index 0000000..78c76b7 --- /dev/null +++ b/script/pack-template.ts @@ -0,0 +1,55 @@ +/* eslint-disable no-console */ +import { copy, emptyDir, ensureDir } from 'fs-extra'; +import { writeFile } from 'fs/promises'; +import { resolve } from 'path'; + +const base = resolve(process.cwd()); +const template = resolve(base, 'template'); + +const serve = `在 2.B 样板中,不再使用先前的启动服务,而使用一个单独的软件。 +你可以加造塔群 959329661 后,在群文件 - 启动服务 中获取,文件夹中会有一个专门的安装教程。`; + +async function packTemplate() { + await ensureDir(template); + await emptyDir(template); + + // 复制必要文件 + const toCopy = [ + '.vscode', + 'packages', + 'packages-user', + 'public', + 'script', + 'src', + '.gitignore', + '.madgerc', + '.prettierignore', + '.prettierrc', + 'eslint.config.js', + 'index.html', + 'LICENSE', + 'package.json', + 'pnpm-lock.yaml', + 'pnpm-workspace.yaml', + 'README.md', + 'tsconfig.json', + 'tsconfig.node.json', + 'vite.config.ts' + ]; + + await Promise.all( + toCopy.map(v => + copy(resolve(base, v), resolve(template, v), { + filter: src => !src.includes('node_modules') + }) + ) + ); + + await writeFile(resolve(template, '启动服务呢?.txt'), serve, 'utf-8'); + + console.log(`样板打包完成`); +} + +(() => { + packTemplate(); +})();