|
1 | 1 | #!/usr/bin/env node
|
2 | 2 |
|
3 |
| -const { spawn, execSync } = require('child_process'); |
4 |
| -const fs = require('fs'); |
5 |
| -const path = require('path'); |
| 3 | +import { execSync, spawn } from 'node:child_process'; |
| 4 | +import fs from 'node:fs'; |
| 5 | +import path from 'node:path'; |
| 6 | +import * as url from 'node:url'; |
| 7 | +const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); |
6 | 8 |
|
7 | 9 | async function command(cmd, args, options) {
|
8 | 10 | if (args == null) args = [];
|
@@ -337,13 +339,28 @@ async function main() {
|
337 | 339 |
|
338 | 340 | let haxeBuildJsArgs = [
|
339 | 341 | '--class-path', 'src',
|
340 |
| - '--js', 'build/loreline.js', |
| 342 | + '--js', 'js/loreline.js', |
341 | 343 | '-D', 'js-es=6',
|
| 344 | + '-D', 'loreline_use_js_types', |
| 345 | + '-D', 'loreline_typedef_options', |
| 346 | + '-D', 'loreline_functions_map_dynamic_access', |
| 347 | + '-D', 'loreline_node_id_class', |
342 | 348 | '--main', 'loreline.lib.Library'
|
343 | 349 | ];
|
344 | 350 |
|
345 | 351 | await command(haxe, haxeBuildJsArgs.concat(haxeBuildArgs).concat([]));
|
346 | 352 |
|
| 353 | + let ln = process.platform == 'win32' ? '\r\n' : '\n'; |
| 354 | + |
| 355 | + let js = fs.readFileSync('js/loreline.js', 'utf8'); |
| 356 | + js = 'let runtime = {}; let globals = {}; ' + js; |
| 357 | + js = js.split('})(typeof exports != "undefined" ? exports : typeof window != "undefined" ? window : typeof self != "undefined" ? self : this, typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this);').join('})(runtime, globals);'); |
| 358 | + js += ln + 'export const Loreline = runtime.loreline.Loreline;'; |
| 359 | + js += ln + 'export const Interpreter = runtime.loreline.Interpreter;'; |
| 360 | + js += ln + 'export const Node = runtime.loreline.Node;'; |
| 361 | + js += ln + 'export const Script = runtime.loreline.Script;'; |
| 362 | + fs.writeFileSync('js/loreline.js', js); |
| 363 | + |
347 | 364 | }
|
348 | 365 |
|
349 | 366 | }
|
|
0 commit comments