-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
35 lines (28 loc) · 916 Bytes
/
main.js
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
const { crawlPage } = require('./crawl.js');
const { printReport, writeReportToFile } = require('./report.js');
/**
* The main function for crawling a website and generating a report of all unique pages within the domain.
*
* @returns {Promise<void>}
*/
async function main () {
if (process.argv.length < 3) {
console.log('no website provided')
process.exit(1)
}
if (process.argv.length > 3) {
console.log('to many command line args')
process.exit(1)
}
// Can access the structure of process.arg array
// first and second element are not command line arg
// for(const arg of process.argv) {
// console.log(arg)
// }
const baseURL = process.argv[2];
console.log(`starting crawl of ${baseURL}`)
const pages = await crawlPage(baseURL, baseURL, {});
printReport(pages)
writeReportToFile(pages, 'report.csv')
}
main()