-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
33 lines (26 loc) · 732 Bytes
/
main.ts
File metadata and controls
33 lines (26 loc) · 732 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
import { crawl } from "./src/crawl"
import { IPages, OutputIPages } from "./src/types"
import { getSitemap } from "./src/api"
// if ran via npm run crawl [URL]
async function main() {
if (process.argv.length < 3) {
console.log("No website provided")
process.exit(1)
}
if (process.argv.length > 3) {
console.log("Too many args, please provide a website")
process.exit(1)
}
let baseURL = process.argv[2]
try {
new URL(baseURL)
}
catch (err: unknown) {
console.log("Invalid URL, exiting")
process.exit(1)
}
console.log("starting crawler on", baseURL)
// valid url from this point on
return await getSitemap(baseURL)
}
main()