Files
tianshu-engine/scripts/pack-html.mjs

37 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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" 类型 → 发布')