littlejsengine 1.19.3 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FAQ.md +841 -820
- package/README.md +29 -25
- package/dist/littlejs.d.ts +2455 -935
- package/dist/littlejs.esm.js +30344 -21110
- package/dist/littlejs.esm.min.js +4 -3
- package/dist/littlejs.js +30259 -21052
- package/dist/littlejs.min.js +2 -2
- package/dist/littlejs.release.js +26567 -20455
- package/package.json +10 -5
- package/plugins/audioEffects.js +28 -24
- package/plugins/box2d.js +2516 -2073
- package/plugins/drawUtilities.js +206 -31
- package/plugins/gltf.js +740 -0
- package/plugins/jsconfig.json +19 -0
- package/plugins/lightSystem.js +719 -332
- package/plugins/math3d.js +58 -17
- package/plugins/medalSystem.js +326 -280
- package/plugins/newgrounds.js +400 -199
- package/plugins/pathFinder.js +208 -175
- package/plugins/pluginExport.js +15 -0
- package/plugins/postProcess.js +56 -13
- package/plugins/render3d.js +1643 -1577
- package/plugins/render3dDebug.js +109 -0
- package/plugins/render3dExtras.js +1754 -0
- package/plugins/render3dVoxels.js +502 -0
- package/plugins/textureSheet.js +496 -458
- package/plugins/threejs.js +183 -163
- package/plugins/tweakables.js +411 -0
- package/plugins/tweenSystem.js +263 -145
- package/plugins/uiSystem.js +2024 -1687
- package/plugins/zzfxm.js +159 -159
- package/src/engine.js +191 -75
- package/src/engineAudio.js +229 -125
- package/src/engineBuild.mjs +289 -256
- package/src/engineDebug.js +912 -742
- package/src/engineDraw.js +295 -193
- package/src/engineEditor.js +2431 -0
- package/src/engineExport.js +12 -0
- package/src/engineInput.js +1462 -1293
- package/src/engineMath.js +1274 -1252
- package/src/engineObject.js +194 -80
- package/src/engineParticles.js +583 -532
- package/src/engineRelease.js +67 -45
- package/src/engineSettings.js +77 -29
- package/src/engineTileLayer.js +995 -741
- package/src/engineUtilities.js +19 -13
- package/src/engineWebGL.js +239 -82
- package/src/jsconfig.json +17 -13
- package/plugins/box2d.wasm.js +0 -630
- package/plugins/box2d.wasm.wasm +0 -0
package/src/engineBuild.mjs
CHANGED
|
@@ -1,257 +1,290 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LittleJS Build System
|
|
3
|
-
* - Concatenates engine source files into distributable bundles
|
|
4
|
-
* - Generates multiple output formats (standard, ES6 module, minified)
|
|
5
|
-
* - Creates debug and release builds (with/without debug code)
|
|
6
|
-
* - Produces TypeScript definition file (.d.ts)
|
|
7
|
-
* - Includes plugin files in builds
|
|
8
|
-
* - Validates code and checks for errors
|
|
9
|
-
* - Outputs to dist/ folder
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import fs from 'node:fs';
|
|
13
|
-
import { execSync } from 'node:child_process';
|
|
14
|
-
import { fileURLToPath } from 'node:url';
|
|
15
|
-
import { basename, dirname, join } from 'node:path';
|
|
16
|
-
|
|
17
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
18
|
-
const __dirname = dirname(__filename);
|
|
19
|
-
const ROOT_DIR = join(__dirname, '..');
|
|
20
|
-
|
|
21
|
-
const ENGINE_NAME = 'littlejs';
|
|
22
|
-
const BUILD_FOLDER = join(ROOT_DIR, 'dist');
|
|
23
|
-
const SOURCE_FOLDER = join(ROOT_DIR, 'src');
|
|
24
|
-
const PLUGIN_FOLDER = join(ROOT_DIR, 'plugins');
|
|
25
|
-
const engineSourceFiles =
|
|
26
|
-
[
|
|
27
|
-
`${SOURCE_FOLDER}/engineMath.js`,
|
|
28
|
-
`${SOURCE_FOLDER}/engineUtilities.js`,
|
|
29
|
-
`${SOURCE_FOLDER}/engineSettings.js`,
|
|
30
|
-
`${SOURCE_FOLDER}/engineObject.js`,
|
|
31
|
-
`${SOURCE_FOLDER}/engineDraw.js`,
|
|
32
|
-
`${SOURCE_FOLDER}/engineInput.js`,
|
|
33
|
-
`${SOURCE_FOLDER}/engineAudio.js`,
|
|
34
|
-
`${SOURCE_FOLDER}/engineTileLayer.js`,
|
|
35
|
-
`${SOURCE_FOLDER}/engineParticles.js`,
|
|
36
|
-
`${SOURCE_FOLDER}/engineWebGL.js`,
|
|
37
|
-
`${SOURCE_FOLDER}/engineLogo.js`,
|
|
38
|
-
];
|
|
39
|
-
const enginePluginFiles =
|
|
40
|
-
[
|
|
41
|
-
`${PLUGIN_FOLDER}/medalSystem.js`,
|
|
42
|
-
`${PLUGIN_FOLDER}/newgrounds.js`,
|
|
43
|
-
`${PLUGIN_FOLDER}/postProcess.js`,
|
|
44
|
-
`${PLUGIN_FOLDER}/lightSystem.js`,
|
|
45
|
-
`${PLUGIN_FOLDER}/zzfxm.js`,
|
|
46
|
-
`${PLUGIN_FOLDER}/audioEffects.js`,
|
|
47
|
-
`${PLUGIN_FOLDER}/uiSystem.js`,
|
|
48
|
-
`${PLUGIN_FOLDER}/box2d.js`,
|
|
49
|
-
`${PLUGIN_FOLDER}/drawUtilities.js`,
|
|
50
|
-
`${PLUGIN_FOLDER}/textureSheet.js`,
|
|
51
|
-
`${PLUGIN_FOLDER}/tweenSystem.js`,
|
|
52
|
-
`${PLUGIN_FOLDER}/pathFinder.js`,
|
|
53
|
-
`${PLUGIN_FOLDER}/math3d.js`,
|
|
54
|
-
`${PLUGIN_FOLDER}/render3d.js`,
|
|
55
|
-
`${PLUGIN_FOLDER}/
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
...
|
|
120
|
-
|
|
121
|
-
],
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
[
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
],
|
|
144
|
-
[
|
|
145
|
-
),
|
|
146
|
-
Build
|
|
147
|
-
(
|
|
148
|
-
'Build Engine -- ESM
|
|
149
|
-
`${BUILD_FOLDER}/${ENGINE_NAME}.esm.
|
|
150
|
-
[
|
|
151
|
-
`${BUILD_FOLDER}/${ENGINE_NAME}.
|
|
152
|
-
`${SOURCE_FOLDER}/engineExport.js`,
|
|
153
|
-
`${PLUGIN_FOLDER}/pluginExport.js`
|
|
154
|
-
],
|
|
155
|
-
[
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
fs.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
try
|
|
215
|
-
{
|
|
216
|
-
execSync(`npx
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
1
|
+
/**
|
|
2
|
+
* LittleJS Build System
|
|
3
|
+
* - Concatenates engine source files into distributable bundles
|
|
4
|
+
* - Generates multiple output formats (standard, ES6 module, minified)
|
|
5
|
+
* - Creates debug and release builds (with/without debug code)
|
|
6
|
+
* - Produces TypeScript definition file (.d.ts)
|
|
7
|
+
* - Includes plugin files in builds
|
|
8
|
+
* - Validates code and checks for errors
|
|
9
|
+
* - Outputs to dist/ folder
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import { execSync } from 'node:child_process';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
import { basename, dirname, join } from 'node:path';
|
|
16
|
+
|
|
17
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
18
|
+
const __dirname = dirname(__filename);
|
|
19
|
+
const ROOT_DIR = join(__dirname, '..');
|
|
20
|
+
|
|
21
|
+
const ENGINE_NAME = 'littlejs';
|
|
22
|
+
const BUILD_FOLDER = join(ROOT_DIR, 'dist');
|
|
23
|
+
const SOURCE_FOLDER = join(ROOT_DIR, 'src');
|
|
24
|
+
const PLUGIN_FOLDER = join(ROOT_DIR, 'plugins');
|
|
25
|
+
const engineSourceFiles =
|
|
26
|
+
[
|
|
27
|
+
`${SOURCE_FOLDER}/engineMath.js`,
|
|
28
|
+
`${SOURCE_FOLDER}/engineUtilities.js`,
|
|
29
|
+
`${SOURCE_FOLDER}/engineSettings.js`,
|
|
30
|
+
`${SOURCE_FOLDER}/engineObject.js`,
|
|
31
|
+
`${SOURCE_FOLDER}/engineDraw.js`,
|
|
32
|
+
`${SOURCE_FOLDER}/engineInput.js`,
|
|
33
|
+
`${SOURCE_FOLDER}/engineAudio.js`,
|
|
34
|
+
`${SOURCE_FOLDER}/engineTileLayer.js`,
|
|
35
|
+
`${SOURCE_FOLDER}/engineParticles.js`,
|
|
36
|
+
`${SOURCE_FOLDER}/engineWebGL.js`,
|
|
37
|
+
`${SOURCE_FOLDER}/engineLogo.js`,
|
|
38
|
+
];
|
|
39
|
+
const enginePluginFiles =
|
|
40
|
+
[
|
|
41
|
+
`${PLUGIN_FOLDER}/medalSystem.js`,
|
|
42
|
+
`${PLUGIN_FOLDER}/newgrounds.js`,
|
|
43
|
+
`${PLUGIN_FOLDER}/postProcess.js`,
|
|
44
|
+
`${PLUGIN_FOLDER}/lightSystem.js`,
|
|
45
|
+
`${PLUGIN_FOLDER}/zzfxm.js`,
|
|
46
|
+
`${PLUGIN_FOLDER}/audioEffects.js`,
|
|
47
|
+
`${PLUGIN_FOLDER}/uiSystem.js`,
|
|
48
|
+
`${PLUGIN_FOLDER}/box2d.js`,
|
|
49
|
+
`${PLUGIN_FOLDER}/drawUtilities.js`,
|
|
50
|
+
`${PLUGIN_FOLDER}/textureSheet.js`,
|
|
51
|
+
`${PLUGIN_FOLDER}/tweenSystem.js`,
|
|
52
|
+
`${PLUGIN_FOLDER}/pathFinder.js`,
|
|
53
|
+
`${PLUGIN_FOLDER}/math3d.js`,
|
|
54
|
+
`${PLUGIN_FOLDER}/render3d.js`,
|
|
55
|
+
`${PLUGIN_FOLDER}/render3dExtras.js`,
|
|
56
|
+
`${PLUGIN_FOLDER}/render3dVoxels.js`,
|
|
57
|
+
`${PLUGIN_FOLDER}/gltf.js`,
|
|
58
|
+
`${PLUGIN_FOLDER}/threejs.js`,
|
|
59
|
+
];
|
|
60
|
+
// debug only, the release build has stubs for these in engineRelease.js and none of their code
|
|
61
|
+
const engineDebugFiles =
|
|
62
|
+
[
|
|
63
|
+
`${PLUGIN_FOLDER}/tweakables.js`,
|
|
64
|
+
`${PLUGIN_FOLDER}/render3dDebug.js`,
|
|
65
|
+
`${SOURCE_FOLDER}/engineEditor.js`,
|
|
66
|
+
];
|
|
67
|
+
const engineExtraFiles =
|
|
68
|
+
[
|
|
69
|
+
`${PLUGIN_FOLDER}/box2d.wasm.js`,
|
|
70
|
+
`${PLUGIN_FOLDER}/box2d.wasm.wasm`,
|
|
71
|
+
];
|
|
72
|
+
const asciiArt =`
|
|
73
|
+
~~~~°°°°ooo°oOo°ooOooOooOo.
|
|
74
|
+
__________ ________ ____'°oO.
|
|
75
|
+
|LittleJS| |Engine| |[]|_._Y
|
|
76
|
+
.|________|_._|______|_._|__|_|_|}
|
|
77
|
+
OOO OOO OO OO OO=OO-oo\\
|
|
78
|
+
`;
|
|
79
|
+
const license = '// LittleJS Engine - MIT License - Copyright 2021 Frank Force\n'+
|
|
80
|
+
'// https://github.com/KilledByAPixel/LittleJS\n\n';
|
|
81
|
+
|
|
82
|
+
console.log(asciiArt);
|
|
83
|
+
console.log('Choo Choo... Building LittleJS Engine!');
|
|
84
|
+
const startTime = Date.now();
|
|
85
|
+
|
|
86
|
+
try
|
|
87
|
+
{
|
|
88
|
+
// Setup build folder
|
|
89
|
+
fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
|
|
90
|
+
fs.mkdirSync(BUILD_FOLDER);
|
|
91
|
+
|
|
92
|
+
// copy extra files to build folder
|
|
93
|
+
for (const file of engineExtraFiles)
|
|
94
|
+
fs.copyFileSync(file, join(BUILD_FOLDER, basename(file)));
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
catch (e) { handleError(e, 'Failed to create build folder!'); }
|
|
98
|
+
|
|
99
|
+
// Build all versions
|
|
100
|
+
await buildAll();
|
|
101
|
+
|
|
102
|
+
console.log(`Engine built in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds! ✨`);
|
|
103
|
+
|
|
104
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
105
|
+
|
|
106
|
+
async function buildAll()
|
|
107
|
+
{
|
|
108
|
+
// Build independent base versions
|
|
109
|
+
await Promise.all([
|
|
110
|
+
Build
|
|
111
|
+
(
|
|
112
|
+
'Build Engine -- all',
|
|
113
|
+
`${BUILD_FOLDER}/${ENGINE_NAME}.js`,
|
|
114
|
+
[
|
|
115
|
+
`${SOURCE_FOLDER}/engine.js`,
|
|
116
|
+
`${SOURCE_FOLDER}/engineDebug.js`,
|
|
117
|
+
...engineSourceFiles,
|
|
118
|
+
...enginePluginFiles,
|
|
119
|
+
...engineDebugFiles
|
|
120
|
+
],
|
|
121
|
+
[], true
|
|
122
|
+
),
|
|
123
|
+
Build
|
|
124
|
+
(
|
|
125
|
+
'Build Engine -- release',
|
|
126
|
+
`${BUILD_FOLDER}/${ENGINE_NAME}.release.js`,
|
|
127
|
+
[
|
|
128
|
+
`${SOURCE_FOLDER}/engine.js`,
|
|
129
|
+
`${SOURCE_FOLDER}/engineRelease.js`,
|
|
130
|
+
...engineSourceFiles,
|
|
131
|
+
...enginePluginFiles
|
|
132
|
+
],
|
|
133
|
+
[stripDebugCallsStep], true
|
|
134
|
+
)
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
// Build dependent versions
|
|
138
|
+
await Promise.all([
|
|
139
|
+
Build
|
|
140
|
+
(
|
|
141
|
+
'Build Engine -- minified',
|
|
142
|
+
`${BUILD_FOLDER}/${ENGINE_NAME}.min.js`,
|
|
143
|
+
[`${BUILD_FOLDER}/${ENGINE_NAME}.release.js`],
|
|
144
|
+
[closureCompilerStep, uglifyBuildStep, addLicenseStep]
|
|
145
|
+
),
|
|
146
|
+
Build
|
|
147
|
+
(
|
|
148
|
+
'Build Engine -- ESM',
|
|
149
|
+
`${BUILD_FOLDER}/${ENGINE_NAME}.esm.js`,
|
|
150
|
+
[
|
|
151
|
+
`${BUILD_FOLDER}/${ENGINE_NAME}.js`,
|
|
152
|
+
`${SOURCE_FOLDER}/engineExport.js`,
|
|
153
|
+
`${PLUGIN_FOLDER}/pluginExport.js`
|
|
154
|
+
],
|
|
155
|
+
[typeScriptBuildStep]
|
|
156
|
+
),
|
|
157
|
+
Build
|
|
158
|
+
(
|
|
159
|
+
'Build Engine -- ESM minified release',
|
|
160
|
+
`${BUILD_FOLDER}/${ENGINE_NAME}.esm.min.js`,
|
|
161
|
+
[
|
|
162
|
+
`${BUILD_FOLDER}/${ENGINE_NAME}.release.js`,
|
|
163
|
+
`${SOURCE_FOLDER}/engineExport.js`,
|
|
164
|
+
`${PLUGIN_FOLDER}/pluginExport.js`
|
|
165
|
+
],
|
|
166
|
+
[uglifyModuleBuildStep, addLicenseStep]
|
|
167
|
+
)
|
|
168
|
+
]);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
172
|
+
|
|
173
|
+
// A single build with its own source files, build steps, and output file
|
|
174
|
+
// - each build step is a callback that accepts a single filename
|
|
175
|
+
async function Build(message, outputFile, files=[], buildSteps=[], isPrimaryBuild)
|
|
176
|
+
{
|
|
177
|
+
console.log(message);
|
|
178
|
+
|
|
179
|
+
// copy files into a buffer
|
|
180
|
+
let buffer = '';
|
|
181
|
+
if (isPrimaryBuild)
|
|
182
|
+
{
|
|
183
|
+
// add license and strict mode to top
|
|
184
|
+
buffer += license;
|
|
185
|
+
buffer += `'use strict';\n\n`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
for (const file of files)
|
|
189
|
+
{
|
|
190
|
+
// get file content
|
|
191
|
+
let fileContent = fs.readFileSync(file) + '\n';
|
|
192
|
+
|
|
193
|
+
// remove first 'use strict' and surrounding new lines
|
|
194
|
+
if (isPrimaryBuild)
|
|
195
|
+
fileContent = fileContent.replace(/'use strict';\s*\n/g, '');
|
|
196
|
+
|
|
197
|
+
// add it to the buffer
|
|
198
|
+
buffer += fileContent;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// output file
|
|
202
|
+
fs.writeFileSync(outputFile, buffer, {flag: 'w+'});
|
|
203
|
+
|
|
204
|
+
// execute build steps in order
|
|
205
|
+
for (const buildStep of buildSteps)
|
|
206
|
+
buildStep(outputFile);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Process with Closure Compiler to minify and check for errors
|
|
210
|
+
function closureCompilerStep(filename)
|
|
211
|
+
{
|
|
212
|
+
const filenameTemp = filename + '.tmp';
|
|
213
|
+
fs.copyFileSync(filename, filenameTemp);
|
|
214
|
+
try
|
|
215
|
+
{
|
|
216
|
+
execSync(`npx google-closure-compiler --js="${filenameTemp}" --js_output_file="${filename}" --jscomp_off=*`);
|
|
217
|
+
fs.rmSync(filenameTemp);
|
|
218
|
+
}
|
|
219
|
+
catch (e) { handleError(e, 'Failed to run Closure Compiler step!'); }
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Process with Uglify to minify
|
|
223
|
+
function uglifyBuildStep(filename)
|
|
224
|
+
{
|
|
225
|
+
try
|
|
226
|
+
{
|
|
227
|
+
execSync(`npx uglifyjs "${filename}" -o "${filename}"`);
|
|
228
|
+
}
|
|
229
|
+
catch (e) { handleError(e,'Failed to run Uglify minification step!'); }
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// Process an ES module with Uglify, compressed so the guarded debug calls are dropped, Closure does that for the
|
|
233
|
+
// script build before its Uglify step
|
|
234
|
+
function uglifyModuleBuildStep(filename)
|
|
235
|
+
{
|
|
236
|
+
try
|
|
237
|
+
{
|
|
238
|
+
execSync(`npx uglifyjs "${filename}" -c --module -o "${filename}"`);
|
|
239
|
+
}
|
|
240
|
+
catch (e) { handleError(e,'Failed to run Uglify minification step!'); }
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// Guard every ASSERT and LOG call in the release build so its arguments are never evaluated
|
|
244
|
+
// - engineRelease.js makes them empty functions, but a call still evaluates its arguments first,
|
|
245
|
+
// so isVector3 checks and message strings would run in release; false&& short circuits them
|
|
246
|
+
// and the minifiers then drop the dead calls entirely
|
|
247
|
+
// - The helpers like ASSERT_VECTOR3_VALID are guarded the same way, their definitions are skipped by name
|
|
248
|
+
function stripDebugCallsStep(filename)
|
|
249
|
+
{
|
|
250
|
+
const source = fs.readFileSync(filename, 'utf8');
|
|
251
|
+
fs.writeFileSync(filename, source.replace(/(?<!function )\b(ASSERT\w*|LOG)\(/g, 'false&&$1('), {flag: 'w+'});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Add license to top of file
|
|
255
|
+
function addLicenseStep(filename)
|
|
256
|
+
{
|
|
257
|
+
try
|
|
258
|
+
{
|
|
259
|
+
// add license to top of minified file
|
|
260
|
+
let fileContent = fs.readFileSync(filename, 'utf8');
|
|
261
|
+
fileContent = license + fileContent;
|
|
262
|
+
fs.writeFileSync(filename, fileContent);
|
|
263
|
+
}
|
|
264
|
+
catch (e) { handleError(e, 'Failed to add license to minified file!'); }
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// Build TypeScript definitions
|
|
268
|
+
function typeScriptBuildStep(filename)
|
|
269
|
+
{
|
|
270
|
+
try
|
|
271
|
+
{
|
|
272
|
+
const tsFilename = join(BUILD_FOLDER, `${ENGINE_NAME}.d.ts`);
|
|
273
|
+
execSync(`npx -p typescript tsc "${filename}" --declaration --allowJs --emitDeclarationOnly --outFile "${tsFilename}"`);
|
|
274
|
+
|
|
275
|
+
// Make declare module part use the package name littlejsengine
|
|
276
|
+
let fileContent = fs.readFileSync(tsFilename, 'utf8');
|
|
277
|
+
fileContent = fileContent.replace(`${ENGINE_NAME}\.esm`, 'littlejsengine')
|
|
278
|
+
fs.writeFileSync(tsFilename, fileContent);
|
|
279
|
+
|
|
280
|
+
}
|
|
281
|
+
catch (e) { handleError(e, 'Failed to run TypeScript build step!'); }
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// display the error and exit
|
|
285
|
+
function handleError(e,message)
|
|
286
|
+
{
|
|
287
|
+
console.error(e);
|
|
288
|
+
console.error(message);
|
|
289
|
+
process.exit(1);
|
|
257
290
|
}
|