littlejsengine 1.18.29 → 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.
Files changed (51) hide show
  1. package/FAQ.md +841 -815
  2. package/README.md +211 -199
  3. package/dist/littlejs.d.ts +4383 -812
  4. package/dist/littlejs.esm.js +31848 -16680
  5. package/dist/littlejs.esm.min.js +14 -1
  6. package/dist/littlejs.js +31230 -16166
  7. package/dist/littlejs.min.js +13 -1
  8. package/dist/littlejs.release.js +27419 -15457
  9. package/package.json +10 -5
  10. package/plugins/audioEffects.js +375 -0
  11. package/plugins/box2d.js +2516 -2073
  12. package/plugins/drawUtilities.js +206 -31
  13. package/plugins/gltf.js +740 -0
  14. package/plugins/jsconfig.json +19 -0
  15. package/plugins/lightSystem.js +719 -330
  16. package/plugins/math3d.js +911 -0
  17. package/plugins/medalSystem.js +118 -72
  18. package/plugins/newgrounds.js +400 -199
  19. package/plugins/pathFinder.js +208 -175
  20. package/plugins/pluginExport.js +196 -115
  21. package/plugins/postProcess.js +284 -166
  22. package/plugins/render3d.js +4072 -0
  23. package/plugins/render3dDebug.js +109 -0
  24. package/plugins/render3dExtras.js +1754 -0
  25. package/plugins/render3dVoxels.js +502 -0
  26. package/plugins/textureSheet.js +86 -48
  27. package/plugins/threejs.js +183 -158
  28. package/plugins/tweakables.js +411 -0
  29. package/plugins/tweenSystem.js +646 -526
  30. package/plugins/uiSystem.js +2024 -1687
  31. package/plugins/zzfxm.js +8 -15
  32. package/src/engine.js +345 -194
  33. package/src/engineAudio.js +1022 -777
  34. package/src/engineBuild.mjs +289 -253
  35. package/src/engineDebug.js +912 -735
  36. package/src/engineDraw.js +1774 -1510
  37. package/src/engineEditor.js +2431 -0
  38. package/src/engineExport.js +419 -396
  39. package/src/engineInput.js +1462 -1293
  40. package/src/engineLogo.js +4 -3
  41. package/src/engineMath.js +1274 -1183
  42. package/src/engineObject.js +674 -551
  43. package/src/engineParticles.js +583 -532
  44. package/src/engineRelease.js +67 -45
  45. package/src/engineSettings.js +808 -726
  46. package/src/engineTileLayer.js +995 -741
  47. package/src/engineUtilities.js +32 -13
  48. package/src/engineWebGL.js +1162 -941
  49. package/src/jsconfig.json +17 -13
  50. package/plugins/box2d.wasm.js +0 -630
  51. package/plugins/box2d.wasm.wasm +0 -0
