forked from Utility-Gods/node-sitemap-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
42 lines (35 loc) · 960 Bytes
/
cli.js
File metadata and controls
42 lines (35 loc) · 960 Bytes
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
39
40
41
42
#!/usr/bin/env node
const { generateSitemapAndRobots } = require("./dist/index.js");
const defaultOptions = {
baseUrl: "http://localhost:3000",
outDir: "./public",
maxDepth: 3,
};
function run(args = process.argv.slice(2)) {
const options = {
...defaultOptions,
...Object.fromEntries(
args
.map((arg) => arg.split("="))
.map(([key, value]) => [
key,
key === "maxDepth" ? parseInt(value) : value,
])
),
};
console.log("Generating sitemap with options:", options);
return generateSitemapAndRobots(options)
.then(() => {
console.log("Sitemap generated successfully");
})
.catch((err) => {
console.error("Sitemap generation failed:", err);
process.exit(1);
});
}
// Only run the function if this script is executed directly
if (require.main === module) {
run();
}
// Export the run function for testing or external use
module.exports = { run };