fix(definitions): gracefully handle sitemap fetch failure in codegen
The postinstall codegen script crashes CI when homarr.dev/sitemap.xml is unreachable. Now catches fetch errors and keeps the existing committed homarr-docs-sitemap.ts instead of crashing.
This commit is contained in:
1 file changed
+25
-19
@@ -56,33 +56,39 @@ const updateSitemapTypeFileAsync = async (sitemapPathType: string) => {
|
|||||||
sitemapPathType +
|
sitemapPathType +
|
||||||
";\n";
|
";\n";
|
||||||
|
|
||||||
await fs.writeFile(path.join(__dirname, "homarr-docs-sitemap.ts"), content);
|
await fs.writeFile(outputPath, content);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
const slugMapPaths = [
|
||||||
* This script fetches the sitemap.xml and generates the HomarrDocumentationPath type
|
...Object.values(integrationDocSlugs).filter(Boolean).map((slug) => `/docs/integrations/${slug}`),
|
||||||
* which is used for typesafe documentation links
|
...Object.values(widgetDocSlugs).filter(Boolean).map((slug) => `/docs/widgets/${slug}`),
|
||||||
*/
|
];
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
|
||||||
const main = async () => {
|
|
||||||
const sitemapXml = await fetchSitemapAsync();
|
|
||||||
const sitemapData = parseXml(sitemapXml);
|
|
||||||
const paths = mapSitemapXmlToPaths(sitemapData);
|
|
||||||
paths.push("/sitemap.xml");
|
|
||||||
|
|
||||||
const slugMapPaths = [
|
const outputPath = path.join(__dirname, "homarr-docs-sitemap.ts");
|
||||||
...Object.values(integrationDocSlugs)
|
|
||||||
.filter(Boolean)
|
const main = async () => {
|
||||||
.map((slug) => `/docs/integrations/${slug}`),
|
let paths: string[];
|
||||||
...Object.values(widgetDocSlugs)
|
try {
|
||||||
.filter(Boolean)
|
const sitemapXml = await fetchSitemapAsync();
|
||||||
.map((slug) => `/docs/widgets/${slug}`),
|
const sitemapData = parseXml(sitemapXml);
|
||||||
];
|
paths = mapSitemapXmlToPaths(sitemapData);
|
||||||
|
} catch {
|
||||||
|
const exists = await fs.access(outputPath).then(() => true, () => false);
|
||||||
|
if (exists) {
|
||||||
|
console.warn("Could not fetch sitemap from homarr.dev, keeping existing generated file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.warn("Could not fetch sitemap from homarr.dev and no existing file, generating from slug maps only");
|
||||||
|
paths = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
paths.push("/sitemap.xml");
|
||||||
for (const p of slugMapPaths) {
|
for (const p of slugMapPaths) {
|
||||||
if (!paths.includes(p)) {
|
if (!paths.includes(p)) {
|
||||||
paths.push(p);
|
paths.push(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sitemapPathType = createSitemapPathType(paths);
|
const sitemapPathType = createSitemapPathType(paths);
|
||||||
await updateSitemapTypeFileAsync(sitemapPathType);
|
await updateSitemapTypeFileAsync(sitemapPathType);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user