-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
72 lines (60 loc) · 2.12 KB
/
bundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//@ts-check
const crypto = require('crypto')
const fsp = require('fs/promises')
const path = require('path')
const alias = require('tsc-alias')
const { build } = require('esbuild')
/**
*
* @param {string} entry
* @param {string} out
* @param {import('esbuild').Format} format
* @param {import('esbuild').Platform} platform
* @param {string | undefined} tsconfig
* @param {import('esbuild').BuildOptions | undefined} more
*/
async function bundleBuild(entry, out, format, platform, tsconfig = undefined, more = {}, transformPath = false) {
console.time(entry)
const temp = crypto.randomBytes(8).toString('hex')
const isDir = out[0] === '^' && (out = out.slice(1), true)
const parRef = path.dirname(out)
// options
/** @type {import('esbuild').BuildOptions} */
const opts = {
entryPoints: [entry],
[isDir ? 'outdir' : 'outfile']: temp,
format,
platform,
tsconfig,
bundle: true,
minify: true
}
// build
await build(Object.assign(opts, more))
await fsp.rm(isDir ? out : parRef, { force: true, recursive: true })
await fsp.mkdir(parRef, { recursive: true })
await fsp.rename(temp, out)
if (transformPath && !opts.bundle) alias.replaceTscAliasPaths({
configFile: tsconfig,
resolveFullExtension: '.js',
resolveFullPaths: true
})
console.timeEnd(entry)
}
bundleBuild('app/src/index.ts', 'app/scripts/index.js', 'esm', 'browser', 'app/tsconfig.json', undefined, true)
bundleBuild('pack/src/debugger/index.ts', 'pack/scripts/debugger/bundle.js', 'esm', 'neutral', 'pack/tsconfig.json', {
external: [
'@minecraft/server',
'@minecraft/server-gametest',
'@minecraft/server-ui',
'@minecraft/server-net',
'@minecraft/server-admin'
]
}).then(async () => {
await fsp.writeFile('pack/scripts/debugger/index.js', "import './bundle.js'\nimport './dropper.js'")
await fsp.writeFile('pack/scripts/debugger/dropper.js', "//")
})
bundleBuild('server/src/**/*', '^server/app', 'cjs', 'node', 'server/tsconfig.json', {
bundle: false,
packages: 'external'
}, true)