@wllzhang/afsim-compiler 0.3.0 → 0.5.2
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/README.md +3 -11
- package/index.mjs +4 -46
- package/package.json +3 -12
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @wllzhang/afsim-compiler
|
|
2
2
|
|
|
3
|
-
JSON to AFSIM DSL compiler.
|
|
3
|
+
JSON to AFSIM DSL compiler. WebAssembly build for **browsers** and Node.js — no native binaries, single package for all platforms.
|
|
4
4
|
|
|
5
5
|
Pass a JavaScript object describing your AFSIM scenario and get back the compiled DSL text — all in memory, no temp files needed.
|
|
6
6
|
|
|
@@ -10,8 +10,6 @@ Pass a JavaScript object describing your AFSIM scenario and get back the compile
|
|
|
10
10
|
npm install @wllzhang/afsim-compiler
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
The correct native binary for your platform is installed automatically via `optionalDependencies`.
|
|
14
|
-
|
|
15
13
|
## Usage
|
|
16
14
|
|
|
17
15
|
```javascript
|
|
@@ -62,15 +60,9 @@ end_platform_type
|
|
|
62
60
|
| **Returns** | `string` | Compiled AFSIM DSL text |
|
|
63
61
|
| **Throws** | `Error` | On invalid input or compilation failure |
|
|
64
62
|
|
|
65
|
-
##
|
|
63
|
+
## Platforms
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
|----|------|--------|
|
|
69
|
-
| Windows | x64 | `afsim_compiler.dll` |
|
|
70
|
-
| Linux | x64 | `libafsim_compiler.so` |
|
|
71
|
-
| Linux | arm64 | `libafsim_compiler.so` |
|
|
72
|
-
| macOS | x64 | `libafsim_compiler.dylib` |
|
|
73
|
-
| macOS | arm64 | `libafsim_compiler.dylib` |
|
|
65
|
+
Works everywhere: **browsers** (Chrome, Firefox, Safari, Edge), **Node.js** (v18+), and any bundler (Vite, webpack, etc.). No architecture-specific packages — one build fits all.
|
|
74
66
|
|
|
75
67
|
## License
|
|
76
68
|
|
package/index.mjs
CHANGED
|
@@ -1,49 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
const require = createRequire(import.meta.url);
|
|
6
|
-
|
|
7
|
-
const PLATFORMS = {
|
|
8
|
-
'win32-x64': { pkg: '@wllzhang/afsim-compiler-win32-x64', file: 'afsim_compiler.dll' },
|
|
9
|
-
'linux-x64': { pkg: '@wllzhang/afsim-compiler-linux-x64', file: 'libafsim_compiler.so' },
|
|
10
|
-
'linux-arm64': { pkg: '@wllzhang/afsim-compiler-linux-arm64', file: 'libafsim_compiler.so' },
|
|
11
|
-
'darwin-x64': { pkg: '@wllzhang/afsim-compiler-darwin-x64', file: 'libafsim_compiler.dylib' },
|
|
12
|
-
'darwin-arm64': { pkg: '@wllzhang/afsim-compiler-darwin-arm64', file: 'libafsim_compiler.dylib' },
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
function loadLibrary() {
|
|
16
|
-
const key = `${process.platform}-${process.arch}`;
|
|
17
|
-
const entry = PLATFORMS[key];
|
|
18
|
-
if (!entry) {
|
|
19
|
-
throw new Error(
|
|
20
|
-
`@wllzhang/afsim-compiler: unsupported platform ${key}. ` +
|
|
21
|
-
`Supported: ${Object.keys(PLATFORMS).join(', ')}`
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let pkgDir;
|
|
26
|
-
try {
|
|
27
|
-
const pkgJson = require.resolve(`${entry.pkg}/package.json`);
|
|
28
|
-
pkgDir = path.dirname(pkgJson);
|
|
29
|
-
} catch {
|
|
30
|
-
throw new Error(
|
|
31
|
-
`@wllzhang/afsim-compiler: platform package ${entry.pkg} is not installed. ` +
|
|
32
|
-
`Run: npm install ${entry.pkg}`
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return koffi.load(path.join(pkgDir, entry.file));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const lib = loadLibrary();
|
|
40
|
-
const _compile_json = lib.func('compile_json', 'str', ['str']);
|
|
41
|
-
const _free_string = lib.func('free_string', 'void', ['str']);
|
|
1
|
+
import { compile_json } from './pkg/afsim_compiler.js';
|
|
42
2
|
|
|
43
3
|
/**
|
|
44
4
|
* Compile a JSON object into AFSIM DSL text.
|
|
5
|
+
* Works in browsers and Node.js (no native bindings, pure WebAssembly).
|
|
45
6
|
*
|
|
46
|
-
* @param {Record<string, any>} data - The scenario definition as a plain JS object.
|
|
7
|
+
* @param {Record<string, any> | string} data - The scenario definition as a plain JS object or JSON string.
|
|
47
8
|
* @returns {string} The compiled AFSIM DSL output.
|
|
48
9
|
* @throws {Error} If the input is invalid or compilation fails.
|
|
49
10
|
*/
|
|
@@ -53,11 +14,8 @@ export function compile(data) {
|
|
|
53
14
|
}
|
|
54
15
|
|
|
55
16
|
const jsonStr = typeof data === 'string' ? data : JSON.stringify(data);
|
|
56
|
-
const result =
|
|
17
|
+
const result = compile_json(jsonStr);
|
|
57
18
|
|
|
58
|
-
if (!result) {
|
|
59
|
-
throw new Error('compile: received null from native library');
|
|
60
|
-
}
|
|
61
19
|
if (result.startsWith('ERROR:')) {
|
|
62
20
|
throw new Error(result);
|
|
63
21
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wllzhang/afsim-compiler",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "JSON to AFSIM DSL compiler —
|
|
3
|
+
"version": "0.5.2",
|
|
4
|
+
"description": "JSON to AFSIM DSL compiler — WebAssembly build for browsers and Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.mjs",
|
|
7
7
|
"exports": {
|
|
@@ -14,18 +14,9 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"index.mjs",
|
|
16
16
|
"index.d.ts",
|
|
17
|
+
"pkg",
|
|
17
18
|
"README.md"
|
|
18
19
|
],
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"koffi": "^2"
|
|
21
|
-
},
|
|
22
|
-
"optionalDependencies": {
|
|
23
|
-
"@wllzhang/afsim-compiler-win32-x64": "0.3.0",
|
|
24
|
-
"@wllzhang/afsim-compiler-linux-x64": "0.3.0",
|
|
25
|
-
"@wllzhang/afsim-compiler-linux-arm64": "0.3.0",
|
|
26
|
-
"@wllzhang/afsim-compiler-darwin-x64": "0.3.0",
|
|
27
|
-
"@wllzhang/afsim-compiler-darwin-arm64": "0.3.0"
|
|
28
|
-
},
|
|
29
20
|
"repository": {
|
|
30
21
|
"type": "git",
|
|
31
22
|
"url": "https://github.com/wllzhang/AFScriptGenerator.git",
|