@aiot-nexus/plugin-sdk 1.0.2 → 1.1.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 CHANGED
@@ -22,10 +22,31 @@ nexus-plugin validate <plugin-package-directory>
22
22
  nexus-plugin create <plugin-id> --template minimal|sqlite --output <parent-directory>
23
23
  nexus-plugin dev [plugin-project-directory]
24
24
  nexus-plugin dev:web [plugin-project-directory]
25
+ nexus-plugin dev:nexus [plugin-project-directory] --host <nexus.exe-or-directory>
25
26
  ```
26
27
 
27
28
  `npm run pack:sdk` 将离线安装包写入 `package/`。该目录是本地构建产物,不进入 Git。`npm run publish:sdk` 发布到官方 npm registry;`prepack` 会强制运行测试、构建并核对实际 npm 文件清单,缺少任一公开入口时拒绝发布。
28
29
 
30
+ ## SDK 版本提示
31
+
32
+ SDK 提供两层非阻塞版本检查:
33
+
34
+ - 安装阶段的 `postinstall` 会强制查询 `dist-tags.latest` 并写入当前用户缓存。npm 7+ 默认隐藏依赖包的 lifecycle 输出;需要看到安装阶段 notice 时使用 `npm install --foreground-scripts`。`npm install --ignore-scripts` 会跳过该阶段,但不影响后续 CLI 检查。
35
+ - `nexus-plugin` 启动时先读取缓存。缓存新鲜期为 24 小时;缓存缺失或过期时在后台检查,不等待网络,不改变命令退出码。检测到普通更新时会显示:
36
+
37
+ ```text
38
+ npm notice Update available for @aiot-nexus/plugin-sdk: 1.1.1 -> 1.2.0
39
+ npm notice Run npm install --save-dev @aiot-nexus/plugin-sdk@latest
40
+ ```
41
+
42
+ 检查会优先使用 npm 当前配置的 registry(包括私有 registry),主源失败后回退官方 npm registry;不会发送 token、密码或项目路径。离线、超时、registry 返回非法数据或缓存损坏都静默降级,安装、构建、调试和正式宿主启动不会被阻断。
43
+
44
+ 大版本更新会额外提示先确认 Nexus Framework API 兼容性;检查不会自动修改 `package.json`、升级依赖或新增交互式命令。确认兼容后,推荐手动执行 `npm install --save-dev @aiot-nexus/plugin-sdk@latest`。
45
+
46
+ 可用环境变量:`NEXUS_PLUGIN_SDK_UPDATE_CHECK=0` 或 `NO_UPDATE_NOTIFIER=1` 会同时关闭安装和 CLI 检查。内部 SDK 打包环境也会自动跳过联网检查。
47
+
48
+ 使用本地 `--sdk-source ...tgz` 时,生成工程依赖的是 tgz 内记录的 SDK 版本;安装阶段仍可能按 npm registry 写入该版本的缓存,CLI 后续按“当前版本 + registry”读取。完全离线开发可设置上述禁用变量,或接受检查静默失败;本地 SDK 不会自动替换正式 npm SDK,也不会因为有新版本自动升级。
49
+
29
50
  ## 创建插件
30
51
 
31
52
  ```bash
@@ -43,7 +64,7 @@ nexus-plugin create my-frame-plugin \
43
64
  - 目标目录非空时命令以返回码 `2` 拒绝覆盖。生成或安装失败返回 `1`。
44
65
  - 两套模板均读取宿主 `PluginRendererContext.language` 和 `themeMode`,通过 `onContextChanged` 在同一 iframe 内响应运行时语言与主题切换,并内置 `zh-CN` / `en-US` renderer 文案;manifest 使用相同文化资源本地化宿主入口。模板页面自身不提供语言或主题选择控件。
45
66
 
46
- 默认来源从 npm registry 安装。离线开发时先执行 `npm run pack:sdk`,再通过 `--sdk-source /path/to/aiot-nexus-plugin-sdk-1.0.2.tgz` 指定本地包;CLI 会把本地包一并放入生成工程。
67
+ 默认来源从 npm registry 安装。离线开发时先执行 `npm run pack:sdk`,再通过 `--sdk-source /path/to/aiot-nexus-plugin-sdk-1.1.1.tgz` 指定本地包;CLI 会把本地包一并放入生成工程。
47
68
 
48
69
  ## 独立调试
49
70
 
@@ -81,3 +102,21 @@ nexus-plugin dev [plugin-project-directory]
81
102
  调试宿主工具栏中的语言和主题选择器用于模拟 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
103
 
83
104
  浏览器 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 输出不会覆盖正式插件制品。
