Skip to content

Commit 8be7dfa

Browse files
committed
Start working on JS/TS version
1 parent e4009bc commit 8be7dfa

File tree

13 files changed

+634
-128
lines changed

13 files changed

+634
-128
lines changed

build-js.hxml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--class-path src
2+
--main loreline.lib.Library
3+
--js js/loreline.js
4+
--no-output
5+
-D js-es=6
6+
-D no-compilation
7+
-D loreline_use_js_types
8+
-D loreline_typedef_options
9+
-D loreline_functions_map_dynamic_access
10+
-D loreline_node_id_class

cs/Loreline/Runtime/Interpreter.cs

+75-75
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cs/Loreline/Runtime/Loreline.cs

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env node
22

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));
68

79
async function command(cmd, args, options) {
810
if (args == null) args = [];
@@ -337,13 +339,28 @@ async function main() {
337339

338340
let haxeBuildJsArgs = [
339341
'--class-path', 'src',
340-
'--js', 'build/loreline.js',
342+
'--js', 'js/loreline.js',
341343
'-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',
342348
'--main', 'loreline.lib.Library'
343349
];
344350

345351
await command(haxe, haxeBuildJsArgs.concat(haxeBuildArgs).concat([]));
346352

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+
347364
}
348365

349366
}

0 commit comments

Comments
 (0)