forked from overextended/ox_core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
98 lines (85 loc) · 2.32 KB
/
build.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import esbuild from 'esbuild';
import { readFile, readFileSync, writeFileSync } from 'fs';
/** @type {import('esbuild').BuildOptions} */
const server = {
platform: 'node',
target: ['node16'],
format: 'cjs',
};
/** @type {import('esbuild').BuildOptions} */
const client = {
platform: 'browser',
target: ['es2021'],
format: 'iife',
};
const production = process.argv.includes('--mode=production');
const buildCmd = production ? esbuild.build : esbuild.context;
const wordWrap = new RegExp(`.{1,65}\\s+|\\S+`, 'g');
const packageJson = JSON.parse(readFileSync('package.json', { encoding: 'utf8' }));
const copyright = readFileSync('README.md', { encoding: 'utf8' })
.replace(/[\s\S]*?## Copyright/, '')
.match(wordWrap)
.join('\n * ')
.replace(/\n{2,}/g, '\n');
console.log(copyright.split('\n')[0]);
writeFileSync(
'.yarn.installed',
new Date().toLocaleString('en-AU', { timeZone: 'UTC', timeStyle: 'long', dateStyle: 'full' })
);
writeFileSync(
'fxmanifest.lua',
`fx_version 'cerulean'
game 'gta5'
name '${packageJson.name}'
author '${packageJson.author}'
version '${packageJson.version}'
license '${packageJson.license}'
repository '${packageJson.repository.url}'
description '${packageJson.description}'
dependencies {
'/server:7290',
'/onesync',
}
files {
'lib/init.lua',
'lib/client/**.lua',
'imports/client.lua',
'locales/*.json',
'common/data/*.json',
}
client_script 'dist/client.js'
server_script 'dist/server.js'
`
);
for (const context of ['client', 'server']) {
buildCmd({
bundle: true,
entryPoints: [`${context}/index.ts`],
outfile: `dist/${context}.js`,
keepNames: true,
dropLabels: production ? ['DEV'] : undefined,
legalComments: 'inline',
banner: {
js: `/**\n * ${copyright} */`,
},
plugins: production
? undefined
: [
{
name: 'rebuild',
setup(build) {
const cb = (result) => {
if (!result || result.errors.length === 0) console.log(`Successfully built ${context}`);
};
build.onEnd(cb);
},
},
],
...(context === 'client' ? client : server),
})
.then((build) => {
if (production) return console.log(`Successfully built ${context}`);
build.watch();
})
.catch(() => process.exit(1));
}