forked from evanderkoogh/node-sitemap-stream-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·50 lines (42 loc) · 1.15 KB
/
cli.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
#!/usr/bin/env node
var program = require('commander'),
baseurl;
program
.arguments('<baseurl>')
.option('-o, --outfile <file>', 'a file to output the URL list to')
.option('-v, --verbose', 'output additional status info')
.action(function(base) {
var sitemaps = require('./index'),
fs = require('fs'), wstream;
baseurl = base;
if (program.outfile) {
wstream = fs.createWriteStream(program.outfile);
}
var urlOut = function(url, sitemap) {
if (wstream) {
wstream.write(url + '\n');
} else {
console.log(url);
}
},
done = function(err, sitemaps) {
if (wstream) {
wstream.end();
}
if (err) {
console.error(new Error(err));
} else if (sitemaps && program.verbose) {
console.error('Parsed sitemaps: ' + sitemaps);
}
};
sitemaps.sitemapsInRobots(base + '/robots.txt', function(err, urls) {
if (!urls || urls.length < 1) {
urls = [base + '/sitemap.xml'];
}
sitemaps.parseSitemaps(urls, urlOut, done);
});
})
.parse(process.argv);
if (typeof baseurl === 'undefined') {
program.help();
}