@wllzhang/afsim-compiler 0.5.6 → 0.5.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wllzhang/afsim-compiler",
3
- "version": "0.5.6",
3
+ "version": "0.5.8",
4
4
  "description": "JSON to AFSIM DSL compiler — WebAssembly build for browsers and Node.js",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
package/pkg/README.md ADDED
@@ -0,0 +1,198 @@
1
+ # AFScriptGenerator
2
+
3
+ JSON to AFSIM DSL compiler.
4
+
5
+ 这个项目包含两个主要用法:
6
+
7
+ - Rust 命令行工具:把 `.json` 文件编译为同名 `.txt` 文件。
8
+ - npm/WASM 包:在前端或 Node 项目里通过 `compile()` 直接把 JS 对象或 JSON 字符串编译成 DSL 文本。
9
+
10
+ ## 环境准备
11
+
12
+ 需要安装:
13
+
14
+ - Rust / Cargo
15
+ - Node.js / npm
16
+ - `wasm-pack`,用于构建 npm 包里的 WASM 文件
17
+
18
+ 安装 `wasm-pack`:
19
+
20
+ ```powershell
21
+ cargo install wasm-pack
22
+ ```
23
+
24
+ 安装 WASM target:
25
+
26
+ ```powershell
27
+ rustup target add wasm32-unknown-unknown
28
+ ```
29
+
30
+ ## Rust 命令行
31
+
32
+ 查看帮助:
33
+
34
+ ```powershell
35
+ cargo run -- --help
36
+ ```
37
+
38
+ 运行编译器:
39
+
40
+ ```powershell
41
+ cargo run -- docx\afsim_script\define.json
42
+ ```
43
+
44
+ 输出文件会自动写到输入文件同目录,扩展名改为 `.txt`:
45
+
46
+ ```text
47
+ docx\afsim_script\define.txt
48
+ ```
49
+
50
+ 也可以先构建再运行:
51
+
52
+ ```powershell
53
+ cargo build
54
+ .\target\debug\afsim-compiler.exe docx\afsim_script\define.json
55
+ ```
56
+
57
+ 构建 release 版本:
58
+
59
+ ```powershell
60
+ cargo build --release
61
+ .\target\release\afsim-compiler.exe docx\afsim_script\define.json
62
+ ```
63
+
64
+ ## Rust 常用检查
65
+
66
+ 格式化代码:
67
+
68
+ ```powershell
69
+ cargo fmt
70
+ ```
71
+
72
+ 检查编译:
73
+
74
+ ```powershell
75
+ cargo check
76
+ ```
77
+
78
+ 运行测试:
79
+
80
+ ```powershell
81
+ cargo test
82
+ ```
83
+
84
+ ## 本地 npm 包
85
+
86
+ npm 包目录在:
87
+
88
+ ```text
89
+ npm
90
+ ```
91
+
92
+ 包名是:
93
+
94
+ ```text
95
+ @wllzhang/afsim-compiler
96
+ ```
97
+
98
+ 改动 `src` 后,运行一键脚本重新构建 WASM,并准备好本地 npm 包目录:
99
+
100
+ ```powershell
101
+ .\script\package-npm.ps1
102
+ ```
103
+
104
+ 或者使用 cmd 包装脚本:
105
+
106
+ ```powershell
107
+ .\script\package-npm.cmd
108
+ ```
109
+
110
+ 脚本会自动:
111
+
112
+ - 检查 `cargo`、`node`、`npm`、`wasm-pack`、`wasm32-unknown-unknown`
113
+ - 从 Rust `src` 重新构建 WASM 到 `npm\pkg`
114
+ - 清理 `wasm-pack` 生成的 `npm\pkg\.gitignore`
115
+ - 输出本地目录安装命令
116
+
117
+ 如果依赖缺失,脚本会打印对应的下载地址和安装命令。
118
+
119
+ 指定 npm 包版本:
120
+
121
+ ```powershell
122
+ .\script\package-npm.ps1 -Version 0.1.1
123
+ ```
124
+
125
+ 跳过 WASM 构建,只整理当前 npm 目录:
126
+
127
+ ```powershell
128
+ .\script\package-npm.ps1 -SkipWasmBuild
129
+ ```
130
+
131
+ ## 安装到另一个项目
132
+
133
+ 在目标项目里直接通过目录安装:
134
+
135
+ ```powershell
136
+ cd D:\your-other-project
137
+ npm install D:\code_spaces\AFScriptGenerator\npm
138
+ ```
139
+
140
+ 使用示例:
141
+
142
+ ```js
143
+ import { compile } from '@wllzhang/afsim-compiler';
144
+
145
+ const dsl = compile({
146
+ my_platform: {
147
+ type: 'platform_type',
148
+ parent_model: 'WSF_PLATFORM',
149
+ icon: 'missile',
150
+ },
151
+ });
152
+
153
+ console.log(dsl);
154
+ ```
155
+
156
+ ## Vite 项目使用
157
+
158
+ 这个 npm 包包含 WASM。Vite 项目建议安装 `vite-plugin-wasm`:
159
+
160
+ ```powershell
161
+ npm install vite-plugin-wasm
162
+ ```
163
+
164
+ `vite.config.js`:
165
+
166
+ ```js
167
+ import wasm from 'vite-plugin-wasm';
168
+
169
+ export default {
170
+ plugins: [wasm()],
171
+ build: { target: 'esnext' },
172
+ };
173
+ ```
174
+
175
+ ## 发布
176
+
177
+ 发布 Rust 二进制和 npm 包的 GitHub Actions 在:
178
+
179
+ ```text
180
+ .github\workflows\release-rust.yml
181
+ ```
182
+
183
+ 发布 workflow 当前只构建 Linux 和 Windows 产物,不再构建 macOS 产物。
184
+
185
+ 打 tag 后推送:
186
+
187
+ ```powershell
188
+ git tag v0.1.0
189
+ git push origin v0.1.0
190
+ ```
191
+
192
+ ## 清理
193
+
194
+ 清理 Rust 构建产物:
195
+
196
+ ```powershell
197
+ cargo clean
198
+ ```
@@ -1,7 +1,7 @@
1
1
  /* @ts-self-types="./afsim_compiler_lib.d.ts" */
2
-
3
2
  import * as wasm from "./afsim_compiler_lib_bg.wasm";
4
3
  import { __wbg_set_wasm } from "./afsim_compiler_lib_bg.js";
4
+
5
5
  __wbg_set_wasm(wasm);
6
6
 
7
7
  export {
@@ -39,8 +39,7 @@ function getDataViewMemory0() {
39
39
  }
40
40
 
41
41
  function getStringFromWasm0(ptr, len) {
42
- ptr = ptr >>> 0;
43
- return decodeText(ptr, len);
42
+ return decodeText(ptr >>> 0, len);
44
43
  }
45
44
 
46
45
  let cachedUint8ArrayMemory0 = null;
Binary file