@droposs/plugin-cli 0.3.0 → 0.4.0

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.
@@ -13,6 +13,36 @@ import path from "node:path";
13
13
  const command = process.argv[2];
14
14
  const args = process.argv.slice(3);
15
15
 
16
+ async function runValidate(dir) {
17
+ const manifestPath = path.join(
18
+ path.resolve(process.cwd(), dir),
19
+ "drop-plugin.json",
20
+ );
21
+ const manifest = JSON.parse(await readFile(manifestPath, "utf-8"));
22
+ const validation = await validateManifest(manifest);
23
+ if (!validation.valid) {
24
+ console.error("Validation failed:");
25
+ for (const err of validation.errors) {
26
+ console.error(` - ${err}`);
27
+ }
28
+ process.exit(1);
29
+ }
30
+ console.log(`Manifest at ${manifestPath} is valid.`);
31
+ }
32
+
33
+ function printUsage() {
34
+ console.log(`Drop Plugin CLI (drop-plugin)
35
+
36
+ Usage:
37
+ drop-plugin init [dir] Initialize a new plugin from starter template
38
+ drop-plugin build [dir] Bundle server/client entry points with esbuild and sign
39
+ drop-plugin sign [dir] Calculate SHA-256 digests and sign drop-plugin.json
40
+ drop-plugin validate [dir] Validate drop-plugin.json against official schema
41
+ drop-plugin test [dir] Run plugin tests with Node test runner
42
+ drop-plugin pack [dir] [out] Verify, sign, and package bundle into .dropplugin archive
43
+ `);
44
+ }
45
+
16
46
  async function main() {
17
47
  switch (command) {
18
48
  case "sign": {
@@ -48,47 +78,36 @@ async function main() {
48
78
  case "init": {
49
79
  const dir = args[0] || "my-drop-plugin";
50
80
  const res = await initPlugin(dir);
51
- console.log(`Initialized new Drop plugin '${res.id}' at ${res.targetPath}`);
81
+ console.log(
82
+ `Initialized new Drop plugin '${res.id}' at ${res.targetPath}`,
83
+ );
52
84
  break;
53
85
  }
54
86
  case "validate": {
55
- const dir = args[0] || ".";
56
- const manifestPath = path.join(path.resolve(process.cwd(), dir), "drop-plugin.json");
57
- const manifest = JSON.parse(await readFile(manifestPath, "utf-8"));
58
- const validation = await validateManifest(manifest);
59
- if (!validation.valid) {
60
- console.error("Validation failed:");
61
- for (const err of validation.errors) {
62
- console.error(` - ${err}`);
63
- }
64
- process.exit(1);
65
- } else {
66
- console.log(`Manifest at ${manifestPath} is valid.`);
67
- }
87
+ await runValidate(args[0] || ".");
68
88
  break;
69
89
  }
70
90
  case "help":
71
91
  case "--help":
72
92
  case "-h":
73
- default:
74
- console.log(`Drop Plugin CLI (drop-plugin)
75
-
76
- Usage:
77
- drop-plugin init [dir] Initialize a new plugin from starter template
78
- drop-plugin build [dir] Bundle server/client entry points with esbuild and sign
79
- drop-plugin sign [dir] Calculate SHA-256 digests and sign drop-plugin.json
80
- drop-plugin validate [dir] Validate drop-plugin.json against official schema
81
- drop-plugin test [dir] Run plugin tests with Node test runner
82
- drop-plugin pack [dir] [out] Verify, sign, and package bundle into .dropplugin archive
83
- `);
84
- if (command && command !== "help" && command !== "--help" && command !== "-h") {
93
+ default: {
94
+ printUsage();
95
+ const isHelp =
96
+ !command ||
97
+ command === "help" ||
98
+ command === "--help" ||
99
+ command === "-h";
100
+ if (!isHelp) {
85
101
  process.exit(1);
86
102
  }
87
103
  break;
104
+ }
88
105
  }
89
106
  }
90
107
 
91
- main().catch((err) => {
108
+ try {
109
+ await main();
110
+ } catch (err) {
92
111
  console.error(`Error: ${err.message}`);
93
112
  process.exit(1);
94
- });
113
+ }
package/dist/builder.js CHANGED
@@ -34,12 +34,7 @@ export async function buildPlugin(targetDir = ".", options = {}) {
34
34
  format: "esm",
35
35
  sourcemap: options.sourcemap ?? true,
36
36
  minify: options.minify ?? false,
37
- external: [
38
- "@droposs/plugin-sdk",
39
- "@drop/plugin-sdk",
40
- "h3",
41
- "pino",
42
- ],
37
+ external: ["@droposs/plugin-sdk", "@drop/plugin-sdk", "h3", "pino"],
43
38
  });
44
39
  serverBuilt = true;
45
40
  }
@@ -68,11 +63,7 @@ export async function buildPlugin(targetDir = ".", options = {}) {
68
63
  format: "esm",
69
64
  sourcemap: options.sourcemap ?? true,
70
65
  minify: options.minify ?? false,
71
- external: [
72
- "vue",
73
- "@droposs/plugin-sdk",
74
- "@drop/plugin-sdk",
75
- ],
66
+ external: ["vue", "@droposs/plugin-sdk", "@drop/plugin-sdk"],
76
67
  });
