feat: electron packaging, build scripts, gitignore and docs update
This commit is contained in:
45
scripts/pack-html.cjs
Normal file
45
scripts/pack-html.cjs
Normal 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`)
|
||||
Reference in New Issue
Block a user