@binblink/wasmnest-plugin-sdk-mobile 0.0.0-stage → 0.0.1
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 +363 -2
- package/README_en.md +353 -0
- package/bin/build.js +269 -0
- package/bin/cli.js +96 -0
- package/bin/lib.js +349 -0
- package/bin/manifest-gen.js +324 -0
- package/bin/package.js +150 -0
- package/bin/scaffold.js +285 -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 +51 -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 +328 -0
- package/dev-shell/src/locales/index.ts +70 -0
- package/dev-shell/src/locales/shell.ts +328 -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 +351 -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 +155 -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 +496 -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 +378 -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 +316 -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 +415 -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 +35 -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/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/styles/shell.css +841 -0
- package/dev-shell/src/shell/types.ts +137 -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 +884 -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 +84 -0
- package/dist/index.js +161 -0
- package/dist/types.d.ts +637 -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 +80 -3
- package/src/constants.ts +6 -0
- package/src/global-dialog.ts +168 -0
- package/src/index.ts +87 -0
- package/src/runtime.ts +44 -0
- package/src/types.ts +715 -0
- package/src/ui/PluginGlobalDialog.vue +388 -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/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/README_en.md
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
# @binblink/wasmnest-plugin-sdk-mobile
|
|
2
|
+
|
|
3
|
+
The WasmNest Mobile WASM app development kit — provides **type definitions**, **runtime proxies**, a **Vite build plugin**, and **shared UI components**. Compared to the desktop SDK, it additionally wraps mobile-only capabilities: SAF storage access, dialogs / system notifications, dynamic routing, lifecycle hooks, and the dev-shell mock data protocol.
|
|
4
|
+
|
|
5
|
+
> Terminology: this repository calls "plugins" WASM apps; the package name, CLI name and identifiers keep the original `plugin` words (`plugin.json`, `wasmnest-plugin-api-mobile`).
|
|
6
|
+
>
|
|
7
|
+
> Full development guide: [`wasm-app-dev-mobile.md`](../../docs/wasm-app-dev-mobile.md) (Chinese); development red-line checklist [`wasm-app-development-checklist.md`](../../../docs/knowledge/wasm-app-development-checklist.md).
|
|
8
|
+
|
|
9
|
+
English | [简体中文](README.md)
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add -D @binblink/wasmnest-plugin-sdk-mobile
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Peer dependencies (provided by the host at runtime; installed in the plugin for building & type-checking):
|
|
18
|
+
|
|
19
|
+
| Dependency | Version |
|
|
20
|
+
|------------|---------|
|
|
21
|
+
| vite | ^5.0.0 |
|
|
22
|
+
| vue | ^3.4.0 |
|
|
23
|
+
|
|
24
|
+
## Quick Start (recommended: scaffold)
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Create a WASM app project (id and name are positional args, not interactive; a WASM backend is included by default, --ts-only for frontend-only)
|
|
28
|
+
wasmnest-plugin create com.example.my-app "My App" --author "you"
|
|
29
|
+
|
|
30
|
+
cd my-app
|
|
31
|
+
pnpm install
|
|
32
|
+
ppnpm run dev # Browser dev environment (Dev Shell: empty host shell + mobile skeleton, HMR)
|
|
33
|
+
ppnpm run build # Build output dist/
|
|
34
|
+
ppnpm run package # Pack the dist/{id}.zip app bundle
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
More commands (run the CLI directly inside the app project, not as npm scripts):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
wasmnest-plugin manifest [--check] # auto-fill plugin.json contributes / permissions from source
|
|
41
|
+
wasmnest-plugin validate [--dir] # validate plugin.json
|
|
42
|
+
wasmnest-plugin doctor # environment self-check
|
|
43
|
+
wasmnest-plugin build --watch # rebuild on change
|
|
44
|
+
wasmnest-plugin dev --host # bind the LAN so a phone browser can open http://<pc-ip>:5173
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
> [!NOTE]
|
|
48
|
+
> `ppnpm run dev` auto-installs dev-shell dependencies on first run and opens http://localhost:5173 in the browser; WASM backends and mobile-only capabilities (SAF, system back key, ...) still need verification on a real device.
|
|
49
|
+
|
|
50
|
+
**Installing on a phone**: transfer `dist/{id}.zip` to the phone → WasmNest Mobile → Plugin Management → Install from file (remote download with SHA256 verification is also supported).
|
|
51
|
+
|
|
52
|
+
## Creating a Plugin Manually
|
|
53
|
+
|
|
54
|
+
A minimal plugin needs just two files:
|
|
55
|
+
|
|
56
|
+
**`plugin.json`** — plugin manifest (id / permissions / extension point declarations):
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"id": "com.example.my-plugin",
|
|
61
|
+
"name": "My Plugin",
|
|
62
|
+
"version": "0.1.0",
|
|
63
|
+
"platform": "mobile",
|
|
64
|
+
"description": "Example plugin",
|
|
65
|
+
"author": "you",
|
|
66
|
+
"icon": "🧩",
|
|
67
|
+
"main": "index.js",
|
|
68
|
+
"pluginType": "ts-only",
|
|
69
|
+
"permissions": ["storage", "ui:input"],
|
|
70
|
+
"contributes": {
|
|
71
|
+
"commands": [{ "id": "my-plugin.hello", "title": "Hello" }],
|
|
72
|
+
"terminal": {
|
|
73
|
+
"toolbarItems": [{ "id": "my-plugin.toolbar", "title": "My Plugin", "icon": "🧩" }]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**`src/index.ts`** — plugin entry (must export `activate`):
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import type { PluginContext } from '@binblink/wasmnest-plugin-sdk-mobile'
|
|
83
|
+
|
|
84
|
+
export async function activate(context: PluginContext): Promise<void> {
|
|
85
|
+
// Register a terminal toolbar button
|
|
86
|
+
context.ui.registerTerminalToolbarItem({
|
|
87
|
+
id: 'my-plugin.toolbar',
|
|
88
|
+
label: 'My Plugin',
|
|
89
|
+
icon: '🧩',
|
|
90
|
+
onClick: () => {
|
|
91
|
+
context.dialogs.showToast('Hello WasmNest!', 'success')
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function deactivate(): Promise<void> {
|
|
97
|
+
// Clean up (all Disposables registered via context are collected by the host automatically)
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## PluginContext API
|
|
102
|
+
|
|
103
|
+
The `PluginContext` received by `activate(context)` is the **single channel** through which a plugin accesses host capabilities, grouped by permission:
|
|
104
|
+
|
|
105
|
+
| API | Description | Required permission |
|
|
106
|
+
|-----|-------------|---------------------|
|
|
107
|
+
| `context.commands` | Register / execute commands (`register` / `execute`) — including the app's own business commands (e.g. `file-transfer.list-remote`) | granted by default |
|
|
108
|
+
| `context.session` | Session list, single-session lookup, status change subscription | `session:read` / `session:write` |
|
|
109
|
+
| `context.ui` | Host-shell surface / home quick cards / capsule menu / platform settings entries / dynamic routes (`registerSurface` / `registerSlot` / `registerCapsuleItem` / `registerSettingsEntry` / `registerRoute`), navigation (`openPage` / `goBack`), system back-key interception (`onBackPressed`), global dialogs (`showDialog`) | `ui:route` / `ui:back` / `ui:dialog` / `ui:settings` |
|
|
110
|
+
| `context.events` | Host event subscription & publishing (`on` / `emit`) | granted by default |
|
|
111
|
+
| `context.storage` | Key-value storage (`get` / `set` / `delete`) | `storage` (**always granted on mobile** — see note below) |
|
|
112
|
+
| `context.lifecycle` | App lifecycle hooks (`onAppStartup` / `onAppShutdown` / `onAuthSuccess` / `onDisconnect` / `onSessionCreated` / `onSessionStopped`) | granted by default |
|
|
113
|
+
| `context.dialogs` | Dialogs (`showDialog` / `showConfirm` / `showPrompt` / `showToast`) | granted by default |
|
|
114
|
+
| `context.notifications` | System notifications (`notify(title, body?)`) | granted by default |
|
|
115
|
+
| `context.status` | Lifecycle status reporting (`reportReady` / `reportError`) | granted by default |
|
|
116
|
+
| `context.logger` | Leveled logging (`info` / `debug` / `warn` / `error`) | granted by default |
|
|
117
|
+
| `context.i18n` | Register app translations, `t()` helper | granted by default |
|
|
118
|
+
| `context.system` | System-level operations (`openFile` / `revealInDir` / `revealReceivedFileLocation` / `requestAllFilesAccess` / `openDownloadDir`) | `system:open` |
|
|
119
|
+
| `context._disposables` | List of Disposables collected by the host on deactivation (internal) | — |
|
|
120
|
+
|
|
121
|
+
> Note: mobile has **no** `context.terminal` / `context.fileService` / `context.http` (those three are desktop-only).
|
|
122
|
+
> On mobile, terminal output is subscribed through the host-shell run surface (the app owns the protocol), file access goes through the `system` domain APIs (gated by `system:open` and SAF authorization), and cross-device transfer goes through app-owned `context.commands` (the underlying peer-network primitives live in the business core crate).
|
|
123
|
+
|
|
124
|
+
> Permissions are declared **per risk domain** — no default grants except `storage`: the host grants the effective set from the manifest `permissions`, and anything undeclared is denied.
|
|
125
|
+
> The exception is `storage` — mobile treats it as **always granted** (reading/writing the app's own configuration space; turning it off would make the app unusable), so there is no toggle: the host's `src-tauri/src/plugin/approval.rs::effective_permissions` unconditionally `insert("storage")`, and the shell marks it as a locked entry in `src/shell/permissions.ts::SHELL_LOCKED_PERMISSIONS`.
|
|
126
|
+
|
|
127
|
+
All `register*` / `on*` calls return a `Disposable`; the host collects them automatically on plugin deactivation — no manual `dispose()` needed.
|
|
128
|
+
|
|
129
|
+
## Mobile-Only Capabilities
|
|
130
|
+
|
|
131
|
+
### Dynamic Routing
|
|
132
|
+
|
|
133
|
+
Plugins can register routes at any depth; the host mounts them under `/mobile/plugins/{pluginId}/{id}`:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
context.ui.registerRoute({
|
|
137
|
+
id: 'settings', // may contain '/' for deep paths
|
|
138
|
+
title: 'Plugin Settings', // host header title (omitted when header: false)
|
|
139
|
+
component: SettingsPage, // any Vue component
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
context.ui.openPage('settings') // full navigation
|
|
143
|
+
context.ui.goBack() // go back
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
> [!NOTE]
|
|
147
|
+
> `context.ui.onBackPressed()` can intercept the Android system back key (Android devices only; it fires only while this app's surface is in the foreground — a backgrounded app never consumes the back press); on iOS / dev-shell it silently downgrades to never firing.
|
|
148
|
+
|
|
149
|
+
### Dialogs & Notifications
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
const ok = await context.dialogs.showConfirm({ title: 'Confirm', message: 'Delete?', variant: 'danger' })
|
|
153
|
+
const name = await context.dialogs.showPrompt({ title: 'Name', inputPlaceholder: 'Enter name' })
|
|
154
|
+
context.dialogs.showToast('Saved', 'success')
|
|
155
|
+
|
|
156
|
+
await context.notifications.notify('Task done', 'Session #3 finished')
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Lifecycle Hooks
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
context.lifecycle.onAppStartup(() => { /* app start (foreground launches only) */ })
|
|
163
|
+
context.lifecycle.onAuthSuccess(() => { /* refresh peer data after pairing */ })
|
|
164
|
+
context.lifecycle.onDisconnect((reason) => { /* disconnected from desktop */ })
|
|
165
|
+
context.lifecycle.onSessionCreated((sessionId) => { /* new session established */ })
|
|
166
|
+
context.lifecycle.onSessionStopped((sessionId) => { /* session ended */ })
|
|
167
|
+
context.lifecycle.onAppShutdown(() => { /* clean up before shutdown */ })
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
> `onTerminalInput` / `onTerminalOutput` were retired in ticket 15 phase B — terminal I/O no longer flows through lifecycle hooks; the app owns its subscription channel (host-shell run surface).
|
|
171
|
+
|
|
172
|
+
### Peer Desktop HTTP Capabilities (MobileHostApi)
|
|
173
|
+
|
|
174
|
+
`getMobileApi()` provides reactive connection state plus a peer REST client (task queue, session auto mode, task history, scheduled jobs — the HTTP paths are owned by each business app):
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import { getMobileApi } from '@binblink/wasmnest-plugin-sdk-mobile'
|
|
178
|
+
|
|
179
|
+
const api = getMobileApi()
|
|
180
|
+
console.log(api.isConnected.value, api.activeSessionId.value, api.isPaired.value)
|
|
181
|
+
|
|
182
|
+
// Generic REST client (path and payload shapes are app-owned)
|
|
183
|
+
const res = await api.httpRequest<{ tasks: unknown[]; queue_count: number }>(
|
|
184
|
+
`/task-queue/${api.activeSessionId}`, { method: 'GET' },
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
await api.loadActiveSessions() // refresh active sessions
|
|
188
|
+
api.onSessionEvent((evt) => { /* session event push */ })
|
|
189
|
+
const settings = await api.readAllSettings() // read all settings (flat key/value table)
|
|
190
|
+
await api.writeSetting('my-key', 'my-value') // write a single setting key
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### File & System Access
|
|
194
|
+
|
|
195
|
+
Mobile has **no** `context.fileService`. File-related capabilities split into two paths:
|
|
196
|
+
|
|
197
|
+
- **`context.system`** (`system:open` permission): `openFile(path, displayName?)` opens with the system viewer, `revealInDir(path)` / `revealReceivedFileLocation(fileName)` locate a file in the file manager, `openDownloadDir()` opens the shared downloads directory, `requestAllFilesAccess()` guides the user to grant MANAGE_EXTERNAL_STORAGE (unauthorized access to the shared downloads directory rejects with a message starting with `needs_all_files_access` — catch it and show the guidance dialog instead of failing silently).
|
|
198
|
+
- **Cross-device file transfer**: goes through app-owned `context.commands` (e.g. `file-transfer.list-remote`); the underlying peer-network / resumable transfer lives in the business core crate (`应用仓 apps/file-transfer/rust/core`) and is not exposed as a shared SDK API.
|
|
199
|
+
|
|
200
|
+
### dev-shell Mock Data (devMock)
|
|
201
|
+
|
|
202
|
+
Apps can export a `devMock` field with business demo data for the browser dev environment (queue seeds, SAF tree, ...); the real host ignores it — no conditional compilation needed:
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
export const devMock: PluginDevMock = {
|
|
206
|
+
queueSeed: [{ id: '1', prompt: 'Example task', position: 0, status: 'pending', created_at: '' }],
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
> `PluginDevMock` is typed as `Record<string, unknown>` — key names are a convention between the app and the dev-shell, with no compile-time validation.
|
|
211
|
+
|
|
212
|
+
## Shared Modules (avoid bundling vue etc.)
|
|
213
|
+
|
|
214
|
+
During plugin builds, `vue` / `vue-i18n` / `pinia` are externalized and read at runtime from the host global `window.__WASMNEST_SHARED__`. **Always access them via the SDK proxy functions — never touch the global directly**:
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
import { getVue, getPinia, getRouter, getPresetTasks, getMobileApi, getPluginContext } from '@binblink/wasmnest-plugin-sdk-mobile'
|
|
218
|
+
|
|
219
|
+
const { ref, computed } = getVue() // Host Vue instance (components can import vue directly — externalized at build time)
|
|
220
|
+
const presetTasks = getPresetTasks() // Host preset-tasks composable
|
|
221
|
+
const context = getPluginContext() // PluginContext via inject inside component setup
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### App run and stores (Pinia)
|
|
225
|
+
|
|
226
|
+
The host scopes plugin stores to a single **app run**: everything between `activate` and `deactivate`
|
|
227
|
+
(including swipe-away / × / "disable" in the app detail / uninstall) belongs to that run. **Stopping
|
|
228
|
+
the app disposes every store created in it** — the next launch starts from the setup initial state and
|
|
229
|
+
never sees leftovers from the previous run.
|
|
230
|
+
|
|
231
|
+
Two contracts follow:
|
|
232
|
+
|
|
233
|
+
1. **Define stores at the top level of your plugin module** (`const useX = defineStore(...)`). The host
|
|
234
|
+
records ownership while the module is loaded; because the module is cached and evaluated only once,
|
|
235
|
+
that is still enough for the next run to get a fresh scope. Stores defined in async chunks fall back
|
|
236
|
+
to the host Pinia with a warning (not guaranteed to be disposed on app stop).
|
|
237
|
+
2. **Module-level mutable singletons must be cleared in `deactivate`** (or tied to a `context`
|
|
238
|
+
disposable). The host does not re-evaluate your module; state that survives across activations is a
|
|
239
|
+
plugin defect. Data that must outlive a run belongs in storage / plugin-database.
|
|
240
|
+
|
|
241
|
+
## Vite Build Integration
|
|
242
|
+
|
|
243
|
+
Add `wasmnestPlugin()` to the plugin's `vite.config.ts`; it marks shared modules as external and rewrites them to read from the host global:
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
import { defineConfig } from 'vite'
|
|
247
|
+
import vue from '@vitejs/plugin-vue'
|
|
248
|
+
import { wasmnestPlugin } from '@binblink/wasmnest-plugin-sdk-mobile/vite'
|
|
249
|
+
|
|
250
|
+
export default defineConfig({
|
|
251
|
+
plugins: [vue(), wasmnestPlugin()],
|
|
252
|
+
build: {
|
|
253
|
+
lib: {
|
|
254
|
+
entry: 'src/index.ts',
|
|
255
|
+
formats: ['es'],
|
|
256
|
+
fileName: () => 'index.js',
|
|
257
|
+
},
|
|
258
|
+
outDir: 'dist',
|
|
259
|
+
},
|
|
260
|
+
})
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
The output filename must be `index.js` (matching `main` in `plugin.json`).
|
|
264
|
+
|
|
265
|
+
## Rust WASM Backend (`--rust` plugins)
|
|
266
|
+
|
|
267
|
+
The `--rust` scaffold includes the Rust-side SDK crate **`wasmnest-plugin-api-mobile`** (in this package's `rust/` directory, MIT) for backend logic compiled into a WASM component that runs inside the host's wasmtime sandbox.
|
|
268
|
+
|
|
269
|
+
### Enable
|
|
270
|
+
|
|
271
|
+
```toml
|
|
272
|
+
[dependencies]
|
|
273
|
+
wasmnest-plugin-api-mobile = { path = "<host>/packages/plugin-sdk-mobile/rust", features = ["wasm"] }
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
The `wasm` feature provides:
|
|
277
|
+
|
|
278
|
+
- `WasmPlugin` trait + `wasm_entry!` macro — generates all component exports defined by the WIT contract (`rust/wit/wasmnest.wit`, single source of truth)
|
|
279
|
+
- `WasmHost` — host API bindings (import backend), calling host capabilities via bindgen
|
|
280
|
+
|
|
281
|
+
### Minimal Example
|
|
282
|
+
|
|
283
|
+
```rust
|
|
284
|
+
use wasmnest_plugin_api_mobile::{CommandArgs, WasmHost, WasmPlugin};
|
|
285
|
+
|
|
286
|
+
struct MyPlugin;
|
|
287
|
+
|
|
288
|
+
impl WasmPlugin for MyPlugin {
|
|
289
|
+
fn activate() -> anyhow::Result<()> {
|
|
290
|
+
// Access host capabilities via WasmHost (events, storage, file service, ...)
|
|
291
|
+
Ok(())
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
wasmnest_plugin_api_mobile::wasm_entry!(MyPlugin);
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Build
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
cargo build --target wasm32-unknown-unknown --no-default-features --features wasm --release
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
The output is a WASM component (Component Model) loaded by the host inside the wasmtime sandbox — a crashing plugin never affects the host. Mobile-only capabilities (SAF, system back key, ...) need verification on a real Android device.
|
|
305
|
+
|
|
306
|
+
## Shared UI Components
|
|
307
|
+
|
|
308
|
+
Components exported via the `./ui` subpath follow the host design tokens so plugin UI matches the host look & feel (**native `<select>` etc. system controls are banned**):
|
|
309
|
+
|
|
310
|
+
```vue
|
|
311
|
+
<script setup lang="ts">
|
|
312
|
+
import { ref } from 'vue'
|
|
313
|
+
import Select from '@binblink/wasmnest-plugin-sdk-mobile/ui'
|
|
314
|
+
|
|
315
|
+
const value = ref('a')
|
|
316
|
+
const options = [
|
|
317
|
+
{ value: 'a', label: 'Option A' },
|
|
318
|
+
{ value: 'b', label: 'Option B' },
|
|
319
|
+
]
|
|
320
|
+
</script>
|
|
321
|
+
|
|
322
|
+
<template>
|
|
323
|
+
<Select v-model="value" :options="options" size="sm" />
|
|
324
|
+
</template>
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Currently provided (each subpath is an independent export):
|
|
328
|
+
|
|
329
|
+
| Subpath | Contents | Purpose |
|
|
330
|
+
|---------|----------|---------|
|
|
331
|
+
| `./ui` | `Select` component | Dropdown (`update:modelValue` / `open` events, `md` / `sm` sizes) |
|
|
332
|
+
| `./ui/plugin-global-dialog` | `PluginGlobalDialog` component | Mobile host global dialog (mounted once at the app root; rendering driven by the global dialog controller, same shape as desktop) |
|
|
333
|
+
| `./ui/swipe-tabs` | `useSwipeTabs` composable | Horizontal swipe switching for dialog/tab content areas (a dominant-horizontal swipe past the threshold fires `onSwitch`; dominant-vertical swipes record no offset; `shouldSkip` excludes touch origins that must not act as page-swipe gestures, e.g. input controls) |
|
|
334
|
+
| `./global-dialog` | global dialog controller | Publish-subscribe dialog queue (FIFO, at most one open at a time; `update()` builds a fresh entry object before broadcasting), shared by the host and the dev-shell |
|
|
335
|
+
|
|
336
|
+
## Subpath Exports
|
|
337
|
+
|
|
338
|
+
| Subpath | Contents |
|
|
339
|
+
|---------|----------|
|
|
340
|
+
| `@binblink/wasmnest-plugin-sdk-mobile` | Main API: types + runtime proxies |
|
|
341
|
+
| `@binblink/wasmnest-plugin-sdk-mobile/vite` | `wasmnestPlugin()` Vite build plugin |
|
|
342
|
+
| `@binblink/wasmnest-plugin-sdk-mobile/types` | Pure types (types only, no runtime) |
|
|
343
|
+
| `@binblink/wasmnest-plugin-sdk-mobile/ui` | Shared Vue component: `Select` |
|
|
344
|
+
| `@binblink/wasmnest-plugin-sdk-mobile/ui/plugin-global-dialog` | `PluginGlobalDialog` |
|
|
345
|
+
| `@binblink/wasmnest-plugin-sdk-mobile/ui/swipe-tabs` | `useSwipeTabs` |
|
|
346
|
+
| `@binblink/wasmnest-plugin-sdk-mobile/global-dialog` | global dialog controller |
|
|
347
|
+
|
|
348
|
+
## Developing this SDK
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
pnpm run build # tsup build → dist (ESM + d.ts)
|
|
352
|
+
pnpm run test:run # vitest run
|
|
353
|
+
```
|
package/bin/build.js
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
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
|
+
const hasWasm = pluginType === 'wasm' && rustLibrary
|
|
89
|
+
const viteBin = findViteBin(cwd)
|
|
90
|
+
if (!viteBin) {
|
|
91
|
+
console.error(
|
|
92
|
+
'[wasmnest-plugin] vite 未找到(自插件目录向上查找 node_modules/vite 均无)— 先在插件目录或仓库根运行 pnpm install',
|
|
93
|
+
)
|
|
94
|
+
process.exit(1)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const dest = join(resolve(cwd, resourcesDir), id)
|
|
98
|
+
const distDir = join(cwd, 'dist')
|
|
99
|
+
const wasmPath = hasWasm ? resolveWasmPath(cwd, rustLibrary) : null
|
|
100
|
+
|
|
101
|
+
console.log('\n[wasmnest-plugin] ====== watch 前端构建(vite build --watch) ======')
|
|
102
|
+
console.log(`[wasmnest-plugin] 产物自动复制到: ${dest}`)
|
|
103
|
+
console.log(
|
|
104
|
+
'[wasmnest-plugin] 修改插件前端源码后自动重建 + 复制(WASM 改动需一次性 pnpm run build)',
|
|
105
|
+
)
|
|
106
|
+
console.log('[wasmnest-plugin] Ctrl+C 退出\n')
|
|
107
|
+
|
|
108
|
+
// WASM 缺失预检:全新 resources 目录(从未跑过全量 build)时,复制完成后插件
|
|
109
|
+
// 加载仍会因缺 .wasm 失败,提前给出可执行指引
|
|
110
|
+
if (hasWasm && !existsSync(wasmPath)) {
|
|
111
|
+
console.warn(`[wasmnest-plugin] ⚠ WASM 产物缺失:${wasmPath}`)
|
|
112
|
+
console.warn('[wasmnest-plugin] watch 只重建前端。首次请先执行一次全量构建:')
|
|
113
|
+
console.warn('[wasmnest-plugin] pnpm run build(含 cargo wasm32 构建)')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 长驻 vite watch 构建(首次启动即完整构建一次)
|
|
117
|
+
const child = spawn(process.execPath, [viteBin, 'build', '--watch'], { cwd, stdio: 'inherit' })
|
|
118
|
+
child.on('exit', (code) => process.exit(code ?? 0))
|
|
119
|
+
|
|
120
|
+
// 复制产物到宿主资源目录(覆盖式,不删目录:宿主运行时可能正持有文件句柄)
|
|
121
|
+
const copy = () => {
|
|
122
|
+
try {
|
|
123
|
+
if (!existsSync(join(distDir, main))) return
|
|
124
|
+
mkdirSync(dest, { recursive: true })
|
|
125
|
+
copyDirContents(distDir, dest)
|
|
126
|
+
copyFileSync(join(cwd, 'plugin.json'), join(dest, 'plugin.json'))
|
|
127
|
+
// 插件图标(PluginIcon 经 asset protocol 加载 icon.svg)
|
|
128
|
+
const iconSrc = join(cwd, 'icon.svg')
|
|
129
|
+
if (existsSync(iconSrc)) copyFileSync(iconSrc, join(dest, 'icon.svg'))
|
|
130
|
+
// WASM 已构建则一并带上(缺失不报错:watch 场景以前端热更为主)
|
|
131
|
+
if (hasWasm && wasmPath && existsSync(wasmPath)) {
|
|
132
|
+
copyFileSync(wasmPath, join(dest, `${rustLibrary}.wasm`))
|
|
133
|
+
}
|
|
134
|
+
console.log(`[wasmnest-plugin] ${new Date().toLocaleTimeString()} 产物已复制 → ${dest}`)
|
|
135
|
+
} catch (e) {
|
|
136
|
+
console.error(`[wasmnest-plugin] 复制失败: ${e.message}`)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// dist 任意文件事件都防抖复制(Windows 上 fs.watch 的 filename 常为 null,按时间聚合最稳)
|
|
141
|
+
let timer = null
|
|
142
|
+
const schedule = () => {
|
|
143
|
+
clearTimeout(timer)
|
|
144
|
+
timer = setTimeout(copy, 500)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!existsSync(distDir)) mkdirSync(distDir, { recursive: true })
|
|
148
|
+
const watcher = watch(distDir, { persistent: true }, schedule)
|
|
149
|
+
watcher.on('error', (e) => console.error(`[wasmnest-plugin] dist 监听错误: ${e.message}`))
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ==================== 命令:build ====================
|
|
153
|
+
|
|
154
|
+
function cmdBuild(flags) {
|
|
155
|
+
const cwd = process.cwd()
|
|
156
|
+
const manifestPath = join(cwd, 'plugin.json')
|
|
157
|
+
if (!existsSync(manifestPath)) {
|
|
158
|
+
console.error(`[wasmnest-plugin] 当前目录不是插件工程(缺少 plugin.json): ${cwd}`)
|
|
159
|
+
console.error('请在插件目录内运行,或先用 wasmnest-plugin create 生成工程')
|
|
160
|
+
process.exit(1)
|
|
161
|
+
}
|
|
162
|
+
const manifest = readJson(manifestPath, 'plugin.json')
|
|
163
|
+
const { id, main, rustLibrary, pluginType } = manifest
|
|
164
|
+
const hasWasm = pluginType === 'wasm' && rustLibrary
|
|
165
|
+
const frontendOnly = flags['frontend-only'] === true
|
|
166
|
+
const rustOnly = flags['rust-only'] === true
|
|
167
|
+
const resourcesDir = flags['resources-dir']
|
|
168
|
+
|
|
169
|
+
// 0. 根据源码自动填充 contributes/permissions(构建前同步,保证产物与源码一致)
|
|
170
|
+
try {
|
|
171
|
+
const { changed, report } = generateManifest(cwd)
|
|
172
|
+
if (changed) {
|
|
173
|
+
for (const line of report) console.log(`[wasmnest-plugin] ${line}`)
|
|
174
|
+
console.log('[wasmnest-plugin] plugin.json 已自动填充')
|
|
175
|
+
}
|
|
176
|
+
} catch (e) {
|
|
177
|
+
console.error(`[wasmnest-plugin] manifest 自动填充失败: ${e.message}`)
|
|
178
|
+
process.exit(1)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// 0.5 watch 模式:vite 长驻构建 + 产物变化自动复制(需 --resources-dir 指定复制目标)
|
|
182
|
+
if (flags.watch) {
|
|
183
|
+
if (!resourcesDir) {
|
|
184
|
+
console.error(
|
|
185
|
+
'[wasmnest-plugin] --watch 需要 --resources-dir <宿主资源目录>(前端产物复制目标)',
|
|
186
|
+
)
|
|
187
|
+
process.exit(1)
|
|
188
|
+
}
|
|
189
|
+
startBuildWatch(cwd, resourcesDir, manifest)
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const distMain = join(cwd, 'dist', main || 'index.js')
|
|
194
|
+
const wasmPath = hasWasm ? resolveWasmPath(cwd, rustLibrary) : null
|
|
195
|
+
|
|
196
|
+
// 1. 前端构建
|
|
197
|
+
if (!rustOnly) {
|
|
198
|
+
const viteBin = join(cwd, 'node_modules/vite/bin/vite.js')
|
|
199
|
+
if (!existsSync(viteBin)) {
|
|
200
|
+
console.error(`[wasmnest-plugin] vite 未安装 — 先在插件目录运行 pnpm install`)
|
|
201
|
+
process.exit(1)
|
|
202
|
+
}
|
|
203
|
+
console.log('\n[wasmnest-plugin] ====== 构建前端 (vite) ======')
|
|
204
|
+
run(process.execPath, [viteBin, 'build'], cwd)
|
|
205
|
+
if (!existsSync(distMain)) {
|
|
206
|
+
console.error(`[wasmnest-plugin] vite 构建未产出 dist/${main || 'index.js'}`)
|
|
207
|
+
process.exit(1)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// 2. WASM 构建
|
|
212
|
+
if (hasWasm && !frontendOnly) {
|
|
213
|
+
console.log('\n[wasmnest-plugin] ====== 构建 WASM (cargo) ======')
|
|
214
|
+
run(
|
|
215
|
+
'cargo',
|
|
216
|
+
[
|
|
217
|
+
'build',
|
|
218
|
+
'--target',
|
|
219
|
+
'wasm32-unknown-unknown',
|
|
220
|
+
'--no-default-features',
|
|
221
|
+
'--features',
|
|
222
|
+
'wasm',
|
|
223
|
+
'--manifest-path',
|
|
224
|
+
'rust/Cargo.toml',
|
|
225
|
+
'--release',
|
|
226
|
+
],
|
|
227
|
+
cwd,
|
|
228
|
+
)
|
|
229
|
+
if (!existsSync(wasmPath)) {
|
|
230
|
+
console.error(`[wasmnest-plugin] WASM 构建未产出 ${rustLibrary}.wasm`)
|
|
231
|
+
console.error(' 若提示 target 缺失: rustup target add wasm32-unknown-unknown')
|
|
232
|
+
process.exit(1)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// 组件化:将 wit-bindgen 产出的 core module(含 component-type 自定义段)
|
|
236
|
+
// 编码为 Component Model 组件(等价 wasm-tools component new)。
|
|
237
|
+
// 工具幂等——产物已是组件(0d 00 01 00)时直接复制,支持增量构建。
|
|
238
|
+
// 迁移 spec §4 S2:产物字节形态 `00 61 73 6d 0d 00 01 00`(模块段在组件头前)
|
|
239
|
+
// 工具随桌面 SDK 发布(`tools/componentize`;P1 起从平台仓级 `tools/` 迁入;file-transfer
|
|
240
|
+
// 单产物后双端共用同一编码路径,2026-10-13 自 SDK rust/tools/ 提升)
|
|
241
|
+
console.log('\n[wasmnest-plugin] ====== 组件化 WASM (Component Model) ======')
|
|
242
|
+
const componentizeManifest = resolveComponentizeManifest(cwd)
|
|
243
|
+
run(
|
|
244
|
+
'cargo',
|
|
245
|
+
['run', '--release', '--manifest-path', componentizeManifest, '--', wasmPath, '-o', wasmPath],
|
|
246
|
+
cwd,
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// 3. 复制产物到宿主资源目录(--resources-dir <父目录>,按插件 id 建子目录)
|
|
251
|
+
if (resourcesDir) {
|
|
252
|
+
const dest = join(resolve(cwd, resourcesDir), id)
|
|
253
|
+
mkdirSync(dest, { recursive: true })
|
|
254
|
+
copyDirContents(join(cwd, 'dist'), dest)
|
|
255
|
+
copyFileSync(manifestPath, join(dest, 'plugin.json'))
|
|
256
|
+
// 插件图标(PluginIcon 经 asset protocol 加载 icon.svg)
|
|
257
|
+
const iconSrc = join(cwd, 'icon.svg')
|
|
258
|
+
if (existsSync(iconSrc)) copyFileSync(iconSrc, join(dest, 'icon.svg'))
|
|
259
|
+
if (hasWasm && !frontendOnly) {
|
|
260
|
+
copyFileSync(wasmPath, join(dest, `${rustLibrary}.wasm`))
|
|
261
|
+
}
|
|
262
|
+
console.log(`\n[wasmnest-plugin] 产物已复制到: ${dest}`)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
console.log('\n[wasmnest-plugin] 构建完成')
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
export { cmdDev, cmdBuild }
|