mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 07:57:40 +00:00
Docs: unify link audit entrypoint (#55912)
Merged via squash.
Prepared head SHA: 6b1ccb9f1f
Co-authored-by: velvet-shark <126378+velvet-shark@users.noreply.github.com>
Co-authored-by: velvet-shark <126378+velvet-shark@users.noreply.github.com>
Reviewed-by: @velvet-shark
This commit is contained in:
committed by
GitHub
parent
d35f37a58c
commit
47ae562cc9
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { spawnSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
@@ -288,12 +289,32 @@ export function auditDocsLinks() {
|
||||
return { checked, broken };
|
||||
}
|
||||
|
||||
function isCliEntry() {
|
||||
const cliArg = process.argv[1];
|
||||
return cliArg ? import.meta.url === pathToFileURL(cliArg).href : false;
|
||||
}
|
||||
/**
|
||||
* @param {{
|
||||
* args?: string[];
|
||||
* spawnSyncImpl?: typeof spawnSync;
|
||||
* }} [options]
|
||||
*/
|
||||
export function runDocsLinkAuditCli(options = {}) {
|
||||
const args = options.args ?? process.argv.slice(2);
|
||||
if (args.includes("--anchors")) {
|
||||
const spawnSyncImpl = options.spawnSyncImpl ?? spawnSync;
|
||||
const result = spawnSyncImpl("mint", ["broken-links", "--check-anchors"], {
|
||||
cwd: DOCS_DIR,
|
||||
stdio: "inherit",
|
||||
});
|
||||
|
||||
if (result.error?.code === "ENOENT") {
|
||||
const fallback = spawnSyncImpl("pnpm", ["dlx", "mint", "broken-links", "--check-anchors"], {
|
||||
cwd: DOCS_DIR,
|
||||
stdio: "inherit",
|
||||
});
|
||||
return fallback.status ?? 1;
|
||||
}
|
||||
|
||||
return result.status ?? 1;
|
||||
}
|
||||
|
||||
if (isCliEntry()) {
|
||||
const { checked, broken } = auditDocsLinks();
|
||||
console.log(`checked_internal_links=${checked}`);
|
||||
console.log(`broken_links=${broken.length}`);
|
||||
@@ -302,7 +323,14 @@ if (isCliEntry()) {
|
||||
console.log(`${item.file}:${item.line} :: ${item.link} :: ${item.reason}`);
|
||||
}
|
||||
|
||||
if (broken.length > 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
return broken.length > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
function isCliEntry() {
|
||||
const cliArg = process.argv[1];
|
||||
return cliArg ? import.meta.url === pathToFileURL(cliArg).href : false;
|
||||
}
|
||||
|
||||
if (isCliEntry()) {
|
||||
process.exit(runDocsLinkAuditCli());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user