scripts/verify-links: add support for verifying links to new API reference
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
+29
-2
@@ -99,6 +99,17 @@ async function verifyUrl(basePath, absUrl, docPages) {
|
||||
}
|
||||
}
|
||||
|
||||
if (url.startsWith('/api/stable/')) {
|
||||
const apiPath = resolvePath(
|
||||
projectRoot,
|
||||
`type-docs/${url.slice('/api/stable/'.length)}`,
|
||||
);
|
||||
if (existsSync(apiPath)) {
|
||||
return undefined;
|
||||
}
|
||||
return { url, basePath, apiPath, problem: 'api-missing' };
|
||||
}
|
||||
|
||||
const staticPath = resolvePath(projectRoot, 'microsite/static', `.${url}`);
|
||||
if (existsSync(staticPath)) {
|
||||
return undefined;
|
||||
@@ -182,7 +193,6 @@ async function main() {
|
||||
process.chdir(projectRoot);
|
||||
|
||||
const isCI = Boolean(process.env.CI);
|
||||
const hasReference = existsSync(resolvePath(projectRoot, 'docs/reference'));
|
||||
|
||||
const files = await listFiles('.');
|
||||
const mdFiles = files.filter(f => f.endsWith('.md'));
|
||||
@@ -196,15 +206,24 @@ async function main() {
|
||||
badUrls.push(...badFileUrls);
|
||||
}
|
||||
|
||||
const hasReference = existsSync(resolvePath(projectRoot, 'docs/reference'));
|
||||
if (!hasReference) {
|
||||
console.log(
|
||||
"Skipping API reference link validation, no docs/reference/ dir. Reference docs can be built with 'yarn build:api-docs'",
|
||||
);
|
||||
}
|
||||
|
||||
const hasApiDocs = existsSync(resolvePath(projectRoot, 'type-docs'));
|
||||
if (!hasApiDocs) {
|
||||
console.log(
|
||||
"Skipping API docs link validation, no type-docs/ dir. API docs can be built with 'yarn backstage-repo-tools package-docs'",
|
||||
);
|
||||
}
|
||||
|
||||
if (badUrls.length) {
|
||||
console.log(`Found ${badUrls.length} bad links within repo`);
|
||||
for (const { url, basePath, problem } of badUrls) {
|
||||
for (const badUrl of badUrls) {
|
||||
const { url, basePath, problem } = badUrl;
|
||||
if (problem === 'missing') {
|
||||
if (url.startsWith('../reference/') && !isCI && !hasReference) {
|
||||
continue;
|
||||
@@ -238,6 +257,14 @@ async function main() {
|
||||
if (suggestion) {
|
||||
console.error(` Replace with: ${suggestion}`);
|
||||
}
|
||||
} else if (problem === 'api-missing') {
|
||||
if (!hasApiDocs) {
|
||||
continue;
|
||||
}
|
||||
console.error('Invalid API docs link');
|
||||
console.error(` From: ${basePath}`);
|
||||
console.error(` To: ${url}`);
|
||||
console.error(` Resolved path: ${badUrl.apiPath}`);
|
||||
} else if (problem === 'not-relative') {
|
||||
console.error('Links within /docs/ must be relative');
|
||||
console.error(` From: ${basePath}`);
|
||||
|
||||
Reference in New Issue
Block a user