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