-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.js
63 lines (47 loc) · 1.53 KB
/
report.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const {Readable} = require('stream')
const chalk = require('chalk')
const fs = require('fs')
class Report {
constructor({visitedUrls, errors, count, mixedContentLocations, path}) {
Object.assign(this, {
visitedUrls,
errors,
count,
path,
mixedContentLocations
})
}
generate() {
return new Promise((resolve, reject) => {
// const writeStream = fs.createWriteStream(this.path)
// const readStream = new Readable({objectMode: true})
// readStream._read = () => {
// // Must be implemeted, but we're pushing manually
// }
// readStream.on('error', () => {
// })
// readStream.on('end', () => {
// resolve(true)
// })
// TODO: Implement HTML, CSV, text formats using a TransformStream in objectMode
//readStream.pipe(writeStream)
const report = `
${chalk.yellow('VISITED URLS')}
${[...this.visitedUrls].map(url => {return `${url} (found ${chalk.blue.bold(this.count[url])} times while crawling)`}).join('\n')}
${chalk.red('ERRORS')}
${this.errors.size > 0 ? [...this.errors].join('\n') : chalk.white.bgGreen.bold('No errors')}
${chalk.blue('Mixed content issues')}
${JSON.stringify(this.mixedContentLocations)}
${chalk.yellow('Number of times we encountered internal links')}
${JSON.stringify(this.count, null, 2)}
`
fs.writeFile(this.path, report, 'utf-8', error => {
if (error) {
reject(error)
}
resolve(report)
})
})
}
}
module.exports = { Report }