105
+
106
+ ## 使用正式 Nexus 调试
107
+
108
+ 已经安装并构建插件后,可直接把编译好的正式 Nexus 作为宿主:
109
+
110
+ ```powershell
111
+ npm run dev:nexus -- --host D:\prj\tmp\aiot-nexus\dist\electron\nexus-win32-x64\nexus.exe
112
+ ```
113
+
114
+ `dev:nexus` 首次启动会完成正式构建,通过 staging 原子部署到 `<exeDir>/Plugins/<pluginId>/`,再由 CLI 以 `--plugin-dev`、随机控制管道和会话令牌启动 Nexus。开发通道只在这次由 CLI 管理的进程中启用;普通双击或不带 `--plugin-dev` 启动时不会创建控制管道,也不会打开 DevTools。
115
+
116
+ | 修改范围 | 行为 |
117
+ | --- | --- |
118
+ | `src/renderer/**` | 只运行 `build:web` 并替换 renderer;宿主 PID 不变,iframe 重新完成 `ready/init`。 |
119
+ | `src/manifest.json` 的展示、贡献点等安全字段 | 构建 renderer、原子替换 manifest 后重扫插件目录;宿主 PID 不变。 |
120
+ | `src/main.ts`、依赖、原生模块或主进程相关 manifest 字段 | 完整构建成功后请求旧宿主退出,替换完整插件包并启动新宿主;宿主 PID 变化。 |
121
+
122
+ 更新构建或 manifest 重扫失败时保留上一个可运行部署;新宿主启动失败时回滚插件包并恢复旧版本。`mainEntry` 不通过清理 `require.cache` 热替换,主进程变化始终使用完整重启。默认打开 Renderer DevTools;可传 `--no-devtools`。主进程调试支持 `--inspect[=<port>]` 和 `--inspect-brk[=<port>]`,贡献点选择支持 `--surface` 与 `--contribution-id`。按 `Ctrl+C` 停止 CLI 时,CLI 会关闭其启动的正式宿主。
@@ -3,5 +3,5 @@ export interface CliIo {
3
3
  stdout(message: string): void;
4
4
  stderr(message: string): void;
5
5
  }
6
- export declare function runCli(args: string[], io: CliIo): number;
6
+ export declare function runCli(args: string[], io: CliIo): number | Promise<number>;
7
7
  export declare function usage(): string;
@@ -29,6 +29,7 @@ const index_1 = require("../index");
29
29
  const scaffold_1 = require("../scaffold");
30
30
  const dev_1 = require("../dev");
31
31
  const web_dev_1 = require("../web-dev");
32
+ const nexus_dev_1 = require("../nexus-dev");
32
33
  const nodeEngine = ">=16.20.0 <17";
33
34
  function runCli(args, io) {
34
35
  const command = args[0];
@@ -70,6 +71,9 @@ function runCli(args, io) {
70
71
  if (command === "dev:web") {
71
72
  return runWebDev(args.slice(1), io);
72
73
  }
74
+ if (command === "dev:nexus") {
75
+ return runNexusDev(args.slice(1), io);
76
+ }
73
77
  return usageError(io, command ? "Unknown command: " + command : "A command is required.");
74
78
  }
75
79
  exports.runCli = runCli;
@@ -85,10 +89,100 @@ function usage() {
85
89
  " [--contribution-id <id>] [--no-devtools]",
86
90
  " nexus-plugin dev:web [plugin-project-directory] [--no-build] [--no-open] [--port <port>]",
87
91
  " [--language <culture>] [--theme system|light|dark] [--surface business|tool|settings]",
92
+ " [--contribution-id <id>]",
93
+ " nexus-plugin dev:nexus [plugin-project-directory] --host <nexus.exe-or-directory>",
94
+ " [--inspect[=<port>] | --inspect-brk[=<port>]] [--no-devtools]",
95
+ " [--language <culture>] [--theme system|light|dark] [--surface business|tool|settings]",
88
96
  " [--contribution-id <id>]"
89
97
  ].join("\n");
90
98
  }
91
99
  exports.usage = usage;