77
68
  clientBuilt = true;
78
69
  }
package/dist/signer.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createHash, createHmac } from "node:crypto";
2
- import { readdir, readFile, realpath, stat, writeFile, mkdir } from "node:fs/promises";
2
+ import { readdir, readFile, realpath, stat, writeFile, mkdir, } from "node:fs/promises";
3
3
  import { createRequire } from "node:module";
4
4
  import path from "node:path";
5
5
  import Ajv from "ajv";
@@ -1,34 +1,32 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import path from "node:path";
3
3
  import { readdir, stat } from "node:fs/promises";
4
+ async function directoryExists(dir) {
5
+ return Boolean(await stat(dir).catch(() => null));
6
+ }
7
+ async function collectTestFiles(dir, extension) {
8
+ const entries = await readdir(dir, { recursive: true });
9
+ return entries
10
+ .filter((entry) => typeof entry === "string" &&
11
+ (entry.endsWith(`.test${extension}`) ||
12
+ entry.endsWith(`.spec${extension}`)))
13
+ .map((entry) => path.join(dir, entry));
14
+ }
4
15
  export async function testPlugin(targetDir = ".") {
5
16
  const dir = path.resolve(process.cwd(), targetDir);
6
- const candidates = [
7
- path.join(dir, "dist", "test"),
8
- path.join(dir, "test"),
9
- ];
17
+ const candidates = [path.join(dir, "dist", "test"), path.join(dir, "test")];
10
18
  let testFiles = [];
11
19
  for (const cand of candidates) {
12
- if (await stat(cand).catch(() => null)) {
13
- const files = await readdir(cand, { recursive: true });
14
- for (const f of files) {
15
- if (typeof f === "string" &&
16
- (f.endsWith(".test.js") || f.endsWith(".spec.js"))) {
17
- testFiles.push(path.join(cand, f));
18
- }
19
- }
20
+ if (await directoryExists(cand)) {
21
+ testFiles = await collectTestFiles(cand, ".js");
20
22
  if (testFiles.length > 0)
21
23
  break;
22
24
  }
23
25
  }
24
26
  if (testFiles.length === 0) {
25
27
  const testDir = path.join(dir, "test");
26
- if (await stat(testDir).catch(() => null)) {
27
- const files = await readdir(testDir, { recursive: true });
28
- testFiles = files
29
- .filter((f) => typeof f === "string" &&
30
- (f.endsWith(".test.ts") || f.endsWith(".spec.ts")))
31
- .map((f) => path.join(testDir, f));
28
+ if (await directoryExists(testDir)) {
29
+ testFiles = await collectTestFiles(testDir, ".ts");
32
30
  }
33
31
  }
34
32
  if (testFiles.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@droposs/plugin-cli",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Drop Plugin build, test, signing, and packaging CLI for Drop OSS",
5
5
  "type": "module",
6
6
  "bin": {
@@ -42,7 +42,7 @@
42
42
  "dependencies": {
43
43
  "ajv": "^8.20.0",
44
44
  "esbuild": "^0.28.2",
45
- "@droposs/plugin-sdk": "0.3.0"
45
+ "@droposs/plugin-sdk": "0.4.0"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsc",