-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·66 lines (53 loc) · 1.32 KB
/
index.js
File metadata and controls
executable file
·66 lines (53 loc) · 1.32 KB
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
#!/usr/bin/env node
/**
* Created by shyam on 30/05/16.
*/
"use strict";
let program = require('commander');
let validator = require("./validator");
let Crawler = require("./crawler");
let urlx = require("url");
let chalk = require("chalk");
let url = null;
let crawler = null;
program.version('0.1.4')
.option('-d, --depth <depth>', 'Depth to search. Should be a number')
.arguments('<url>')
.action(function(urlParam) {
url = urlParam;
})
.parse(process.argv);
function init () {
var options = {
depth: program.depth,
url: url
};
if (! validator.validateOptions(options)) {
/**
* Print help if input is not valid
*/
program.outputHelp();
process.exit(-1)
} else {
/**
* If depth is not mentioned the crawler continues until the process is killed
*/
crawler = new Crawler(options);
crawler.crawl(options.url, options.depth).then(() => {
exit(0);
});
}
process.on("exit", function(code) {
if(code != -1) {
onFinish();
}
});
process.on("SIGINT", function() {
process.exit(2);
})
}
function onFinish() {
console.log(chalk.green(crawler.urlRepo.size +" Result(s) found"));
process.exit();
}
init();