@notedge/panduck 0.0.0 → 0.0.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.
@@ -1,84 +1,84 @@
1
- import { access, mkdtemp, rm } from "node:fs/promises";
2
- import { constants } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
-
6
- import type { Cli, ParsedOptions } from "@vmz/commander";
7
-
8
- import { loadBindings } from "../context.js";
9
- import { emitHuman, emitJson } from "../diagnostics.js";
10
- import { readSharedOptions } from "../options.js";
11
-
12
- type DoctorCheck = {
13
- id: string;
14
- ok: boolean;
15
- message: string;
16
- };
17
-
18
- export function registerDoctorCommand(cli: Cli): void {
19
- cli.command("doctor", "cli.cmd.doctor")
20
- .option("--json", "cli.opt.json")
21
- .action((options: ParsedOptions) => runDoctor(options));
22
- }
23
-
24
- async function runDoctor(options: ParsedOptions): Promise<number> {
25
- const shared = readSharedOptions(options);
26
- const checks: DoctorCheck[] = [];
27
-
28
- checks.push({
29
- id: "node",
30
- ok: Number(process.versions.node.split(".")[0]) >= 20,
31
- message: `node ${process.version}`,
32
- });
33
-
34
- const bindings = loadBindings();
35
- if (bindings) {
36
- checks.push({
37
- id: "native",
38
- ok: true,
39
- message: `panduck-napi ${bindings.panduckVersion()}; formats=${bindings.supportedFormats().join(",")}`,
40
- });
41
- } else {
42
- checks.push({
43
- id: "native",
44
- ok: false,
45
- message: "native bindings are not installed for this platform",
46
- });
47
- }
48
-
49
- try {
50
- const dir = await mkdtemp(join(tmpdir(), "panduck-doctor-"));
51
- await access(dir, constants.W_OK);
52
- await rm(dir, { recursive: true, force: true });
53
- checks.push({ id: "tempdir", ok: true, message: tmpdir() });
54
- } catch (error) {
55
- checks.push({
56
- id: "tempdir",
57
- ok: false,
58
- message: error instanceof Error ? error.message : String(error),
59
- });
60
- }
61
-
62
- const ok = checks.every((check) => check.ok);
63
- const payload = {
64
- schema_version: "panduck.doctor/v1",
65
- status: ok ? "ok" : "issues",
66
- checks,
67
- };
68
-
69
- if (shared.json || options.json === true) {
70
- emitJson(payload);
71
- } else if (ok) {
72
- emitHuman("Panduck environment looks healthy");
73
- for (const check of checks) {
74
- emitHuman(` ok ${check.id}: ${check.message}`);
75
- }
76
- } else {
77
- emitHuman("Panduck environment has issues");
78
- for (const check of checks) {
79
- emitHuman(` ${check.ok ? "ok" : "fail"} ${check.id}: ${check.message}`);
80
- }
81
- }
82
-
83
- return ok ? 0 : 2;
84
- }
1
+ import { access, mkdtemp, rm } from "node:fs/promises";
2
+ import { constants } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+
6
+ import type { Cli, ParsedOptions } from "@vmz/commander";
7
+
8
+ import { loadBindings } from "../context.js";
9
+ import { emitHuman, emitJson } from "../diagnostics.js";
10
+ import { readSharedOptions } from "../options.js";
11
+
12
+ type DoctorCheck = {
13
+ id: string;
14
+ ok: boolean;
15
+ message: string;
16
+ };
17
+
18
+ export function registerDoctorCommand(cli: Cli): void {
19
+ cli.command("doctor", "cli.cmd.doctor")
20
+ .option("--json", "cli.opt.json")
21
+ .action((options: ParsedOptions) => runDoctor(options));
22
+ }
23
+
24
+ async function runDoctor(options: ParsedOptions): Promise<number> {
25
+ const shared = readSharedOptions(options);
26
+ const checks: DoctorCheck[] = [];
27
+
28
+ checks.push({
29
+ id: "node",
30
+ ok: Number(process.versions.node.split(".")[0]) >= 20,
31
+ message: `node ${process.version}`,
32
+ });
33
+
34
+ const bindings = loadBindings();
35
+ if (bindings) {
36
+ checks.push({
37
+ id: "native",
38
+ ok: true,
39
+ message: `panduck-napi ${bindings.panduckVersion()}; formats=${bindings.supportedFormats().join(",")}`,
40
+ });
41
+ } else {
42
+ checks.push({
43
+ id: "native",
44
+ ok: false,
45
+ message: "native bindings are not installed for this platform",
46
+ });
47
+ }
48
+
49
+ try {
50
+ const dir = await mkdtemp(join(tmpdir(), "panduck-doctor-"));
51
+ await access(dir, constants.W_OK);
52
+ await rm(dir, { recursive: true, force: true });
53
+ checks.push({ id: "tempdir", ok: true, message: tmpdir() });
54
+ } catch (error) {
55
+ checks.push({
56
+ id: "tempdir",
57
+ ok: false,
58
+ message: error instanceof Error ? error.message : String(error),
59
+ });
60
+ }
61
+
62
+ const ok = checks.every((check) => check.ok);
63
+ const payload = {
64
+ schema_version: "panduck.doctor/v1",
65
+ status: ok ? "ok" : "issues",
66
+ checks,
67
+ };
68
+
69
+ if (shared.json || options.json === true) {
70
+ emitJson(payload);
71
+ } else if (ok) {
72
+ emitHuman("Panduck environment looks healthy");
73
+ for (const check of checks) {
74
+ emitHuman(` ok ${check.id}: ${check.message}`);
75
+ }
76
+ } else {
77
+ emitHuman("Panduck environment has issues");
78
+ for (const check of checks) {
79
+ emitHuman(` ${check.ok ? "ok" : "fail"} ${check.id}: ${check.message}`);
80
+ }
81
+ }
82
+
83
+ return ok ? 0 : 2;
84
+ }
@@ -1,50 +1,50 @@
1
- import type { Cli, ParsedOptions } from "@vmz/commander";
2
-
3
- import { createContext } from "../context.js";
4
- import { emitJson } from "../diagnostics.js";
5
- import { findFormat, type OperationKind } from "../format-registry.js";
6
- import { readSharedOptions, readString } from "../options.js";
7
-
8
- export function registerFormatsCommand(cli: Cli): void {
9
- cli.command("formats", "cli.cmd.formats")
10
- .option("--operation <kind>", "cli.opt.operation")
11
- .option("--json", "cli.opt.json")
12
- .action((options: ParsedOptions) => runFormats(options));
13
- }
14
-
15
- function runFormats(options: ParsedOptions): number {
16
- const shared = readSharedOptions(options);
17
- const ctx = createContext();
18
- const formatId = options._[0] ?? readString(options, "format");
19
- const operation = readString(options, "operation") as OperationKind | undefined;
20
- const selected = formatId ? findFormat(ctx.registry, formatId) : undefined;
21
- if (formatId && !selected) {
22
- console.error(`unknown format: ${formatId}`);
23
- return 2;
24
- }
25
-
26
- const records = selected ? [selected] : ctx.registry;
27
- const payload = records.map((record) => {
28
- if (operation === "read") {
29
- return { format: record.format, reader: record.reader, container: record.container, coverage: record.coverage };
30
- }
31
- if (operation === "write") {
32
- return { format: record.format, writer: record.writer, container: record.container, coverage: record.coverage };
33
- }
34
- return record;
35
- });
36
-
37
- if (shared.json || options.json === true) {
38
- emitJson({
39
- schema_version: "panduck.formats/v1",
40
- formats: payload,
41
- conversions: ctx.bindings?.supportedConversions?.() ?? [],
42
- });
43
- return 0;
44
- }
45
-
46
- for (const record of records) {
47
- console.log(`${record.format}\tread=${record.reader.state}\twrite=${record.writer.state}`);
48
- }
49
- return 0;
50
- }
1
+ import type { Cli, ParsedOptions } from "@vmz/commander";
2
+
3
+ import { createContext } from "../context.js";
4
+ import { emitJson } from "../diagnostics.js";
5
+ import { findFormat, type OperationKind } from "../format-registry.js";
6
+ import { readSharedOptions, readString } from "../options.js";
7
+
8
+ export function registerFormatsCommand(cli: Cli): void {
9
+ cli.command("formats", "cli.cmd.formats")
10
+ .option("--operation <kind>", "cli.opt.operation")
11
+ .option("--json", "cli.opt.json")
12
+ .action((options: ParsedOptions) => runFormats(options));
13
+ }
14
+
15
+ function runFormats(options: ParsedOptions): number {
16
+ const shared = readSharedOptions(options);
17
+ const ctx = createContext();
18
+ const formatId = options._[0] ?? readString(options, "format");
19
+ const operation = readString(options, "operation") as OperationKind | undefined;
20
+ const selected = formatId ? findFormat(ctx.registry, formatId) : undefined;
21
+ if (formatId && !selected) {
22
+ console.error(`unknown format: ${formatId}`);
23
+ return 2;
24
+ }
25
+
26
+ const records = selected ? [selected] : ctx.registry;
27
+ const payload = records.map((record) => {
28
+ if (operation === "read") {
29
+ return { format: record.format, reader: record.reader, container: record.container, coverage: record.coverage };
30
+ }
31
+ if (operation === "write") {
32
+ return { format: record.format, writer: record.writer, container: record.container, coverage: record.coverage };
33
+ }
34
+ return record;
35
+ });
36
+
37
+ if (shared.json || options.json === true) {
38
+ emitJson({
39
+ schema_version: "panduck.formats/v1",
40
+ formats: payload,
41
+ conversions: ctx.bindings?.supportedConversions?.() ?? [],
42
+ });
43
+ return 0;
44
+ }
45
+
46
+ for (const record of records) {
47
+ console.log(`${record.format}\tread=${record.reader.state}\twrite=${record.writer.state}`);
48
+ }
49
+ return 0;
50
+ }