-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsitemap-copier.ts
38 lines (34 loc) · 1.18 KB
/
sitemap-copier.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/** BUG: https://github.com/withastro/adapters/issues/445 */
import { readdir, cp } from "node:fs/promises";
import * as path from "node:path";
import type { AstroIntegration } from "astro";
export function sitemapCopier(): AstroIntegration {
return {
name: "sitemap-copier",
hooks: {
"astro:build:done": async ({ logger }) => {
const buildLogger = logger.fork("sitemap-copier");
buildLogger.info("Copying xml files from dist to vercel out");
try {
const files = await readdir("./dist");
const xmlFiles = files.filter(
(file) =>
path.extname(file).toLowerCase() === ".xml" &&
path.basename(file).toLowerCase().startsWith("sitemap"),
);
buildLogger.info(xmlFiles.join(", "));
// eslint-disable-next-line no-restricted-syntax
for (const file of xmlFiles) {
const sourcePath = path.join("./dist", file);
const destPath = path.join("./.vercel/output/static", file);
// eslint-disable-next-line no-await-in-loop
await cp(sourcePath, destPath);
}
buildLogger.info("All XML files copied successfully");
} catch (error) {
buildLogger.error(`Error copying files: ${error}`);
}
},
},
};
}