feat: electron packaging, build scripts, gitignore and docs update

This commit is contained in:
2026-06-09 23:53:32 +08:00
parent 48fb89449a
commit 25d73f5443
7 changed files with 260 additions and 94 deletions

45
scripts/pack-html.cjs Normal file
View File

@@ -0,0 +1,45 @@
const { execSync } = require('child_process')
const fs = require('fs')
const path = require('path')
const root = path.join(__dirname, '..')
const dist = path.join(root, 'dist')
const release = path.join(root, 'release')
const jsonPath = path.join(root, 'public', 'scenes', 'demo.json')
// 1. Verify JSON exists and is valid
if (!fs.existsSync(jsonPath)) {
console.error('❌ public/scenes/demo.json not found')
process.exit(1)
}
try {
JSON.parse(fs.readFileSync(jsonPath, 'utf-8'))
console.log('✅ JSON valid')
} catch (e) {
console.error('❌ JSON parse error:', e.message)
process.exit(1)
}
// 2. Build
console.log('🔨 Building...')
execSync('npx vite build', { cwd: root, stdio: 'inherit' })
// 3. Copy public assets into dist
console.log('📁 Copying assets...')
;['videos', 'audio', 'images', 'scenes', 'subtitles'].forEach((dir) => {
const src = path.join(root, 'public', dir)
const dest = path.join(dist, dir)
if (fs.existsSync(src)) {
execSync(`cp -r "${src}" "${dest}"`)
}
})
// 4. Zip
console.log('📦 Creating zip...')
fs.rmSync(release, { recursive: true, force: true })
fs.mkdirSync(release, { recursive: true })
const outName = 'mygame'
execSync(`cd "${dist}" && zip -r "${path.join(release, outName)}.zip" .`)
console.log(`✅ Packaged: release/${outName}.zip`)