@specglass/cli 0.0.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.
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +58 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/build.d.ts +6 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +86 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/dev.d.ts +7 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +81 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/ui/error-display.d.ts +7 -0
- package/dist/ui/error-display.d.ts.map +1 -0
- package/dist/ui/error-display.js +6 -0
- package/dist/ui/error-display.js.map +1 -0
- package/dist/utils/astro-config-writer.d.ts +12 -0
- package/dist/utils/astro-config-writer.d.ts.map +1 -0
- package/dist/utils/astro-config-writer.js +32 -0
- package/dist/utils/astro-config-writer.js.map +1 -0
- package/dist/utils/config-loader.d.ts +2 -0
- package/dist/utils/config-loader.d.ts.map +1 -0
- package/dist/utils/config-loader.js +3 -0
- package/dist/utils/config-loader.js.map +1 -0
- package/dist/utils/error-handler.d.ts +12 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +46 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/package.json +53 -0
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.tsx"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import meow from "meow";
|
|
4
|
+
import { render } from "ink";
|
|
5
|
+
import { SpecglassError } from "@specglass/core";
|
|
6
|
+
import { DevCommand } from "./commands/dev.js";
|
|
7
|
+
import { BuildCommand } from "./commands/build.js";
|
|
8
|
+
import { setupErrorHandlers, setupSigintHandler, renderErrorAndExit, EXIT_CODES } from "./utils/error-handler.js";
|
|
9
|
+
setupErrorHandlers();
|
|
10
|
+
setupSigintHandler();
|
|
11
|
+
const cli = meow(`
|
|
12
|
+
Usage
|
|
13
|
+
$ specglass <command>
|
|
14
|
+
|
|
15
|
+
Commands
|
|
16
|
+
dev Start the development server
|
|
17
|
+
build Build static site for production
|
|
18
|
+
|
|
19
|
+
Options
|
|
20
|
+
--port, -p Port for the dev server (default: 4321)
|
|
21
|
+
--config, -c Path to specglass.config.ts
|
|
22
|
+
--help Show this help message
|
|
23
|
+
--version Show version number
|
|
24
|
+
|
|
25
|
+
Examples
|
|
26
|
+
$ specglass dev
|
|
27
|
+
$ specglass dev --port 3000
|
|
28
|
+
$ specglass dev --config ./custom.config.ts
|
|
29
|
+
$ specglass build
|
|
30
|
+
$ specglass build --config ./custom.config.ts
|
|
31
|
+
`, {
|
|
32
|
+
importMeta: import.meta,
|
|
33
|
+
flags: {
|
|
34
|
+
port: {
|
|
35
|
+
type: "number",
|
|
36
|
+
shortFlag: "p",
|
|
37
|
+
default: 4321,
|
|
38
|
+
},
|
|
39
|
+
config: {
|
|
40
|
+
type: "string",
|
|
41
|
+
shortFlag: "c",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const [command] = cli.input;
|
|
46
|
+
if (!command || command === "help") {
|
|
47
|
+
cli.showHelp(0);
|
|
48
|
+
}
|
|
49
|
+
else if (command === "dev") {
|
|
50
|
+
render(_jsx(DevCommand, { port: cli.flags.port, configPath: cli.flags.config }));
|
|
51
|
+
}
|
|
52
|
+
else if (command === "build") {
|
|
53
|
+
render(_jsx(BuildCommand, { configPath: cli.flags.config }));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
renderErrorAndExit(new SpecglassError(`Unknown command: ${command}`, "UNKNOWN_COMMAND", undefined, undefined, "Available commands: dev, build. Run 'specglass --help' for usage."), EXIT_CODES.ERROR);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.tsx"],"names":[],"mappings":";;AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAElH,kBAAkB,EAAE,CAAC;AACrB,kBAAkB,EAAE,CAAC;AAErB,MAAM,GAAG,GAAG,IAAI,CACd;;;;;;;;;;;;;;;;;;;;CAoBD,EACC;IACE,UAAU,EAAE,MAAM,CAAC,IAAI;IACvB,KAAK,EAAE;QACL,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,GAAG;YACd,OAAO,EAAE,IAAI;SACd;QACD,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,GAAG;SACf;KACF;CACF,CACF,CAAC;AAEF,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC;AAE5B,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;IACnC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;KAAM,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;IAC7B,MAAM,CACJ,KAAC,UAAU,IAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,GAAI,CACnE,CAAC;AACJ,CAAC;KAAM,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;IAC/B,MAAM,CACJ,KAAC,YAAY,IAAC,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,GAAI,CAC/C,CAAC;AACJ,CAAC;KAAM,CAAC;IACN,kBAAkB,CAChB,IAAI,cAAc,CAChB,oBAAoB,OAAO,EAAE,EAC7B,iBAAiB,EACjB,SAAS,EACT,SAAS,EACT,mEAAmE,CACpE,EACD,UAAU,CAAC,KAAK,CACjB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.tsx"],"names":[],"mappings":"AAWA,UAAU,iBAAiB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,YAAY,CAAC,EAAE,UAAU,EAAE,EAAE,iBAAiB,2CA+H7D"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
import { Box, Text } from "ink";
|
|
4
|
+
import { Spinner } from "@inkjs/ui";
|
|
5
|
+
import { loadConfig, SpecglassError } from "@specglass/core";
|
|
6
|
+
import { writeAstroConfig } from "../utils/astro-config-writer.js";
|
|
7
|
+
import { ErrorDisplay } from "../ui/error-display.js";
|
|
8
|
+
import { isConfigError, EXIT_CODES } from "../utils/error-handler.js";
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
export function BuildCommand({ configPath }) {
|
|
11
|
+
const [status, setStatus] = useState("validating");
|
|
12
|
+
const [error, setError] = useState(null);
|
|
13
|
+
const [output, setOutput] = useState([]);
|
|
14
|
+
const [outDir, setOutDir] = useState("dist");
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
let child = null;
|
|
17
|
+
let aborted = false;
|
|
18
|
+
async function start() {
|
|
19
|
+
try {
|
|
20
|
+
// Phase 1: Load & validate config
|
|
21
|
+
const config = await loadConfig(configPath);
|
|
22
|
+
if (aborted)
|
|
23
|
+
return;
|
|
24
|
+
setStatus("building");
|
|
25
|
+
setOutDir(config.build?.outDir ?? "dist");
|
|
26
|
+
// Phase 2: Write Astro config bridge
|
|
27
|
+
const astroConfigPath = await writeAstroConfig(config, process.cwd());
|
|
28
|
+
if (aborted)
|
|
29
|
+
return;
|
|
30
|
+
// Phase 3: Spawn Astro build
|
|
31
|
+
child = spawn("npx", ["astro", "build", "--config", astroConfigPath], {
|
|
32
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
33
|
+
env: { ...process.env },
|
|
34
|
+
});
|
|
35
|
+
child.stdout?.on("data", (data) => {
|
|
36
|
+
const line = data.toString().trim();
|
|
37
|
+
if (line) {
|
|
38
|
+
setOutput((prev) => [...prev.slice(-20), line]);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
child.stderr?.on("data", (data) => {
|
|
42
|
+
const line = data.toString().trim();
|
|
43
|
+
if (line) {
|
|
44
|
+
setOutput((prev) => [...prev.slice(-20), line]);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
child.on("close", (code) => {
|
|
48
|
+
if (aborted)
|
|
49
|
+
return;
|
|
50
|
+
if (code === 0) {
|
|
51
|
+
setStatus("done");
|
|
52
|
+
setTimeout(() => process.exit(EXIT_CODES.SUCCESS), 100);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
setError(new SpecglassError(`Astro build exited with code ${code}`, "BUILD_FAILED", undefined, undefined, "Check the output above for details."));
|
|
56
|
+
setStatus("error");
|
|
57
|
+
setTimeout(() => process.exit(EXIT_CODES.ERROR), 100);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
if (aborted)
|
|
63
|
+
return;
|
|
64
|
+
const specglassErr = err instanceof SpecglassError
|
|
65
|
+
? err
|
|
66
|
+
: new SpecglassError(err instanceof Error ? err.message : String(err), "BUILD_UNEXPECTED_ERROR");
|
|
67
|
+
setError(specglassErr);
|
|
68
|
+
setStatus("error");
|
|
69
|
+
const exitCode = isConfigError(specglassErr) ? EXIT_CODES.CONFIG_ERROR : EXIT_CODES.ERROR;
|
|
70
|
+
setTimeout(() => process.exit(exitCode), 100);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
start();
|
|
74
|
+
return () => {
|
|
75
|
+
aborted = true;
|
|
76
|
+
if (child) {
|
|
77
|
+
child.kill("SIGTERM");
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}, [configPath]);
|
|
81
|
+
if (status === "error" && error) {
|
|
82
|
+
return (_jsx(Box, { flexDirection: "column", children: _jsx(ErrorDisplay, { error: error }) }));
|
|
83
|
+
}
|
|
84
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, children: [status === "validating" && (_jsx(Box, { children: _jsx(Spinner, { label: "Loading specglass config..." }) })), status === "building" && (_jsx(Box, { children: _jsx(Spinner, { label: "Building site..." }) })), status === "done" && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "green", bold: true, children: "Build complete" }), _jsxs(Text, { dimColor: true, children: ["Output written to ", outDir, "/"] })] })), output.length > 0 && (_jsx(Box, { flexDirection: "column", marginTop: 1, children: output.map((line, i) => (_jsx(Text, { dimColor: true, children: line }, i))) }))] }));
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AA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|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
import { Box, Text } from "ink";
|
|
4
|
+
import { Spinner } from "@inkjs/ui";
|
|
5
|
+
import { loadConfig, SpecglassError } from "@specglass/core";
|
|
6
|
+
import { writeAstroConfig } from "../utils/astro-config-writer.js";
|
|
7
|
+
import { ErrorDisplay } from "../ui/error-display.js";
|
|
8
|
+
import { isConfigError, EXIT_CODES } from "../utils/error-handler.js";
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
export function DevCommand({ port, configPath }) {
|
|
11
|
+
const [status, setStatus] = useState("validating");
|
|
12
|
+
const [error, setError] = useState(null);
|
|
13
|
+
const [output, setOutput] = useState([]);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
let child = null;
|
|
16
|
+
let aborted = false;
|
|
17
|
+
async function start() {
|
|
18
|
+
try {
|
|
19
|
+
// Phase 1: Load & validate config
|
|
20
|
+
const config = await loadConfig(configPath);
|
|
21
|
+
if (aborted)
|
|
22
|
+
return;
|
|
23
|
+
setStatus("starting");
|
|
24
|
+
// Phase 2: Write Astro config bridge
|
|
25
|
+
const astroConfigPath = await writeAstroConfig(config, process.cwd());
|
|
26
|
+
if (aborted)
|
|
27
|
+
return;
|
|
28
|
+
// Phase 3: Spawn Astro dev server
|
|
29
|
+
child = spawn("npx", ["astro", "dev", "--config", astroConfigPath, "--port", String(port)], {
|
|
30
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
31
|
+
env: { ...process.env },
|
|
32
|
+
});
|
|
33
|
+
child.stdout?.on("data", (data) => {
|
|
34
|
+
const line = data.toString().trim();
|
|
35
|
+
if (line) {
|
|
36
|
+
setOutput((prev) => [...prev.slice(-20), line]);
|
|
37
|
+
}
|
|
38
|
+
if (line.includes("localhost") || line.includes("Local")) {
|
|
39
|
+
setStatus("running");
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
child.stderr?.on("data", (data) => {
|
|
43
|
+
const line = data.toString().trim();
|
|
44
|
+
if (line) {
|
|
45
|
+
setOutput((prev) => [...prev.slice(-20), line]);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
child.on("close", (code) => {
|
|
49
|
+
if (!aborted && code !== 0 && code !== null) {
|
|
50
|
+
setError(new SpecglassError(`Astro dev server exited with code ${code}`, "DEV_SERVER_ERROR", undefined, undefined, "Check the output above for details."));
|
|
51
|
+
setStatus("error");
|
|
52
|
+
setTimeout(() => process.exit(EXIT_CODES.ERROR), 100);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
if (aborted)
|
|
58
|
+
return;
|
|
59
|
+
const specglassErr = err instanceof SpecglassError
|
|
60
|
+
? err
|
|
61
|
+
: new SpecglassError(err instanceof Error ? err.message : String(err), "DEV_UNEXPECTED_ERROR");
|
|
62
|
+
setError(specglassErr);
|
|
63
|
+
setStatus("error");
|
|
64
|
+
const exitCode = isConfigError(specglassErr) ? EXIT_CODES.CONFIG_ERROR : EXIT_CODES.ERROR;
|
|
65
|
+
setTimeout(() => process.exit(exitCode), 100);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
start();
|
|
69
|
+
return () => {
|
|
70
|
+
aborted = true;
|
|
71
|
+
if (child) {
|
|
72
|
+
child.kill("SIGTERM");
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}, [configPath, port]);
|
|
76
|
+
if (status === "error" && error) {
|
|
77
|
+
return (_jsx(Box, { flexDirection: "column", children: _jsx(ErrorDisplay, { error: error }) }));
|
|
78
|
+
}
|
|
79
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, children: [status === "validating" && (_jsx(Box, { children: _jsx(Spinner, { label: "Loading specglass config..." }) })), status === "starting" && (_jsx(Box, { children: _jsx(Spinner, { label: "Starting Astro dev server..." }) })), status === "running" && (_jsx(Box, { children: _jsx(Text, { color: "green", bold: true, children: "specglass dev server running" }) })), output.length > 0 && (_jsx(Box, { flexDirection: "column", marginTop: 1, children: output.map((line, i) => (_jsx(Text, { dimColor: true, children: line }, i))) }))] }));
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/commands/dev.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAS9D,MAAM,UAAU,UAAU,CAAC,EAAE,IAAI,EAAE,UAAU,EAAmB;IAC9D,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAS,YAAY,CAAC,CAAC;IAC3D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAwB,IAAI,CAAC,CAAC;IAChE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAW,EAAE,CAAC,CAAC;IAEnD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,KAAK,GAAwB,IAAI,CAAC;QACtC,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,KAAK,UAAU,KAAK;YAClB,IAAI,CAAC;gBACH,kCAAkC;gBAClC,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC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sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B,4CAA4C;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,YAAY;AACZ,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SpecglassError } from "@specglass/core";
|
|
2
|
+
interface ErrorDisplayProps {
|
|
3
|
+
error: SpecglassError;
|
|
4
|
+
}
|
|
5
|
+
export declare function ErrorDisplay({ error }: ErrorDisplayProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=error-display.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-display.d.ts","sourceRoot":"","sources":["../../src/ui/error-display.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,UAAU,iBAAiB;IACzB,KAAK,EAAE,cAAc,CAAC;CACvB;AAED,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,EAAE,iBAAiB,2CA0BxD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
export function ErrorDisplay({ error }) {
|
|
4
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, children: [_jsx(Box, { children: _jsxs(Text, { color: "red", bold: true, children: ["Error [", error.code, "]"] }) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { children: error.message }) }), error.filePath && (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { color: "gray", children: ["File: ", error.filePath, error.line ? `:${error.line}` : ""] }) })), error.hint && (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { color: "yellow", children: ["Hint: ", error.hint] }) }))] }));
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=error-display.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-display.js","sourceRoot":"","sources":["../../src/ui/error-display.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAOhC,MAAM,UAAU,YAAY,CAAC,EAAE,KAAK,EAAqB;IACvD,OAAO,CACL,MAAC,GAAG,IAAC,aAAa,EAAC,QAAQ,EAAC,QAAQ,EAAE,CAAC,aACrC,KAAC,GAAG,cACF,MAAC,IAAI,IAAC,KAAK,EAAC,KAAK,EAAC,IAAI,8BACZ,KAAK,CAAC,IAAI,SACb,GACH,EACN,KAAC,GAAG,IAAC,SAAS,EAAE,CAAC,YACf,KAAC,IAAI,cAAE,KAAK,CAAC,OAAO,GAAQ,GACxB,EACL,KAAK,CAAC,QAAQ,IAAI,CACjB,KAAC,GAAG,IAAC,SAAS,EAAE,CAAC,YACf,MAAC,IAAI,IAAC,KAAK,EAAC,MAAM,uBACT,KAAK,CAAC,QAAQ,EACpB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAC9B,GACH,CACP,EACA,KAAK,CAAC,IAAI,IAAI,CACb,KAAC,GAAG,IAAC,SAAS,EAAE,CAAC,YACf,MAAC,IAAI,IAAC,KAAK,EAAC,QAAQ,uBAAQ,KAAK,CAAC,IAAI,IAAQ,GAC1C,CACP,IACG,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SpecglassConfig } from "@specglass/core";
|
|
2
|
+
/**
|
|
3
|
+
* Generates an Astro config file that wires up the specglass integration.
|
|
4
|
+
* Writes to `.specglass/astro.config.mjs` in the project root so Astro
|
|
5
|
+
* can be spawned with `--config .specglass/astro.config.mjs`.
|
|
6
|
+
*
|
|
7
|
+
* @param config - The fully resolved SpecglassConfig
|
|
8
|
+
* @param projectRoot - Absolute path to the project root
|
|
9
|
+
* @returns Relative path to the generated config file (Astro requires relative paths for --config)
|
|
10
|
+
*/
|
|
11
|
+
export declare function writeAstroConfig(config: SpecglassConfig, projectRoot: string): Promise<string>;
|
|
12
|
+
//# sourceMappingURL=astro-config-writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astro-config-writer.d.ts","sourceRoot":"","sources":["../../src/utils/astro-config-writer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqBpG"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join, relative } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Generates an Astro config file that wires up the specglass integration.
|
|
5
|
+
* Writes to `.specglass/astro.config.mjs` in the project root so Astro
|
|
6
|
+
* can be spawned with `--config .specglass/astro.config.mjs`.
|
|
7
|
+
*
|
|
8
|
+
* @param config - The fully resolved SpecglassConfig
|
|
9
|
+
* @param projectRoot - Absolute path to the project root
|
|
10
|
+
* @returns Relative path to the generated config file (Astro requires relative paths for --config)
|
|
11
|
+
*/
|
|
12
|
+
export async function writeAstroConfig(config, projectRoot) {
|
|
13
|
+
const specglassDir = join(projectRoot, ".specglass");
|
|
14
|
+
await mkdir(specglassDir, { recursive: true });
|
|
15
|
+
const outDir = config.build?.outDir ?? "dist";
|
|
16
|
+
const configJson = JSON.stringify(config);
|
|
17
|
+
const configContent = `// Auto-generated by specglass — do not edit
|
|
18
|
+
import { defineConfig } from "astro/config";
|
|
19
|
+
import { specglassIntegration } from "@specglass/core";
|
|
20
|
+
|
|
21
|
+
const specglassConfig = ${configJson};
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
outDir: ${JSON.stringify(outDir)},
|
|
25
|
+
integrations: [specglassIntegration({ config: specglassConfig })],
|
|
26
|
+
});
|
|
27
|
+
`;
|
|
28
|
+
const absolutePath = join(specglassDir, "astro.config.mjs");
|
|
29
|
+
await writeFile(absolutePath, configContent, "utf-8");
|
|
30
|
+
return relative(projectRoot, absolutePath);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=astro-config-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astro-config-writer.js","sourceRoot":"","sources":["../../src/utils/astro-config-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAG3C;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAuB,EAAE,WAAmB;IACjF,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IACrD,MAAM,KAAK,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE/C,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,MAAM,IAAI,MAAM,CAAC;IAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,aAAa,GAAG;;;;0BAIE,UAAU;;;YAGxB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;;;CAGjC,CAAC;IAEA,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;IAC5D,MAAM,SAAS,CAAC,YAAY,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IACtD,OAAO,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/utils/config-loader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../../src/utils/config-loader.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SpecglassError } from "@specglass/core";
|
|
2
|
+
export declare const EXIT_CODES: {
|
|
3
|
+
readonly SUCCESS: 0;
|
|
4
|
+
readonly ERROR: 1;
|
|
5
|
+
readonly CONFIG_ERROR: 2;
|
|
6
|
+
readonly SIGINT: 130;
|
|
7
|
+
};
|
|
8
|
+
export declare function isConfigError(error: SpecglassError): boolean;
|
|
9
|
+
export declare function renderErrorAndExit(error: SpecglassError, exitCode: number): void;
|
|
10
|
+
export declare function setupErrorHandlers(): void;
|
|
11
|
+
export declare function setupSigintHandler(): void;
|
|
12
|
+
//# sourceMappingURL=error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/utils/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,eAAO,MAAM,UAAU;;;;;CAKb,CAAC;AAQX,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAE5D;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAUhF;AAED,wBAAgB,kBAAkB,IAAI,IAAI,CAsBzC;AAED,wBAAgB,kBAAkB,IAAI,IAAI,CAIzC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SpecglassError } from "@specglass/core";
|
|
2
|
+
export const EXIT_CODES = {
|
|
3
|
+
SUCCESS: 0,
|
|
4
|
+
ERROR: 1,
|
|
5
|
+
CONFIG_ERROR: 2,
|
|
6
|
+
SIGINT: 130,
|
|
7
|
+
};
|
|
8
|
+
const CONFIG_ERROR_CODES = new Set([
|
|
9
|
+
"CONFIG_NOT_FOUND",
|
|
10
|
+
"CONFIG_LOAD_ERROR",
|
|
11
|
+
"CONFIG_INVALID",
|
|
12
|
+
]);
|
|
13
|
+
export function isConfigError(error) {
|
|
14
|
+
return CONFIG_ERROR_CODES.has(error.code);
|
|
15
|
+
}
|
|
16
|
+
export function renderErrorAndExit(error, exitCode) {
|
|
17
|
+
let output = `Error [${error.code}]: ${error.message}`;
|
|
18
|
+
if (error.filePath) {
|
|
19
|
+
output += `\nFile: ${error.filePath}${error.line ? `:${error.line}` : ""}`;
|
|
20
|
+
}
|
|
21
|
+
if (error.hint) {
|
|
22
|
+
output += `\nHint: ${error.hint}`;
|
|
23
|
+
}
|
|
24
|
+
process.stderr.write(output + "\n");
|
|
25
|
+
process.exit(exitCode);
|
|
26
|
+
}
|
|
27
|
+
export function setupErrorHandlers() {
|
|
28
|
+
process.on("uncaughtException", (err) => {
|
|
29
|
+
const error = err instanceof SpecglassError
|
|
30
|
+
? err
|
|
31
|
+
: new SpecglassError(err instanceof Error ? err.message : String(err), "UNHANDLED_ERROR");
|
|
32
|
+
renderErrorAndExit(error, EXIT_CODES.ERROR);
|
|
33
|
+
});
|
|
34
|
+
process.on("unhandledRejection", (reason) => {
|
|
35
|
+
const error = reason instanceof SpecglassError
|
|
36
|
+
? reason
|
|
37
|
+
: new SpecglassError(reason instanceof Error ? reason.message : String(reason), "UNHANDLED_ERROR");
|
|
38
|
+
renderErrorAndExit(error, EXIT_CODES.ERROR);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export function setupSigintHandler() {
|
|
42
|
+
process.on("SIGINT", () => {
|
|
43
|
+
process.exit(EXIT_CODES.SIGINT);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/utils/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,CAAC;IACR,YAAY,EAAE,CAAC;IACf,MAAM,EAAE,GAAG;CACH,CAAC;AAEX,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,kBAAkB;IAClB,mBAAmB;IACnB,gBAAgB;CACjB,CAAC,CAAC;AAEH,MAAM,UAAU,aAAa,CAAC,KAAqB;IACjD,OAAO,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAqB,EAAE,QAAgB;IACxE,IAAI,MAAM,GAAG,UAAU,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;IACvD,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,MAAM,IAAI,WAAW,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAC7E,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,MAAM,IAAI,WAAW,KAAK,CAAC,IAAI,EAAE,CAAC;IACpC,CAAC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LI for Specglass documentation framework (dev, build commands)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/Not-Diamond/ndocs.git",
|
|
10
|
+
"directory": "packages/cli"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/Not-Diamond/ndocs#readme",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"specglass": "./dist/cli.js"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"lint": "eslint src/"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@inkjs/ui": "^2.0.0",
|
|
38
|
+
"@specglass/core": "*",
|
|
39
|
+
"ink": "^6.0.0",
|
|
40
|
+
"meow": "^13.0.0",
|
|
41
|
+
"react": "^19.0.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"astro": "^5.17"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/react": "^19.0.0",
|
|
48
|
+
"astro": "^5.17",
|
|
49
|
+
"ink-testing-library": "^4.0.0",
|
|
50
|
+
"typescript": "^5.5",
|
|
51
|
+
"vitest": "^3.0"
|
|
52
|
+
}
|
|
53
|
+
}
|