@aiot-nexus/plugin-sdk 1.0.0 → 1.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 +16 -7
- package/dev-host/host.html +82 -15
- package/dev-host/main.js +98 -8
- package/dist/dev-host-metadata.json +3 -0
- package/dist/src/cli/run.js +105 -8
- package/dist/src/dev.d.ts +21 -9
- package/dist/src/dev.js +100 -19
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/scaffold.js +2 -0
- package/dist/src/validation.d.ts +4 -1
- package/dist/src/validation.js +8 -6
- package/dist/src/web-dev.d.ts +11 -0
- package/dist/src/web-dev.js +379 -0
- package/package.json +10 -3
- package/templates/minimal/README.md.tmpl +5 -2
- package/templates/minimal/scripts/build.js.tmpl +21 -4
- package/templates/minimal/src/renderer/app.ts.tmpl +37 -4
- package/templates/minimal/src/renderer/index.html +2 -2
- package/templates/minimal/src/renderer/plugin.css +34 -27
- package/templates/sqlite/README.md.tmpl +5 -2
- package/templates/sqlite/scripts/build.js.tmpl +28 -7
- package/templates/sqlite/src/renderer/app.ts.tmpl +37 -4
- package/templates/sqlite/src/renderer/index.html +2 -2
- package/templates/sqlite/src/renderer/plugin.css +52 -38
package/README.md
CHANGED
|
@@ -15,14 +15,16 @@ AIoT Nexus 独立插件开发包,包含公开 TypeScript 契约、PluginFrame
|
|
|
15
15
|
npm run build
|
|
16
16
|
npm test
|
|
17
17
|
npm run pack:sdk
|
|
18
|
+
npm run publish:sdk
|
|
18
19
|
|
|
19
20
|
nexus-plugin info
|
|
20
21
|
nexus-plugin validate <plugin-package-directory>
|
|
21
22
|
nexus-plugin create <plugin-id> --template minimal|sqlite --output <parent-directory>
|
|
22
23
|
nexus-plugin dev [plugin-project-directory]
|
|
24
|
+
nexus-plugin dev:web [plugin-project-directory]
|
|
23
25
|
```
|
|
24
26
|
|
|
25
|
-
`npm run pack:sdk` 将离线安装包写入 `package/`。该目录是本地构建产物,不进入 Git
|
|
27
|
+
`npm run pack:sdk` 将离线安装包写入 `package/`。该目录是本地构建产物,不进入 Git。`npm run publish:sdk` 发布到官方 npm registry;`prepack` 会强制运行测试、构建并核对实际 npm 文件清单,缺少任一公开入口时拒绝发布。
|
|
26
28
|
|
|
27
29
|
## 创建插件
|
|
28
30
|
|
|
@@ -31,31 +33,35 @@ nexus-plugin create my-frame-plugin \
|
|
|
31
33
|
--template minimal \
|
|
32
34
|
--output . \
|
|
33
35
|
--display-name "My Frame Plugin" \
|
|
34
|
-
--
|
|
36
|
+
--install
|
|
35
37
|
```
|
|
36
38
|
|
|
37
39
|
- `--template` 默认为 `minimal`,也可选择带 `better-sqlite3` 的 `sqlite`。
|
|
38
40
|
- `--output` 默认为当前目录,目标固定为 `<output>/<plugin-id>`。
|
|
39
|
-
- `--sdk-source`
|
|
41
|
+
- `--sdk-source` 默认为当前 CLI 的 SDK 版本。也可传入严格的 `X.Y.Z` npm 版本、`@aiot-nexus/plugin-sdk@X.Y.Z` 或本地 `.tgz` 进行覆盖;本地包会复制到生成工程的 `vendor/`,并写入可迁移的相对 `file:` 依赖。
|
|
40
42
|
- 默认不安装依赖;传入 `--install` 后执行 `npm install`。SQLite 模板在每次 `npm run build` 前强制执行 Electron 22.3.27 native rebuild。
|
|
41
43
|
- 目标目录非空时命令以返回码 `2` 拒绝覆盖。生成或安装失败返回 `1`。
|
|
42
|
-
- 两套模板均读取宿主 `PluginRendererContext.language`,通过 `onContextChanged` 在同一 iframe
|
|
44
|
+
- 两套模板均读取宿主 `PluginRendererContext.language` 和 `themeMode`,通过 `onContextChanged` 在同一 iframe 内响应运行时语言与主题切换,并内置 `zh-CN` / `en-US` renderer 文案;manifest 使用相同文化资源本地化宿主入口。模板页面自身不提供语言或主题选择控件。
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
默认来源从 npm registry 安装。离线开发时先执行 `npm run pack:sdk`,再通过 `--sdk-source /path/to/aiot-nexus-plugin-sdk-1.0.2.tgz` 指定本地包;CLI 会把本地包一并放入生成工程。
|
|
45
47
|
|
|
46
48
|
## 独立调试
|
|
47
49
|
|
|
48
50
|
生成工程安装依赖后,可以完全在插件目录启动调试宿主:
|
|
49
51
|
|
|
50
52
|
```bash
|
|
53
|
+
npm run dev:web
|
|
51
54
|
npm run dev
|
|
52
55
|
npm run dev:debug
|
|
53
56
|
```
|
|
54
57
|
|
|
58
|
+
- `npm run dev:web` 先运行模板独立的 `build:web`,只编译 Renderer 到 `.nexus-plugin-dev/web-package/<plugin-id>/`,再启动仅绑定 `127.0.0.1:4173` 的本地 HTTP 宿主并打开系统浏览器;它不执行 native rebuild、不复制原生运行时、不覆盖正式 `dist`,支持浏览器 DevTools 与源码映射。
|
|
59
|
+
- 浏览器模式不加载 `mainEntry`,`invokeMain` 会返回 `PluginCapabilityUnsupported`;设置仅在本次服务进程内保存,日志输出到 CLI。涉及主进程、SQLite 或 Host API 时使用 `npm run dev`。
|
|
55
60
|
- `npm run dev` 先构建和校验插件,再使用工程本地固定的 `electron@22.3.27` 启动 SDK 调试宿主;Renderer DevTools 默认自动打开。
|
|
61
|
+
- Electron 调试宿主的 `host.hostVersion` 默认是 SDK 构建时记录的 Nexus 应用版本;使用 `nexus-plugin dev . --host-version <X.Y.Z>` 可模拟其他应用版本,并按 manifest `minHostVersion` 拒绝不兼容组合。
|
|
56
62
|
- `npm run dev:debug` 额外使用 `--inspect-brk=9229` 暂停 Electron 主进程,可在 `src/main.ts` 启动阶段命中断点。
|
|
57
63
|
- 生成工程包含 `.vscode/launch.json`。在 VS Code 中选择 `Debug Nexus plugin` 可直接启动;若本机关闭了子进程自动附加,则先运行 `npm run dev:debug`,再选择 `Attach Nexus plugin main (9229)`。renderer 断点在自动打开的 DevTools `Sources` 中设置。
|
|
58
|
-
- 调试构建会内联 `src/main.ts` 和 `src/renderer/app.ts` source map。普通 `npm run build`
|
|
64
|
+
- Electron 调试构建会内联 `src/main.ts` 和 `src/renderer/app.ts` source map;浏览器 `build:web` 只内联 Renderer source map。普通 `npm run build` 不内联源码,不改变部署制品形态。模板在收到首个 Host context 前隐藏正文,应用语言和主题后再显示。
|
|
59
65
|
- 调试数据保存在工程的 `.nexus-plugin-dev/`,该目录默认被忽略。关闭调试窗口会结束独立 Electron 进程;修改源码后重新运行调试命令。
|
|
60
66
|
|
|
61
67
|
可直接使用的 CLI 选项:
|
|
@@ -64,6 +70,7 @@ npm run dev:debug
|
|
|
64
70
|
nexus-plugin dev [plugin-project-directory]
|
|
65
71
|
[--no-build]
|
|
66
72
|
[--inspect[=<port>] | --inspect-brk[=<port>]]
|
|
73
|
+
[--host-version <X.Y.Z>]
|
|
67
74
|
[--language <culture>]
|
|
68
75
|
[--theme system|light|dark]
|
|
69
76
|
[--surface business|tool|settings]
|
|
@@ -71,4 +78,6 @@ nexus-plugin dev [plugin-project-directory]
|
|
|
71
78
|
[--no-devtools]
|
|
72
79
|
```
|
|
73
80
|
|
|
74
|
-
|
|
81
|
+
调试宿主工具栏中的语言和主题选择器用于模拟 Nexus 主框架 context,不属于插件页面。切换后调试宿主向同一 iframe 重发框架 `1.0.0` 已有的 `init` 消息;SDK 将后续 `init` 作为 context 更新并原地刷新语言和主题,同时仍接受可选的 `context-changed` 消息。调试宿主还复用正式的 `nexus-plugin://` 资源协议、iframe sandbox、CSP、消息结构、operation 校验以及当前 Host API 权限语义,但不包含 Nexus 的完整页面路由、Pinia 状态和应用级功能。交付前仍需把 `dist/<plugin-id>/` 放入正式 Nexus 完成集成验证。
|
|
82
|
+
|
|
83
|
+
浏览器 UI 命令支持 `--no-build`、`--no-open`、`--port <port>`,以及与 Electron 调试宿主相同的 `--language`、`--theme`、`--surface` 和 `--contribution-id` 参数。它使用普通 `http://127.0.0.1` iframe,不模拟 `nexus-plugin://` 协议或 Electron sandbox,因此只作为 UI 开发入口。Renderer-only 输出不会覆盖正式插件制品。
|
package/dev-host/host.html
CHANGED
|
@@ -154,18 +154,18 @@
|
|
|
154
154
|
<header class="toolbar">
|
|
155
155
|
<strong id="pluginName" class="plugin-name">Nexus Plugin Dev</strong>
|
|
156
156
|
<label class="control" for="languageSelect">
|
|
157
|
-
<span>Language</span>
|
|
157
|
+
<span data-host-i18n="control.language">Language</span>
|
|
158
158
|
<select id="languageSelect"></select>
|
|
159
159
|
</label>
|
|
160
160
|
<label class="control" for="themeSelect">
|
|
161
|
-
<span>Theme</span>
|
|
161
|
+
<span data-host-i18n="control.theme">Theme</span>
|
|
162
162
|
<select id="themeSelect">
|
|
163
|
-
<option value="system">System</option>
|
|
164
|
-
<option value="light">Light</option>
|
|
165
|
-
<option value="dark">Dark</option>
|
|
163
|
+
<option value="system" data-host-i18n="theme.system">System</option>
|
|
164
|
+
<option value="light" data-host-i18n="theme.light">Light</option>
|
|
165
|
+
<option value="dark" data-host-i18n="theme.dark">Dark</option>
|
|
166
166
|
</select>
|
|
167
167
|
</label>
|
|
168
|
-
<button id="reloadButton" type="button">Reload frame</button>
|
|
168
|
+
<button id="reloadButton" type="button" data-host-i18n="action.reload">Reload frame</button>
|
|
169
169
|
<span id="status" class="status" data-connected="false">Waiting</span>
|
|
170
170
|
</header>
|
|
171
171
|
<main class="frame-shell">
|
|
@@ -174,13 +174,13 @@
|
|
|
174
174
|
<script>
|
|
175
175
|
"use strict";
|
|
176
176
|
|
|
177
|
-
var api = window.nexusPluginDevHost;
|
|
177
|
+
var api = window.nexusPluginDevHost || createBrowserHostApi();
|
|
178
178
|
var iframe = document.getElementById("pluginFrame");
|
|
179
179
|
var pluginName = document.getElementById("pluginName");
|
|
180
180
|
var languageSelect = document.getElementById("languageSelect");
|
|
181
181
|
var themeSelect = document.getElementById("themeSelect");
|
|
182
182
|
var reloadButton = document.getElementById("reloadButton");
|
|
183
|
-
var
|
|
183
|
+
var statusOutput = document.getElementById("status");
|
|
184
184
|
var configuration;
|
|
185
185
|
var context;
|
|
186
186
|
var initialized = false;
|
|
@@ -188,6 +188,32 @@
|
|
|
188
188
|
var resizeSeen = false;
|
|
189
189
|
var pendingRequests = 0;
|
|
190
190
|
var smokeTimer;
|
|
191
|
+
var statusKey = "status.waiting";
|
|
192
|
+
var statusConnected = false;
|
|
193
|
+
var hostMessages = {
|
|
194
|
+
"en-US": {
|
|
195
|
+
"control.language": "Language",
|
|
196
|
+
"control.theme": "Theme",
|
|
197
|
+
"theme.system": "System",
|
|
198
|
+
"theme.light": "Light",
|
|
199
|
+
"theme.dark": "Dark",
|
|
200
|
+
"action.reload": "Reload frame",
|
|
201
|
+
"status.waiting": "Waiting",
|
|
202
|
+
"status.connected": "Connected",
|
|
203
|
+
"status.hostError": "Host error"
|
|
204
|
+
},
|
|
205
|
+
"zh-CN": {
|
|
206
|
+
"control.language": "语言",
|
|
207
|
+
"control.theme": "主题",
|
|
208
|
+
"theme.system": "跟随系统",
|
|
209
|
+
"theme.light": "浅色",
|
|
210
|
+
"theme.dark": "深色",
|
|
211
|
+
"action.reload": "重新加载",
|
|
212
|
+
"status.waiting": "等待中",
|
|
213
|
+
"status.connected": "已连接",
|
|
214
|
+
"status.hostError": "宿主错误"
|
|
215
|
+
}
|
|
216
|
+
};
|
|
191
217
|
|
|
192
218
|
window.addEventListener("message", handleMessage);
|
|
193
219
|
languageSelect.addEventListener("change", updateContext);
|
|
@@ -203,10 +229,11 @@
|
|
|
203
229
|
iframe.title = value.pluginId;
|
|
204
230
|
populateLanguages(value.supportedCultures, context.language);
|
|
205
231
|
themeSelect.value = context.themeMode;
|
|
232
|
+
applyHostLanguage();
|
|
206
233
|
applyTheme();
|
|
207
234
|
iframe.src = value.frameUrl;
|
|
208
235
|
}).catch(function reportInitializationFailure(error) {
|
|
209
|
-
setStatus("
|
|
236
|
+
setStatus("status.hostError", false);
|
|
210
237
|
console.error(error);
|
|
211
238
|
});
|
|
212
239
|
|
|
@@ -221,7 +248,7 @@
|
|
|
221
248
|
if (message.type === "nexus-plugin:ready") {
|
|
222
249
|
initialized = true;
|
|
223
250
|
postToFrame({ type: "nexus-plugin:init", context: context });
|
|
224
|
-
setStatus("
|
|
251
|
+
setStatus("status.connected", true);
|
|
225
252
|
return;
|
|
226
253
|
}
|
|
227
254
|
if (message.type === "nexus-plugin:resize" && typeof message.height === "number") {
|
|
@@ -260,9 +287,10 @@
|
|
|
260
287
|
language: languageSelect.value,
|
|
261
288
|
themeMode: themeSelect.value
|
|
262
289
|
});
|
|
290
|
+
applyHostLanguage();
|
|
263
291
|
applyTheme();
|
|
264
292
|
if (initialized) {
|
|
265
|
-
postToFrame({ type: "nexus-plugin:
|
|
293
|
+
postToFrame({ type: "nexus-plugin:init", context: context });
|
|
266
294
|
}
|
|
267
295
|
}
|
|
268
296
|
|
|
@@ -275,7 +303,7 @@
|
|
|
275
303
|
resizeSeen = false;
|
|
276
304
|
pendingRequests = 0;
|
|
277
305
|
cancelSmokeReport();
|
|
278
|
-
setStatus("
|
|
306
|
+
setStatus("status.waiting", false);
|
|
279
307
|
iframe.src = "about:blank";
|
|
280
308
|
window.setTimeout(function restoreFrame() {
|
|
281
309
|
iframe.src = configuration.frameUrl;
|
|
@@ -306,6 +334,15 @@
|
|
|
306
334
|
document.documentElement.dataset.theme = dark ? "dark" : "light";
|
|
307
335
|
}
|
|
308
336
|
|
|
337
|
+
function applyHostLanguage() {
|
|
338
|
+
var language = context && String(context.language).toLowerCase().startsWith("zh") ? "zh-CN" : "en-US";
|
|
339
|
+
document.documentElement.lang = language;
|
|
340
|
+
document.querySelectorAll("[data-host-i18n]").forEach(function localize(element) {
|
|
341
|
+
element.textContent = hostMessages[language][element.dataset.hostI18n] || element.textContent;
|
|
342
|
+
});
|
|
343
|
+
statusOutput.textContent = hostMessages[language][statusKey];
|
|
344
|
+
}
|
|
345
|
+
|
|
309
346
|
function respond(requestId, result) {
|
|
310
347
|
postToFrame({ type: "nexus-plugin:response", requestId: requestId, result: result });
|
|
311
348
|
}
|
|
@@ -314,9 +351,39 @@
|
|
|
314
351
|
iframe.contentWindow && iframe.contentWindow.postMessage(message, configuration.frameOrigin);
|
|
315
352
|
}
|
|
316
353
|
|
|
317
|
-
function setStatus(
|
|
318
|
-
|
|
319
|
-
|
|
354
|
+
function setStatus(key, connected) {
|
|
355
|
+
statusKey = key;
|
|
356
|
+
statusConnected = connected;
|
|
357
|
+
var language = context && String(context.language).toLowerCase().startsWith("zh") ? "zh-CN" : "en-US";
|
|
358
|
+
statusOutput.textContent = hostMessages[language][statusKey];
|
|
359
|
+
statusOutput.dataset.connected = statusConnected ? "true" : "false";
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function createBrowserHostApi() {
|
|
363
|
+
return {
|
|
364
|
+
getConfig: function getConfig() {
|
|
365
|
+
return requestBrowserHost("/__nexus_plugin_dev/config");
|
|
366
|
+
},
|
|
367
|
+
invoke: function invoke(request) {
|
|
368
|
+
return requestBrowserHost("/__nexus_plugin_dev/invoke", {
|
|
369
|
+
method: "POST",
|
|
370
|
+
headers: { "Content-Type": "application/json" },
|
|
371
|
+
body: JSON.stringify(request)
|
|
372
|
+
});
|
|
373
|
+
},
|
|
374
|
+
notifyFrameReady: function notifyFrameReady() {}
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function requestBrowserHost(url, options) {
|
|
379
|
+
return window.fetch(url, Object.assign({ credentials: "same-origin" }, options)).then(function parseResponse(response) {
|
|
380
|
+
return response.json().then(function handleBody(body) {
|
|
381
|
+
if (!response.ok) {
|
|
382
|
+
throw new Error(body && body.error ? body.error : "Browser host request failed.");
|
|
383
|
+
}
|
|
384
|
+
return body;
|
|
385
|
+
});
|
|
386
|
+
});
|
|
320
387
|
}
|
|
321
388
|
|
|
322
389
|
function scheduleSmokeReport() {
|
package/dev-host/main.js
CHANGED
|
@@ -43,6 +43,7 @@ app.setName("Nexus Plugin Dev: " + configuration.manifest.pluginId);
|
|
|
43
43
|
|
|
44
44
|
let mainWindow;
|
|
45
45
|
let smokeTimeout;
|
|
46
|
+
let smokeVerificationRunning = false;
|
|
46
47
|
|
|
47
48
|
app.whenReady().then(function startDevHost() {
|
|
48
49
|
registerPluginRendererProtocol();
|
|
@@ -69,6 +70,10 @@ function loadConfiguration(args) {
|
|
|
69
70
|
const contributionId = requiredArgument(args, "--contribution-id");
|
|
70
71
|
const language = requiredArgument(args, "--language");
|
|
71
72
|
const themeMode = requiredArgument(args, "--theme");
|
|
73
|
+
const hostVersion = requiredArgument(args, "--host-version");
|
|
74
|
+
if (!isStrictVersion(hostVersion)) {
|
|
75
|
+
throw new Error("--host-version must use X.Y.Z format.");
|
|
76
|
+
}
|
|
72
77
|
if (!hasContribution(manifest, surface, contributionId)) {
|
|
73
78
|
throw new Error("Selected PluginFrame contribution is not declared: " + surface + ":" + contributionId);
|
|
74
79
|
}
|
|
@@ -84,6 +89,7 @@ function loadConfiguration(args) {
|
|
|
84
89
|
contributionId,
|
|
85
90
|
language,
|
|
86
91
|
themeMode,
|
|
92
|
+
hostVersion,
|
|
87
93
|
openDevTools: !args.includes("--no-devtools"),
|
|
88
94
|
smoke: args.includes("--smoke"),
|
|
89
95
|
devDataDirectory,
|
|
@@ -178,7 +184,7 @@ function activatePluginMain() {
|
|
|
178
184
|
function createHostApi() {
|
|
179
185
|
const manifest = configuration.manifest;
|
|
180
186
|
return {
|
|
181
|
-
hostVersion:
|
|
187
|
+
hostVersion: configuration.hostVersion,
|
|
182
188
|
hostApiVersion: sdk.PLUGIN_FRAMEWORK_VERSION,
|
|
183
189
|
pluginId: manifest.pluginId,
|
|
184
190
|
pluginDataDirectory: configuration.pluginDataDirectory,
|
|
@@ -291,16 +297,93 @@ function registerIpcHandlers() {
|
|
|
291
297
|
});
|
|
292
298
|
ipcMain.on(ipcChannels.frameReady, function frameReady(event) {
|
|
293
299
|
assertMainWindowSender(event);
|
|
294
|
-
if (configuration.smoke) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
+
if (configuration.smoke && !smokeVerificationRunning) {
|
|
301
|
+
smokeVerificationRunning = true;
|
|
302
|
+
void verifyRendererContextSmoke().then(function reportSmokeSuccess() {
|
|
303
|
+
clearTimeout(smokeTimeout);
|
|
304
|
+
process.stdout.write("[nexus-plugin-dev] renderer context synchronization smoke passed.\n");
|
|
305
|
+
setTimeout(function exitAfterSmokeSettles() {
|
|
306
|
+
app.exit(0);
|
|
307
|
+
}, 100);
|
|
308
|
+
}).catch(function reportSmokeFailure(error) {
|
|
309
|
+
clearTimeout(smokeTimeout);
|
|
310
|
+
process.stderr.write("[nexus-plugin-dev] renderer context synchronization smoke failed: " + errorMessage(error) + "\n");
|
|
311
|
+
app.exit(1);
|
|
312
|
+
});
|
|
300
313
|
}
|
|
301
314
|
});
|
|
302
315
|
}
|
|
303
316
|
|
|
317
|
+
async function verifyRendererContextSmoke() {
|
|
318
|
+
if (!mainWindow || mainWindow.isDestroyed()) {
|
|
319
|
+
throw new Error("Development host window is unavailable.");
|
|
320
|
+
}
|
|
321
|
+
const frame = findPluginRendererFrame(mainWindow.webContents.mainFrame);
|
|
322
|
+
if (!frame) {
|
|
323
|
+
throw new Error("Plugin renderer frame was not found.");
|
|
324
|
+
}
|
|
325
|
+
const hostApi = createHostApi();
|
|
326
|
+
if (hostApi.hostVersion !== configuration.hostVersion
|
|
327
|
+
|| hostApi.hostApiVersion !== sdk.PLUGIN_FRAMEWORK_VERSION
|
|
328
|
+
|| configuration.manifest.minHostVersion === undefined) {
|
|
329
|
+
throw new Error("Development Host API version contract is inconsistent.");
|
|
330
|
+
}
|
|
331
|
+
const initialState = await readRendererContextState(frame);
|
|
332
|
+
const targetLanguage = configuration.manifest.supportedCultures.find(function findAlternative(culture) {
|
|
333
|
+
return culture !== configuration.language;
|
|
334
|
+
}) || configuration.language;
|
|
335
|
+
const targetTheme = configuration.themeMode === "dark" ? "light" : "dark";
|
|
336
|
+
await mainWindow.webContents.executeJavaScript(`(() => {
|
|
337
|
+
const languageSelect = document.getElementById("languageSelect");
|
|
338
|
+
const themeSelect = document.getElementById("themeSelect");
|
|
339
|
+
languageSelect.value = ${JSON.stringify(targetLanguage)};
|
|
340
|
+
languageSelect.dispatchEvent(new Event("change", { bubbles: true }));
|
|
341
|
+
themeSelect.value = ${JSON.stringify(targetTheme)};
|
|
342
|
+
themeSelect.dispatchEvent(new Event("change", { bubbles: true }));
|
|
343
|
+
})()`, true);
|
|
344
|
+
|
|
345
|
+
const deadline = Date.now() + 5000;
|
|
346
|
+
let lastState = initialState;
|
|
347
|
+
while (Date.now() < deadline) {
|
|
348
|
+
lastState = await readRendererContextState(frame);
|
|
349
|
+
const languageChanged = lastState.language === targetLanguage
|
|
350
|
+
&& (targetLanguage === configuration.language || lastState.localizedText !== initialState.localizedText);
|
|
351
|
+
if (languageChanged && lastState.theme === targetTheme) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
await new Promise(function wait(resolve) {
|
|
355
|
+
setTimeout(resolve, 100);
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
throw new Error(
|
|
359
|
+
"Expected language=" + targetLanguage + " and theme=" + targetTheme
|
|
360
|
+
+ ", received " + JSON.stringify(lastState) + "."
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function findPluginRendererFrame(frame) {
|
|
365
|
+
for (const childFrame of frame.frames) {
|
|
366
|
+
if (childFrame.url.startsWith(pluginRendererProtocol + "://" + configuration.manifest.pluginId + "/")) {
|
|
367
|
+
return childFrame;
|
|
368
|
+
}
|
|
369
|
+
const nested = findPluginRendererFrame(childFrame);
|
|
370
|
+
if (nested) {
|
|
371
|
+
return nested;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return undefined;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
async function readRendererContextState(frame) {
|
|
378
|
+
return frame.executeJavaScript(`({
|
|
379
|
+
language: document.documentElement.lang,
|
|
380
|
+
theme: document.documentElement.dataset.theme || "",
|
|
381
|
+
localizedText: document.querySelector("[data-i18n]")
|
|
382
|
+
? document.querySelector("[data-i18n]").textContent
|
|
383
|
+
: ""
|
|
384
|
+
})`, true);
|
|
385
|
+
}
|
|
386
|
+
|
|
304
387
|
function createRendererConfiguration() {
|
|
305
388
|
const manifest = configuration.manifest;
|
|
306
389
|
const frameOrigin = pluginRendererProtocol + "://" + manifest.pluginId;
|
|
@@ -457,7 +540,7 @@ function createWindow() {
|
|
|
457
540
|
}
|
|
458
541
|
if (configuration.smoke) {
|
|
459
542
|
smokeTimeout = setTimeout(function failSmokeTimeout() {
|
|
460
|
-
process.stderr.write("[nexus-plugin-dev] renderer
|
|
543
|
+
process.stderr.write("[nexus-plugin-dev] renderer context synchronization smoke timed out.\n");
|
|
461
544
|
app.exit(1);
|
|
462
545
|
}, 15000);
|
|
463
546
|
}
|
|
@@ -660,6 +743,13 @@ function requiredPathArgument(args, name) {
|
|
|
660
743
|
return resolved;
|
|
661
744
|
}
|
|
662
745
|
|
|
746
|
+
function isStrictVersion(value) {
|
|
747
|
+
const match = /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/.exec(value);
|
|
748
|
+
return Boolean(match && [match[1], match[2], match[3]].every(function isSafe(segment) {
|
|
749
|
+
return Number.isSafeInteger(Number(segment));
|
|
750
|
+
}));
|
|
751
|
+
}
|
|
752
|
+
|
|
663
753
|
function requiredArgument(args, name) {
|
|
664
754
|
const prefix = name + "=";
|
|
665
755
|
const argument = args.find(function findArgument(value) {
|
package/dist/src/cli/run.js
CHANGED
|
@@ -28,6 +28,7 @@ const path = __importStar(require("path"));
|
|
|
28
28
|
const index_1 = require("../index");
|
|
29
29
|
const scaffold_1 = require("../scaffold");
|
|
30
30
|
const dev_1 = require("../dev");
|
|
31
|
+
const web_dev_1 = require("../web-dev");
|
|
31
32
|
const nodeEngine = ">=16.20.0 <17";
|
|
32
33
|
function runCli(args, io) {
|
|
33
34
|
const command = args[0];
|
|
@@ -66,6 +67,9 @@ function runCli(args, io) {
|
|
|
66
67
|
if (command === "dev") {
|
|
67
68
|
return runDev(args.slice(1), io);
|
|
68
69
|
}
|
|
70
|
+
if (command === "dev:web") {
|
|
71
|
+
return runWebDev(args.slice(1), io);
|
|
72
|
+
}
|
|
69
73
|
return usageError(io, command ? "Unknown command: " + command : "A command is required.");
|
|
70
74
|
}
|
|
71
75
|
exports.runCli = runCli;
|
|
@@ -75,13 +79,99 @@ function usage() {
|
|
|
75
79
|
" nexus-plugin info",
|
|
76
80
|
" nexus-plugin validate <plugin-package-directory>",
|
|
77
81
|
" nexus-plugin create <plugin-id> [--template minimal|sqlite] [--output <parent-directory>]",
|
|
78
|
-
" [--display-name <name>] --sdk-source <version-or-local-tgz> [--install]",
|
|
82
|
+
" [--display-name <name>] [--sdk-source <version-or-local-tgz>] [--install]",
|
|
79
83
|
" nexus-plugin dev [plugin-project-directory] [--no-build] [--inspect[=<port>] | --inspect-brk[=<port>]]",
|
|
84
|
+
" [--host-version <X.Y.Z>] [--language <culture>] [--theme system|light|dark] [--surface business|tool|settings]",
|
|
85
|
+
" [--contribution-id <id>] [--no-devtools]",
|
|
86
|
+
" nexus-plugin dev:web [plugin-project-directory] [--no-build] [--no-open] [--port <port>]",
|
|
80
87
|
" [--language <culture>] [--theme system|light|dark] [--surface business|tool|settings]",
|
|
81
|
-
" [--contribution-id <id>]
|
|
88
|
+
" [--contribution-id <id>]"
|
|
82
89
|
].join("\n");
|
|
83
90
|
}
|
|
84
91
|
exports.usage = usage;
|
|
92
|
+
function runWebDev(args, io) {
|
|
93
|
+
if (args.length === 1 && (args[0] === "--help" || args[0] === "-h")) {
|
|
94
|
+
io.stdout(usage());
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
let projectDirectory = io.cwd();
|
|
98
|
+
let index = 0;
|
|
99
|
+
if (args[0] && !args[0].startsWith("--")) {
|
|
100
|
+
projectDirectory = path.resolve(io.cwd(), args[0]);
|
|
101
|
+
index = 1;
|
|
102
|
+
}
|
|
103
|
+
const options = {
|
|
104
|
+
projectDirectory,
|
|
105
|
+
build: true,
|
|
106
|
+
openBrowser: true,
|
|
107
|
+
port: 4173
|
|
108
|
+
};
|
|
109
|
+
const seen = new Set();
|
|
110
|
+
for (; index < args.length; index += 1) {
|
|
111
|
+
const option = args[index];
|
|
112
|
+
if (option === "--no-build" || option === "--no-open") {
|
|
113
|
+
if (seen.has(option)) {
|
|
114
|
+
return usageError(io, "Duplicate option: " + option);
|
|
115
|
+
}
|
|
116
|
+
seen.add(option);
|
|
117
|
+
if (option === "--no-build") {
|
|
118
|
+
options.build = false;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
options.openBrowser = false;
|
|
122
|
+
}
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (!["--port", "--language", "--theme", "--surface", "--contribution-id"].includes(option)) {
|
|
126
|
+
return usageError(io, "Unknown dev:web option: " + option);
|
|
127
|
+
}
|
|
128
|
+
if (seen.has(option)) {
|
|
129
|
+
return usageError(io, "Duplicate option: " + option);
|
|
130
|
+
}
|
|
131
|
+
seen.add(option);
|
|
132
|
+
const value = args[index + 1];
|
|
133
|
+
if (value === undefined || value.startsWith("--")) {
|
|
134
|
+
return usageError(io, option + " requires a value.");
|
|
135
|
+
}
|
|
136
|
+
index += 1;
|
|
137
|
+
if (option === "--port") {
|
|
138
|
+
const port = Number(value);
|
|
139
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
140
|
+
return usageError(io, "port must be an integer from 1 to 65535.");
|
|
141
|
+
}
|
|
142
|
+
options.port = port;
|
|
143
|
+
}
|
|
144
|
+
else if (option === "--language") {
|
|
145
|
+
options.language = value;
|
|
146
|
+
}
|
|
147
|
+
else if (option === "--theme") {
|
|
148
|
+
if (value !== "system" && value !== "light" && value !== "dark") {
|
|
149
|
+
return usageError(io, "theme must be system, light, or dark.");
|
|
150
|
+
}
|
|
151
|
+
options.themeMode = value;
|
|
152
|
+
}
|
|
153
|
+
else if (option === "--surface") {
|
|
154
|
+
if (value !== "business" && value !== "tool" && value !== "settings") {
|
|
155
|
+
return usageError(io, "surface must be business, tool, or settings.");
|
|
156
|
+
}
|
|
157
|
+
options.surface = value;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
options.contributionId = value;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
return (0, web_dev_1.runPluginWebDev)(options, io);
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (error instanceof dev_1.PluginDevError) {
|
|
168
|
+
io.stderr(error.message);
|
|
169
|
+
return error.exitCode;
|
|
170
|
+
}
|
|
171
|
+
io.stderr("Plugin browser dev host failed: " + (error instanceof Error ? error.message : String(error)));
|
|
172
|
+
return 1;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
85
175
|
function runDev(args, io) {
|
|
86
176
|
if (args.length === 1 && (args[0] === "--help" || args[0] === "-h")) {
|
|
87
177
|
io.stdout(usage());
|
|
@@ -131,7 +221,7 @@ function runDev(args, io) {
|
|
|
131
221
|
options.inspectorPort = inspector.port;
|
|
132
222
|
continue;
|
|
133
223
|
}
|
|
134
|
-
if (!["--language", "--theme", "--surface", "--contribution-id"].includes(option)) {
|
|
224
|
+
if (!["--host-version", "--language", "--theme", "--surface", "--contribution-id"].includes(option)) {
|
|
135
225
|
return usageError(io, "Unknown dev option: " + option);
|
|
136
226
|
}
|
|
137
227
|
if (seen.has(option)) {
|
|
@@ -143,7 +233,13 @@ function runDev(args, io) {
|
|
|
143
233
|
return usageError(io, option + " requires a value.");
|
|
144
234
|
}
|
|
145
235
|
index += 1;
|
|
146
|
-
if (option === "--
|
|
236
|
+
if (option === "--host-version") {
|
|
237
|
+
if (!isStrictVersion(value)) {
|
|
238
|
+
return usageError(io, "host-version must use X.Y.Z format.");
|
|
239
|
+
}
|
|
240
|
+
options.hostVersion = value;
|
|
241
|
+
}
|
|
242
|
+
else if (option === "--language") {
|
|
147
243
|
options.language = value;
|
|
148
244
|
}
|
|
149
245
|
else if (option === "--theme") {
|
|
@@ -185,6 +281,10 @@ function parseInspectorOption(option) {
|
|
|
185
281
|
}
|
|
186
282
|
return { mode: match[1], port };
|
|
187
283
|
}
|
|
284
|
+
function isStrictVersion(value) {
|
|
285
|
+
const match = /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/.exec(value);
|
|
286
|
+
return Boolean(match && [match[1], match[2], match[3]].every((segment) => Number.isSafeInteger(Number(segment))));
|
|
287
|
+
}
|
|
188
288
|
function runCreate(args, io) {
|
|
189
289
|
if (args.length === 0 || args[0].startsWith("--")) {
|
|
190
290
|
return usageError(io, "create requires a plugin-id.");
|
|
@@ -193,7 +293,7 @@ function runCreate(args, io) {
|
|
|
193
293
|
let template = "minimal";
|
|
194
294
|
let outputDirectory = io.cwd();
|
|
195
295
|
let displayName = (0, scaffold_1.defaultPluginDisplayName)(pluginId);
|
|
196
|
-
let sdkSource;
|
|
296
|
+
let sdkSource = index_1.PLUGIN_SDK_VERSION;
|
|
197
297
|
let install = false;
|
|
198
298
|
const seen = new Set();
|
|
199
299
|
for (let index = 1; index < args.length; index += 1) {
|
|
@@ -234,9 +334,6 @@ function runCreate(args, io) {
|
|
|
234
334
|
sdkSource = value;
|
|
235
335
|
}
|
|
236
336
|
}
|
|
237
|
-
if (!sdkSource) {
|
|
238
|
-
return usageError(io, "create requires --sdk-source; use a local SDK .tgz until @aiot-nexus/plugin-sdk is published.");
|
|
239
|
-
}
|
|
240
337
|
try {
|
|
241
338
|
const result = (0, scaffold_1.createPluginScaffold)({
|
|
242
339
|
pluginId,
|
package/dist/src/dev.d.ts
CHANGED
|
@@ -1,36 +1,48 @@
|
|
|
1
1
|
import type { PluginManifest, PluginRendererSurface, ThemeMode } from "./types";
|
|
2
2
|
export type PluginMainInspectorMode = "inspect" | "inspect-brk";
|
|
3
|
-
export interface
|
|
3
|
+
export interface PluginDebugSelection {
|
|
4
4
|
projectDirectory: string;
|
|
5
|
-
build: boolean;
|
|
6
|
-
openDevTools: boolean;
|
|
7
|
-
inspectorMode?: PluginMainInspectorMode;
|
|
8
|
-
inspectorPort?: number;
|
|
9
5
|
language?: string;
|
|
10
6
|
themeMode?: ThemeMode;
|
|
11
7
|
surface?: PluginRendererSurface;
|
|
12
8
|
contributionId?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface PluginDevOptions extends PluginDebugSelection {
|
|
11
|
+
build: boolean;
|
|
12
|
+
openDevTools: boolean;
|
|
13
|
+
hostVersion?: string;
|
|
14
|
+
inspectorMode?: PluginMainInspectorMode;
|
|
15
|
+
inspectorPort?: number;
|
|
13
16
|
smoke?: boolean;
|
|
14
17
|
}
|
|
15
18
|
export interface PluginDevIo {
|
|
16
19
|
stdout(message: string): void;
|
|
17
20
|
stderr(message: string): void;
|
|
18
21
|
}
|
|
19
|
-
export interface
|
|
22
|
+
export interface PluginDebugTarget {
|
|
20
23
|
projectDirectory: string;
|
|
21
24
|
packageDirectory: string;
|
|
22
25
|
pluginId: string;
|
|
23
|
-
manifest: PluginManifest
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
manifest: PluginManifest & {
|
|
27
|
+
rendererEntry: string;
|
|
28
|
+
};
|
|
26
29
|
surface: PluginRendererSurface;
|
|
27
30
|
contributionId: string;
|
|
28
31
|
language: string;
|
|
29
32
|
themeMode: ThemeMode;
|
|
30
33
|
}
|
|
34
|
+
export interface PluginDevTarget extends PluginDebugTarget {
|
|
35
|
+
electronExecutable: string;
|
|
36
|
+
devHostMainPath: string;
|
|
37
|
+
hostVersion: string;
|
|
38
|
+
}
|
|
31
39
|
export declare class PluginDevError extends Error {
|
|
32
40
|
readonly exitCode: 1;
|
|
33
41
|
constructor(message: string);
|
|
34
42
|
}
|
|
35
43
|
export declare function runPluginDev(options: PluginDevOptions, io: PluginDevIo): number;
|
|
36
44
|
export declare function preparePluginDev(options: PluginDevOptions): PluginDevTarget;
|
|
45
|
+
export declare function preparePluginDebugTarget(options: PluginDebugSelection): PluginDebugTarget;
|
|
46
|
+
export declare function preparePluginBrowserDebugTarget(options: PluginDebugSelection, packageKind?: "auto" | "web" | "package"): PluginDebugTarget;
|
|
47
|
+
export declare function buildPluginForDevelopment(projectDirectory: string): void;
|
|
48
|
+
export declare function buildPluginRendererForDevelopment(projectDirectory: string): "web" | "package";
|