@worm-print-platform/marketplace 1.6.1 → 1.6.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.
@@ -300,7 +300,7 @@ async function installPlugin(options) {
300
300
  }
301
301
  const npmExecutor = options.npmExecutor ?? defaultNpmExecutor;
302
302
  const gitExecutor = options.gitExecutor ?? defaultGitExecutor;
303
- const sources = options.source === "auto" ? ["npm", "github", "gitee"] : [options.source];
303
+ const sources = options.source === "auto" ? ["npm", "gitee", "github"] : [options.source];
304
304
  let lastError;
305
305
  for (const source of sources) {
306
306
  let fetched;
@@ -374,12 +374,69 @@ async function removePlugin(options) {
374
374
  // src/catalog.generated.ts
375
375
  var BUNDLED_CATALOG = {
376
376
  "schemaVersion": 1,
377
+ "format": "worm-market-v1",
378
+ "title": {
379
+ "zh-CN": "Worm \u63D2\u4EF6\u5E02\u573A",
380
+ "en": "Worm Plugin Market"
381
+ },
382
+ "description": {
383
+ "zh-CN": "worm-print-platform \u5B98\u65B9\u63D2\u4EF6\u7D22\u5F15\uFF1A\u5143\u7D20\u3001\u529F\u80FD\u4E0E\u5BFC\u51FA\u63D2\u4EF6\u3002",
384
+ "en": "Official plugin index for worm-print-platform: element, functional and export plugins."
385
+ },
386
+ "metadata": {
387
+ "categories": {
388
+ "element": {
389
+ "title": {
390
+ "zh-CN": "\u5143\u7D20\u63D2\u4EF6",
391
+ "en": "Element"
392
+ }
393
+ },
394
+ "functional": {
395
+ "title": {
396
+ "zh-CN": "\u529F\u80FD\u63D2\u4EF6",
397
+ "en": "Functional"
398
+ }
399
+ },
400
+ "export": {
401
+ "title": {
402
+ "zh-CN": "\u5BFC\u51FA\u63D2\u4EF6",
403
+ "en": "Export"
404
+ }
405
+ }
406
+ },
407
+ "labels": {
408
+ "official": {
409
+ "title": {
410
+ "zh-CN": "\u5B98\u65B9",
411
+ "en": "Official"
412
+ }
413
+ }
414
+ },
415
+ "sortKeys": {
416
+ "publishedAt": {
417
+ "title": {
418
+ "zh-CN": "\u53D1\u5E03\u65F6\u95F4",
419
+ "en": "Published"
420
+ },
421
+ "order": "desc"
422
+ }
423
+ }
424
+ },
377
425
  "plugins": [
378
426
  {
379
427
  "id": "echarts",
428
+ "uniqueId": "worm-echarts",
429
+ "type": "element",
380
430
  "name": "\u767E\u5EA6\u56FE\u8868\u5143\u7D20",
381
- "description": "\u57FA\u4E8E ECharts \u7684\u5341\u7C7B\u6253\u5370\u56FE\u8868\u5143\u7D20\uFF0C\u6D4F\u89C8\u5668\u4E0E\u670D\u52A1\u7AEF\u540C\u6784\u51FA\u56FE\u3002\u56FE\u8868\u5E93\u5305 @worm-print-platform/echarts \u72EC\u7ACB\u53D1\u5E03\uFF0C\u672C\u63D2\u4EF6\u4EC5\u505A\u526F\u4F5C\u7528\u6CE8\u518C\u3002",
382
- "version": "1.6.1",
431
+ "title": {
432
+ "zh-CN": "\u767E\u5EA6\u56FE\u8868\u5143\u7D20",
433
+ "en": "ECharts Charts"
434
+ },
435
+ "description": {
436
+ "zh-CN": "\u57FA\u4E8E ECharts \u7684\u5341\u7C7B\u6253\u5370\u56FE\u8868\u5143\u7D20\uFF0C\u6D4F\u89C8\u5668\u4E0E\u670D\u52A1\u7AEF\u540C\u6784\u51FA\u56FE\u3002\u672C\u63D2\u4EF6\u901A\u8FC7\u63D2\u4EF6\u5E02\u573A CLI \u5206\u53D1\uFF0C\u4E0D\u518D\u5355\u72EC\u53D1\u5E03 npm\uFF1B\u517C\u5BB9\u5E93 @worm-print-platform/echarts \u7EE7\u7EED\u72EC\u7ACB\u53D1\u5E03\u3002",
437
+ "en": "Ten print chart elements based on ECharts, rendered isomorphically in browser and server. Distributed via the plugin marketplace CLI."
438
+ },
439
+ "version": "1.6.2",
383
440
  "npmName": "@worm-print-platform/plugin-echarts",
384
441
  "path": "plugins/echarts",
385
442
  "entry": "dist/marketplace.js",
@@ -398,12 +455,43 @@ var BUNDLED_CATALOG = {
398
455
  "exportFormats": [],
399
456
  "homepage": "https://github.com/worm-longliu/worm-print-platform/tree/master/marketplace/plugins/echarts",
400
457
  "license": "MIT",
401
- "minCoreVersion": "1.5.2"
458
+ "minCoreVersion": "1.5.2",
459
+ "engines": {
460
+ "core": ">=1.5.2 <2"
461
+ },
462
+ "publishTimestamp": 1795427088,
463
+ "metadata": {
464
+ "category": "element",
465
+ "labels": [
466
+ "official"
467
+ ],
468
+ "sortKeys": {
469
+ "publishedAt": 1795427088
470
+ }
471
+ },
472
+ "versions": [
473
+ {
474
+ "version": "1.6.2",
475
+ "publishTimestamp": 1795427088,
476
+ "engines": {
477
+ "core": ">=1.5.2 <2"
478
+ }
479
+ }
480
+ ]
402
481
  },
403
482
  {
404
483
  "id": "data-preview",
484
+ "uniqueId": "worm-data-preview",
485
+ "type": "functional",
405
486
  "name": "\u6570\u636E\u6E90\u9884\u89C8",
406
- "description": "\u5B57\u6BB5\u6811\u7236\u8282\u70B9\u589E\u52A0\u67E5\u770B\u6570\u636E\u6E90\u6309\u94AE\uFF0C\u628A designData \u6309 JSON \u5F62\u6001\u89E3\u6790\u4E3A\u591A tab \u8868\u5355/\u8868\u683C\uFF08\u603B\u89C8\u6C47\u603B\u8868 + \u5B50\u6807\u7B7E\u9875\u8DF3\u8F6C\uFF09\uFF0C\u7B2C\u4E00\u7248\u4E0D\u5206\u9875\u3002",
487
+ "title": {
488
+ "zh-CN": "\u6570\u636E\u6E90\u9884\u89C8",
489
+ "en": "Data Source Preview"
490
+ },
491
+ "description": {
492
+ "zh-CN": "\u628A designData \u6309 JSON \u5F62\u6001\u89E3\u6790\u4E3A\u591A tab \u8868\u5355/\u8868\u683C\u9884\u89C8\uFF0C\u7531\u5BBF\u4E3B\u6309\u9700\u6302\u8F7D\u5165\u53E3\u3002",
493
+ "en": "Parses designData as JSON into multi-tab form/table previews; the host mounts the entry point."
494
+ },
407
495
  "version": "0.1.0",
408
496
  "npmName": "@worm-print-platform/plugin-data-preview",
409
497
  "path": "plugins/data-preview",
@@ -412,11 +500,116 @@ var BUNDLED_CATALOG = {
412
500
  "exportFormats": [],
413
501
  "homepage": "https://github.com/worm-longliu/worm-print-platform/tree/master/marketplace/plugins/data-preview",
414
502
  "license": "MIT",
415
- "minCoreVersion": "1.5.3"
503
+ "minCoreVersion": "1.5.3",
504
+ "engines": {
505
+ "core": ">=1.5.3 <2"
506
+ },
507
+ "publishTimestamp": 17637e5,
508
+ "metadata": {
509
+ "category": "functional",
510
+ "labels": [
511
+ "official"
512
+ ],
513
+ "sortKeys": {
514
+ "publishedAt": 17637e5
515
+ }
516
+ },
517
+ "versions": [
518
+ {
519
+ "version": "0.1.0",
520
+ "publishTimestamp": 17637e5,
521
+ "source": {
522
+ "type": "npm",
523
+ "name": "@worm-print-platform/plugin-data-preview"
524
+ },
525
+ "engines": {
526
+ "core": ">=1.5.3 <2"
527
+ }
528
+ }
529
+ ]
416
530
  }
417
531
  ]
418
532
  };
419
533
 
534
+ // src/localize.ts
535
+ function localize(text, locale) {
536
+ if (text === void 0) return "";
537
+ if (typeof text === "string") return text;
538
+ const wanted = locale.trim().toLowerCase();
539
+ if (!wanted) return text["zh-CN"] ?? "";
540
+ if (text[wanted] !== void 0) return text[wanted];
541
+ const prefix = wanted.split("-")[0];
542
+ if (prefix !== wanted && text[prefix] !== void 0) return text[prefix];
543
+ return text["zh-CN"] ?? "";
544
+ }
545
+
546
+ // src/validate-index.ts
547
+ var UNIQUE_ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$/;
548
+ var TYPES = /* @__PURE__ */ new Set(["element", "functional", "export"]);
549
+ function isLocalizedTextObject(value) {
550
+ return typeof value === "object" && value !== null;
551
+ }
552
+ function validateIndex(index) {
553
+ const issues = [];
554
+ const add = (path, message) => {
555
+ issues.push({ path, message });
556
+ };
557
+ if (index.schemaVersion !== 1) add("schemaVersion", `schemaVersion \u5FC5\u987B\u4E3A 1\uFF0C\u5B9E\u9645\u4E3A ${index.schemaVersion}`);
558
+ const seenIds = /* @__PURE__ */ new Set();
559
+ const seenUnique = /* @__PURE__ */ new Set();
560
+ const decl = index.metadata;
561
+ const categories = new Set(Object.keys(decl?.categories ?? {}));
562
+ const labels = new Set(Object.keys(decl?.labels ?? {}));
563
+ const sortKeys = new Set(Object.keys(decl?.sortKeys ?? {}));
564
+ const checkLocalized = (value, path) => {
565
+ if (value === void 0) return;
566
+ if (isLocalizedTextObject(value) && !value["zh-CN"]) add(path, "\u591A\u8BED\u8A00\u6587\u672C\u5FC5\u987B\u542B zh-CN");
567
+ };
568
+ index.plugins.forEach((plugin, i) => {
569
+ const base = `plugins[${i}]`;
570
+ if (!plugin.id) add(`${base}.id`, "id \u4E0D\u80FD\u4E3A\u7A7A");
571
+ else if (seenIds.has(plugin.id)) add(`${base}.id`, `id \u91CD\u590D\uFF1A${plugin.id}`);
572
+ else seenIds.add(plugin.id);
573
+ if (plugin.uniqueId === void 0) {
574
+ } else if (!plugin.uniqueId) {
575
+ add(`${base}.uniqueId`, "uniqueId \u4E0D\u80FD\u4E3A\u7A7A");
576
+ } else if (!UNIQUE_ID.test(plugin.uniqueId)) {
577
+ add(`${base}.uniqueId`, `uniqueId \u987B\u4E3A\u300C\u4F5C\u8005\u4EE3\u53F7-\u63D2\u4EF6\u540D\u300D\u5F62\u5F0F\uFF1A${plugin.uniqueId}`);
578
+ } else if (seenUnique.has(plugin.uniqueId)) {
579
+ add(`${base}.uniqueId`, `uniqueId \u91CD\u590D\uFF1A${plugin.uniqueId}`);
580
+ } else {
581
+ seenUnique.add(plugin.uniqueId);
582
+ }
583
+ if (plugin.type !== void 0 && !TYPES.has(plugin.type)) {
584
+ add(`${base}.type`, `\u672A\u77E5\u7C7B\u578B\uFF1A${plugin.type}`);
585
+ }
586
+ checkLocalized(plugin.title, `${base}.title`);
587
+ checkLocalized(plugin.description, `${base}.description`);
588
+ const meta = plugin.metadata;
589
+ if (meta) {
590
+ if (meta.category !== void 0 && !categories.has(meta.category)) {
591
+ add(`${base}.metadata.category`, `\u672A\u58F0\u660E\u7684\u5206\u7C7B\uFF1A${meta.category}`);
592
+ }
593
+ for (const label of meta.labels ?? []) {
594
+ if (!labels.has(label)) add(`${base}.metadata.labels`, `\u672A\u58F0\u660E\u7684\u6807\u7B7E\uFF1A${label}`);
595
+ }
596
+ for (const key of Object.keys(meta.sortKeys ?? {})) {
597
+ if (!sortKeys.has(key)) add(`${base}.metadata.sortKeys`, `\u672A\u58F0\u660E\u7684\u6392\u5E8F\u952E\uFF1A${key}`);
598
+ }
599
+ }
600
+ if (plugin.engines !== void 0) {
601
+ if (!plugin.engines.core) add(`${base}.engines.core`, "engines.core \u4E0D\u80FD\u4E3A\u7A7A");
602
+ }
603
+ if (plugin.versions !== void 0) {
604
+ if (plugin.versions.length === 0) add(`${base}.versions`, "versions \u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");
605
+ plugin.versions.forEach((v, vi) => {
606
+ if (!parseSemver(v.version)) add(`${base}.versions[${vi}].version`, `\u975E\u6CD5\u7248\u672C\u53F7\uFF1A${v.version}`);
607
+ });
608
+ }
609
+ });
610
+ return issues;
611
+ }
612
+
420
613
  export {
421
614
  manifestPath,
422
615
  readManifest,
@@ -440,5 +633,7 @@ export {
440
633
  defaultGitExecutor,
441
634
  installPlugin,
442
635
  removePlugin,
443
- BUNDLED_CATALOG
636
+ BUNDLED_CATALOG,
637
+ localize,
638
+ validateIndex
444
639
  };
package/dist/cli.d.ts CHANGED
@@ -1,24 +1,47 @@
1
1
  #!/usr/bin/env node
2
- import { i as installPlugin, r as removePlugin, M as MarketIndex, a as MarketSource } from './install-_nzKFo4K.js';
2
+ import { i as installPlugin, r as removePlugin, M as MarketIndex, P as PluginType, a as MarketSource, b as MarketIndexEntry, c as MarketMetadataDecl } from './install-GAO58ijj.js';
3
3
 
4
4
  interface ParsedArgs {
5
- command?: 'list' | 'install' | 'remove';
5
+ command?: 'list' | 'validate' | 'install' | 'remove';
6
6
  name?: string;
7
7
  version?: string;
8
8
  source: MarketSource | 'auto';
9
9
  dir?: string;
10
10
  repo?: string;
11
+ index?: string;
12
+ type?: PluginType;
13
+ category?: string;
14
+ label?: string;
15
+ search?: string;
16
+ locale?: string;
17
+ sort?: string;
18
+ json: boolean;
11
19
  force: boolean;
12
20
  help: boolean;
13
21
  helpVersion: boolean;
14
22
  }
15
23
  declare function parseArgs(argv: string[]): ParsedArgs;
24
+ interface ListOptions {
25
+ type?: PluginType;
26
+ category?: string;
27
+ label?: string;
28
+ search?: string;
29
+ locale?: string;
30
+ sort?: string;
31
+ }
32
+ /** 按筛选条件过滤并按可选排序键排序;缺值排最后,保持原数组顺序稳定。 */
33
+ declare function filterAndSortPlugins(index: MarketIndex, opts: ListOptions): MarketIndexEntry[];
34
+ /** 格式化 list 的展示行;categories 缺省时用内置中文类型名。 */
35
+ declare function formatPluginLines(entries: readonly MarketIndexEntry[], locale: string, categories?: MarketMetadataDecl['categories']): string;
16
36
  interface CliDeps {
17
37
  install?: typeof installPlugin;
18
38
  remove?: typeof removePlugin;
19
39
  index?: MarketIndex;
20
40
  out?: (message: string) => void;
41
+ err?: (message: string) => void;
21
42
  }
22
43
  declare function main(argv: string[], deps?: CliDeps): Promise<number>;
44
+ /** 判断是否直接执行本 CLI;经 npm bin 软链调用时 argv[1] 是链接路径,需先归一。 */
45
+ declare function isCliEntry(argv1: string | undefined, moduleUrl: string): boolean;
23
46
 
24
- export { type CliDeps, type ParsedArgs, main, parseArgs };
47
+ export { type CliDeps, type ListOptions, type ParsedArgs, filterAndSortPlugins, formatPluginLines, isCliEntry, main, parseArgs };
package/dist/cli.js CHANGED
@@ -3,30 +3,60 @@ import {
3
3
  BUNDLED_CATALOG,
4
4
  MarketError,
5
5
  installPlugin,
6
- removePlugin
7
- } from "./chunk-EUYKASVQ.js";
6
+ localize,
7
+ removePlugin,
8
+ validateIndex
9
+ } from "./chunk-2P3ACAZV.js";
8
10
 
9
11
  // src/cli.ts
10
- import { resolve } from "path";
11
- import { fileURLToPath } from "url";
12
- var VERSION = true ? "1.6.1" : "1.6.1";
12
+ import { realpathSync } from "fs";
13
+ import { pathToFileURL } from "url";
14
+ var VERSION = true ? "1.6.2" : "1.6.2";
13
15
  var SOURCES = /* @__PURE__ */ new Set(["npm", "github", "gitee", "auto", "local"]);
16
+ var PLUGIN_TYPES = /* @__PURE__ */ new Set(["element", "functional", "export"]);
17
+ var VALUE_FLAGS = /* @__PURE__ */ new Set([
18
+ "--source",
19
+ "--dir",
20
+ "--repo",
21
+ "--index",
22
+ "--type",
23
+ "--category",
24
+ "--label",
25
+ "--search",
26
+ "--locale",
27
+ "--sort"
28
+ ]);
14
29
  var USAGE = `\u7528\u6CD5: worm-print-marketplace <\u547D\u4EE4> [\u9009\u9879]
15
30
 
16
31
  \u547D\u4EE4:
17
- list \u5217\u51FA\u5185\u7F6E\u7D22\u5F15\u4E2D\u7684\u63D2\u4EF6
32
+ list \u5217\u51FA\u5185\u7F6E\u7D22\u5F15\u4E2D\u7684\u63D2\u4EF6\uFF08\u53EF\u6309\u7C7B\u578B/\u5206\u7C7B/\u6807\u7B7E/\u5173\u952E\u8BCD\u7B5B\u9009\uFF09
33
+ validate \u6821\u9A8C\u5185\u7F6E\u7D22\u5F15\u6216\u7528 --index \u6307\u5B9A\u7684\u7D22\u5F15\u6587\u4EF6
18
34
  install <\u540D\u79F0>[@\u7248\u672C] \u5B89\u88C5\u5355\u4E2A\u63D2\u4EF6\uFF08\u7F3A\u7701\u7248\u672C = \u6700\u65B0\u7A33\u5B9A\u7248\uFF09
19
35
  remove <\u540D\u79F0> \u5378\u8F7D\u63D2\u4EF6
20
36
 
21
37
  \u9009\u9879:
22
- --source npm|github|gitee|auto \u5B89\u88C5\u6765\u6E90\uFF0C\u9ED8\u8BA4 auto\uFF08npm \u2192 GitHub \u2192 Gitee\uFF09
38
+ --source npm|gitee|github|auto \u5B89\u88C5\u6765\u6E90\uFF0C\u9ED8\u8BA4 auto\uFF08npm \u2192 Gitee \u2192 GitHub\uFF09
23
39
  --dir <\u8DEF\u5F84> \u63D2\u4EF6\u6839\u76EE\u5F55\uFF0C\u9ED8\u8BA4 .worm-print/plugins
24
40
  --repo <\u8DEF\u5F84\u6216URL> \u672C\u5730\u5E02\u573A\u76EE\u5F55\u6216\u81EA\u5B9A\u4E49 git \u4ED3\u5E93\u5730\u5740
25
41
  --force \u5DF2\u5B58\u5728\u65F6\u8986\u76D6\u5B89\u88C5
42
+ --index <\u8DEF\u5F84> validate \u6821\u9A8C\u7684\u7D22\u5F15\u6587\u4EF6\uFF08\u7F3A\u7701\u7528\u5185\u7F6E\u7D22\u5F15\uFF09
43
+ --type element|functional|export list \u6309\u63D2\u4EF6\u7C7B\u578B\u7B5B\u9009
44
+ --category <id> list \u6309\u5206\u7C7B\u7B5B\u9009
45
+ --label <id> list \u6309\u6807\u7B7E\u7B5B\u9009
46
+ --search <\u6587\u672C> list \u6309\u6807\u8BC6/\u540D\u79F0/\u6807\u9898/\u63CF\u8FF0\u641C\u7D22
47
+ --locale <bcp47> list \u5C55\u793A\u8BED\u8A00\uFF0C\u9ED8\u8BA4 zh-CN
48
+ --sort <\u6392\u5E8F\u952E> list \u6309\u7D22\u5F15\u58F0\u660E\u7684\u6392\u5E8F\u952E\u6392\u5E8F
49
+ --json list \u8F93\u51FA\u7ED3\u6784\u5316 JSON
26
50
  -h, --help \u663E\u793A\u5E2E\u52A9
27
51
  -v, --version \u663E\u793A\u7248\u672C`;
28
52
  function parseArgs(argv) {
29
- const result = { source: "auto", force: false, help: false, helpVersion: false };
53
+ const result = {
54
+ source: "auto",
55
+ json: false,
56
+ force: false,
57
+ help: false,
58
+ helpVersion: false
59
+ };
30
60
  for (let i = 0; i < argv.length; i += 1) {
31
61
  const arg = argv[i];
32
62
  if (arg === "-h" || arg === "--help") {
@@ -41,19 +71,32 @@ function parseArgs(argv) {
41
71
  result.force = true;
42
72
  continue;
43
73
  }
44
- if (arg === "--source" || arg === "--dir" || arg === "--repo") {
74
+ if (arg === "--json") {
75
+ result.json = true;
76
+ continue;
77
+ }
78
+ if (VALUE_FLAGS.has(arg)) {
45
79
  const value = argv[++i];
46
80
  if (!value) throw new MarketError("BAD_ARGUMENT", `${arg} \u7F3A\u5C11\u503C`);
47
81
  if (arg === "--source") {
48
82
  if (!SOURCES.has(value)) throw new MarketError("BAD_ARGUMENT", `\u4E0D\u652F\u6301\u7684\u6765\u6E90\uFF08--source\uFF09\uFF1A${value}`);
49
83
  result.source = value;
50
84
  } else if (arg === "--dir") result.dir = value;
51
- else result.repo = value;
85
+ else if (arg === "--repo") result.repo = value;
86
+ else if (arg === "--index") result.index = value;
87
+ else if (arg === "--type") {
88
+ if (!PLUGIN_TYPES.has(value)) throw new MarketError("BAD_ARGUMENT", `\u4E0D\u652F\u6301\u7684\u63D2\u4EF6\u7C7B\u578B\uFF08--type\uFF09\uFF1A${value}`);
89
+ result.type = value;
90
+ } else if (arg === "--category") result.category = value;
91
+ else if (arg === "--label") result.label = value;
92
+ else if (arg === "--search") result.search = value;
93
+ else if (arg === "--locale") result.locale = value;
94
+ else if (arg === "--sort") result.sort = value;
52
95
  continue;
53
96
  }
54
97
  if (arg.startsWith("-")) throw new MarketError("BAD_ARGUMENT", `\u672A\u77E5\u9009\u9879\uFF1A${arg}`);
55
98
  if (!result.command) {
56
- if (arg === "list" || arg === "install" || arg === "remove") result.command = arg;
99
+ if (arg === "list" || arg === "validate" || arg === "install" || arg === "remove") result.command = arg;
57
100
  else throw new MarketError("BAD_ARGUMENT", `\u672A\u77E5\u547D\u4EE4\uFF1A${arg}`);
58
101
  continue;
59
102
  }
@@ -69,6 +112,61 @@ function parseArgs(argv) {
69
112
  }
70
113
  return result;
71
114
  }
115
+ function resolveType(plugin) {
116
+ if (plugin.type) return plugin.type;
117
+ if (plugin.exportFormats.length) return "export";
118
+ if (plugin.kinds.length) return "element";
119
+ return "functional";
120
+ }
121
+ function filterAndSortPlugins(index, opts) {
122
+ const search = opts.search?.trim().toLowerCase();
123
+ const matches = index.plugins.filter((plugin) => {
124
+ if (opts.type && resolveType(plugin) !== opts.type) return false;
125
+ if (opts.category && plugin.metadata?.category !== opts.category) return false;
126
+ if (opts.label && !plugin.metadata?.labels?.includes(opts.label)) return false;
127
+ if (search) {
128
+ const haystack = [
129
+ plugin.uniqueId ?? plugin.id,
130
+ plugin.id,
131
+ plugin.name,
132
+ ...Object.values(typeof plugin.title === "string" ? {} : plugin.title ?? {}),
133
+ ...Object.values(typeof plugin.description === "string" ? {} : plugin.description ?? {})
134
+ ].join(" ").toLowerCase();
135
+ if (!haystack.includes(search)) return false;
136
+ }
137
+ return true;
138
+ });
139
+ if (!opts.sort) return [...matches];
140
+ const order = index.metadata?.sortKeys?.[opts.sort]?.order ?? "asc";
141
+ const direction = order === "desc" ? -1 : 1;
142
+ return [...matches].sort((a, b) => {
143
+ const av = a.metadata?.sortKeys?.[opts.sort];
144
+ const bv = b.metadata?.sortKeys?.[opts.sort];
145
+ if (av === null || av === void 0) return bv === null || bv === void 0 ? 0 : 1;
146
+ if (bv === null || bv === void 0) return -1;
147
+ return (av - bv) * direction;
148
+ });
149
+ }
150
+ var BUILTIN_TYPE_NAMES = {
151
+ element: { "zh-CN": "\u5143\u7D20\u63D2\u4EF6", en: "Element" },
152
+ functional: { "zh-CN": "\u529F\u80FD\u63D2\u4EF6", en: "Functional" },
153
+ export: { "zh-CN": "\u5BFC\u51FA\u63D2\u4EF6", en: "Export" }
154
+ };
155
+ function formatPluginLines(entries, locale, categories) {
156
+ const wanted = locale || "zh-CN";
157
+ return entries.map((plugin) => {
158
+ const categoryId = plugin.metadata?.category ?? resolveType(plugin);
159
+ const categoryTitle = categories?.[categoryId]?.title ?? BUILTIN_TYPE_NAMES[categoryId];
160
+ const typeName = localize(categoryTitle, wanted);
161
+ const title = localize(plugin.title ?? plugin.name, wanted);
162
+ const engine = plugin.engines?.core ?? plugin.minCoreVersion;
163
+ const labels = plugin.metadata?.labels?.length ? ` \xB7 ${plugin.metadata.labels.join("\u3001")}` : "";
164
+ const head = `${plugin.uniqueId ?? plugin.id} ${typeName} ${title} v${plugin.version}`;
165
+ const second = ` npm ${plugin.npmName}${engine ? ` \xB7 core ${engine}` : ""}${labels}`;
166
+ return `${head}
167
+ ${second}`;
168
+ }).join("\n");
169
+ }
72
170
  function errorCode(err) {
73
171
  if (err instanceof MarketError) {
74
172
  const map = {
@@ -79,6 +177,7 @@ function errorCode(err) {
79
177
  VERSION_NOT_FOUND: 3,
80
178
  ALREADY_EXISTS: 4,
81
179
  INVALID_PLUGIN: 5,
180
+ INVALID_INDEX: 5,
82
181
  NPM_FAILED: 6,
83
182
  CLONE_FAILED: 6,
84
183
  GIT_MISSING: 6
@@ -87,13 +186,24 @@ function errorCode(err) {
87
186
  }
88
187
  return 1;
89
188
  }
189
+ async function loadIndex(path, fallback, err) {
190
+ if (!path) return fallback;
191
+ try {
192
+ const { readFileSync } = await import("fs");
193
+ return JSON.parse(readFileSync(path, "utf8"));
194
+ } catch (readErr) {
195
+ err(`\u8BFB\u53D6\u7D22\u5F15\u5931\u8D25\uFF1A${readErr instanceof Error ? readErr.message : String(readErr)}`);
196
+ return null;
197
+ }
198
+ }
90
199
  async function main(argv, deps = {}) {
91
200
  const out = deps.out ?? console.log;
201
+ const err = deps.err ?? console.error;
92
202
  let parsed;
93
203
  try {
94
204
  parsed = parseArgs(argv);
95
- } catch (err) {
96
- out(err instanceof Error ? err.message : String(err));
205
+ } catch (err2) {
206
+ out(err2 instanceof Error ? err2.message : String(err2));
97
207
  return 1;
98
208
  }
99
209
  if (parsed.help) {
@@ -108,15 +218,32 @@ async function main(argv, deps = {}) {
108
218
  out(USAGE);
109
219
  return 1;
110
220
  }
111
- const index = deps.index ?? BUNDLED_CATALOG;
112
- if (parsed.command === "list") {
113
- out(index.plugins.map((p) => `${p.id}@${p.version} ${p.npmName}`).join("\n") || "\uFF08\u7D22\u5F15\u4E3A\u7A7A\uFF09");
221
+ const fallbackIndex = deps.index ?? BUNDLED_CATALOG;
222
+ if (parsed.command === "list" || parsed.command === "validate") {
223
+ const target = await loadIndex(parsed.index, fallbackIndex, err);
224
+ if (!target) return 1;
225
+ if (parsed.command === "list") {
226
+ const entries = filterAndSortPlugins(target, parsed);
227
+ if (parsed.json) {
228
+ out(JSON.stringify(entries, null, 2));
229
+ } else {
230
+ out(formatPluginLines(entries, parsed.locale ?? "zh-CN", target.metadata?.categories) || "\uFF08\u7D22\u5F15\u4E3A\u7A7A\uFF09");
231
+ }
232
+ return 0;
233
+ }
234
+ const issues = validateIndex(target);
235
+ if (issues.length) {
236
+ for (const issue of issues) err(`${issue.path}: ${issue.message}`);
237
+ return 1;
238
+ }
239
+ out("\u7D22\u5F15\u6821\u9A8C\u901A\u8FC7");
114
240
  return 0;
115
241
  }
116
242
  if (!parsed.name) {
117
243
  out("\u7F3A\u5C11\u63D2\u4EF6\u540D");
118
244
  return 1;
119
245
  }
246
+ const index = fallbackIndex;
120
247
  try {
121
248
  if (parsed.command === "install") {
122
249
  const options = {
@@ -139,17 +266,28 @@ async function main(argv, deps = {}) {
139
266
  });
140
267
  out(`\u5DF2\u5378\u8F7D ${parsed.name}`);
141
268
  return 0;
142
- } catch (err) {
143
- out(err instanceof Error ? err.message : String(err));
144
- return errorCode(err);
269
+ } catch (err2) {
270
+ out(err2 instanceof Error ? err2.message : String(err2));
271
+ return errorCode(err2);
272
+ }
273
+ }
274
+ function isCliEntry(argv1, moduleUrl) {
275
+ if (!argv1) return false;
276
+ try {
277
+ return pathToFileURL(realpathSync(argv1)).href === moduleUrl;
278
+ } catch {
279
+ return false;
145
280
  }
146
281
  }
147
- if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
282
+ if (isCliEntry(process.argv[1], import.meta.url)) {
148
283
  main(process.argv.slice(2)).then((code) => {
149
284
  process.exitCode = code;
150
285
  });
151
286
  }
152
287
  export {
288
+ filterAndSortPlugins,
289
+ formatPluginLines,
290
+ isCliEntry,
153
291
  main,
154
292
  parseArgs
155
293
  };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MarketIndex, a as MarketSource, R as RepoSource, P as PluginsManifest, b as ManifestEntry } from './install-_nzKFo4K.js';
2
- export { C as CommandResult, G as GitExecutor, I as InstallOptions, c as InstallResult, d as MarketError, e as MarketErrorCode, f as MarketIndexEntry, N as NpmExecutor, g as PluginJsonEntry, h as RemoveOptions, W as WormPrintMeta, j as defaultGitExecutor, k as defaultNpmExecutor, i as installPlugin, r as removePlugin } from './install-_nzKFo4K.js';
1
+ import { M as MarketIndex, a as MarketSource, R as RepoSource, d as PluginsManifest, e as ManifestEntry, L as LocalizedText, I as IndexIssue } from './install-GAO58ijj.js';
2
+ export { C as CommandResult, G as GitExecutor, f as InstallOptions, g as InstallResult, h as MarketError, j as MarketErrorCode, b as MarketIndexEntry, c as MarketMetadataDecl, k as MarketVersionEntry, N as NpmExecutor, l as PluginJsonEntry, P as PluginType, m as RemoveOptions, W as WormPrintMeta, n as defaultGitExecutor, o as defaultNpmExecutor, i as installPlugin, r as removePlugin } from './install-GAO58ijj.js';
3
3
 
4
4
  interface ParsedSemver {
5
5
  major: number;
@@ -43,6 +43,15 @@ declare function writeManifest(dir: string, manifest: PluginsManifest, cwd?: str
43
43
  declare function upsertManifestEntry(dir: string, id: string, entry: ManifestEntry, cwd?: string): void;
44
44
  declare function removeManifestEntry(dir: string, id: string, cwd?: string): void;
45
45
 
46
+ /**
47
+ * 取多语言文本的当前语言值。回退链:精确 locale → 语言前缀 → zh-CN → 空串。
48
+ * 字符串形式视为已是目标文本,原样返回。
49
+ */
50
+ declare function localize(text: LocalizedText | undefined, locale: string): string;
51
+
52
+ /** 校验一份市场索引,返回全部问题;合法索引返回空数组。 */
53
+ declare function validateIndex(index: MarketIndex): IndexIssue[];
54
+
46
55
  declare const BUNDLED_CATALOG: MarketIndex;
47
56
 
48
- export { BUNDLED_CATALOG, DEFAULT_GITEE_REPO, DEFAULT_GITHUB_REPO, ManifestEntry, MarketIndex, MarketSource, type ParsedSemver, PluginsManifest, RepoSource, buildGitTag, compareStable, extractVersion, isStableVersion, latestStable, manifestPath, parseRepoUrl, parseSemver, readManifest, removeManifestEntry, resolveGitSource, resolvePluginName, resolveVersion, upsertManifestEntry, writeManifest };
57
+ export { BUNDLED_CATALOG, DEFAULT_GITEE_REPO, DEFAULT_GITHUB_REPO, IndexIssue, LocalizedText, ManifestEntry, MarketIndex, MarketSource, type ParsedSemver, PluginsManifest, RepoSource, buildGitTag, compareStable, extractVersion, isStableVersion, latestStable, localize, manifestPath, parseRepoUrl, parseSemver, readManifest, removeManifestEntry, resolveGitSource, resolvePluginName, resolveVersion, upsertManifestEntry, validateIndex, writeManifest };
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  installPlugin,
12
12
  isStableVersion,
13
13
  latestStable,
14
+ localize,
14
15
  manifestPath,
15
16
  parseRepoUrl,
16
17
  parseSemver,
@@ -21,8 +22,9 @@ import {
21
22
  resolvePluginName,
22
23
  resolveVersion,
23
24
  upsertManifestEntry,
25
+ validateIndex,
24
26
  writeManifest
25
- } from "./chunk-EUYKASVQ.js";
27
+ } from "./chunk-2P3ACAZV.js";
26
28
  export {
27
29
  BUNDLED_CATALOG,
28
30
  DEFAULT_GITEE_REPO,
@@ -36,6 +38,7 @@ export {
36
38
  installPlugin,
37
39
  isStableVersion,
38
40
  latestStable,
41
+ localize,
39
42
  manifestPath,
40
43
  parseRepoUrl,
41
44
  parseSemver,
@@ -46,5 +49,6 @@ export {
46
49
  resolvePluginName,
47
50
  resolveVersion,
48
51
  upsertManifestEntry,
52
+ validateIndex,
49
53
  writeManifest
50
54
  };
@@ -1,5 +1,47 @@
1
1
  /** 插件安装来源 */
2
2
  type MarketSource = 'npm' | 'github' | 'gitee' | 'local';
3
+ /** 多语言文本:字符串视为 zh-CN;对象必须含基准语言 zh-CN */
4
+ type LocalizedText = string | ({
5
+ 'zh-CN': string;
6
+ } & Record<string, string>);
7
+ /** 插件类型:元素插件 / 功能插件 / 导出插件 */
8
+ type PluginType = 'element' | 'functional' | 'export';
9
+ /** 索引里的精简版本条目 */
10
+ interface MarketVersionEntry {
11
+ version: string;
12
+ publishTimestamp?: number;
13
+ source?: {
14
+ type: 'npm';
15
+ name?: string;
16
+ registry?: string;
17
+ } | {
18
+ type: 'git';
19
+ url: string;
20
+ commit: string;
21
+ path?: string;
22
+ };
23
+ engines?: {
24
+ core?: string;
25
+ };
26
+ }
27
+ /** 索引根级声明:分类 / 标签 / 排序键的 id → 多语言标题 */
28
+ interface MarketMetadataDecl {
29
+ categories?: Record<string, {
30
+ title: LocalizedText;
31
+ }>;
32
+ labels?: Record<string, {
33
+ title: LocalizedText;
34
+ }>;
35
+ sortKeys?: Record<string, {
36
+ title: LocalizedText;
37
+ order?: 'asc' | 'desc';
38
+ }>;
39
+ }
40
+ /** 索引校验问题 */
41
+ interface IndexIssue {
42
+ path: string;
43
+ message: string;
44
+ }
3
45
  /** marketplace.json 中的一条插件索引 */
4
46
  interface MarketIndexEntry {
5
47
  id: string;
@@ -10,14 +52,32 @@ interface MarketIndexEntry {
10
52
  entry: string;
11
53
  kinds: readonly string[];
12
54
  exportFormats: readonly string[];
13
- description?: string;
55
+ description?: LocalizedText;
14
56
  homepage?: string;
15
57
  license?: string;
16
58
  minCoreVersion?: string;
59
+ /** 全局唯一标识,形如 worm-echarts;缺省时读取端回退 id */
60
+ uniqueId?: string;
61
+ type?: PluginType;
62
+ title?: LocalizedText;
63
+ engines?: {
64
+ core?: string;
65
+ };
66
+ publishTimestamp?: number;
67
+ metadata?: {
68
+ category?: string;
69
+ labels?: string[];
70
+ sortKeys?: Record<string, number | null>;
71
+ };
72
+ versions?: readonly MarketVersionEntry[];
17
73
  }
18
74
  interface MarketIndex {
19
75
  schemaVersion: number;
20
76
  plugins: readonly MarketIndexEntry[];
77
+ format?: string;
78
+ title?: LocalizedText;
79
+ description?: LocalizedText;
80
+ metadata?: MarketMetadataDecl;
21
81
  }
22
82
  /** 插件目录内 plugin.json */
23
83
  interface PluginJsonEntry {
@@ -91,7 +151,7 @@ interface InstallOptions {
91
151
  name: string;
92
152
  /** 指定版本;缺省取最新稳定版 */
93
153
  version?: string;
94
- /** 安装来源;auto 按 npm → github → gitee 回退 */
154
+ /** 安装来源;auto 按 npm → gitee → github 回退 */
95
155
  source: MarketSource | 'auto';
96
156
  /** 目标插件根目录,默认 .worm-print/plugins */
97
157
  dir?: string;
@@ -118,7 +178,7 @@ interface RemoveOptions {
118
178
  cwd?: string;
119
179
  npmExecutor?: NpmExecutor;
120
180
  }
121
- type MarketErrorCode = 'BAD_ARGUMENT' | 'BAD_PLUGIN_ID' | 'BAD_REPO' | 'ALREADY_EXISTS' | 'NOT_FOUND' | 'VERSION_NOT_FOUND' | 'INVALID_PLUGIN' | 'NPM_FAILED' | 'CLONE_FAILED' | 'GIT_MISSING';
181
+ type MarketErrorCode = 'BAD_ARGUMENT' | 'BAD_PLUGIN_ID' | 'BAD_REPO' | 'ALREADY_EXISTS' | 'NOT_FOUND' | 'VERSION_NOT_FOUND' | 'INVALID_PLUGIN' | 'INVALID_INDEX' | 'NPM_FAILED' | 'CLONE_FAILED' | 'GIT_MISSING';
122
182
  /** 带稳定错误码的领域错误,CLI 据此映射退出码 */
123
183
  declare class MarketError extends Error {
124
184
  readonly code: MarketErrorCode;
@@ -130,4 +190,4 @@ declare const defaultGitExecutor: GitExecutor;
130
190
  declare function installPlugin(options: InstallOptions): Promise<InstallResult>;
131
191
  declare function removePlugin(options: RemoveOptions): Promise<void>;
132
192
 
133
- export { type CommandResult as C, type GitExecutor as G, type InstallOptions as I, type MarketIndex as M, type NpmExecutor as N, type PluginsManifest as P, type RepoSource as R, type WormPrintMeta as W, type MarketSource as a, type ManifestEntry as b, type InstallResult as c, MarketError as d, type MarketErrorCode as e, type MarketIndexEntry as f, type PluginJsonEntry as g, type RemoveOptions as h, installPlugin as i, defaultGitExecutor as j, defaultNpmExecutor as k, removePlugin as r };
193
+ export { type CommandResult as C, type GitExecutor as G, type IndexIssue as I, type LocalizedText as L, type MarketIndex as M, type NpmExecutor as N, type PluginType as P, type RepoSource as R, type WormPrintMeta as W, type MarketSource as a, type MarketIndexEntry as b, type MarketMetadataDecl as c, type PluginsManifest as d, type ManifestEntry as e, type InstallOptions as f, type InstallResult as g, MarketError as h, installPlugin as i, type MarketErrorCode as j, type MarketVersionEntry as k, type PluginJsonEntry as l, type RemoveOptions as m, defaultGitExecutor as n, defaultNpmExecutor as o, removePlugin as r };
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@worm-print-platform/marketplace",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "type": "module",
5
5
  "description": "worm-print-platform 插件市场安装器:从 npm / GitHub / Gitee 安装单个插件,默认取最新稳定版。",
6
6
  "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/worm-longliu/worm-print-platform.git"
10
+ },
7
11
  "publishConfig": {
8
12
  "access": "public",
9
13
  "registry": "https://registry.npmjs.org"
@@ -19,7 +23,9 @@
19
23
  "import": "./dist/index.js"
20
24
  }
21
25
  },
22
- "files": ["dist"],
26
+ "files": [
27
+ "dist"
28
+ ],
23
29
  "engines": {
24
30
  "node": ">=18"
25
31
  },
@@ -35,5 +41,11 @@
35
41
  "typescript": "~5.9.3",
36
42
  "vitest": "^1.6.0"
37
43
  },
38
- "keywords": ["print", "plugin", "marketplace", "cli", "worm-print-platform"]
44
+ "keywords": [
45
+ "print",
46
+ "plugin",
47
+ "marketplace",
48
+ "cli",
49
+ "worm-print-platform"
50
+ ]
39
51
  }