@binblink/wasmnest-plugin-sdk-mobile 0.0.0-stage → 0.0.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 +439 -2
- package/README_en.md +415 -0
- package/bin/build.js +271 -0
- package/bin/cli.js +96 -0
- package/bin/lib.js +349 -0
- package/bin/manifest-gen.js +327 -0
- package/bin/package.js +151 -0
- package/bin/scaffold.js +299 -0
- package/dev-shell/README.md +151 -0
- package/dev-shell/index.html +27 -0
- package/dev-shell/package.json +27 -0
- package/dev-shell/pnpm-workspace.yaml +9 -0
- package/dev-shell/postcss.config.js +6 -0
- package/dev-shell/src/App.vue +90 -0
- package/dev-shell/src/apps/mock-terminal/MockTerminalSlotCard.vue +43 -0
- package/dev-shell/src/apps/mock-terminal/MockTerminalView.vue +168 -0
- package/dev-shell/src/apps/mock-terminal/index.ts +50 -0
- package/dev-shell/src/components/DevToolbar.vue +100 -0
- package/dev-shell/src/components/DialogHost.vue +119 -0
- package/dev-shell/src/components/LogPanel.vue +80 -0
- package/dev-shell/src/i18n.ts +22 -0
- package/dev-shell/src/loader.ts +239 -0
- package/dev-shell/src/locale.ts +29 -0
- package/dev-shell/src/locales/en-shell.ts +332 -0
- package/dev-shell/src/locales/index.ts +70 -0
- package/dev-shell/src/locales/shell.ts +331 -0
- package/dev-shell/src/main.ts +58 -0
- package/dev-shell/src/mock/dialog-service.ts +58 -0
- package/dev-shell/src/mock/file-transfer.ts +390 -0
- package/dev-shell/src/mock/mobile-api.ts +369 -0
- package/dev-shell/src/mock/preset-tasks.ts +186 -0
- package/dev-shell/src/mock/session.ts +121 -0
- package/dev-shell/src/mock-context.ts +374 -0
- package/dev-shell/src/registry.ts +151 -0
- package/dev-shell/src/shared-runtime.ts +44 -0
- package/dev-shell/src/shell/ShellView.vue +52 -0
- package/dev-shell/src/shell/adapters/devAppSource.ts +144 -0
- package/dev-shell/src/shell/components/PluginContextHost.vue +40 -0
- package/dev-shell/src/shell/components/ShellAppCell.vue +75 -0
- package/dev-shell/src/shell/components/ShellAppIcon.vue +111 -0
- package/dev-shell/src/shell/components/ShellAppSurface.vue +46 -0
- package/dev-shell/src/shell/components/ShellBrandTile.vue +27 -0
- package/dev-shell/src/shell/components/ShellCapsuleMenu.vue +123 -0
- package/dev-shell/src/shell/components/ShellChip.vue +49 -0
- package/dev-shell/src/shell/components/ShellGroupCard.vue +17 -0
- package/dev-shell/src/shell/components/ShellHost.vue +75 -0
- package/dev-shell/src/shell/components/ShellNotificationShade.vue +501 -0
- package/dev-shell/src/shell/components/ShellPermissionPrompt.vue +127 -0
- package/dev-shell/src/shell/components/ShellPlaceholderSurface.vue +33 -0
- package/dev-shell/src/shell/components/ShellSection.vue +27 -0
- package/dev-shell/src/shell/components/ShellSheet.vue +74 -0
- package/dev-shell/src/shell/components/ShellStatusbar.vue +84 -0
- package/dev-shell/src/shell/components/screens/PluginRoutePage.vue +98 -0
- package/dev-shell/src/shell/components/screens/ShellAppDetailScreen.vue +359 -0
- package/dev-shell/src/shell/components/screens/ShellAppRunScreen.vue +90 -0
- package/dev-shell/src/shell/components/screens/ShellAppsScreen.vue +195 -0
- package/dev-shell/src/shell/components/screens/ShellHomeScreen.vue +357 -0
- package/dev-shell/src/shell/components/screens/ShellPermissionsScreen.vue +376 -0
- package/dev-shell/src/shell/components/screens/ShellSettingsScreen.vue +240 -0
- package/dev-shell/src/shell/components/screens/ShellSwitcherScreen.vue +559 -0
- package/dev-shell/src/shell/components/ui/ConfirmDialog.vue +137 -0
- package/dev-shell/src/shell/components/ui/Toggle.vue +53 -0
- package/dev-shell/src/shell/composables/useShellApps.ts +417 -0
- package/dev-shell/src/shell/composables/useShellNavigation.ts +197 -0
- package/dev-shell/src/shell/composables/useShellNotifications.ts +115 -0
- package/dev-shell/src/shell/composables/useShellOpen.ts +44 -0
- package/dev-shell/src/shell/composables/useShellOverlays.ts +101 -0
- package/dev-shell/src/shell/composables/useShellPreferences.ts +143 -0
- package/dev-shell/src/shell/composables/useShellRecent.ts +84 -0
- package/dev-shell/src/shell/composables/useSlotCarousel.ts +238 -0
- package/dev-shell/src/shell/composables/useToast.ts +33 -0
- package/dev-shell/src/shell/index.ts +88 -0
- package/dev-shell/src/shell/logger.ts +45 -0
- package/dev-shell/src/shell/permissions.ts +145 -0
- package/dev-shell/src/shell/registry.ts +220 -0
- package/dev-shell/src/shell/slotCards.ts +47 -0
- package/dev-shell/src/shell/styles/shell.css +1155 -0
- package/dev-shell/src/shell/surfaceIntent.ts +107 -0
- package/dev-shell/src/shell/types.ts +152 -0
- package/dev-shell/src/shell/utils.ts +54 -0
- package/dev-shell/src/styles/main.css +153 -0
- package/dev-shell/src/styles/mobile.css +981 -0
- package/dev-shell/src/styles/wallpaper.css +130 -0
- package/dev-shell/src/theme.ts +71 -0
- package/dev-shell/src/vite-env.d.ts +20 -0
- package/dev-shell/tailwind.config.js +101 -0
- package/dev-shell/tsconfig.json +16 -0
- package/dev-shell/vite.config.ts +130 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +229 -0
- package/dist/types.d.ts +738 -0
- package/dist/types.js +0 -0
- package/dist/vite-plugin.d.ts +16 -0
- package/dist/vite-plugin.js +95 -0
- package/package.json +88 -3
- package/src/constants.ts +6 -0
- package/src/global-dialog.ts +168 -0
- package/src/index.ts +96 -0
- package/src/runtime.ts +44 -0
- package/src/types.ts +822 -0
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/PluginGlobalDialog.vue +388 -0
- package/src/ui/QuickCard.d.ts +33 -0
- package/src/ui/QuickCard.vue +167 -0
- package/src/ui/Select.d.ts +37 -0
- package/src/ui/Select.vue +307 -0
- package/src/ui/plugin-global-dialog.d.ts +11 -0
- package/src/ui/useSwipeTabs.d.ts +20 -0
- package/src/ui/useSwipeTabs.ts +53 -0
- package/src/update.ts +123 -0
- package/src/vite-plugin.ts +132 -0
- package/template/.gitignore +4 -0
- package/template/README.md +46 -0
- package/template/package.json +23 -0
- package/template/plugin.json +13 -0
- package/template/rust/Cargo.toml +19 -0
- package/template/rust/src/lib.rs +33 -0
- package/template/src/env.d.ts +24 -0
- package/template/src/index.ts +37 -0
- package/template/tsconfig.json +17 -0
- package/template/vite.config.ts +21 -0
package/bin/build.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wasmnest-plugin 构建命令:dev / build(含 watch)(自 cli.js 拆出)
|
|
3
|
+
*/
|
|
4
|
+
import { copyFileSync, existsSync, mkdirSync, watch } from "node:fs"
|
|
5
|
+
import { join, resolve } from "node:path"
|
|
6
|
+
import { spawn } from "node:child_process"
|
|
7
|
+
import { generateManifest } from "./manifest-gen.js"
|
|
8
|
+
import { resolveComponentizeManifest, resolveCargoTargetDir, resolveWasmPath, resolveDevShellDir, copyDirContents, readJson, run, toPosix, DEV_SHELL_VITE, findViteBin } from "./lib.js"
|
|
9
|
+
|
|
10
|
+
// ==================== 命令:dev(浏览器开发环境) ====================
|
|
11
|
+
|
|
12
|
+
/** 启动 dev-shell:缺依赖时自动安装,然后以长驻 vite 进程运行 */
|
|
13
|
+
function cmdDev(positional, flags) {
|
|
14
|
+
const cwd = process.cwd()
|
|
15
|
+
const pluginDir = resolve(cwd, positional[0] || '.')
|
|
16
|
+
const entry = flags.entry ? resolve(cwd, flags.entry) : resolve(pluginDir, 'src/index.ts')
|
|
17
|
+
|
|
18
|
+
if (!existsSync(join(pluginDir, 'plugin.json')) && !existsSync(entry)) {
|
|
19
|
+
console.error(`[wasmnest-plugin] 目标不是插件工程(缺少 plugin.json 与 ${entry}): ${pluginDir}`)
|
|
20
|
+
console.error('用法: wasmnest-plugin dev [pluginDir] [--entry <file>] [--port <port>] [--open]')
|
|
21
|
+
process.exit(1)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const devShellDir = resolveDevShellDir(pluginDir)
|
|
25
|
+
if (!existsSync(devShellDir)) {
|
|
26
|
+
console.error(`[wasmnest-plugin] dev-shell 不存在: ${devShellDir}(SDK 包不完整)`)
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// dev-shell 首次运行需要安装自身依赖(vue / vite / tailwind 等)。
|
|
31
|
+
// 不加任何 pnpm 参数:dev-shell 自带 pnpm-workspace.yaml(packages: - .)既锚定安装
|
|
32
|
+
// 目录又是 allowBuilds 白名单的载体,而 --ignore-workspace 会连白名单一起忽略,
|
|
33
|
+
// 导致依赖构建脚本被跳过、pnpm 以 ERR_PNPM_IGNORED_BUILDS 非零退出(pnpm 12 已无
|
|
34
|
+
// --no-audit / --no-fund,传了直接报未知参数)
|
|
35
|
+
const viteBin = join(devShellDir, DEV_SHELL_VITE)
|
|
36
|
+
if (!existsSync(viteBin)) {
|
|
37
|
+
console.log('[wasmnest-plugin] dev-shell 依赖缺失,正在安装(仅首次)…')
|
|
38
|
+
run('pnpm', ['install'], devShellDir)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const args = [
|
|
42
|
+
viteBin,
|
|
43
|
+
'--config',
|
|
44
|
+
join(devShellDir, 'vite.config.ts'),
|
|
45
|
+
'--port',
|
|
46
|
+
String(flags.port || 5173),
|
|
47
|
+
// --force:依赖预构建缓存(dev-shell/node_modules/.vite)会残留插件改名 / 搬目录前的
|
|
48
|
+
// 绝对路径,vite 重跑优化器时读到即ENOENT,且只对前端返 504、页面空白且不自愈;
|
|
49
|
+
// 强制忽略缓存重建是唯一自愈手段(dev-shell 启动成本可接受)
|
|
50
|
+
'--force',
|
|
51
|
+
]
|
|
52
|
+
// --host:监听局域网(vite 默认仅 localhost),手机浏览器可访问查看页面
|
|
53
|
+
if (flags.host) args.push('--host', typeof flags.host === 'string' ? flags.host : '0.0.0.0')
|
|
54
|
+
if (flags.open) args.push('--open')
|
|
55
|
+
|
|
56
|
+
console.log(`[wasmnest-plugin] 启动 dev-shell(插件: ${pluginDir})`)
|
|
57
|
+
if (flags.host) {
|
|
58
|
+
console.log(
|
|
59
|
+
`[wasmnest-plugin] 已监听局域网 — 手机与电脑同一 WiFi 时,手机浏览器打开 http://<电脑IP>:${flags.port || 5173}/ 查看(建议关掉手机框开关)`,
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
console.log(
|
|
63
|
+
`[wasmnest-plugin] 浏览器打开 http://localhost:${flags.port || 5173}/ 预览(Ctrl+C 退出)`,
|
|
64
|
+
)
|
|
65
|
+
const child = spawn(process.execPath, args, {
|
|
66
|
+
cwd: devShellDir,
|
|
67
|
+
stdio: 'inherit',
|
|
68
|
+
env: {
|
|
69
|
+
...process.env,
|
|
70
|
+
WASMNEST_DEV_PLUGINS: `${pluginDir}::${entry}`,
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
child.on('exit', (code) => {
|
|
74
|
+
process.exit(code ?? 0)
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// ==================== 命令:build(watch 模式) ====================
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* watch 模式:vite build --watch 长驻构建前端,重建完成后自动复制产物到宿主资源目录。
|
|
83
|
+
*
|
|
84
|
+
* 只 watch 前端:WASM 产物不参与(已构建时随复制一并带上;Rust 改动需一次性 `wasmnest-plugin build`)。
|
|
85
|
+
*/
|
|
86
|
+
function startBuildWatch(cwd, resourcesDir, manifest) {
|
|
87
|
+
const { id, main = 'index.js', rustLibrary, pluginType } = manifest
|
|
88
|
+
// 形态三档(wasmnest-apps#21):backend / full 都携带 wasm 后端
|
|
89
|
+
const hasWasm = (pluginType === 'full' || pluginType === 'backend') && rustLibrary
|
|
90
|
+
const viteBin = findViteBin(cwd)
|
|
91
|
+
if (!viteBin) {
|
|
92
|
+
console.error(
|
|
93
|
+
'[wasmnest-plugin] vite 未找到(自插件目录向上查找 node_modules/vite 均无)— 先在插件目录或仓库根运行 pnpm install',
|
|
94
|
+
)
|
|
95
|
+
process.exit(1)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const dest = join(resolve(cwd, resourcesDir), id)
|
|
99
|
+
const distDir = join(cwd, 'dist')
|
|
100
|
+
const wasmPath = hasWasm ? resolveWasmPath(cwd, rustLibrary) : null
|
|
101
|
+
|
|
102
|
+
console.log('\n[wasmnest-plugin] ====== watch 前端构建(vite build --watch) ======')
|
|
103
|
+
console.log(`[wasmnest-plugin] 产物自动复制到: ${dest}`)
|
|
104
|
+
console.log(
|
|
105
|
+
'[wasmnest-plugin] 修改插件前端源码后自动重建 + 复制(WASM 改动需一次性 pnpm run build)',
|
|
106
|
+
)
|
|
107
|
+
console.log('[wasmnest-plugin] Ctrl+C 退出\n')
|
|
108
|
+
|
|
109
|
+
// WASM 缺失预检:全新 resources 目录(从未跑过全量 build)时,复制完成后插件
|
|
110
|
+
// 加载仍会因缺 .wasm 失败,提前给出可执行指引
|
|
111
|
+
if (hasWasm && !existsSync(wasmPath)) {
|
|
112
|
+
console.warn(`[wasmnest-plugin] ⚠ WASM 产物缺失:${wasmPath}`)
|
|
113
|
+
console.warn('[wasmnest-plugin] watch 只重建前端。首次请先执行一次全量构建:')
|
|
114
|
+
console.warn('[wasmnest-plugin] pnpm run build(含 cargo wasm32 构建)')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 长驻 vite watch 构建(首次启动即完整构建一次)
|
|
118
|
+
const child = spawn(process.execPath, [viteBin, 'build', '--watch'], { cwd, stdio: 'inherit' })
|
|
119
|
+
child.on('exit', (code) => process.exit(code ?? 0))
|
|
120
|
+
|
|
121
|
+
// 复制产物到宿主资源目录(覆盖式,不删目录:宿主运行时可能正持有文件句柄)
|
|
122
|
+
const copy = () => {
|
|
123
|
+
try {
|
|
124
|
+
if (!existsSync(join(distDir, main))) return
|
|
125
|
+
mkdirSync(dest, { recursive: true })
|
|
126
|
+
copyDirContents(distDir, dest)
|
|
127
|
+
copyFileSync(join(cwd, 'plugin.json'), join(dest, 'plugin.json'))
|
|
128
|
+
// 插件图标(PluginIcon 经 asset protocol 加载 icon.svg)
|
|
129
|
+
const iconSrc = join(cwd, 'icon.svg')
|
|
130
|
+
if (existsSync(iconSrc)) copyFileSync(iconSrc, join(dest, 'icon.svg'))
|
|
131
|
+
// WASM 已构建则一并带上(缺失不报错:watch 场景以前端热更为主)
|
|
132
|
+
if (hasWasm && wasmPath && existsSync(wasmPath)) {
|
|
133
|
+
copyFileSync(wasmPath, join(dest, `${rustLibrary}.wasm`))
|
|
134
|
+
}
|
|
135
|
+
console.log(`[wasmnest-plugin] ${new Date().toLocaleTimeString()} 产物已复制 → ${dest}`)
|
|
136
|
+
} catch (e) {
|
|
137
|
+
console.error(`[wasmnest-plugin] 复制失败: ${e.message}`)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// dist 任意文件事件都防抖复制(Windows 上 fs.watch 的 filename 常为 null,按时间聚合最稳)
|
|
142
|
+
let timer = null
|
|
143
|
+
const schedule = () => {
|
|
144
|
+
clearTimeout(timer)
|
|
145
|
+
timer = setTimeout(copy, 500)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!existsSync(distDir)) mkdirSync(distDir, { recursive: true })
|
|
149
|
+
const watcher = watch(distDir, { persistent: true }, schedule)
|
|
150
|
+
watcher.on('error', (e) => console.error(`[wasmnest-plugin] dist 监听错误: ${e.message}`))
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ==================== 命令:build ====================
|
|
154
|
+
|
|
155
|
+
function cmdBuild(flags) {
|
|
156
|
+
const cwd = process.cwd()
|
|
157
|
+
const manifestPath = join(cwd, 'plugin.json')
|
|
158
|
+
if (!existsSync(manifestPath)) {
|
|
159
|
+
console.error(`[wasmnest-plugin] 当前目录不是插件工程(缺少 plugin.json): ${cwd}`)
|
|
160
|
+
console.error('请在插件目录内运行,或先用 wasmnest-plugin create 生成工程')
|
|
161
|
+
process.exit(1)
|
|
162
|
+
}
|
|
163
|
+
const manifest = readJson(manifestPath, 'plugin.json')
|
|
164
|
+
const { id, main, rustLibrary, pluginType } = manifest
|
|
165
|
+
// 形态三档(wasmnest-apps#21):backend / full 都携带 wasm 后端
|
|
166
|
+
const hasWasm = (pluginType === 'full' || pluginType === 'backend') && rustLibrary
|
|
167
|
+
const frontendOnly = flags['frontend-only'] === true
|
|
168
|
+
const rustOnly = flags['rust-only'] === true
|
|
169
|
+
const resourcesDir = flags['resources-dir']
|
|
170
|
+
|
|
171
|
+
// 0. 根据源码自动填充 contributes/permissions(构建前同步,保证产物与源码一致)
|
|
172
|
+
try {
|
|
173
|
+
const { changed, report } = generateManifest(cwd)
|
|
174
|
+
if (changed) {
|
|
175
|
+
for (const line of report) console.log(`[wasmnest-plugin] ${line}`)
|
|
176
|
+
console.log('[wasmnest-plugin] plugin.json 已自动填充')
|
|
177
|
+
}
|
|
178
|
+
} catch (e) {
|
|
179
|
+
console.error(`[wasmnest-plugin] manifest 自动填充失败: ${e.message}`)
|
|
180
|
+
process.exit(1)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 0.5 watch 模式:vite 长驻构建 + 产物变化自动复制(需 --resources-dir 指定复制目标)
|
|
184
|
+
if (flags.watch) {
|
|
185
|
+
if (!resourcesDir) {
|
|
186
|
+
console.error(
|
|
187
|
+
'[wasmnest-plugin] --watch 需要 --resources-dir <宿主资源目录>(前端产物复制目标)',
|
|
188
|
+
)
|
|
189
|
+
process.exit(1)
|
|
190
|
+
}
|
|
191
|
+
startBuildWatch(cwd, resourcesDir, manifest)
|
|
192
|
+
return
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const distMain = join(cwd, 'dist', main || 'index.js')
|
|
196
|
+
const wasmPath = hasWasm ? resolveWasmPath(cwd, rustLibrary) : null
|
|
197
|
+
|
|
198
|
+
// 1. 前端构建
|
|
199
|
+
if (!rustOnly) {
|
|
200
|
+
const viteBin = join(cwd, 'node_modules/vite/bin/vite.js')
|
|
201
|
+
if (!existsSync(viteBin)) {
|
|
202
|
+
console.error(`[wasmnest-plugin] vite 未安装 — 先在插件目录运行 pnpm install`)
|
|
203
|
+
process.exit(1)
|
|
204
|
+
}
|
|
205
|
+
console.log('\n[wasmnest-plugin] ====== 构建前端 (vite) ======')
|
|
206
|
+
run(process.execPath, [viteBin, 'build'], cwd)
|
|
207
|
+
if (!existsSync(distMain)) {
|
|
208
|
+
console.error(`[wasmnest-plugin] vite 构建未产出 dist/${main || 'index.js'}`)
|
|
209
|
+
process.exit(1)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// 2. WASM 构建
|
|
214
|
+
if (hasWasm && !frontendOnly) {
|
|
215
|
+
console.log('\n[wasmnest-plugin] ====== 构建 WASM (cargo) ======')
|
|
216
|
+
run(
|
|
217
|
+
'cargo',
|
|
218
|
+
[
|
|
219
|
+
'build',
|
|
220
|
+
'--target',
|
|
221
|
+
'wasm32-unknown-unknown',
|
|
222
|
+
'--no-default-features',
|
|
223
|
+
'--features',
|
|
224
|
+
'wasm',
|
|
225
|
+
'--manifest-path',
|
|
226
|
+
'rust/Cargo.toml',
|
|
227
|
+
'--release',
|
|
228
|
+
],
|
|
229
|
+
cwd,
|
|
230
|
+
)
|
|
231
|
+
if (!existsSync(wasmPath)) {
|
|
232
|
+
console.error(`[wasmnest-plugin] WASM 构建未产出 ${rustLibrary}.wasm`)
|
|
233
|
+
console.error(' 若提示 target 缺失: rustup target add wasm32-unknown-unknown')
|
|
234
|
+
process.exit(1)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// 组件化:将 wit-bindgen 产出的 core module(含 component-type 自定义段)
|
|
238
|
+
// 编码为 Component Model 组件(等价 wasm-tools component new)。
|
|
239
|
+
// 工具幂等——产物已是组件(0d 00 01 00)时直接复制,支持增量构建。
|
|
240
|
+
// 迁移 spec §4 S2:产物字节形态 `00 61 73 6d 0d 00 01 00`(模块段在组件头前)
|
|
241
|
+
// 工具随桌面 SDK 发布(`tools/componentize`;P1 起从平台仓级 `tools/` 迁入;file-transfer
|
|
242
|
+
// 单产物后双端共用同一编码路径,2026-10-13 自 SDK rust/tools/ 提升)
|
|
243
|
+
console.log('\n[wasmnest-plugin] ====== 组件化 WASM (Component Model) ======')
|
|
244
|
+
const componentizeManifest = resolveComponentizeManifest(cwd)
|
|
245
|
+
run(
|
|
246
|
+
'cargo',
|
|
247
|
+
['run', '--release', '--manifest-path', componentizeManifest, '--', wasmPath, '-o', wasmPath],
|
|
248
|
+
cwd,
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// 3. 复制产物到宿主资源目录(--resources-dir <父目录>,按插件 id 建子目录)
|
|
253
|
+
if (resourcesDir) {
|
|
254
|
+
const dest = join(resolve(cwd, resourcesDir), id)
|
|
255
|
+
mkdirSync(dest, { recursive: true })
|
|
256
|
+
copyDirContents(join(cwd, 'dist'), dest)
|
|
257
|
+
copyFileSync(manifestPath, join(dest, 'plugin.json'))
|
|
258
|
+
// 插件图标(PluginIcon 经 asset protocol 加载 icon.svg)
|
|
259
|
+
const iconSrc = join(cwd, 'icon.svg')
|
|
260
|
+
if (existsSync(iconSrc)) copyFileSync(iconSrc, join(dest, 'icon.svg'))
|
|
261
|
+
if (hasWasm && !frontendOnly) {
|
|
262
|
+
copyFileSync(wasmPath, join(dest, `${rustLibrary}.wasm`))
|
|
263
|
+
}
|
|
264
|
+
console.log(`\n[wasmnest-plugin] 产物已复制到: ${dest}`)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
console.log('\n[wasmnest-plugin] 构建完成')
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
export { cmdDev, cmdBuild }
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* wasmnest-plugin — WasmNest 移动端插件开发工具包命令行
|
|
4
|
+
*
|
|
5
|
+
* 用法:
|
|
6
|
+
* wasmnest-plugin create <id> <name> [--author <author>] [--dir <dir>] [--ts-only] [--registry]
|
|
7
|
+
* wasmnest-plugin build [--resources-dir <dir>] [--frontend-only] [--rust-only] [--watch]
|
|
8
|
+
* wasmnest-plugin package [-o <file>] [--hash]
|
|
9
|
+
* wasmnest-plugin dev [pluginDir] [--entry <file>] [--port <port>] [--host] [--open]
|
|
10
|
+
* wasmnest-plugin manifest [--check]
|
|
11
|
+
* wasmnest-plugin validate [--dir <dir>]
|
|
12
|
+
* wasmnest-plugin doctor
|
|
13
|
+
*
|
|
14
|
+
* create 从 SDK 内置模板生成插件工程(填充 id/name/author/crate 名);
|
|
15
|
+
* --ts-only 生成纯前端插件(无 rust/ 目录);--registry 时引用已发布版本
|
|
16
|
+
* build 串联 vite build → cargo wasm32 构建 → componentize 组件化(Component Model);
|
|
17
|
+
* --resources-dir 时复制产物到宿主资源目录;
|
|
18
|
+
* --watch 时 vite 长驻构建前端,重建后自动复制产物(前端热更)
|
|
19
|
+
* package 将产物打包为 {id}.zip 插件包(分发单元);--hash 时计算并写入 wasmHash
|
|
20
|
+
* dev 启动浏览器开发环境(dev-shell):vite dev server + HMR,插件源码在
|
|
21
|
+
* mock 宿主的移动端骨架中实时预览(WASM 后端不在浏览器运行);
|
|
22
|
+
* --host 时监听局域网,手机浏览器访问 http://<PC-IP>:<port> 可查看页面
|
|
23
|
+
* validate 校验 plugin.json 结构与字段合法性(CI 用,exit 1 表示不合法)
|
|
24
|
+
* doctor 环境自检:Node / Rust / wasm32 target / dev-shell 依赖 / SDK 构建产物
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { spawn, spawnSync } from 'node:child_process'
|
|
28
|
+
|
|
29
|
+
import { join } from 'node:path'
|
|
30
|
+
import { parseArgs, readJson, SDK_ROOT } from './lib.js'
|
|
31
|
+
import { cmdCreate, cmdManifest, cmdValidate } from './scaffold.js'
|
|
32
|
+
import { cmdDev, cmdBuild } from './build.js'
|
|
33
|
+
import { cmdPackage, cmdDoctor } from './package.js'
|
|
34
|
+
|
|
35
|
+
// ==================== 入口 ====================
|
|
36
|
+
|
|
37
|
+
function main() {
|
|
38
|
+
const { positional, flags } = parseArgs(process.argv.slice(2))
|
|
39
|
+
const [cmd] = positional
|
|
40
|
+
const rest = positional.slice(1)
|
|
41
|
+
const pkg = readJson(join(SDK_ROOT, 'package.json'), 'SDK package.json')
|
|
42
|
+
|
|
43
|
+
if (flags.version || flags.v) {
|
|
44
|
+
console.log(pkg.version)
|
|
45
|
+
process.exit(0)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (flags.help || flags.h || !cmd) {
|
|
49
|
+
console.log(`wasmnest-plugin v${pkg.version}`)
|
|
50
|
+
console.log('\nWasmNest 移动端插件开发工具包\n')
|
|
51
|
+
console.log('用法:')
|
|
52
|
+
console.log(
|
|
53
|
+
' wasmnest-plugin create <id> <name> [--author <author>] [--dir <dir>] [--ts-only] [--registry]',
|
|
54
|
+
)
|
|
55
|
+
console.log(
|
|
56
|
+
' wasmnest-plugin build [--resources-dir <dir>] [--frontend-only] [--rust-only] [--watch]',
|
|
57
|
+
)
|
|
58
|
+
console.log(' wasmnest-plugin package [-o <file>] [--hash] # --hash 写入 wasmHash 完整性校验')
|
|
59
|
+
console.log(
|
|
60
|
+
' wasmnest-plugin dev [pluginDir] [--entry <file>] [--port <port>] [--host] [--open] # 浏览器开发环境(HMR;--host 供手机访问)',
|
|
61
|
+
)
|
|
62
|
+
console.log(' wasmnest-plugin manifest [--check] # 按源码自动填充 contributes/permissions')
|
|
63
|
+
console.log(' wasmnest-plugin validate [--dir <dir>] # 校验 plugin.json 结构')
|
|
64
|
+
console.log(' wasmnest-plugin doctor # 环境自检(Node/Rust/wasm32/dev-shell/SDK)')
|
|
65
|
+
process.exit(0)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
switch (cmd) {
|
|
69
|
+
case 'create':
|
|
70
|
+
cmdCreate(rest, flags)
|
|
71
|
+
break
|
|
72
|
+
case 'build':
|
|
73
|
+
cmdBuild(flags)
|
|
74
|
+
break
|
|
75
|
+
case 'package':
|
|
76
|
+
cmdPackage(flags)
|
|
77
|
+
break
|
|
78
|
+
case 'dev':
|
|
79
|
+
cmdDev(rest, flags)
|
|
80
|
+
break
|
|
81
|
+
case 'manifest':
|
|
82
|
+
cmdManifest(flags)
|
|
83
|
+
break
|
|
84
|
+
case 'validate':
|
|
85
|
+
cmdValidate(flags)
|
|
86
|
+
break
|
|
87
|
+
case 'doctor':
|
|
88
|
+
cmdDoctor()
|
|
89
|
+
break
|
|
90
|
+
default:
|
|
91
|
+
console.error(`未知命令: ${cmd}(运行 wasmnest-plugin --help 查看用法)`)
|
|
92
|
+
process.exit(1)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
main()
|