@@ -1,254 +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}/uiSystem.js`,
47
- `${PLUGIN_FOLDER}/box2d.js`,
48
- `${PLUGIN_FOLDER}/drawUtilities.js`,
49
- `${PLUGIN_FOLDER}/textureSheet.js`,
50
- `${PLUGIN_FOLDER}/tweenSystem.js`,
51
- `${PLUGIN_FOLDER}/pathFinder.js`,
52
- `${PLUGIN_FOLDER}/threejs.js`,
53
- ];
54
- const engineExtraFiles =
55
- [
56
- `${PLUGIN_FOLDER}/box2d.wasm.js`,
57
- `${PLUGIN_FOLDER}/box2d.wasm.wasm`,
58
- ];
59
- const asciiArt =`
60
- ~~~~°°°°ooo°oOo°ooOooOooOo.
61
- __________ ________ ____'°oO.
62
- |LittleJS| |Engine| |[]|_._Y
63
- .|________|_._|______|_._|__|_|_|}
64
- OOO OOO OO OO OO=OO-oo\\
65
- `;
66
- const license = '// LittleJS Engine - MIT License - Copyright 2021 Frank Force\n'+
67
- '// https://github.com/KilledByAPixel/LittleJS\n\n';
68
-
69
- console.log(asciiArt);
70
- console.log('Choo Choo... Building LittleJS Engine!');
71
- const startTime = Date.now();
72
-
73
- try
74
- {
75
- // Setup build folder
76
- fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
77
- fs.mkdirSync(BUILD_FOLDER);
78
-
79
- // copy extra files to build folder
80
- for (const file of engineExtraFiles)
81
- fs.copyFileSync(file, join(BUILD_FOLDER, basename(file)));
82
-
83
- }
84
- catch (e) { handleError(e, 'Failed to create build folder!'); }
85
-
86
- // Build all versions
87
- await buildAll();
88
-
89
- console.log(`Engine built in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds! ✨`);
90
-
91
- ///////////////////////////////////////////////////////////////////////////////
92
-
93
- async function buildAll()
94
- {
95
- // Build independent base versions in parallel
96
- await Promise.all([
97
- Build
98
- (
99
- 'Build Engine -- all',
100
- `${BUILD_FOLDER}/${ENGINE_NAME}.js`,
101
- [
102
- `${SOURCE_FOLDER}/engine.js`,
103
- `${SOURCE_FOLDER}/engineDebug.js`,
104
- ...engineSourceFiles,
105
- ...enginePluginFiles
106
- ],
107
- [], true
108
- ),
109
- Build
110
- (
111
- 'Build Engine -- release',
112
- `${BUILD_FOLDER}/${ENGINE_NAME}.release.js`,
113
- [
114
- `${SOURCE_FOLDER}/engine.js`,
115
- `${SOURCE_FOLDER}/engineRelease.js`,
116
- ...engineSourceFiles,
117
- ...enginePluginFiles
118
- ],
119
- [], true
120
- )
121
- ]);
122
-
123
- // Build dependent versions in parallel
124
- await Promise.all([
125
- Build
126
- (
127
- 'Build Engine -- minified',
128
- `${BUILD_FOLDER}/${ENGINE_NAME}.min.js`,
129
- [`${BUILD_FOLDER}/${ENGINE_NAME}.release.js`],
130
- [closureCompilerStep, uglifyBuildStep, addLicenseStep]
131
- ),
132
- Build
133
- (
134
- 'Build Engine -- ESM',
135
- `${BUILD_FOLDER}/${ENGINE_NAME}.esm.js`,
136
- [
137
- `${BUILD_FOLDER}/${ENGINE_NAME}.js`,
138
- `${SOURCE_FOLDER}/engineExport.js`,
139
- `${PLUGIN_FOLDER}/pluginExport.js`
140
- ],
141
- [typeScriptBuildStep]
142
- ),
143
- Build
144
- (
145
- 'Build Engine -- ESM minified release',
146
- `${BUILD_FOLDER}/${ENGINE_NAME}.esm.min.js`,
147
- [
148
- `${BUILD_FOLDER}/${ENGINE_NAME}.release.js`,
149
- `${SOURCE_FOLDER}/engineExport.js`,
150
- `${PLUGIN_FOLDER}/pluginExport.js`
151
- ],
152
- [uglifyBuildStep, addLicenseStep]
153
- )
154
- ]);
155
- }
156
-
157
- ///////////////////////////////////////////////////////////////////////////////
158
-
159
- // A single build with its own source files, build steps, and output file
160
- // - each build step is a callback that accepts a single filename
161
- async function Build(message, outputFile, files=[], buildSteps=[], isPrimaryBuild)
162
- {
163
- console.log(message);
164
-
165
- // copy files into a buffer
166
- let buffer = '';
167
- if (isPrimaryBuild)
168
- {
169
- // add license and strict mode to top
170
- buffer += license;
171
- buffer += `'use strict';\n\n`;
172
- }
173
-
174
- for (const file of files)
175
- {
176
- // get file content
177
- let fileContent = fs.readFileSync(file) + '\n';
178
-
179
- // remove first 'use strict' and surrounding new lines
180
- if (isPrimaryBuild)
181
- fileContent = fileContent.replace(/'use strict';\s*\n/g, '');
182
-
183
- // add it to the buffer
184
- buffer += fileContent;
185
- }
186
-
187
- // output file
188
- fs.writeFileSync(outputFile, buffer, {flag: 'w+'});
189
-
190
- // execute build steps in order
191
- for (const buildStep of buildSteps)
192
- buildStep(outputFile);
193
- }
194
-
195
- // Process with Closure Compiler to minify and check for errors
196
- function closureCompilerStep(filename)
197
- {
198
- const filenameTemp = filename + '.tmp';
199
- fs.copyFileSync(filename, filenameTemp);
200
- try
201
- {
202
- execSync(`npx google-closure-compiler --js=${filenameTemp} --js_output_file=${filename} --jscomp_off=*`);
203
- fs.rmSync(filenameTemp);
204
- }
205
- catch (e) { handleError(e, 'Failed to run Closure Compiler step!'); }
206
- }
207
-
208
- // Process with Uglify to minify
209
- function uglifyBuildStep(filename)
210
- {
211
- try
212
- {
213
- execSync(`npx uglifyjs ${filename} -o ${filename}`);
214
- }
215
- catch (e) { handleError(e,'Failed to run Uglify minification step!'); }
216
- };
217
-
218
- // Add license to top of file
219
- function addLicenseStep(filename)
220
- {
221
- try
222
- {
223
- // add license to top of minified file
224
- let fileContent = fs.readFileSync(filename, 'utf8');
225
- fileContent = license + fileContent;
226
- fs.writeFileSync(filename, fileContent);
227
- }
228
- catch (e) { handleError(e, 'Failed to add license to minified file!'); }
229
- };
230
-
231
- // Build TypeScript definitions
232
- function typeScriptBuildStep(filename)
233
- {
234
- try
235
- {
236
- const tsFilename = join(BUILD_FOLDER, `${ENGINE_NAME}.d.ts`);
237
- execSync(`npx -p typescript tsc ${filename} --declaration --allowJs --emitDeclarationOnly --outFile ${tsFilename}`);
238
-
239
- // Make declare module part use the package name littlejsengine
240
- let fileContent = fs.readFileSync(tsFilename, 'utf8');
241
- fileContent = fileContent.replace(`${ENGINE_NAME}\.esm`, 'littlejsengine')
242
- fs.writeFileSync(tsFilename, fileContent);
243
-
244
- }
245
- catch (e) { handleError(e, 'Failed to run TypeScript build step!'); }
246
- };
247
-
248
- // display the error and exit
249
- function handleError(e,message)
250
- {
251
- console.error(e);
252
- console.error(message);
253
- 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}/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);
254
290
  }