-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
121 lines (108 loc) · 4.36 KB
/
app.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#! /usr/bin/env node
const path = require("path");
const readline = require("readline");
const fs = require("fs");
const os = require("os");
const claP = require(path.join(__dirname,'/core_modules/claParser')).init();
const dirH = require(path.join(__dirname,'/core_modules/dirHandler'));
const urlVl = require(path.join(__dirname,'/core_modules/urlValidator')).init;
const processor = require(path.join(__dirname,'/core_modules/processor'));
const logger = require(path.join(__dirname,'/core_modules/logger.js')).init();
dirH.init();
var rl = readline.createInterface({
input : process.stdin,
output: process.stdout,
terminal:false
})
var rlAssist = {
getInput : function(){
var that = this;
rl.question("->enter the path to the file containing urls :\n",function(ans){
if(ans.length>0){
that.key = ans;
that.getConfirm();
}else{
that.getInput();
}
})
},
getConfirm :function(){
var that = this;
rl.question("->press 'y' to continue 'c' to cancel\n",function(ans){
switch(ans){
case 'y':
if(that.isValidSysPath(that.key)){
that.forWard(that.key);
}else{
logger.warn("file not found");
that.getInput();
}
break;
case 'c':
rl.close();
break;
default:
that.getConfirm();
}
})
},
isValidSysPath : function(path){
var fExist = (fs.existsSync(path))?true:false;
return(fExist);
},
isValidUri : function(path){
var success;
urlVl(path,function(data){
success = (data)?true:false;
})
return success;
},
forWard : function(data,target,type){
switch(type){
case "link":
processor.init(data,target);
break;
case "dir":
var payload = fs.readFileSync(data,"utf8");
urlVl(payload,function(data){
if(data){
processor.init(data,target);
}else{
logger.error("no urls found");
// rlAssist.getInput();
process.exit(1);
}
})
break;
}
}
}
var kickStart = function(){
if(process.argv.length>=3){
if(claP.dir || claP.link){
if(claP.dir){
if(rlAssist.isValidSysPath(claP.dir)){
var targetDir = claP.project || false;//(process.argv[3])?process.argv[3]:false;
rlAssist.forWard(claP.dir,targetDir,"dir");
}else{
logger.warn("file not found");
//rlAssist.getInput();
process.exit(1);
}
}
if(claP.link){
if(rlAssist.isValidUri(claP.link)){
var targetDir = claP.project || false;//(process.argv[3])?process.argv[3]:false;
rlAssist.forWard(claP.link,targetDir,"link");
}else{
logger.warn("invalid url");
process.exit(1);
}
}
}else{
logger.verbose("->invalid arguments. Enter sf -h for help\n");
}
}else{
rlAssist.getInput();
}
}()