100
+ function runNexusDev(args, io) {
101
+ if (args.length === 1 && (args[0] === "--help" || args[0] === "-h")) {
102
+ io.stdout(usage());
103
+ return 0;
104
+ }
105
+ let projectDirectory = io.cwd();
106
+ let index = 0;
107
+ if (args[0] && !args[0].startsWith("--")) {
108
+ projectDirectory = path.resolve(io.cwd(), args[0]);
109
+ index = 1;
110
+ }
111
+ const options = {
112
+ projectDirectory,
113
+ openDevTools: true
114
+ };
115
+ const seen = new Set();
116
+ for (; index < args.length; index += 1) {
117
+ const option = args[index];
118
+ if (option === "--no-devtools") {
119
+ if (seen.has(option)) {
120
+ return usageError(io, "Duplicate option: " + option);
121
+ }
122
+ seen.add(option);
123
+ options.openDevTools = false;
124
+ continue;
125
+ }
126
+ const inspector = parseInspectorOption(option);
127
+ if (inspector) {
128
+ if (options.inspectorMode) {
129
+ return usageError(io, "Only one main-process inspector option can be used.");
130
+ }
131
+ const key = "--" + inspector.mode;
132
+ if (seen.has(key)) {
133
+ return usageError(io, "Duplicate option: " + key);
134
+ }
135
+ seen.add(key);
136
+ options.inspectorMode = inspector.mode;
137
+ options.inspectorPort = inspector.port;
138
+ continue;
139
+ }
140
+ if (!["--host", "--language", "--theme", "--surface", "--contribution-id"].includes(option)) {
141
+ return usageError(io, "Unknown dev:nexus option: " + option);
142
+ }
143
+ if (seen.has(option)) {
144
+ return usageError(io, "Duplicate option: " + option);
145
+ }
146
+ seen.add(option);
147
+ const value = args[index + 1];
148
+ if (value === undefined || value.startsWith("--")) {
149
+ return usageError(io, option + " requires a value.");
150
+ }
151
+ index += 1;
152
+ if (option === "--host") {
153
+ options.hostPath = path.resolve(io.cwd(), value);
154
+ }
155
+ else if (option === "--language") {
156
+ options.language = value;
157
+ }
158
+ else if (option === "--theme") {
159
+ if (value !== "system" && value !== "light" && value !== "dark") {
160
+ return usageError(io, "theme must be system, light, or dark.");
161
+ }
162
+ options.themeMode = value;
163
+ }
164
+ else if (option === "--surface") {
165
+ if (value !== "business" && value !== "tool" && value !== "settings") {
166
+ return usageError(io, "surface must be business, tool, or settings.");
167
+ }
168
+ options.surface = value;
169
+ }
170
+ else {
171
+ options.contributionId = value;
172
+ }
173
+ }
174
+ if (!options.hostPath) {
175
+ return usageError(io, "dev:nexus requires --host <nexus.exe-or-directory>.");
176
+ }
177
+ return (0, nexus_dev_1.runPluginNexusDev)(options, io).catch((error) => {
178
+ if (error instanceof dev_1.PluginDevError) {
179
+ io.stderr(error.message);
180
+ return error.exitCode;
181
+ }
182
+ io.stderr("Packaged Nexus plugin development failed: " + (error instanceof Error ? error.message : String(error)));
183
+ return 1;
184
+ });
185
+ }
92
186
  function runWebDev(args, io) {
93
187
  if (args.length === 1 && (args[0] === "--help" || args[0] === "-h")) {
94
188
  io.stdout(usage());
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ export interface SdkUpdateResult {
3
+ status: string;
4
+ hasUpdate: boolean;
5
+ packageName: string;
6
+ currentVersion: string | null;
7
+ latestVersion: string | null;
8
+ isMajorUpdate: boolean;
9
+ }
10
+ export interface SdkUpdateCheckModule {
11
+ checkForSdkUpdate(options: {
12
+ currentVersion: string;
13
+ }): Promise<SdkUpdateResult>;
14
+ formatUpdateNotice(result: SdkUpdateResult): string;
15
+ isDisabled(env: NodeJS.ProcessEnv): boolean;
16
+ readCachedSdkUpdate(options: {
17
+ currentVersion: string;
18
+ }): SdkUpdateResult | null;
19
+ }
20
+ export declare function showSdkUpdateNotice(args: string[], stdout: (message: string) => void, updateCheck: SdkUpdateCheckModule, currentVersion: string): void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.showSdkUpdateNotice = void 0;
4
+ function showSdkUpdateNotice(args, stdout, updateCheck, currentVersion) {
5
+ if (args.includes("--help") || args.includes("-h") || updateCheck.isDisabled(process.env)) {
6
+ return;
7
+ }
8
+ const cached = updateCheck.readCachedSdkUpdate({ currentVersion });
9
+ if (cached && cached.hasUpdate) {
10
+ const notice = updateCheck.formatUpdateNotice(cached);
11
+ if (notice) {
12
+ stdout(notice);
13
+ }
14
+ }
15
+ if (cached) {
16
+ return;
17
+ }
18
+ void updateCheck
19
+ .checkForSdkUpdate({ currentVersion })
20
+ .then((result) => {
21
+ if (result.status !== "checked" || !result.hasUpdate) {
22
+ return;
23
+ }
24
+ const notice = updateCheck.formatUpdateNotice(result);
25
+ if (notice) {
26
+ stdout(notice);
27
+ }
28
+ })
29
+ .catch(() => {
30
+ // Version checks are advisory and must never affect a CLI command.
31
+ });
32
+ }
33
+ exports.showSdkUpdateNotice = showSdkUpdateNotice;
package/dist/src/cli.js CHANGED
@@ -1,9 +1,49 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ /* eslint-disable @typescript-eslint/no-var-requires */
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || function (mod) {
21
+ if (mod && mod.__esModule) return mod;
22
+ var result = {};
23
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
+ __setModuleDefault(result, mod);
25
+ return result;
26
+ };
3
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
+ const path = __importStar(require("path"));
29
+ const index_1 = require("./index");
4
30
  const run_1 = require("./cli/run");
5
- process.exitCode = (0, run_1.runCli)(process.argv.slice(2), {
31
+ const update_notice_1 = require("./cli/update-notice");
32
+ const sdkUpdateCheck = require(path.resolve(__dirname, "../../scripts/sdk-update-check.js"));
33
+ const args = process.argv.slice(2);
34
+ const io = {
6
35
  cwd: () => process.cwd(),
7
36
  stdout: (message) => process.stdout.write(message + "\n"),
8
37
  stderr: (message) => process.stderr.write(message + "\n")
9
- });
38
+ };
39
+ (0, update_notice_1.showSdkUpdateNotice)(args, io.stdout, sdkUpdateCheck, index_1.PLUGIN_SDK_VERSION);
40
+ const result = (0, run_1.runCli)(args, io);
41
+ if (typeof result === "number") {
42
+ process.exitCode = result;
43
+ }
44
+ else {
45
+ result.then((exitCode) => { process.exitCode = exitCode; }, (error) => {
46
+ process.stderr.write("nexus-plugin failed: " + (error instanceof Error ? error.message : String(error)) + "\n");
47
+ process.exitCode = 1;
48
+ });
49
+ }
@@ -1,5 +1,5 @@
1
1
  import pluginManifestSchema from "../.generated/plugin-manifest.schema.json";
2
- export declare const PLUGIN_SDK_VERSION = "1.0.2";
2
+ export declare const PLUGIN_SDK_VERSION = "1.1.1";
3
3
  export { pluginManifestSchema };
4
4
  export * from "../.generated/plugin-framework-version";
5
5
  export * from "./types";
package/dist/src/index.js CHANGED
@@ -20,7 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.pluginManifestSchema = exports.PLUGIN_SDK_VERSION = void 0;
21
21
  const plugin_manifest_schema_json_1 = __importDefault(require("../.generated/plugin-manifest.schema.json"));
22
22
  exports.pluginManifestSchema = plugin_manifest_schema_json_1.default;
23
- exports.PLUGIN_SDK_VERSION = "1.0.2";
23
+ exports.PLUGIN_SDK_VERSION = "1.1.1";
24
24
  __exportStar(require("../.generated/plugin-framework-version"), exports);
25
25
  __exportStar(require("./types"), exports);
26
26
  __exportStar(require("./browser/frame-client"), exports);
@@ -0,0 +1,42 @@
1
+ export type NexusDevUpdateType = "rendererUpdated" | "manifestUpdated";
2
+ export interface NexusDevUpdateResult {
3
+ ok: boolean;
4
+ message: string;
5
+ requiresRestart?: boolean;
6
+ }
7
+ export declare class NexusDevControlServer {
8
+ readonly token: string;
9
+ readonly pipePath: string;
10
+ private server;
11
+ private socket;
12
+ private receiveBuffer;
13
+ private helloAccepted;
14
+ private authenticated;
15
+ private authenticationResolve;
16
+ private authenticationReject;
17
+ private authenticationPromise;
18
+ private disconnectionPromise;
19
+ private disconnectionResolve;
20
+ private disconnectHandler;
21
+ private readonly pendingUpdates;
22
+ private readonly pendingShutdowns;
23
+ private nextRequestId;
24
+ start(): Promise<void>;
25
+ waitForAuthentication(timeoutMs?: number): Promise<void>;
26
+ sendUpdate(type: NexusDevUpdateType, pluginId: string): Promise<NexusDevUpdateResult>;
27
+ requestShutdown(): Promise<void>;
28
+ waitForDisconnection(timeoutMs?: number): Promise<void>;
29
+ setDisconnectHandler(handler: (error: Error) => void): () => void;
30
+ isConnected(): boolean;
31
+ close(): Promise<void>;
32
+ private handleConnection;
33
+ private handleData;
34
+ private handleMessage;
35
+ private handleDisconnect;
36
+ private rejectPending;
37
+ private rejectPendingShutdowns;
38
+ private ensureAuthenticationPromise;
39
+ private ensureDisconnectionPromise;
40
+ private rejectAuthentication;
41
+ }
42
+ export declare function helloProofPayload(version: number, pid: number, nonce: string): string;