@specglass/cli 0.0.4 → 0.0.6
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.js +60 -7
- package/dist/commands/check.d.ts +7 -0
- package/dist/commands/check.js +84 -0
- package/dist/commands/migrate.d.ts +16 -0
- package/dist/commands/migrate.js +172 -0
- package/dist/migration/converter.d.ts +51 -0
- package/dist/migration/converter.js +110 -0
- package/dist/migration/detector.d.ts +45 -0
- package/dist/migration/detector.js +196 -0
- package/dist/migration/planner.d.ts +55 -0
- package/dist/migration/planner.js +129 -0
- package/dist/migration/writer.d.ts +42 -0
- package/dist/migration/writer.js +150 -0
- package/dist/ui/check-results-display.d.ts +6 -0
- package/dist/ui/check-results-display.js +50 -0
- package/dist/ui/consent-prompt.d.ts +24 -0
- package/dist/ui/consent-prompt.js +40 -0
- package/dist/utils/astro-config-writer.js +4 -0
- package/dist/utils/context-builder.d.ts +9 -0
- package/dist/utils/context-builder.js +63 -0
- package/package.json +2 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Consent prompt component for the migration command.
|
|
4
|
+
*
|
|
5
|
+
* Warns the user that content will be sent to an external AI API
|
|
6
|
+
* and requires explicit consent before proceeding.
|
|
7
|
+
*/
|
|
8
|
+
import React from "react";
|
|
9
|
+
import { Box, Text, useInput } from "ink";
|
|
10
|
+
/**
|
|
11
|
+
* Displays the AI consent warning and waits for user input.
|
|
12
|
+
*
|
|
13
|
+
* Shows:
|
|
14
|
+
* - Warning about external API usage
|
|
15
|
+
* - Summary of what will be sent (file count)
|
|
16
|
+
* - Y/N prompt
|
|
17
|
+
*/
|
|
18
|
+
export function ConsentPrompt({ plan, autoConsent, onDecision, }) {
|
|
19
|
+
// Auto-consent via --yes flag
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
if (autoConsent) {
|
|
22
|
+
onDecision(true);
|
|
23
|
+
}
|
|
24
|
+
}, [autoConsent, onDecision]);
|
|
25
|
+
// Use Ink's built-in input handling (avoids raw stdin conflicts)
|
|
26
|
+
useInput((input, key) => {
|
|
27
|
+
if (autoConsent)
|
|
28
|
+
return;
|
|
29
|
+
if (input === "y" || input === "Y") {
|
|
30
|
+
onDecision(true);
|
|
31
|
+
}
|
|
32
|
+
else if (input === "n" || input === "N" || key.escape) {
|
|
33
|
+
onDecision(false);
|
|
34
|
+
}
|
|
35
|
+
}, { isActive: !autoConsent });
|
|
36
|
+
if (autoConsent) {
|
|
37
|
+
return (_jsx(Box, { flexDirection: "column", children: _jsx(Text, { color: "yellow", children: "\u26A1 Auto-consent enabled (--yes flag)" }) }));
|
|
38
|
+
}
|
|
39
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, children: [_jsxs(Box, { borderStyle: "round", borderColor: "yellow", flexDirection: "column", paddingX: 1, paddingY: 0, children: [_jsx(Text, { bold: true, color: "yellow", children: "\u26A0\uFE0F AI Content Conversion Notice" }), _jsx(Text, { children: " " }), _jsxs(Text, { children: ["This migration will send your documentation content to the", " ", _jsx(Text, { bold: true, children: "Claude AI API" }), " for semantic conversion."] }), _jsx(Text, { children: " " }), _jsxs(Text, { children: ["\u2022 ", _jsx(Text, { bold: true, children: plan.aiConversionCount }), " files will be sent for AI conversion"] }), _jsx(Text, { children: "\u2022 Content will be processed by an external API (Anthropic)" }), _jsxs(Text, { children: ["\u2022 You must have a valid ", _jsx(Text, { bold: true, children: "ANTHROPIC_API_KEY" }), " environment variable set"] })] }), _jsx(Text, { children: " " }), _jsxs(Text, { children: ["Do you want to proceed? (", _jsx(Text, { bold: true, color: "green", children: "Y" }), "/", _jsx(Text, { bold: true, color: "red", children: "N" }), ")"] })] }));
|
|
40
|
+
}
|
|
@@ -18,6 +18,7 @@ export async function writeAstroConfig(config, projectRoot) {
|
|
|
18
18
|
import { defineConfig } from "astro/config";
|
|
19
19
|
import mdx from "@astrojs/mdx";
|
|
20
20
|
import react from "@astrojs/react";
|
|
21
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
21
22
|
import { specglassIntegration } from "@specglass/core";
|
|
22
23
|
|
|
23
24
|
const specglassConfig = ${configJson};
|
|
@@ -25,6 +26,9 @@ const specglassConfig = ${configJson};
|
|
|
25
26
|
export default defineConfig({
|
|
26
27
|
outDir: ${JSON.stringify(outDir)},
|
|
27
28
|
integrations: [specglassIntegration({ config: specglassConfig }), mdx(), react()],
|
|
29
|
+
vite: {
|
|
30
|
+
plugins: [tailwindcss()],
|
|
31
|
+
},
|
|
28
32
|
});
|
|
29
33
|
`;
|
|
30
34
|
const absolutePath = join(specglassDir, "astro.config.mjs");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ValidatorContext, SpecglassConfig } from "@specglass/core";
|
|
2
|
+
/**
|
|
3
|
+
* Build a ValidatorContext from the loaded config and project root.
|
|
4
|
+
*
|
|
5
|
+
* @param config - Resolved Specglass config object
|
|
6
|
+
* @param projectRoot - Absolute path to the project root (usually `process.cwd()`)
|
|
7
|
+
* @returns A ready-to-use ValidatorContext for `runValidators`
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildValidatorContext(config: SpecglassConfig, projectRoot: string): Promise<ValidatorContext>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a ValidatorContext from the loaded Specglass config.
|
|
3
|
+
*
|
|
4
|
+
* Resolves the content directory, scans for known pages,
|
|
5
|
+
* and extracts OpenAPI spec paths — everything the composable
|
|
6
|
+
* validators need to run.
|
|
7
|
+
*/
|
|
8
|
+
import { readdir } from "node:fs/promises";
|
|
9
|
+
import { join, relative, resolve } from "node:path";
|
|
10
|
+
/**
|
|
11
|
+
* Recursively collect MDX/MD page slugs under `dir`.
|
|
12
|
+
* Slugs are relative paths without extension, e.g. "getting-started" or "api/overview".
|
|
13
|
+
*/
|
|
14
|
+
async function collectPageSlugs(dir, base) {
|
|
15
|
+
const slugs = [];
|
|
16
|
+
let entries;
|
|
17
|
+
try {
|
|
18
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Directory doesn't exist or is unreadable — no pages
|
|
22
|
+
return slugs;
|
|
23
|
+
}
|
|
24
|
+
for (const entry of entries) {
|
|
25
|
+
const fullPath = join(dir, entry.name);
|
|
26
|
+
if (entry.isDirectory()) {
|
|
27
|
+
const nested = await collectPageSlugs(fullPath, base);
|
|
28
|
+
slugs.push(...nested);
|
|
29
|
+
}
|
|
30
|
+
else if (entry.isFile() && /\.(mdx|md)$/i.test(entry.name)) {
|
|
31
|
+
const rel = relative(base, fullPath)
|
|
32
|
+
.replace(/\.(mdx|md)$/i, "")
|
|
33
|
+
.replace(/\\/g, "/"); // normalise Windows paths
|
|
34
|
+
slugs.push(rel);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return slugs;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build a ValidatorContext from the loaded config and project root.
|
|
41
|
+
*
|
|
42
|
+
* @param config - Resolved Specglass config object
|
|
43
|
+
* @param projectRoot - Absolute path to the project root (usually `process.cwd()`)
|
|
44
|
+
* @returns A ready-to-use ValidatorContext for `runValidators`
|
|
45
|
+
*/
|
|
46
|
+
export async function buildValidatorContext(config, projectRoot) {
|
|
47
|
+
const contentDir = resolve(projectRoot, "src", "content", "docs");
|
|
48
|
+
// Scan content directory for known page slugs
|
|
49
|
+
const knownPages = await collectPageSlugs(contentDir, contentDir);
|
|
50
|
+
// Extract spec paths from config
|
|
51
|
+
const specPaths = config.openapi?.specs?.map((s) => s.path) ?? [];
|
|
52
|
+
// Register dynamic routes generated by Specglass at build time.
|
|
53
|
+
// When OpenAPI specs are configured, specglass generates /api-reference/* routes.
|
|
54
|
+
if (specPaths.length > 0) {
|
|
55
|
+
knownPages.push("api-reference");
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
contentDir,
|
|
59
|
+
knownPages,
|
|
60
|
+
specPaths,
|
|
61
|
+
projectRoot,
|
|
62
|
+
};
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@specglass/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "CLI for Specglass documentation framework (dev, build commands)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"lint": "eslint src/"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@anthropic-ai/sdk": "^0.74.0",
|
|
37
38
|
"@inkjs/ui": "^2.0.0",
|
|
38
39
|
"@specglass/core": "*",
|
|
39
40
|
"ink": "^6.0.0",
|