feat: move to typescript, miniplex ecs
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { build, context } from 'esbuild'
|
||||
import { cpSync, copyFileSync, mkdirSync, readdirSync, rmSync } from 'node:fs'
|
||||
import { dirname, join, relative } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const root = dirname(fileURLToPath(import.meta.url))
|
||||
const dist = join(root, 'dist')
|
||||
const watch = process.argv.includes('--watch')
|
||||
|
||||
const rootFiles = ['index.html', 'game.html', 'style.css', 'serve.json']
|
||||
const jsDir = 'js'
|
||||
const imgFiles = ['sprite.svg']
|
||||
|
||||
function listFiles(dir) {
|
||||
@@ -22,14 +23,33 @@ for (const file of rootFiles) {
|
||||
copyFileSync(join(root, file), join(dist, file))
|
||||
}
|
||||
|
||||
cpSync(join(root, jsDir), join(dist, jsDir), { recursive: true })
|
||||
|
||||
mkdirSync(join(dist, 'img'))
|
||||
for (const file of imgFiles) {
|
||||
copyFileSync(join(root, 'img', file), join(dist, 'img', file))
|
||||
}
|
||||
|
||||
console.log('Собрано в dist:')
|
||||
for (const file of listFiles(dist)) {
|
||||
console.log(' ' + relative(dist, file))
|
||||
const options = {
|
||||
entryPoints: {
|
||||
game: join(root, 'src/entries/game.ts'),
|
||||
index: join(root, 'src/entries/index.ts'),
|
||||
},
|
||||
outdir: dist,
|
||||
bundle: true,
|
||||
minify: true,
|
||||
sourcemap: false,
|
||||
format: 'iife',
|
||||
target: 'es2020',
|
||||
logLevel: 'info',
|
||||
}
|
||||
|
||||
if (watch) {
|
||||
const contexts = await Promise.all([context(options)])
|
||||
await Promise.all(contexts.map((c) => c.watch()))
|
||||
console.log('Слежу за изменениями src/...')
|
||||
} else {
|
||||
await build(options)
|
||||
console.log('Собрано в dist:')
|
||||
for (const file of listFiles(dist)) {
|
||||
console.log(' ' + relative(dist, file))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user