@miclivs/cadcli 0.1.2 → 0.2.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.
- package/README.md +22 -13
- package/dist/commands/edit.d.ts +42 -2
- package/dist/commands/edit.js +281 -7
- package/dist/commands/json.js +0 -1
- package/dist/commands/shared.d.ts +0 -1
- package/dist/commands/shared.js +0 -1
- package/dist/commands/svg.js +0 -1
- package/dist/commands/thumbnail.js +0 -1
- package/dist/commands/view.d.ts +0 -1
- package/dist/commands/view.js +5 -7
- package/dist/core/acad-edit.d.ts +142 -0
- package/dist/core/acad-edit.js +234 -0
- package/dist/core/acad-view.d.ts +6 -0
- package/dist/core/acad-view.js +22 -0
- package/dist/core/acad.d.ts +11 -0
- package/dist/core/acad.js +82 -0
- package/dist/core/adapter.d.ts +0 -6
- package/dist/core/adapter.js +0 -13
- package/dist/core/drawing.d.ts +0 -1
- package/dist/index.d.ts +2 -1
- package/dist/main.js +82 -7
- package/dist/sdk.d.ts +5 -7
- package/dist/sdk.js +6 -6
- package/package.json +1 -2
- package/skills/cadcli/SKILL.md +21 -4
- package/dist/core/libredwg.d.ts +0 -37
- package/dist/core/libredwg.js +0 -86
package/dist/core/libredwg.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export type LibreDwgToolName = "dwgread" | "dwgfilter";
|
|
2
|
-
export interface LibreDwgEditResult {
|
|
3
|
-
input: string;
|
|
4
|
-
output: string;
|
|
5
|
-
expression: string;
|
|
6
|
-
backend: "LibreDWG";
|
|
7
|
-
tool: "dwgfilter";
|
|
8
|
-
stderr: string;
|
|
9
|
-
}
|
|
10
|
-
export interface LibreDwgViewResult {
|
|
11
|
-
input: string;
|
|
12
|
-
output?: string;
|
|
13
|
-
svg: string;
|
|
14
|
-
backend: "LibreDWG";
|
|
15
|
-
tool: "dwgread";
|
|
16
|
-
stderr: string;
|
|
17
|
-
}
|
|
18
|
-
export interface LibreDwgJsonResult {
|
|
19
|
-
input: string;
|
|
20
|
-
json: unknown;
|
|
21
|
-
backend: "LibreDWG";
|
|
22
|
-
tool: "dwgread";
|
|
23
|
-
stderr: string;
|
|
24
|
-
}
|
|
25
|
-
export declare function readJsonWithLibreDwg(file: string, opts?: {
|
|
26
|
-
toolDir?: string;
|
|
27
|
-
}): LibreDwgJsonResult;
|
|
28
|
-
export declare function renderSvgWithLibreDwg(file: string, opts?: {
|
|
29
|
-
toolDir?: string;
|
|
30
|
-
}): LibreDwgViewResult;
|
|
31
|
-
export declare function editWithLibreDwgFilter(opts: {
|
|
32
|
-
input: string;
|
|
33
|
-
output: string;
|
|
34
|
-
expression: string;
|
|
35
|
-
overwrite?: boolean;
|
|
36
|
-
toolDir?: string;
|
|
37
|
-
}): LibreDwgEditResult;
|
package/dist/core/libredwg.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { copyFileSync, existsSync } from "node:fs";
|
|
3
|
-
import { basename, delimiter, join } from "node:path";
|
|
4
|
-
import { EXIT_ERROR, EXIT_UNAVAILABLE, EXIT_USER_ERROR, } from "../utils/exit-codes.js";
|
|
5
|
-
import { DwgCliError } from "./errors.js";
|
|
6
|
-
const WINDOWS_EXTENSIONS = [".exe", ".cmd", ".bat", ".com"];
|
|
7
|
-
function candidateNames(tool) {
|
|
8
|
-
return [tool, ...WINDOWS_EXTENSIONS.map((ext) => `${tool}${ext}`)];
|
|
9
|
-
}
|
|
10
|
-
function findTool(tool, toolDir) {
|
|
11
|
-
const dirs = toolDir ? [toolDir] : (process.env.PATH ?? "").split(delimiter);
|
|
12
|
-
for (const dir of dirs.filter(Boolean)) {
|
|
13
|
-
for (const name of candidateNames(tool)) {
|
|
14
|
-
const candidate = join(dir, name);
|
|
15
|
-
if (existsSync(candidate))
|
|
16
|
-
return candidate;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
function requireTool(tool, toolDir) {
|
|
22
|
-
const path = findTool(tool, toolDir);
|
|
23
|
-
if (path)
|
|
24
|
-
return path;
|
|
25
|
-
throw new DwgCliError(`LibreDWG tool not found: ${tool}. Install LibreDWG and make sure ${tool} is on PATH.`, "LIBREDWG_TOOL_NOT_FOUND", EXIT_UNAVAILABLE);
|
|
26
|
-
}
|
|
27
|
-
function preview(value) {
|
|
28
|
-
const trimmed = value.trim();
|
|
29
|
-
if (trimmed.length <= 500)
|
|
30
|
-
return trimmed;
|
|
31
|
-
return `${trimmed.slice(0, 500)}…`;
|
|
32
|
-
}
|
|
33
|
-
function runLibreDwgTool(tool, args, toolDir) {
|
|
34
|
-
const path = requireTool(tool, toolDir);
|
|
35
|
-
const result = spawnSync(path, args, { encoding: "utf-8" });
|
|
36
|
-
if (result.error) {
|
|
37
|
-
throw new DwgCliError(`Could not run ${tool}: ${result.error.message}`, "LIBREDWG_RUN_FAILED", EXIT_ERROR);
|
|
38
|
-
}
|
|
39
|
-
if (result.status !== 0) {
|
|
40
|
-
const details = preview(result.stderr || result.stdout);
|
|
41
|
-
throw new DwgCliError(`${tool} failed for ${basename(args.at(-1) ?? "input")}${details ? `: ${details}` : ""}`, "LIBREDWG_RUN_FAILED", EXIT_USER_ERROR);
|
|
42
|
-
}
|
|
43
|
-
return { stdout: result.stdout, stderr: result.stderr };
|
|
44
|
-
}
|
|
45
|
-
export function readJsonWithLibreDwg(file, opts = {}) {
|
|
46
|
-
const result = runLibreDwgTool("dwgread", ["-O", "JSON", file], opts.toolDir);
|
|
47
|
-
try {
|
|
48
|
-
return {
|
|
49
|
-
input: file,
|
|
50
|
-
json: JSON.parse(result.stdout),
|
|
51
|
-
backend: "LibreDWG",
|
|
52
|
-
tool: "dwgread",
|
|
53
|
-
stderr: result.stderr,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
const details = preview(result.stdout);
|
|
58
|
-
throw new DwgCliError(`dwgread produced invalid JSON for ${basename(file)}: ${error.message}${details ? `; stdout: ${details}` : ""}`, "LIBREDWG_INVALID_JSON", EXIT_USER_ERROR);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
export function renderSvgWithLibreDwg(file, opts = {}) {
|
|
62
|
-
const result = runLibreDwgTool("dwgread", ["-O", "SVG", file], opts.toolDir);
|
|
63
|
-
return {
|
|
64
|
-
input: file,
|
|
65
|
-
svg: result.stdout,
|
|
66
|
-
backend: "LibreDWG",
|
|
67
|
-
tool: "dwgread",
|
|
68
|
-
stderr: result.stderr,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
export function editWithLibreDwgFilter(opts) {
|
|
72
|
-
if (opts.input === opts.output && !opts.overwrite) {
|
|
73
|
-
throw new DwgCliError("Refusing to edit in place without --overwrite. Provide --output or pass --overwrite.", "EDIT_REQUIRES_OUTPUT_OR_OVERWRITE", EXIT_USER_ERROR);
|
|
74
|
-
}
|
|
75
|
-
if (opts.input !== opts.output)
|
|
76
|
-
copyFileSync(opts.input, opts.output);
|
|
77
|
-
const result = runLibreDwgTool("dwgfilter", ["-i", opts.expression, opts.output], opts.toolDir);
|
|
78
|
-
return {
|
|
79
|
-
input: opts.input,
|
|
80
|
-
output: opts.output,
|
|
81
|
-
expression: opts.expression,
|
|
82
|
-
backend: "LibreDWG",
|
|
83
|
-
tool: "dwgfilter",
|
|
84
|
-
stderr: result.stderr,
|
|
85
|
-
};
|
|
86
|
-
}
|