@clarify-labs/cli 0.6.4 → 0.6.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/output/cli/commands/check.d.ts +6 -0
- package/output/cli.cjs +152 -3
- package/output/cli.cjs.map +1 -1
- package/output/cli.js +153 -4
- package/output/cli.js.map +1 -1
- package/output/core/builtin.d.ts +5 -0
- package/output/core/config-schema.d.ts +167 -32
- package/output/core/options.d.ts +1 -0
- package/output/core/site.d.ts +17 -0
- package/output/core/ssg.d.ts +3 -1
- package/output/core/theme.d.ts +5 -3
- package/output/core/virtual-modules.d.ts +7 -2
- package/output/index.cjs +1 -1
- package/output/index.js +1 -1
- package/output/parsers/mdx.d.ts +1 -1
- package/output/parsers/routes.d.ts +2 -0
- package/output/{plugin-DChFdTyI.js → plugin-DC2f5YAH.js} +655 -403
- package/output/plugin-DC2f5YAH.js.map +1 -0
- package/output/{plugin--jQ6D6O4.cjs → plugin-GTN_SQ7d.cjs} +656 -398
- package/output/plugin-GTN_SQ7d.cjs.map +1 -0
- package/output/plugins/openapi/parser.d.ts +1 -1
- package/output/plugins/openapi/virtual-modules.d.ts +2 -2
- package/output/plugins/seo/artifacts.d.ts +4 -0
- package/output/plugins/seo/index.d.ts +2 -0
- package/output/plugins/source-links/index.d.ts +2 -0
- package/output/plugins/source-links/source-links.d.ts +3 -0
- package/output/types.d.ts +40 -10
- package/package.json +3 -3
- package/output/plugin--jQ6D6O4.cjs.map +0 -1
- package/output/plugin-DChFdTyI.js.map +0 -1
package/output/cli.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_plugin = require("./plugin
|
|
2
|
+
const require_plugin = require("./plugin-GTN_SQ7d.cjs");
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
|
+
let node_fs_promises = require("node:fs/promises");
|
|
5
6
|
let node_url = require("node:url");
|
|
6
7
|
let vite = require("vite");
|
|
7
8
|
let node_module = require("node:module");
|
|
8
9
|
let cac = require("cac");
|
|
9
|
-
let node_fs_promises = require("node:fs/promises");
|
|
10
10
|
let _clarify_labs_templates = require("@clarify-labs/templates");
|
|
11
11
|
let node_child_process = require("node:child_process");
|
|
12
12
|
//#region source/core/log.ts
|
|
@@ -207,6 +207,152 @@ async function runBuild(options) {
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
//#endregion
|
|
210
|
+
//#region source/cli/commands/check.ts
|
|
211
|
+
var LOCAL_LINK_PATTERN = /(?<!!)(?:\[[^\]]*\]\(([^)\s]+)(?:\s+"[^"]*")?\)|<a\s+[^>]*href=["']([^"']+)["'])/gi;
|
|
212
|
+
var ROUTE_EXTENSIONS = new Set([".md", ".mdx"]);
|
|
213
|
+
var IGNORED_SCHEMES = /^[a-z][a-z0-9+.-]*:/i;
|
|
214
|
+
function addDiagnostic(result, diagnostic) {
|
|
215
|
+
if (diagnostic.level === "error") result.errors.push(diagnostic);
|
|
216
|
+
else result.warnings.push(diagnostic);
|
|
217
|
+
}
|
|
218
|
+
function normalizeRoutePath(path) {
|
|
219
|
+
const [withoutHash] = path.split("#");
|
|
220
|
+
const clean = withoutHash.replace(/\/index$/, "") || "/";
|
|
221
|
+
return clean.startsWith("/") ? clean : `/${clean}`;
|
|
222
|
+
}
|
|
223
|
+
function routePathCandidates(href, route) {
|
|
224
|
+
const [withoutHashOrQuery] = href.split(/[?#]/);
|
|
225
|
+
if (!withoutHashOrQuery || withoutHashOrQuery.startsWith("#")) return [];
|
|
226
|
+
if (withoutHashOrQuery.startsWith("/")) return [normalizeRoutePath(withoutHashOrQuery)];
|
|
227
|
+
const joined = (0, node_path.normalize)((0, node_path.join)((0, node_path.dirname)(route.path), withoutHashOrQuery)).replaceAll("\\", "/");
|
|
228
|
+
const extension = (0, node_path.extname)(joined);
|
|
229
|
+
return [normalizeRoutePath(ROUTE_EXTENSIONS.has(extension) ? joined.slice(0, -extension.length) : joined)];
|
|
230
|
+
}
|
|
231
|
+
async function pathExists(filePath) {
|
|
232
|
+
try {
|
|
233
|
+
await (0, node_fs_promises.stat)(filePath);
|
|
234
|
+
return true;
|
|
235
|
+
} catch {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function isLocalHref(href) {
|
|
240
|
+
return Boolean(href) && !href.startsWith("#") && !href.startsWith("//") && !IGNORED_SCHEMES.test(href);
|
|
241
|
+
}
|
|
242
|
+
async function resolveLocalFileLink(href, route, contentRoot) {
|
|
243
|
+
const [withoutHashOrQuery] = href.split(/[?#]/);
|
|
244
|
+
if (!withoutHashOrQuery || withoutHashOrQuery.startsWith("/")) return false;
|
|
245
|
+
const target = (0, node_path.resolve)((0, node_path.dirname)(route.filePath), withoutHashOrQuery);
|
|
246
|
+
const relativeTarget = (0, node_path.relative)(contentRoot, target);
|
|
247
|
+
if (relativeTarget.startsWith("..") || (0, node_path.isAbsolute)(relativeTarget)) return false;
|
|
248
|
+
if (await pathExists(target)) return true;
|
|
249
|
+
if (!(0, node_path.extname)(target)) return pathExists(`${target}.md`) || pathExists(`${target}.mdx`) || pathExists((0, node_path.join)(target, "index.md")) || pathExists((0, node_path.join)(target, "index.mdx"));
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
async function checkContentDirectory(contentRoot, result) {
|
|
253
|
+
try {
|
|
254
|
+
if (!(await (0, node_fs_promises.lstat)(contentRoot)).isDirectory()) addDiagnostic(result, {
|
|
255
|
+
level: "error",
|
|
256
|
+
code: "content-not-directory",
|
|
257
|
+
message: `Content path is not a directory: ${contentRoot}`,
|
|
258
|
+
filePath: contentRoot
|
|
259
|
+
});
|
|
260
|
+
} catch {
|
|
261
|
+
addDiagnostic(result, {
|
|
262
|
+
level: "error",
|
|
263
|
+
code: "content-missing",
|
|
264
|
+
message: `Content directory does not exist: ${contentRoot}`,
|
|
265
|
+
filePath: contentRoot
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function checkDuplicateRoutes(routes, result) {
|
|
270
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
271
|
+
for (const route of routes) {
|
|
272
|
+
const key = `${route.locale ?? ""}:${route.path}`;
|
|
273
|
+
byPath.set(key, [...byPath.get(key) ?? [], route]);
|
|
274
|
+
}
|
|
275
|
+
for (const duplicated of byPath.values()) {
|
|
276
|
+
if (duplicated.length < 2) continue;
|
|
277
|
+
for (const route of duplicated) addDiagnostic(result, {
|
|
278
|
+
level: "error",
|
|
279
|
+
code: "duplicate-route",
|
|
280
|
+
message: `Route "${route.path}" is defined by multiple files: ${duplicated.map((route) => (0, node_path.relative)(process.cwd(), route.filePath)).join(", ")}`,
|
|
281
|
+
filePath: route.filePath,
|
|
282
|
+
routePath: route.path
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function checkFallbackRoutes(routes, result) {
|
|
287
|
+
for (const route of routes) {
|
|
288
|
+
if (!route.isFallback) continue;
|
|
289
|
+
addDiagnostic(result, {
|
|
290
|
+
level: "warning",
|
|
291
|
+
code: "i18n-fallback-route",
|
|
292
|
+
message: `Route "${route.path}" falls back to ${route.locale ?? "default"} content from ${(0, node_path.relative)(process.cwd(), route.filePath)}`,
|
|
293
|
+
filePath: route.filePath,
|
|
294
|
+
routePath: route.path
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async function checkLocalLinks(routes, contentRoot, result) {
|
|
299
|
+
const routePaths = new Set(routes.map((route) => route.path));
|
|
300
|
+
for (const route of routes) {
|
|
301
|
+
if (route.kind !== "mdx" || !route.content) continue;
|
|
302
|
+
for (const match of route.content.matchAll(LOCAL_LINK_PATTERN)) {
|
|
303
|
+
const href = match[1] ?? match[2];
|
|
304
|
+
if (!href || !isLocalHref(href)) continue;
|
|
305
|
+
if (routePathCandidates(href, route).some((candidate) => routePaths.has(candidate))) continue;
|
|
306
|
+
if (await resolveLocalFileLink(href, route, contentRoot)) continue;
|
|
307
|
+
addDiagnostic(result, {
|
|
308
|
+
level: "error",
|
|
309
|
+
code: "broken-link",
|
|
310
|
+
message: `Broken local link "${href}" in route "${route.path}"`,
|
|
311
|
+
filePath: route.filePath,
|
|
312
|
+
routePath: route.path
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function printTextResult(result, strict) {
|
|
318
|
+
const diagnostics = [...result.errors, ...result.warnings];
|
|
319
|
+
if (diagnostics.length === 0) {
|
|
320
|
+
console.log("✓ Clarify check passed");
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
for (const diagnostic of diagnostics) {
|
|
324
|
+
const location = diagnostic.filePath ? ` ${(0, node_path.relative)(process.cwd(), diagnostic.filePath)}` : "";
|
|
325
|
+
const route = diagnostic.routePath ? ` (${diagnostic.routePath})` : "";
|
|
326
|
+
console.log(`${diagnostic.level.toUpperCase()} ${diagnostic.code}${location}${route}`);
|
|
327
|
+
console.log(` ${diagnostic.message}`);
|
|
328
|
+
}
|
|
329
|
+
const warningExit = strict && result.warnings.length > 0;
|
|
330
|
+
console.log(`\n${result.errors.length} error(s), ${result.warnings.length} warning(s)${warningExit ? " (--strict treats warnings as failures)" : ""}`);
|
|
331
|
+
}
|
|
332
|
+
async function runCheck(options = {}) {
|
|
333
|
+
const root = (0, node_path.resolve)(options.root ?? process.cwd());
|
|
334
|
+
const site = await require_plugin.resolveClarifySite({
|
|
335
|
+
...(0, node_fs.existsSync)(root) ? await require_plugin.loadClarifyConfig(root, {
|
|
336
|
+
command: "build",
|
|
337
|
+
mode: "production"
|
|
338
|
+
}) : {},
|
|
339
|
+
projectRoot: root,
|
|
340
|
+
rootDirectory: options.content,
|
|
341
|
+
outputDirectory: options.output
|
|
342
|
+
}, { includeHtmlShellPlugin: false });
|
|
343
|
+
const result = {
|
|
344
|
+
errors: [],
|
|
345
|
+
warnings: []
|
|
346
|
+
};
|
|
347
|
+
await checkContentDirectory(site.contentRoot, result);
|
|
348
|
+
checkDuplicateRoutes(site.routes, result);
|
|
349
|
+
checkFallbackRoutes(site.routes, result);
|
|
350
|
+
await checkLocalLinks(site.routes, site.contentRoot, result);
|
|
351
|
+
if (options.format === "json") console.log(JSON.stringify(result, null, 2));
|
|
352
|
+
else printTextResult(result, Boolean(options.strict));
|
|
353
|
+
if (result.errors.length > 0 || options.strict && result.warnings.length > 0) process.exitCode = 1;
|
|
354
|
+
}
|
|
355
|
+
//#endregion
|
|
210
356
|
//#region source/cli/commands/dev.ts
|
|
211
357
|
async function runDev(options) {
|
|
212
358
|
const server = await (0, vite.createServer)(await createViteConfig(options, {
|
|
@@ -219,7 +365,7 @@ async function runDev(options) {
|
|
|
219
365
|
}
|
|
220
366
|
var cliPackageVersion = {
|
|
221
367
|
name: "@clarify-labs/cli",
|
|
222
|
-
version: "0.6.
|
|
368
|
+
version: "0.6.6",
|
|
223
369
|
license: "AGPL-3.0-only",
|
|
224
370
|
type: "module",
|
|
225
371
|
repository: {
|
|
@@ -411,6 +557,9 @@ async function main() {
|
|
|
411
557
|
withSharedOptions(cli.command("build", "Build the static documentation site")).action(async (options) => {
|
|
412
558
|
await runBuild(resolveOptions(options));
|
|
413
559
|
});
|
|
560
|
+
withSharedOptions(cli.command("check", "Validate the documentation project")).option("--strict", "Treat warnings as failures").option("--format <format>", "Output format: text or json").action(async (options) => {
|
|
561
|
+
await runCheck(options);
|
|
562
|
+
});
|
|
414
563
|
withSharedOptions(cli.command("init", "Create a Clarify project scaffold")).option("--force", "Overwrite files created by init").option("--template <name>", "Template to use: minimal, standard, or complete").option("--install", "Install dependencies after init").action((options) => {
|
|
415
564
|
runInit(resolveOptions(options), options.force === true, options.template, options.install === true);
|
|
416
565
|
});
|
package/output/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.cjs","names":[],"sources":["../source/core/log.ts","../source/core/vite-config.ts","../source/cli/commands/build.ts","../source/cli/commands/dev.ts","../package.json","../source/cli/package.ts","../source/cli/spawn.ts","../source/cli/commands/init.ts","../source/cli/options.ts","../source/cli/index.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { readFile, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\n\nconst LOG_FILE_NAME = '.clarify.log'\nconst DEFAULT_LOG_ENTRIES = 50\nconst ENTRY_SEPARATOR = '\\n\\n---\\n\\n'\n\nfunction getMaxLogEntries(): number {\n const envValue = process.env.CLARIFY_LOG_MAX_ENTRIES\n if (!envValue) return DEFAULT_LOG_ENTRIES\n const parsed = Number(envValue)\n return Number.isInteger(parsed) && parsed > 0 ? parsed : DEFAULT_LOG_ENTRIES\n}\n\nfunction normalizeErrorMessage(error: unknown): string {\n if (error === undefined) return 'undefined'\n if (error === null) return 'null'\n if (error instanceof Error) return error.message\n if (typeof error === 'object') {\n if ('message' in error && typeof (error as { message?: unknown }).message === 'string') {\n return (error as { message: string }).message\n }\n try {\n return JSON.stringify(error)\n } catch {\n return String(error)\n }\n }\n return String(error)\n}\n\nfunction normalizeErrorStack(error: unknown): string | undefined {\n if (error instanceof Error) {\n return error.stack\n }\n return undefined\n}\n\nfunction formatLogEntry(root: string, error: unknown): string {\n const timestamp = new Date().toISOString()\n const message = normalizeErrorMessage(error)\n const stack = normalizeErrorStack(error)\n\n return [`=== Clarify build error ===`, `Timestamp: ${timestamp}`, `Project root: ${root}`, `Error: ${message}`, stack ? `Stack:\\n${stack}` : undefined]\n .filter(Boolean)\n .join('\\n')\n}\n\nexport async function logBuildError(root: string, error: unknown, maxEntries?: number): Promise<void> {\n const logPath = join(root, LOG_FILE_NAME)\n const entry = formatLogEntry(root, error)\n const max = maxEntries ?? getMaxLogEntries()\n\n let entries: string[] = []\n if (existsSync(logPath)) {\n try {\n const content = await readFile(logPath, 'utf8')\n entries = content\n .split(ENTRY_SEPARATOR)\n .map((item) => item.trim())\n .filter(Boolean)\n } catch {\n entries = []\n }\n }\n\n entries.push(entry)\n if (entries.length > max) {\n entries = entries.slice(-max)\n }\n\n mkdirSync(dirname(logPath), { recursive: true })\n await writeFile(logPath, entries.join(ENTRY_SEPARATOR) + '\\n', 'utf8')\n}\n\nexport function logBuildErrorSync(root: string, error: unknown, maxEntries?: number): void {\n const logPath = join(root, LOG_FILE_NAME)\n const entry = formatLogEntry(root, error)\n const max = maxEntries ?? getMaxLogEntries()\n\n let entries: string[] = []\n if (existsSync(logPath)) {\n try {\n const content = readFileSync(logPath, 'utf8')\n entries = content\n .split(ENTRY_SEPARATOR)\n .map((item) => item.trim())\n .filter(Boolean)\n } catch {\n entries = []\n }\n }\n\n entries.push(entry)\n if (entries.length > max) {\n entries = entries.slice(-max)\n }\n\n mkdirSync(dirname(logPath), { recursive: true })\n writeFileSync(logPath, entries.join(ENTRY_SEPARATOR) + '\\n', 'utf8')\n}\n","import { existsSync, mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\n\nimport { createLogger } from 'vite'\nimport type { ConfigEnv, InlineConfig, Plugin, LogLevel, Logger, LogOptions, LogErrorOptions, LogType } from 'vite'\n\nimport { logBuildErrorSync } from './log.js'\nimport type { ClarifyBuildOptions } from './options.js'\nimport { clarifyPlugin } from './plugin.js'\nimport { createClarifyRuntimeAliases } from './runtime-deps.js'\nimport { loadClarifyConfig } from './user-config.js'\n\nexport type ClarifyViteConfigOptions = {\n root: string\n content: string\n output: string\n host?: string | boolean\n port?: number\n open?: boolean | string\n}\n\nconst DEFAULT_HTML = '<!doctype html><html lang=\"en\"><head><meta charset=\"UTF-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /><title>Clarify</title></head><body><div id=\"root\"></div></body></html>'\n\nfunction ensureHtmlEntry(root: string): string {\n const projectHtmlPath = resolve(root, 'index.html')\n if (existsSync(projectHtmlPath)) return projectHtmlPath\n\n const generatedHtmlPath = resolve(root, '.clarify/index.html')\n mkdirSync(dirname(generatedHtmlPath), { recursive: true })\n writeFileSync(generatedHtmlPath, DEFAULT_HTML, 'utf-8')\n return generatedHtmlPath\n}\n\nfunction createClarifyLogger(root: string, env: ConfigEnv, level: LogLevel): Logger | undefined {\n if (env.command !== 'build') return undefined\n\n const baseLogger = createLogger(level, { allowClearScreen: true })\n\n return {\n info(msg: string, options?: LogOptions) {\n baseLogger.info(msg, options)\n },\n warn(msg: string, options?: LogOptions) {\n baseLogger.warn(msg, options)\n },\n warnOnce(msg: string, options?: LogOptions) {\n baseLogger.warnOnce(msg, options)\n },\n error(msg: string, options?: LogErrorOptions) {\n baseLogger.error(msg, options)\n if (options?.error) {\n logBuildErrorSync(root, options.error)\n } else {\n logBuildErrorSync(root, typeof msg === 'string' ? new Error(msg) : msg)\n }\n },\n clearScreen(type: LogType) {\n baseLogger.clearScreen(type)\n },\n hasErrorLogged(error: Error | unknown) {\n return baseLogger.hasErrorLogged(error as Error)\n },\n get hasWarned() {\n return baseLogger.hasWarned\n },\n }\n}\n\nfunction createHtmlFallbackPlugin(): Plugin {\n return {\n name: 'clarify:cli-html-fallback',\n configureServer(server) {\n server.middlewares.use(async (req, res, next) => {\n const requestPath = req.url?.split('?')[0] ?? '/'\n const acceptsHtml = req.headers.accept?.includes('text/html') ?? false\n const hasFileExtension = /\\.[^/]+$/.test(requestPath)\n if (!acceptsHtml || hasFileExtension) {\n next()\n return\n }\n\n try {\n const html = await server.transformIndexHtml(requestPath, DEFAULT_HTML)\n res.statusCode = 200\n res.setHeader('Content-Type', 'text/html; charset=utf-8')\n res.end(html)\n } catch (error) {\n next(error)\n }\n })\n },\n }\n}\n\nexport async function createViteConfig(options: ClarifyViteConfigOptions, env: ConfigEnv): Promise<InlineConfig> {\n const entryHtmlPath = ensureHtmlEntry(options.root)\n const userConfig = await loadClarifyConfig(options.root, env)\n const buildOptions: ClarifyBuildOptions = {\n ...userConfig,\n projectRoot: options.root,\n rootDirectory: options.content,\n outputDirectory: options.output,\n }\n\n return {\n root: options.root,\n configFile: false,\n appType: 'custom',\n resolve: {\n alias: createClarifyRuntimeAliases(),\n },\n customLogger: createClarifyLogger(options.root, env, 'info'),\n plugins: [\n clarifyPlugin(buildOptions),\n createHtmlFallbackPlugin(),\n ],\n server: {\n host: options.host,\n port: options.port,\n open: options.open,\n },\n build: {\n outDir: options.output,\n rolldownOptions: {\n input: {\n index: entryHtmlPath,\n },\n checks: {\n pluginTimings: false,\n },\n output: {\n codeSplitting: {\n groups: [\n {\n name: 'react-vendor',\n test: /node_modules[\\\\/](react|react-dom|react-router|react-router-dom)[\\\\/]/,\n priority: 40,\n },\n {\n name: 'icons-vendor',\n test: /node_modules[\\\\/]lucide-react[\\\\/]/,\n priority: 35,\n },\n {\n name: 'ui-vendor',\n test: /node_modules[\\\\/](@headlessui|framer-motion)[\\\\/]/,\n priority: 30,\n },\n {\n name: 'vendor',\n test: /node_modules[\\\\/]/,\n priority: 10\n },\n ],\n },\n },\n },\n },\n }\n}\n","import { build as viteBuild } from 'vite'\n\nimport { logBuildError } from '../../core/log.js'\nimport { createViteConfig } from '../../core/vite-config.js'\nimport type { ResolvedCliOptions } from '../options.js'\n\nexport async function runBuild(options: ResolvedCliOptions): Promise<void> {\n try {\n await viteBuild(await createViteConfig(options, { command: 'build', mode: 'production' }))\n } catch (error) {\n await logBuildError(options.root, error)\n throw error\n }\n}\n","import { createServer } from 'vite'\n\nimport { createViteConfig } from '../../core/vite-config.js'\nimport type { ResolvedCliOptions } from '../options.js'\n\nexport async function runDev(options: ResolvedCliOptions): Promise<void> {\n const server = await createServer(await createViteConfig(options, { command: 'serve', mode: 'development' }))\n await server.listen()\n server.printUrls()\n server.bindCLIShortcuts({ print: true })\n}\n","{\n \"name\": \"@clarify-labs/cli\",\n \"version\": \"0.6.4\",\n \"license\": \"AGPL-3.0-only\",\n \"type\": \"module\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/taicode-labs/clarify\",\n \"directory\": \"packages/cli\"\n },\n \"main\": \"output/index.cjs\",\n \"module\": \"output/index.js\",\n \"types\": \"output/index.d.ts\",\n \"bin\": {\n \"clarify\": \"bin/clarify.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./output/index.d.ts\",\n \"import\": \"./output/index.js\",\n \"require\": \"./output/index.cjs\",\n \"default\": \"./output/index.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"LICENSE\",\n \"bin\",\n \"output\"\n ],\n \"scripts\": {\n \"dev\": \"vite build --watch\",\n \"build\": \"vite build\",\n \"lint\": \"eslint source/\",\n \"lint:fix\": \"eslint source/ --fix\",\n \"typecheck\": \"tsc -p tsconfig.json --noEmit\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\"\n },\n \"dependencies\": {\n \"@apidevtools/swagger-parser\": \"^12.1.0\",\n \"@clarify-labs/renderer\": \"workspace:*\",\n \"@clarify-labs/templates\": \"workspace:*\",\n \"@mdx-js/rollup\": \"^3.1.1\",\n \"@tailwindcss/vite\": \"^4.1.11\",\n \"@vitejs/plugin-react\": \"^6.0.2\",\n \"cac\": \"^7.0.0\",\n \"github-slugger\": \"^2.0.0\",\n \"gray-matter\": \"^4.0.3\",\n \"mdast-util-to-string\": \"^4.0.0\",\n \"openapi-types\": \"^12.1.3\",\n \"react\": \"^19.1.0\",\n \"react-dom\": \"^19.1.0\",\n \"react-router\": \"^7.0.0\",\n \"react-router-dom\": \"^7.0.0\",\n \"remark\": \"^15.0.1\",\n \"remark-gfm\": \"^4.0.1\",\n \"shiki\": \"0.14.7\",\n \"unist-util-visit\": \"^5.1.0\",\n \"vite\": \"^8.0.15\",\n \"zod\": \"^4.4.3\"\n },\n \"devDependencies\": {\n \"@mdx-js/mdx\": \"^3.1.1\",\n \"typescript\": \"^5.8.3\",\n \"vite-plugin-dts\": \"^4.5.4\",\n \"vitest\": \"^4.1.9\"\n }\n}\n","import packageJson from '../../package.json' with { type: 'json' }\n\nexport const cliPackageJson = packageJson as { version?: string }\nexport const cliPackageVersion = cliPackageJson.version ?? '0.0.0'\nexport const cliPackageVersionWithCaret = `^${cliPackageVersion}`\n\nexport function readPackageVersion(): string {\n return cliPackageVersion\n}\n","import { spawnSync as nodeSpawnSync, SpawnSyncOptions } from 'node:child_process'\n\ntype SpawnOptions = { cwd?: string; stdio?: 'inherit' | 'ignore' | Array<string> }\n\nexport function spawnSync(command: string, args: string[], options: SpawnOptions) {\n return nodeSpawnSync(command, args, options as SpawnSyncOptions)\n}\n","import { existsSync, readFileSync, writeFileSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nimport { copyTemplateDirectory, getTemplateDirectory, resolveTemplate } from '@clarify-labs/templates'\n\nimport type { ResolvedCliOptions } from '../options.js'\nimport { cliPackageVersionWithCaret } from '../package.js'\nimport { spawnSync } from '../spawn.js'\n\nconst require = createRequire(import.meta.url)\n\nfunction findTemplatesPackagePath(): string {\n try {\n return require.resolve('@clarify-labs/templates/package.json')\n } catch {\n const currentDirectory = dirname(fileURLToPath(import.meta.url))\n const workspacePackagePath = resolve(currentDirectory, '../../../../templates/package.json')\n if (existsSync(workspacePackagePath)) return workspacePackagePath\n throw new Error('[clarify] Templates package not found.')\n }\n}\n\nconst templatesPackagePath = findTemplatesPackagePath()\nconst templatesDirectory = dirname(templatesPackagePath)\n\nfunction commandExists(program: string): boolean {\n const result = spawnSync(program, ['--version'], { stdio: 'ignore' })\n return result.status === 0 && result.error === undefined\n}\n\ntype InstallCommand = { command: string; args: string[] }\n\nfunction getInstallCommand(): InstallCommand {\n if (commandExists('pnpm')) return { command: 'pnpm', args: ['install'] }\n if (commandExists('npm')) return { command: 'npm', args: ['install'] }\n if (commandExists('yarn')) return { command: 'yarn', args: ['install'] }\n return { command: 'npm', args: ['install'] }\n}\n\nfunction installDependencies(root: string): void {\n const { command, args } = getInstallCommand()\n console.log(`[clarify] Installing dependencies with ${command}...`)\n const result = spawnSync(command, args, { cwd: root, stdio: 'inherit' })\n if (result.status !== 0) {\n throw new Error(`[clarify] Dependency install failed with ${command}`)\n }\n}\n\nfunction getSuggestedInstallCommand(): string {\n if (commandExists('pnpm')) return 'pnpm install'\n if (commandExists('npm')) return 'npm install'\n if (commandExists('yarn')) return 'yarn install'\n return 'npm install'\n}\n\nfunction updatePackageJson(root: string, force: boolean): boolean {\n const packageJsonPath = resolve(root, 'package.json')\n const packageJson = existsSync(packageJsonPath)\n ? JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as Record<string, unknown>\n : { type: 'module' }\n\n const scripts = typeof packageJson.scripts === 'object' && packageJson.scripts !== null\n ? packageJson.scripts as Record<string, string>\n : {}\n\n if (force || !scripts.dev) scripts.dev = 'clarify dev'\n if (force || !scripts.build) scripts.build = 'clarify build'\n packageJson.scripts = scripts\n\n const devDependencies = typeof packageJson.devDependencies === 'object' && packageJson.devDependencies !== null\n ? packageJson.devDependencies as Record<string, string>\n : {}\n if (!devDependencies['@clarify-labs/cli']) devDependencies['@clarify-labs/cli'] = cliPackageVersionWithCaret\n packageJson.devDependencies = devDependencies\n\n writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\\n`, 'utf-8')\n return true\n}\n\nexport function runInit(options: ResolvedCliOptions, force: boolean, template?: string, install = false): void {\n const selectedTemplate = resolveTemplate(template)\n const templateDirectory = getTemplateDirectory(templatesDirectory, selectedTemplate)\n const { created } = copyTemplateDirectory(templateDirectory, options.root, {\n contentDir: options.content,\n force,\n })\n\n const packageJsonUpdated = updatePackageJson(options.root, force)\n if (packageJsonUpdated) created.push('package.json')\n\n console.log(`[clarify] Project scaffold created using the ${selectedTemplate} template.`)\n if (created.length > 0) {\n console.log(`[clarify] Created or updated ${created.length} ${created.length === 1 ? 'file' : 'files'}: ${created.join(', ')}`)\n }\n\n if (install) {\n installDependencies(options.root)\n console.log('[clarify] Dependencies installed successfully.')\n console.log('[clarify] You can now run `clarify dev` to start the local documentation server.')\n return\n }\n\n const suggestedInstall = getSuggestedInstallCommand()\n console.log('[clarify] Next steps:')\n console.log(' 1. Change into your new project directory:')\n console.log(` cd ${options.root}`)\n console.log(' 2. Install dependencies:')\n console.log(` ${suggestedInstall}`)\n console.log(' 3. Start the local documentation server:')\n console.log(' clarify dev')\n}\n","import { resolve } from 'node:path'\n\nexport type CliOptions = {\n root?: string\n content?: string\n output?: string\n host?: string | boolean\n port?: string | number\n open?: boolean | string\n}\n\nexport type ResolvedCliOptions = {\n root: string\n content: string\n output: string\n host?: string | boolean\n port?: number\n open?: boolean | string\n}\n\nfunction resolvePort(port: CliOptions['port']): number | undefined {\n if (port === undefined) return undefined\n\n const parsedPort = typeof port === 'string' ? Number(port) : port\n if (!Number.isInteger(parsedPort) || parsedPort < 1 || parsedPort > 65535) {\n throw new Error('[clarify] --port must be an integer between 1 and 65535')\n }\n\n return parsedPort\n}\n\nexport function resolveCliOptions(options: CliOptions): ResolvedCliOptions {\n return {\n root: resolve(options.root ?? process.cwd()),\n content: options.content ?? 'source',\n output: options.output ?? 'output',\n host: options.host,\n port: resolvePort(options.port),\n open: options.open,\n }\n}\n","#!/usr/bin/env node\nimport { cac } from 'cac'\n\nimport { runBuild } from './commands/build.js'\nimport { runDev } from './commands/dev.js'\nimport { runInit } from './commands/init.js'\nimport { resolveCliOptions, type CliOptions, type ResolvedCliOptions } from './options.js'\nimport { cliPackageVersion } from './package.js'\n\ntype InitCommandOptions = CliOptions & {\n force?: boolean\n template?: string\n install?: boolean\n}\n\nfunction withSharedOptions(command: ReturnType<ReturnType<typeof cac>['command']>) {\n return command\n .option('--root <dir>', 'Project root directory')\n .option('--content <dir>', 'Content directory relative to root')\n .option('--output <dir>', 'Build output directory relative to root')\n}\n\nfunction resolveOptions(options: CliOptions): ResolvedCliOptions {\n return resolveCliOptions(options)\n}\n\nasync function main(): Promise<void> {\n const cli = cac('clarify')\n\n cli\n .version(cliPackageVersion)\n .help()\n\n withSharedOptions(cli.command('dev', 'Start the local documentation server'))\n .option('--host [host]', 'Dev server host')\n .option('--port <port>', 'Dev server port')\n .option('--open [path]', 'Open the dev server in a browser')\n .action(async (options: CliOptions) => {\n await runDev(resolveOptions(options))\n })\n\n withSharedOptions(cli.command('build', 'Build the static documentation site'))\n .action(async (options: CliOptions) => {\n await runBuild(resolveOptions(options))\n })\n\n withSharedOptions(cli.command('init', 'Create a Clarify project scaffold'))\n .option('--force', 'Overwrite files created by init')\n .option('--template <name>', 'Template to use: minimal, standard, or complete')\n .option('--install', 'Install dependencies after init')\n .action((options: InitCommandOptions) => {\n runInit(resolveOptions(options), options.force === true, options.template, options.install === true)\n })\n\n const args = process.argv.slice(2)\n cli.parse(process.argv, { run: false })\n\n if (args.length === 0) {\n cli.outputHelp()\n return\n }\n\n await cli.runMatchedCommand()\n}\n\nmain().catch(error => {\n console.error(error instanceof Error ? error.stack ?? error.message : String(error))\n process.exitCode = 1\n})\n"],"mappings":";;;;;;;;;;;;AAIA,IAAM,gBAAgB;AACtB,IAAM,sBAAsB;AAC5B,IAAM,kBAAkB;AAExB,SAAS,mBAA2B;CAClC,MAAM,WAAW,QAAQ,IAAI;CAC7B,IAAI,CAAC,UAAU,OAAO;CACtB,MAAM,SAAS,OAAO,QAAQ;CAC9B,OAAO,OAAO,UAAU,MAAM,KAAK,SAAS,IAAI,SAAS;AAC3D;AAEA,SAAS,sBAAsB,OAAwB;CACrD,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,iBAAiB,OAAO,OAAO,MAAM;CACzC,IAAI,OAAO,UAAU,UAAU;EAC7B,IAAI,aAAa,SAAS,OAAQ,MAAgC,YAAY,UAC5E,OAAQ,MAA8B;EAExC,IAAI;GACF,OAAO,KAAK,UAAU,KAAK;EAC7B,QAAQ;GACN,OAAO,OAAO,KAAK;EACrB;CACF;CACA,OAAO,OAAO,KAAK;AACrB;AAEA,SAAS,oBAAoB,OAAoC;CAC/D,IAAI,iBAAiB,OACnB,OAAO,MAAM;AAGjB;AAEA,SAAS,eAAe,MAAc,OAAwB;CAC5D,MAAM,6BAAY,IAAI,KAAK,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AAQ,YAAgC;EACvC,QAAQ,eAAe,OAAO,GAAG,QAAQ,UAAU,MAAM,QAAQ,UAAU,QAAQ,YAAY,IAAI;CACrG,CAAC;CAEH,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;CACjC,IAAI,MAAM,QAAQ,MAAM,EAAE,KAAK,MAAM,CAAC;CAEtC,IAAI,KAAK,WAAW,GAAG;EACrB,IAAI,WAAW;EACf;CACF;CAEA,MAAM,IAAI,kBAAkB;AAC9B;AAEA,KAAK,EAAE,OAAM,UAAS;CACpB,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,SAAS,MAAM,UAAU,OAAO,KAAK,CAAC;CACnF,QAAQ,WAAW;AACrB,CAAC"}
|
|
1
|
+
{"version":3,"file":"cli.cjs","names":[],"sources":["../source/core/log.ts","../source/core/vite-config.ts","../source/cli/commands/build.ts","../source/cli/commands/check.ts","../source/cli/commands/dev.ts","../package.json","../source/cli/package.ts","../source/cli/spawn.ts","../source/cli/commands/init.ts","../source/cli/options.ts","../source/cli/index.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { readFile, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\n\nconst LOG_FILE_NAME = '.clarify.log'\nconst DEFAULT_LOG_ENTRIES = 50\nconst ENTRY_SEPARATOR = '\\n\\n---\\n\\n'\n\nfunction getMaxLogEntries(): number {\n const envValue = process.env.CLARIFY_LOG_MAX_ENTRIES\n if (!envValue) return DEFAULT_LOG_ENTRIES\n const parsed = Number(envValue)\n return Number.isInteger(parsed) && parsed > 0 ? parsed : DEFAULT_LOG_ENTRIES\n}\n\nfunction normalizeErrorMessage(error: unknown): string {\n if (error === undefined) return 'undefined'\n if (error === null) return 'null'\n if (error instanceof Error) return error.message\n if (typeof error === 'object') {\n if ('message' in error && typeof (error as { message?: unknown }).message === 'string') {\n return (error as { message: string }).message\n }\n try {\n return JSON.stringify(error)\n } catch {\n return String(error)\n }\n }\n return String(error)\n}\n\nfunction normalizeErrorStack(error: unknown): string | undefined {\n if (error instanceof Error) {\n return error.stack\n }\n return undefined\n}\n\nfunction formatLogEntry(root: string, error: unknown): string {\n const timestamp = new Date().toISOString()\n const message = normalizeErrorMessage(error)\n const stack = normalizeErrorStack(error)\n\n return [`=== Clarify build error ===`, `Timestamp: ${timestamp}`, `Project root: ${root}`, `Error: ${message}`, stack ? `Stack:\\n${stack}` : undefined]\n .filter(Boolean)\n .join('\\n')\n}\n\nexport async function logBuildError(root: string, error: unknown, maxEntries?: number): Promise<void> {\n const logPath = join(root, LOG_FILE_NAME)\n const entry = formatLogEntry(root, error)\n const max = maxEntries ?? getMaxLogEntries()\n\n let entries: string[] = []\n if (existsSync(logPath)) {\n try {\n const content = await readFile(logPath, 'utf8')\n entries = content\n .split(ENTRY_SEPARATOR)\n .map((item) => item.trim())\n .filter(Boolean)\n } catch {\n entries = []\n }\n }\n\n entries.push(entry)\n if (entries.length > max) {\n entries = entries.slice(-max)\n }\n\n mkdirSync(dirname(logPath), { recursive: true })\n await writeFile(logPath, entries.join(ENTRY_SEPARATOR) + '\\n', 'utf8')\n}\n\nexport function logBuildErrorSync(root: string, error: unknown, maxEntries?: number): void {\n const logPath = join(root, LOG_FILE_NAME)\n const entry = formatLogEntry(root, error)\n const max = maxEntries ?? getMaxLogEntries()\n\n let entries: string[] = []\n if (existsSync(logPath)) {\n try {\n const content = readFileSync(logPath, 'utf8')\n entries = content\n .split(ENTRY_SEPARATOR)\n .map((item) => item.trim())\n .filter(Boolean)\n } catch {\n entries = []\n }\n }\n\n entries.push(entry)\n if (entries.length > max) {\n entries = entries.slice(-max)\n }\n\n mkdirSync(dirname(logPath), { recursive: true })\n writeFileSync(logPath, entries.join(ENTRY_SEPARATOR) + '\\n', 'utf8')\n}\n","import { existsSync, mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\n\nimport { createLogger } from 'vite'\nimport type { ConfigEnv, InlineConfig, Plugin, LogLevel, Logger, LogOptions, LogErrorOptions, LogType } from 'vite'\n\nimport { logBuildErrorSync } from './log.js'\nimport type { ClarifyBuildOptions } from './options.js'\nimport { clarifyPlugin } from './plugin.js'\nimport { createClarifyRuntimeAliases } from './runtime-deps.js'\nimport { loadClarifyConfig } from './user-config.js'\n\nexport type ClarifyViteConfigOptions = {\n root: string\n content: string\n output: string\n host?: string | boolean\n port?: number\n open?: boolean | string\n}\n\nconst DEFAULT_HTML = '<!doctype html><html lang=\"en\"><head><meta charset=\"UTF-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /><title>Clarify</title></head><body><div id=\"root\"></div></body></html>'\n\nfunction ensureHtmlEntry(root: string): string {\n const projectHtmlPath = resolve(root, 'index.html')\n if (existsSync(projectHtmlPath)) return projectHtmlPath\n\n const generatedHtmlPath = resolve(root, '.clarify/index.html')\n mkdirSync(dirname(generatedHtmlPath), { recursive: true })\n writeFileSync(generatedHtmlPath, DEFAULT_HTML, 'utf-8')\n return generatedHtmlPath\n}\n\nfunction createClarifyLogger(root: string, env: ConfigEnv, level: LogLevel): Logger | undefined {\n if (env.command !== 'build') return undefined\n\n const baseLogger = createLogger(level, { allowClearScreen: true })\n\n return {\n info(msg: string, options?: LogOptions) {\n baseLogger.info(msg, options)\n },\n warn(msg: string, options?: LogOptions) {\n baseLogger.warn(msg, options)\n },\n warnOnce(msg: string, options?: LogOptions) {\n baseLogger.warnOnce(msg, options)\n },\n error(msg: string, options?: LogErrorOptions) {\n baseLogger.error(msg, options)\n if (options?.error) {\n logBuildErrorSync(root, options.error)\n } else {\n logBuildErrorSync(root, typeof msg === 'string' ? new Error(msg) : msg)\n }\n },\n clearScreen(type: LogType) {\n baseLogger.clearScreen(type)\n },\n hasErrorLogged(error: Error | unknown) {\n return baseLogger.hasErrorLogged(error as Error)\n },\n get hasWarned() {\n return baseLogger.hasWarned\n },\n }\n}\n\nfunction createHtmlFallbackPlugin(): Plugin {\n return {\n name: 'clarify:cli-html-fallback',\n configureServer(server) {\n server.middlewares.use(async (req, res, next) => {\n const requestPath = req.url?.split('?')[0] ?? '/'\n const acceptsHtml = req.headers.accept?.includes('text/html') ?? false\n const hasFileExtension = /\\.[^/]+$/.test(requestPath)\n if (!acceptsHtml || hasFileExtension) {\n next()\n return\n }\n\n try {\n const html = await server.transformIndexHtml(requestPath, DEFAULT_HTML)\n res.statusCode = 200\n res.setHeader('Content-Type', 'text/html; charset=utf-8')\n res.end(html)\n } catch (error) {\n next(error)\n }\n })\n },\n }\n}\n\nexport async function createViteConfig(options: ClarifyViteConfigOptions, env: ConfigEnv): Promise<InlineConfig> {\n const entryHtmlPath = ensureHtmlEntry(options.root)\n const userConfig = await loadClarifyConfig(options.root, env)\n const buildOptions: ClarifyBuildOptions = {\n ...userConfig,\n projectRoot: options.root,\n rootDirectory: options.content,\n outputDirectory: options.output,\n }\n\n return {\n root: options.root,\n configFile: false,\n appType: 'custom',\n resolve: {\n alias: createClarifyRuntimeAliases(),\n },\n customLogger: createClarifyLogger(options.root, env, 'info'),\n plugins: [\n clarifyPlugin(buildOptions),\n createHtmlFallbackPlugin(),\n ],\n server: {\n host: options.host,\n port: options.port,\n open: options.open,\n },\n build: {\n outDir: options.output,\n rolldownOptions: {\n input: {\n index: entryHtmlPath,\n },\n checks: {\n pluginTimings: false,\n },\n output: {\n codeSplitting: {\n groups: [\n {\n name: 'react-vendor',\n test: /node_modules[\\\\/](react|react-dom|react-router|react-router-dom)[\\\\/]/,\n priority: 40,\n },\n {\n name: 'icons-vendor',\n test: /node_modules[\\\\/]lucide-react[\\\\/]/,\n priority: 35,\n },\n {\n name: 'ui-vendor',\n test: /node_modules[\\\\/](@headlessui|framer-motion)[\\\\/]/,\n priority: 30,\n },\n {\n name: 'vendor',\n test: /node_modules[\\\\/]/,\n priority: 10\n },\n ],\n },\n },\n },\n },\n }\n}\n","import { build as viteBuild } from 'vite'\n\nimport { logBuildError } from '../../core/log.js'\nimport { createViteConfig } from '../../core/vite-config.js'\nimport type { ResolvedCliOptions } from '../options.js'\n\nexport async function runBuild(options: ResolvedCliOptions): Promise<void> {\n try {\n await viteBuild(await createViteConfig(options, { command: 'build', mode: 'production' }))\n } catch (error) {\n await logBuildError(options.root, error)\n throw error\n }\n}\n","import { existsSync } from 'node:fs'\nimport { lstat, stat } from 'node:fs/promises'\nimport { dirname, extname, isAbsolute, join, normalize, relative, resolve } from 'node:path'\n\nimport type { CliOptions } from '../options.js'\nimport { loadClarifyConfig } from '../../core/user-config.js'\nimport { resolveClarifySite } from '../../core/site.js'\nimport type { ContentRoute } from '../../types.js'\n\nexport type CheckCommandOptions = CliOptions & {\n strict?: boolean\n format?: 'text' | 'json' | string\n}\n\ntype CheckLevel = 'error' | 'warning'\n\ntype CheckDiagnostic = {\n level: CheckLevel\n code: string\n message: string\n filePath?: string\n routePath?: string\n}\n\ntype CheckResult = {\n errors: CheckDiagnostic[]\n warnings: CheckDiagnostic[]\n}\n\nconst LOCAL_LINK_PATTERN = /(?<!!)(?:\\[[^\\]]*\\]\\(([^)\\s]+)(?:\\s+\"[^\"]*\")?\\)|<a\\s+[^>]*href=[\"']([^\"']+)[\"'])/gi\nconst ROUTE_EXTENSIONS = new Set(['.md', '.mdx'])\nconst IGNORED_SCHEMES = /^[a-z][a-z0-9+.-]*:/i\n\nfunction addDiagnostic(result: CheckResult, diagnostic: CheckDiagnostic): void {\n if (diagnostic.level === 'error') result.errors.push(diagnostic)\n else result.warnings.push(diagnostic)\n}\n\nfunction normalizeRoutePath(path: string): string {\n const [withoutHash] = path.split('#')\n const clean = withoutHash.replace(/\\/index$/, '') || '/'\n return clean.startsWith('/') ? clean : `/${clean}`\n}\n\nfunction routePathCandidates(href: string, route: ContentRoute): string[] {\n const [withoutHashOrQuery] = href.split(/[?#]/)\n if (!withoutHashOrQuery || withoutHashOrQuery.startsWith('#')) return []\n if (withoutHashOrQuery.startsWith('/')) return [normalizeRoutePath(withoutHashOrQuery)]\n\n const routeDir = dirname(route.path)\n const joined = normalize(join(routeDir, withoutHashOrQuery)).replaceAll('\\\\', '/')\n const extension = extname(joined)\n const base = ROUTE_EXTENSIONS.has(extension) ? joined.slice(0, -extension.length) : joined\n return [normalizeRoutePath(base)]\n}\n\nasync function pathExists(filePath: string): Promise<boolean> {\n try {\n await stat(filePath)\n return true\n } catch {\n return false\n }\n}\n\nfunction isLocalHref(href: string): boolean {\n return Boolean(href) && !href.startsWith('#') && !href.startsWith('//') && !IGNORED_SCHEMES.test(href)\n}\n\nasync function resolveLocalFileLink(href: string, route: ContentRoute, contentRoot: string): Promise<boolean> {\n const [withoutHashOrQuery] = href.split(/[?#]/)\n if (!withoutHashOrQuery || withoutHashOrQuery.startsWith('/')) return false\n\n const target = resolve(dirname(route.filePath), withoutHashOrQuery)\n const relativeTarget = relative(contentRoot, target)\n if (relativeTarget.startsWith('..') || isAbsolute(relativeTarget)) return false\n if (await pathExists(target)) return true\n\n if (!extname(target)) {\n return pathExists(`${target}.md`) || pathExists(`${target}.mdx`) || pathExists(join(target, 'index.md')) || pathExists(join(target, 'index.mdx'))\n }\n return false\n}\n\nasync function checkContentDirectory(contentRoot: string, result: CheckResult): Promise<void> {\n try {\n const stats = await lstat(contentRoot)\n if (!stats.isDirectory()) {\n addDiagnostic(result, {\n level: 'error',\n code: 'content-not-directory',\n message: `Content path is not a directory: ${contentRoot}`,\n filePath: contentRoot,\n })\n }\n } catch {\n addDiagnostic(result, {\n level: 'error',\n code: 'content-missing',\n message: `Content directory does not exist: ${contentRoot}`,\n filePath: contentRoot,\n })\n }\n}\n\nfunction checkDuplicateRoutes(routes: ContentRoute[], result: CheckResult): void {\n const byPath = new Map<string, ContentRoute[]>()\n for (const route of routes) {\n const key = `${route.locale ?? ''}:${route.path}`\n byPath.set(key, [...(byPath.get(key) ?? []), route])\n }\n\n for (const duplicated of byPath.values()) {\n if (duplicated.length < 2) continue\n for (const route of duplicated) {\n addDiagnostic(result, {\n level: 'error',\n code: 'duplicate-route',\n message: `Route \"${route.path}\" is defined by multiple files: ${duplicated.map(route => relative(process.cwd(), route.filePath)).join(', ')}`,\n filePath: route.filePath,\n routePath: route.path,\n })\n }\n }\n}\n\nfunction checkFallbackRoutes(routes: ContentRoute[], result: CheckResult): void {\n for (const route of routes) {\n if (!route.isFallback) continue\n addDiagnostic(result, {\n level: 'warning',\n code: 'i18n-fallback-route',\n message: `Route \"${route.path}\" falls back to ${route.locale ?? 'default'} content from ${relative(process.cwd(), route.filePath)}`,\n filePath: route.filePath,\n routePath: route.path,\n })\n }\n}\n\nasync function checkLocalLinks(routes: ContentRoute[], contentRoot: string, result: CheckResult): Promise<void> {\n const routePaths = new Set(routes.map(route => route.path))\n\n for (const route of routes) {\n if (route.kind !== 'mdx' || !route.content) continue\n for (const match of route.content.matchAll(LOCAL_LINK_PATTERN)) {\n const href = match[1] ?? match[2]\n if (!href || !isLocalHref(href)) continue\n const candidates = routePathCandidates(href, route)\n if (candidates.some(candidate => routePaths.has(candidate))) continue\n if (await resolveLocalFileLink(href, route, contentRoot)) continue\n\n addDiagnostic(result, {\n level: 'error',\n code: 'broken-link',\n message: `Broken local link \"${href}\" in route \"${route.path}\"`,\n filePath: route.filePath,\n routePath: route.path,\n })\n }\n }\n}\n\nfunction printTextResult(result: CheckResult, strict: boolean): void {\n const diagnostics = [...result.errors, ...result.warnings]\n if (diagnostics.length === 0) {\n console.log('✓ Clarify check passed')\n return\n }\n\n for (const diagnostic of diagnostics) {\n const location = diagnostic.filePath ? ` ${relative(process.cwd(), diagnostic.filePath)}` : ''\n const route = diagnostic.routePath ? ` (${diagnostic.routePath})` : ''\n console.log(`${diagnostic.level.toUpperCase()} ${diagnostic.code}${location}${route}`)\n console.log(` ${diagnostic.message}`)\n }\n\n const warningExit = strict && result.warnings.length > 0\n console.log(`\\n${result.errors.length} error(s), ${result.warnings.length} warning(s)${warningExit ? ' (--strict treats warnings as failures)' : ''}`)\n}\n\nexport async function runCheck(options: CheckCommandOptions = {}): Promise<void> {\n const root = resolve(options.root ?? process.cwd())\n const userConfig = existsSync(root) ? await loadClarifyConfig(root, { command: 'build', mode: 'production' }) : {}\n const site = await resolveClarifySite({\n ...userConfig,\n projectRoot: root,\n rootDirectory: options.content,\n outputDirectory: options.output,\n }, { includeHtmlShellPlugin: false })\n\n const result: CheckResult = { errors: [], warnings: [] }\n await checkContentDirectory(site.contentRoot, result)\n checkDuplicateRoutes(site.routes, result)\n checkFallbackRoutes(site.routes, result)\n await checkLocalLinks(site.routes, site.contentRoot, result)\n\n if (options.format === 'json') {\n console.log(JSON.stringify(result, null, 2))\n } else {\n printTextResult(result, Boolean(options.strict))\n }\n\n if (result.errors.length > 0 || (options.strict && result.warnings.length > 0)) {\n process.exitCode = 1\n }\n}\n","import { createServer } from 'vite'\n\nimport { createViteConfig } from '../../core/vite-config.js'\nimport type { ResolvedCliOptions } from '../options.js'\n\nexport async function runDev(options: ResolvedCliOptions): Promise<void> {\n const server = await createServer(await createViteConfig(options, { command: 'serve', mode: 'development' }))\n await server.listen()\n server.printUrls()\n server.bindCLIShortcuts({ print: true })\n}\n","{\n \"name\": \"@clarify-labs/cli\",\n \"version\": \"0.6.6\",\n \"license\": \"AGPL-3.0-only\",\n \"type\": \"module\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/taicode-labs/clarify\",\n \"directory\": \"packages/cli\"\n },\n \"main\": \"output/index.cjs\",\n \"module\": \"output/index.js\",\n \"types\": \"output/index.d.ts\",\n \"bin\": {\n \"clarify\": \"bin/clarify.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./output/index.d.ts\",\n \"import\": \"./output/index.js\",\n \"require\": \"./output/index.cjs\",\n \"default\": \"./output/index.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"LICENSE\",\n \"bin\",\n \"output\"\n ],\n \"scripts\": {\n \"dev\": \"vite build --watch\",\n \"build\": \"vite build\",\n \"lint\": \"eslint source/\",\n \"lint:fix\": \"eslint source/ --fix\",\n \"typecheck\": \"tsc -p tsconfig.json --noEmit\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\"\n },\n \"dependencies\": {\n \"@apidevtools/swagger-parser\": \"^12.1.0\",\n \"@clarify-labs/renderer\": \"workspace:*\",\n \"@clarify-labs/templates\": \"workspace:*\",\n \"@mdx-js/rollup\": \"^3.1.1\",\n \"@tailwindcss/vite\": \"^4.1.11\",\n \"@vitejs/plugin-react\": \"^6.0.2\",\n \"cac\": \"^7.0.0\",\n \"github-slugger\": \"^2.0.0\",\n \"gray-matter\": \"^4.0.3\",\n \"mdast-util-to-string\": \"^4.0.0\",\n \"openapi-types\": \"^12.1.3\",\n \"react\": \"^19.1.0\",\n \"react-dom\": \"^19.1.0\",\n \"react-router\": \"^7.0.0\",\n \"react-router-dom\": \"^7.0.0\",\n \"remark\": \"^15.0.1\",\n \"remark-gfm\": \"^4.0.1\",\n \"shiki\": \"0.14.7\",\n \"unist-util-visit\": \"^5.1.0\",\n \"vite\": \"^8.0.15\",\n \"zod\": \"^4.4.3\"\n },\n \"devDependencies\": {\n \"@mdx-js/mdx\": \"^3.1.1\",\n \"typescript\": \"^5.8.3\",\n \"vite-plugin-dts\": \"^4.5.4\",\n \"vitest\": \"^4.1.9\"\n }\n}\n","import packageJson from '../../package.json' with { type: 'json' }\n\nexport const cliPackageJson = packageJson as { version?: string }\nexport const cliPackageVersion = cliPackageJson.version ?? '0.0.0'\nexport const cliPackageVersionWithCaret = `^${cliPackageVersion}`\n\nexport function readPackageVersion(): string {\n return cliPackageVersion\n}\n","import { spawnSync as nodeSpawnSync, SpawnSyncOptions } from 'node:child_process'\n\ntype SpawnOptions = { cwd?: string; stdio?: 'inherit' | 'ignore' | Array<string> }\n\nexport function spawnSync(command: string, args: string[], options: SpawnOptions) {\n return nodeSpawnSync(command, args, options as SpawnSyncOptions)\n}\n","import { existsSync, readFileSync, writeFileSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nimport { copyTemplateDirectory, getTemplateDirectory, resolveTemplate } from '@clarify-labs/templates'\n\nimport type { ResolvedCliOptions } from '../options.js'\nimport { cliPackageVersionWithCaret } from '../package.js'\nimport { spawnSync } from '../spawn.js'\n\nconst require = createRequire(import.meta.url)\n\nfunction findTemplatesPackagePath(): string {\n try {\n return require.resolve('@clarify-labs/templates/package.json')\n } catch {\n const currentDirectory = dirname(fileURLToPath(import.meta.url))\n const workspacePackagePath = resolve(currentDirectory, '../../../../templates/package.json')\n if (existsSync(workspacePackagePath)) return workspacePackagePath\n throw new Error('[clarify] Templates package not found.')\n }\n}\n\nconst templatesPackagePath = findTemplatesPackagePath()\nconst templatesDirectory = dirname(templatesPackagePath)\n\nfunction commandExists(program: string): boolean {\n const result = spawnSync(program, ['--version'], { stdio: 'ignore' })\n return result.status === 0 && result.error === undefined\n}\n\ntype InstallCommand = { command: string; args: string[] }\n\nfunction getInstallCommand(): InstallCommand {\n if (commandExists('pnpm')) return { command: 'pnpm', args: ['install'] }\n if (commandExists('npm')) return { command: 'npm', args: ['install'] }\n if (commandExists('yarn')) return { command: 'yarn', args: ['install'] }\n return { command: 'npm', args: ['install'] }\n}\n\nfunction installDependencies(root: string): void {\n const { command, args } = getInstallCommand()\n console.log(`[clarify] Installing dependencies with ${command}...`)\n const result = spawnSync(command, args, { cwd: root, stdio: 'inherit' })\n if (result.status !== 0) {\n throw new Error(`[clarify] Dependency install failed with ${command}`)\n }\n}\n\nfunction getSuggestedInstallCommand(): string {\n if (commandExists('pnpm')) return 'pnpm install'\n if (commandExists('npm')) return 'npm install'\n if (commandExists('yarn')) return 'yarn install'\n return 'npm install'\n}\n\nfunction updatePackageJson(root: string, force: boolean): boolean {\n const packageJsonPath = resolve(root, 'package.json')\n const packageJson = existsSync(packageJsonPath)\n ? JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as Record<string, unknown>\n : { type: 'module' }\n\n const scripts = typeof packageJson.scripts === 'object' && packageJson.scripts !== null\n ? packageJson.scripts as Record<string, string>\n : {}\n\n if (force || !scripts.dev) scripts.dev = 'clarify dev'\n if (force || !scripts.build) scripts.build = 'clarify build'\n packageJson.scripts = scripts\n\n const devDependencies = typeof packageJson.devDependencies === 'object' && packageJson.devDependencies !== null\n ? packageJson.devDependencies as Record<string, string>\n : {}\n if (!devDependencies['@clarify-labs/cli']) devDependencies['@clarify-labs/cli'] = cliPackageVersionWithCaret\n packageJson.devDependencies = devDependencies\n\n writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\\n`, 'utf-8')\n return true\n}\n\nexport function runInit(options: ResolvedCliOptions, force: boolean, template?: string, install = false): void {\n const selectedTemplate = resolveTemplate(template)\n const templateDirectory = getTemplateDirectory(templatesDirectory, selectedTemplate)\n const { created } = copyTemplateDirectory(templateDirectory, options.root, {\n contentDir: options.content,\n force,\n })\n\n const packageJsonUpdated = updatePackageJson(options.root, force)\n if (packageJsonUpdated) created.push('package.json')\n\n console.log(`[clarify] Project scaffold created using the ${selectedTemplate} template.`)\n if (created.length > 0) {\n console.log(`[clarify] Created or updated ${created.length} ${created.length === 1 ? 'file' : 'files'}: ${created.join(', ')}`)\n }\n\n if (install) {\n installDependencies(options.root)\n console.log('[clarify] Dependencies installed successfully.')\n console.log('[clarify] You can now run `clarify dev` to start the local documentation server.')\n return\n }\n\n const suggestedInstall = getSuggestedInstallCommand()\n console.log('[clarify] Next steps:')\n console.log(' 1. Change into your new project directory:')\n console.log(` cd ${options.root}`)\n console.log(' 2. Install dependencies:')\n console.log(` ${suggestedInstall}`)\n console.log(' 3. Start the local documentation server:')\n console.log(' clarify dev')\n}\n","import { resolve } from 'node:path'\n\nexport type CliOptions = {\n root?: string\n content?: string\n output?: string\n host?: string | boolean\n port?: string | number\n open?: boolean | string\n}\n\nexport type ResolvedCliOptions = {\n root: string\n content: string\n output: string\n host?: string | boolean\n port?: number\n open?: boolean | string\n}\n\nfunction resolvePort(port: CliOptions['port']): number | undefined {\n if (port === undefined) return undefined\n\n const parsedPort = typeof port === 'string' ? Number(port) : port\n if (!Number.isInteger(parsedPort) || parsedPort < 1 || parsedPort > 65535) {\n throw new Error('[clarify] --port must be an integer between 1 and 65535')\n }\n\n return parsedPort\n}\n\nexport function resolveCliOptions(options: CliOptions): ResolvedCliOptions {\n return {\n root: resolve(options.root ?? process.cwd()),\n content: options.content ?? 'source',\n output: options.output ?? 'output',\n host: options.host,\n port: resolvePort(options.port),\n open: options.open,\n }\n}\n","#!/usr/bin/env node\nimport { cac } from 'cac'\n\nimport { runBuild } from './commands/build.js'\nimport { runCheck, type CheckCommandOptions } from './commands/check.js'\nimport { runDev } from './commands/dev.js'\nimport { runInit } from './commands/init.js'\nimport { resolveCliOptions, type CliOptions, type ResolvedCliOptions } from './options.js'\nimport { cliPackageVersion } from './package.js'\n\ntype InitCommandOptions = CliOptions & {\n force?: boolean\n template?: string\n install?: boolean\n}\n\nfunction withSharedOptions(command: ReturnType<ReturnType<typeof cac>['command']>) {\n return command\n .option('--root <dir>', 'Project root directory')\n .option('--content <dir>', 'Content directory relative to root')\n .option('--output <dir>', 'Build output directory relative to root')\n}\n\nfunction resolveOptions(options: CliOptions): ResolvedCliOptions {\n return resolveCliOptions(options)\n}\n\nasync function main(): Promise<void> {\n const cli = cac('clarify')\n\n cli\n .version(cliPackageVersion)\n .help()\n\n withSharedOptions(cli.command('dev', 'Start the local documentation server'))\n .option('--host [host]', 'Dev server host')\n .option('--port <port>', 'Dev server port')\n .option('--open [path]', 'Open the dev server in a browser')\n .action(async (options: CliOptions) => {\n await runDev(resolveOptions(options))\n })\n\n withSharedOptions(cli.command('build', 'Build the static documentation site'))\n .action(async (options: CliOptions) => {\n await runBuild(resolveOptions(options))\n })\n\n withSharedOptions(cli.command('check', 'Validate the documentation project'))\n .option('--strict', 'Treat warnings as failures')\n .option('--format <format>', 'Output format: text or json')\n .action(async (options: CheckCommandOptions) => {\n await runCheck(options)\n })\n\n withSharedOptions(cli.command('init', 'Create a Clarify project scaffold'))\n .option('--force', 'Overwrite files created by init')\n .option('--template <name>', 'Template to use: minimal, standard, or complete')\n .option('--install', 'Install dependencies after init')\n .action((options: InitCommandOptions) => {\n runInit(resolveOptions(options), options.force === true, options.template, options.install === true)\n })\n\n const args = process.argv.slice(2)\n cli.parse(process.argv, { run: false })\n\n if (args.length === 0) {\n cli.outputHelp()\n return\n }\n\n await cli.runMatchedCommand()\n}\n\nmain().catch(error => {\n console.error(error instanceof Error ? error.stack ?? error.message : String(error))\n process.exitCode = 1\n})\n"],"mappings":";;;;;;;;;;;;AAIA,IAAM,gBAAgB;AACtB,IAAM,sBAAsB;AAC5B,IAAM,kBAAkB;AAExB,SAAS,mBAA2B;CAClC,MAAM,WAAW,QAAQ,IAAI;CAC7B,IAAI,CAAC,UAAU,OAAO;CACtB,MAAM,SAAS,OAAO,QAAQ;CAC9B,OAAO,OAAO,UAAU,MAAM,KAAK,SAAS,IAAI,SAAS;AAC3D;AAEA,SAAS,sBAAsB,OAAwB;CACrD,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,iBAAiB,OAAO,OAAO,MAAM;CACzC,IAAI,OAAO,UAAU,UAAU;EAC7B,IAAI,aAAa,SAAS,OAAQ,MAAgC,YAAY,UAC5E,OAAQ,MAA8B;EAExC,IAAI;GACF,OAAO,KAAK,UAAU,KAAK;EAC7B,QAAQ;GACN,OAAO,OAAO,KAAK;EACrB;CACF;CACA,OAAO,OAAO,KAAK;AACrB;AAEA,SAAS,oBAAoB,OAAoC;CAC/D,IAAI,iBAAiB,OACnB,OAAO,MAAM;AAGjB;AAEA,SAAS,eAAe,MAAc,OAAwB;CAC5D,MAAM,6BAAY,IAAI,KAAK,GAAE,YAAY;CACzC,MAAM,UAAU,sBAAsB,KAAK;CAC3C,MAAM,QAAQ,oBAAoB,KAAK;CAEvC,OAAO;EAAC;EAA+B,cAAc;EAAa,iBAAiB;EAAQ,UAAU;EAAW,QAAQ,WAAW,UAAU,KAAA;CAAS,EACnJ,OAAO,OAAO,EACd,KAAK,IAAI;AACd;A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,EACnD,OAAO,qBAAqB,iDAAiD,EAC7E,OAAO,aAAa,iCAAiC,EACrD,QAAQ,YAAgC;EACvC,QAAQ,eAAe,OAAO,GAAG,QAAQ,UAAU,MAAM,QAAQ,UAAU,QAAQ,YAAY,IAAI;CACrG,CAAC;CAEH,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;CACjC,IAAI,MAAM,QAAQ,MAAM,EAAE,KAAK,MAAM,CAAC;CAEtC,IAAI,KAAK,WAAW,GAAG;EACrB,IAAI,WAAW;EACf;CACF;CAEA,MAAM,IAAI,kBAAkB;AAC9B;AAEA,KAAK,EAAE,OAAM,UAAS;CACpB,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,SAAS,MAAM,UAAU,OAAO,KAAK,CAAC;CACnF,QAAQ,WAAW;AACrB,CAAC"}
|
package/output/cli.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { i as createClarifyRuntimeAliases, r as loadClarifyConfig, t as clarifyPlugin } from "./plugin-
|
|
2
|
+
import { a as resolveClarifySite, i as createClarifyRuntimeAliases, r as loadClarifyConfig, t as clarifyPlugin } from "./plugin-DC2f5YAH.js";
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { dirname, extname, isAbsolute, join, normalize, relative, resolve } from "node:path";
|
|
5
|
+
import { lstat, readFile, stat, writeFile } from "node:fs/promises";
|
|
5
6
|
import { fileURLToPath } from "node:url";
|
|
6
7
|
import { build, createLogger, createServer } from "vite";
|
|
7
8
|
import { createRequire } from "node:module";
|
|
8
9
|
import { cac } from "cac";
|
|
9
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
10
10
|
import { copyTemplateDirectory, getTemplateDirectory, resolveTemplate } from "@clarify-labs/templates";
|
|
11
11
|
import { spawnSync } from "node:child_process";
|
|
12
12
|
//#region source/core/log.ts
|
|
@@ -207,6 +207,152 @@ async function runBuild(options) {
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
//#endregion
|
|
210
|
+
//#region source/cli/commands/check.ts
|
|
211
|
+
var LOCAL_LINK_PATTERN = /(?<!!)(?:\[[^\]]*\]\(([^)\s]+)(?:\s+"[^"]*")?\)|<a\s+[^>]*href=["']([^"']+)["'])/gi;
|
|
212
|
+
var ROUTE_EXTENSIONS = new Set([".md", ".mdx"]);
|
|
213
|
+
var IGNORED_SCHEMES = /^[a-z][a-z0-9+.-]*:/i;
|
|
214
|
+
function addDiagnostic(result, diagnostic) {
|
|
215
|
+
if (diagnostic.level === "error") result.errors.push(diagnostic);
|
|
216
|
+
else result.warnings.push(diagnostic);
|
|
217
|
+
}
|
|
218
|
+
function normalizeRoutePath(path) {
|
|
219
|
+
const [withoutHash] = path.split("#");
|
|
220
|
+
const clean = withoutHash.replace(/\/index$/, "") || "/";
|
|
221
|
+
return clean.startsWith("/") ? clean : `/${clean}`;
|
|
222
|
+
}
|
|
223
|
+
function routePathCandidates(href, route) {
|
|
224
|
+
const [withoutHashOrQuery] = href.split(/[?#]/);
|
|
225
|
+
if (!withoutHashOrQuery || withoutHashOrQuery.startsWith("#")) return [];
|
|
226
|
+
if (withoutHashOrQuery.startsWith("/")) return [normalizeRoutePath(withoutHashOrQuery)];
|
|
227
|
+
const joined = normalize(join(dirname(route.path), withoutHashOrQuery)).replaceAll("\\", "/");
|
|
228
|
+
const extension = extname(joined);
|
|
229
|
+
return [normalizeRoutePath(ROUTE_EXTENSIONS.has(extension) ? joined.slice(0, -extension.length) : joined)];
|
|
230
|
+
}
|
|
231
|
+
async function pathExists(filePath) {
|
|
232
|
+
try {
|
|
233
|
+
await stat(filePath);
|
|
234
|
+
return true;
|
|
235
|
+
} catch {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function isLocalHref(href) {
|
|
240
|
+
return Boolean(href) && !href.startsWith("#") && !href.startsWith("//") && !IGNORED_SCHEMES.test(href);
|
|
241
|
+
}
|
|
242
|
+
async function resolveLocalFileLink(href, route, contentRoot) {
|
|
243
|
+
const [withoutHashOrQuery] = href.split(/[?#]/);
|
|
244
|
+
if (!withoutHashOrQuery || withoutHashOrQuery.startsWith("/")) return false;
|
|
245
|
+
const target = resolve(dirname(route.filePath), withoutHashOrQuery);
|
|
246
|
+
const relativeTarget = relative(contentRoot, target);
|
|
247
|
+
if (relativeTarget.startsWith("..") || isAbsolute(relativeTarget)) return false;
|
|
248
|
+
if (await pathExists(target)) return true;
|
|
249
|
+
if (!extname(target)) return pathExists(`${target}.md`) || pathExists(`${target}.mdx`) || pathExists(join(target, "index.md")) || pathExists(join(target, "index.mdx"));
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
async function checkContentDirectory(contentRoot, result) {
|
|
253
|
+
try {
|
|
254
|
+
if (!(await lstat(contentRoot)).isDirectory()) addDiagnostic(result, {
|
|
255
|
+
level: "error",
|
|
256
|
+
code: "content-not-directory",
|
|
257
|
+
message: `Content path is not a directory: ${contentRoot}`,
|
|
258
|
+
filePath: contentRoot
|
|
259
|
+
});
|
|
260
|
+
} catch {
|
|
261
|
+
addDiagnostic(result, {
|
|
262
|
+
level: "error",
|
|
263
|
+
code: "content-missing",
|
|
264
|
+
message: `Content directory does not exist: ${contentRoot}`,
|
|
265
|
+
filePath: contentRoot
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function checkDuplicateRoutes(routes, result) {
|
|
270
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
271
|
+
for (const route of routes) {
|
|
272
|
+
const key = `${route.locale ?? ""}:${route.path}`;
|
|
273
|
+
byPath.set(key, [...byPath.get(key) ?? [], route]);
|
|
274
|
+
}
|
|
275
|
+
for (const duplicated of byPath.values()) {
|
|
276
|
+
if (duplicated.length < 2) continue;
|
|
277
|
+
for (const route of duplicated) addDiagnostic(result, {
|
|
278
|
+
level: "error",
|
|
279
|
+
code: "duplicate-route",
|
|
280
|
+
message: `Route "${route.path}" is defined by multiple files: ${duplicated.map((route) => relative(process.cwd(), route.filePath)).join(", ")}`,
|
|
281
|
+
filePath: route.filePath,
|
|
282
|
+
routePath: route.path
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function checkFallbackRoutes(routes, result) {
|
|
287
|
+
for (const route of routes) {
|
|
288
|
+
if (!route.isFallback) continue;
|
|
289
|
+
addDiagnostic(result, {
|
|
290
|
+
level: "warning",
|
|
291
|
+
code: "i18n-fallback-route",
|
|
292
|
+
message: `Route "${route.path}" falls back to ${route.locale ?? "default"} content from ${relative(process.cwd(), route.filePath)}`,
|
|
293
|
+
filePath: route.filePath,
|
|
294
|
+
routePath: route.path
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async function checkLocalLinks(routes, contentRoot, result) {
|
|
299
|
+
const routePaths = new Set(routes.map((route) => route.path));
|
|
300
|
+
for (const route of routes) {
|
|
301
|
+
if (route.kind !== "mdx" || !route.content) continue;
|
|
302
|
+
for (const match of route.content.matchAll(LOCAL_LINK_PATTERN)) {
|
|
303
|
+
const href = match[1] ?? match[2];
|
|
304
|
+
if (!href || !isLocalHref(href)) continue;
|
|
305
|
+
if (routePathCandidates(href, route).some((candidate) => routePaths.has(candidate))) continue;
|
|
306
|
+
if (await resolveLocalFileLink(href, route, contentRoot)) continue;
|
|
307
|
+
addDiagnostic(result, {
|
|
308
|
+
level: "error",
|
|
309
|
+
code: "broken-link",
|
|
310
|
+
message: `Broken local link "${href}" in route "${route.path}"`,
|
|
311
|
+
filePath: route.filePath,
|
|
312
|
+
routePath: route.path
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function printTextResult(result, strict) {
|
|
318
|
+
const diagnostics = [...result.errors, ...result.warnings];
|
|
319
|
+
if (diagnostics.length === 0) {
|
|
320
|
+
console.log("✓ Clarify check passed");
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
for (const diagnostic of diagnostics) {
|
|
324
|
+
const location = diagnostic.filePath ? ` ${relative(process.cwd(), diagnostic.filePath)}` : "";
|
|
325
|
+
const route = diagnostic.routePath ? ` (${diagnostic.routePath})` : "";
|
|
326
|
+
console.log(`${diagnostic.level.toUpperCase()} ${diagnostic.code}${location}${route}`);
|
|
327
|
+
console.log(` ${diagnostic.message}`);
|
|
328
|
+
}
|
|
329
|
+
const warningExit = strict && result.warnings.length > 0;
|
|
330
|
+
console.log(`\n${result.errors.length} error(s), ${result.warnings.length} warning(s)${warningExit ? " (--strict treats warnings as failures)" : ""}`);
|
|
331
|
+
}
|
|
332
|
+
async function runCheck(options = {}) {
|
|
333
|
+
const root = resolve(options.root ?? process.cwd());
|
|
334
|
+
const site = await resolveClarifySite({
|
|
335
|
+
...existsSync(root) ? await loadClarifyConfig(root, {
|
|
336
|
+
command: "build",
|
|
337
|
+
mode: "production"
|
|
338
|
+
}) : {},
|
|
339
|
+
projectRoot: root,
|
|
340
|
+
rootDirectory: options.content,
|
|
341
|
+
outputDirectory: options.output
|
|
342
|
+
}, { includeHtmlShellPlugin: false });
|
|
343
|
+
const result = {
|
|
344
|
+
errors: [],
|
|
345
|
+
warnings: []
|
|
346
|
+
};
|
|
347
|
+
await checkContentDirectory(site.contentRoot, result);
|
|
348
|
+
checkDuplicateRoutes(site.routes, result);
|
|
349
|
+
checkFallbackRoutes(site.routes, result);
|
|
350
|
+
await checkLocalLinks(site.routes, site.contentRoot, result);
|
|
351
|
+
if (options.format === "json") console.log(JSON.stringify(result, null, 2));
|
|
352
|
+
else printTextResult(result, Boolean(options.strict));
|
|
353
|
+
if (result.errors.length > 0 || options.strict && result.warnings.length > 0) process.exitCode = 1;
|
|
354
|
+
}
|
|
355
|
+
//#endregion
|
|
210
356
|
//#region source/cli/commands/dev.ts
|
|
211
357
|
async function runDev(options) {
|
|
212
358
|
const server = await createServer(await createViteConfig(options, {
|
|
@@ -219,7 +365,7 @@ async function runDev(options) {
|
|
|
219
365
|
}
|
|
220
366
|
var cliPackageVersion = {
|
|
221
367
|
name: "@clarify-labs/cli",
|
|
222
|
-
version: "0.6.
|
|
368
|
+
version: "0.6.6",
|
|
223
369
|
license: "AGPL-3.0-only",
|
|
224
370
|
type: "module",
|
|
225
371
|
repository: {
|
|
@@ -411,6 +557,9 @@ async function main() {
|
|
|
411
557
|
withSharedOptions(cli.command("build", "Build the static documentation site")).action(async (options) => {
|
|
412
558
|
await runBuild(resolveOptions(options));
|
|
413
559
|
});
|
|
560
|
+
withSharedOptions(cli.command("check", "Validate the documentation project")).option("--strict", "Treat warnings as failures").option("--format <format>", "Output format: text or json").action(async (options) => {
|
|
561
|
+
await runCheck(options);
|
|
562
|
+
});
|
|
414
563
|
withSharedOptions(cli.command("init", "Create a Clarify project scaffold")).option("--force", "Overwrite files created by init").option("--template <name>", "Template to use: minimal, standard, or complete").option("--install", "Install dependencies after init").action((options) => {
|
|
415
564
|
runInit(resolveOptions(options), options.force === true, options.template, options.install === true);
|
|
416
565
|
});
|