@easyai-canvas/canvas-plugin-sdk 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/bin/easyai-plugin.mjs +12 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
SDK 为商业专有软件。npm 公开下载不自动授予使用或再分发许可,具体权限以 EasyAI 客户协议为准。
|
|
6
6
|
|
|
7
|
+
开发、构建和运行插件需使用 Node 22.22.0 或更新的 Node 22。请先切换 Node 版本,再运行以下初始化命令;`init` 会自动安装项目依赖,无需先在空目录执行 `npm i @easyai-canvas/canvas-plugin-sdk`。若依赖已在其他 Node 主版本下安装,切换后在项目目录运行 `npm ci`,以重装原生依赖。
|
|
8
|
+
|
|
7
9
|
```bash
|
|
8
10
|
npx @easyai-canvas/canvas-plugin-sdk init my-plugin
|
|
9
11
|
cd my-plugin
|
package/bin/easyai-plugin.mjs
CHANGED
|
@@ -18,7 +18,9 @@ const args = process.argv.slice(3);
|
|
|
18
18
|
function fail(message) { throw new Error(message); }
|
|
19
19
|
function nodeVersion() {
|
|
20
20
|
const [major, minor] = process.versions.node.split('.').map(Number);
|
|
21
|
-
if (major !== 22 || minor < 22)
|
|
21
|
+
if (major !== 22 || minor < 22) {
|
|
22
|
+
fail(`当前 Node ${process.versions.node} 不支持 SDK(要求 ${metadata.engines.node})。请先切换 Node 版本,再安装依赖或运行命令。`);
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
25
|
function safeName(value) {
|
|
24
26
|
const name = value.toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '');
|
|
@@ -121,6 +123,7 @@ async function init() {
|
|
|
121
123
|
if (!['node', 'action', 'combined'].includes(template)) fail('模板只支持 node、action 或 combined');
|
|
122
124
|
const targetArg = args.find((arg, index) => !arg.startsWith('--') && args[index - 1] !== '--template');
|
|
123
125
|
if (!targetArg) fail('用法:easyai-plugin init <目录> [--template node|action|combined] [--no-install]');
|
|
126
|
+
nodeVersion();
|
|
124
127
|
const target = resolve(targetArg);
|
|
125
128
|
if (existsSync(target) && (await readdir(target)).length) fail('目标目录非空,不会覆盖已有文件');
|
|
126
129
|
const slug = safeName(basename(target));
|
|
@@ -131,6 +134,7 @@ async function init() {
|
|
|
131
134
|
const spec = process.env.EASYAI_SDK_INSTALL_SPEC ?? metadata.version;
|
|
132
135
|
const project = {
|
|
133
136
|
name: slug, version: '0.1.0', private: true, type: 'module',
|
|
137
|
+
engines: { node: metadata.engines.node },
|
|
134
138
|
scripts: { dev: 'easyai-plugin dev', 'test:contract': 'easyai-plugin test:contract',
|
|
135
139
|
build: 'easyai-plugin build', start: 'easyai-plugin start', doctor: 'easyai-plugin doctor' },
|
|
136
140
|
dependencies: { [metadata.name]: spec, vue: '3.5.21' },
|
|
@@ -281,7 +285,13 @@ async function contractTest() {
|
|
|
281
285
|
async function doctor() {
|
|
282
286
|
const checks = [];
|
|
283
287
|
const [major, minor] = process.versions.node.split('.').map(Number);
|
|
284
|
-
|
|
288
|
+
const nodeCheck = `Node ${metadata.engines.node}(当前 ${process.versions.node})`;
|
|
289
|
+
if (major !== 22 || minor < 22) {
|
|
290
|
+
console.log(`✗ ${nodeCheck}`);
|
|
291
|
+
process.exitCode = 1;
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
checks.push({ name: nodeCheck, ok: true });
|
|
285
295
|
const entries = await pluginEntries().catch(() => []);
|
|
286
296
|
checks.push({ name: `插件入口(${entries.length} 个)`, ok: entries.length > 0 });
|
|
287
297
|
checks.push({ name: '插件 ID 唯一', ok: entries.length > 0 && (await build().then(() => true).catch(() => false)) });
|