-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.js
executable file
·71 lines (61 loc) · 1.82 KB
/
index.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
64
65
66
67
68
69
70
71
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const validurl = require('valid-url').is_web_uri;
const updateNotifier = require('update-notifier');
const crawl = require('./lib/crawl');
const pkg = require('./package.json');
// Check for updates every 12 hours
updateNotifier({
pkg,
updateCheckInterval: 1000 * 60 * 60 * 12,
}).notify();
const cli = meow(
`
Usage
$ backstop-crawl <url>
Options
--outfile, -o Save the backstop config to this file
--debug Logs out errors produced while crawling
--ignore-robots Ignore the sites robots.txt
--ignore-ssl-errors Treat any certificate as valid (e.g. self-signed
or expired)
--allow-subdomains Allow crawling links found to subdomains of the
current domain
--limit-similar[=3] Limits the number of similar URLs to a set number
Defaults to 3
e.g /blog/1, /blog/2, /blog/3
--reference-url Allows a reference URL to be used in testing
Examples
$ backstop-crawl http://localhost
`,
{
alias: {
o: 'outfile',
},
}
);
if (cli.flags.limitSimilar) {
if (!Number.isInteger(cli.flags.limitSimilar)) {
// Set default if true
cli.flags.limitSimilar = 3;
}
}
if (cli.flags.referenceUrl) {
if (!validurl(cli.flags.referenceUrl)) {
console.error(
`> Error: "${cli.flags.referenceUrl}" isn't a valid reference URL`
);
process.exit(1);
}
}
if (cli.input.length > 0) {
if (validurl(cli.input[0])) {
crawl(cli.input[0], cli.flags);
} else {
console.error(`> Error: "${cli.input[0]}" isn't a valid URL`);
process.exit(1);
}
} else {
cli.showHelp();
}