// Web 打包脚本:vite build → 验证 JSON → zip → release/mygame.zip import { execSync } from 'child_process' import { existsSync, readFileSync, mkdirSync, rmSync } from 'fs' import { join, dirname } from 'path' import { fileURLToPath } from 'url' const __dirname = dirname(fileURLToPath(import.meta.url)) const root = join(__dirname, '..') const dist = join(root, 'dist') const release = join(root, 'release') const jsonPath = join(dist, 'scenes', 'my_story.json') console.log('🔨 Building...') execSync('npx vite build', { cwd: root, stdio: 'inherit' }) if (existsSync(jsonPath)) { try { JSON.parse(readFileSync(jsonPath, 'utf-8')) console.log('✅ JSON 格式验证通过') } catch (err) { console.error('❌ JSON 解析失败:', err.message) process.exit(1) } } else { console.log('⚠️ 未找到 my_story.json,跳过验证') } rmSync(release, { recursive: true, force: true }) mkdirSync(release, { recursive: true }) const zipName = 'mygame' console.log('📦 打包中...') execSync(`zip -r ${join(release, zipName)}.zip .`, { cwd: dist, stdio: 'inherit' }) console.log(`\n✅ 打包完成 → ${join(release, zipName)}.zip`) console.log('📤 将此 zip 上传到 itch.io → 选择 "HTML" 类型 → 发布')