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:
Thomas Camlong committed 2026-06-11 18:55:07 +02:00
1 parent 9e421c67bd
commit 7f8b0121b3
1 file changed
+25 -19
+25 -19
View File
@@ -56,33 +56,39 @@ const updateSitemapTypeFileAsync = async (sitemapPathType: string) => {
sitemapPathType +
";\n";
await fs.writeFile(path.join(__dirname, "homarr-docs-sitemap.ts"), content);
await fs.writeFile(outputPath, content);
};
/**
* This script fetches the sitemap.xml and generates the HomarrDocumentationPath type
* which is used for typesafe documentation links
*/
// 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 = [
...Object.values(integrationDocSlugs).filter(Boolean).map((slug) => `/docs/integrations/${slug}`),
...Object.values(widgetDocSlugs).filter(Boolean).map((slug) => `/docs/widgets/${slug}`),
];
const slugMapPaths = [
...Object.values(integrationDocSlugs)
.filter(Boolean)
.map((slug) => `/docs/integrations/${slug}`),
...Object.values(widgetDocSlugs)
.filter(Boolean)
.map((slug) => `/docs/widgets/${slug}`),
];
const outputPath = path.join(__dirname, "homarr-docs-sitemap.ts");
const main = async () => {
let paths: string[];
try {
const sitemapXml = await fetchSitemapAsync();
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) {
if (!paths.includes(p)) {
paths.push(p);
}
}
const sitemapPathType = createSitemapPathType(paths);
await updateSitemapTypeFileAsync(sitemapPathType);
};