forked from Laboratoria/MEX008-FE-md-link
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
97 lines (90 loc) · 3.18 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
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
const path = require('path');
const fs = require('fs');
const validateLinks = require('./modules/validate.js');
const stats = require('./modules/stats.js');
const read = require('./modules/readMarkdown.js');
const convert = require('./modules/convertMarkdown.js');
const broken = require('./modules/broken');
const help = require('./modules/help');
module.exports = mdLinks = (url,optionOne,optionTwo) =>{
const comandos = new Promise ( (resolve,reject) => {
if(url === 'help'){
const instrucciones = help();
resolve(instrucciones);
}
else if(url != null && optionOne == null && optionTwo == null){
// const URL = path.resolve(url);
read(url)
.then((data)=>{
// console.log(data);
return convert(data,url)
})
.then((arrayObject)=>{
resolve(arrayObject);
})
.catch((error)=>{
reject(error);
})
}
else if(url != null && optionOne != null && optionTwo == null){
if(optionOne === '--validate'){
read(url)
.then((data)=>{
return convert(data,url);
})
.then((arrayObject)=>{
return validateLinks(arrayObject);
})
.then((objectValidated)=>{
return Promise.all(objectValidated);
})
.then(data => resolve(data))
.catch((error)=>{
reject(error);
})
}
else if(optionOne === '--stats'){
read(url)
.then((data)=>{
return convert(data,url);
})
.then((arrayObject)=>{
return stats(arrayObject);
})
.then(data=> resolve(data))
.catch((error)=>{
reject(error);
})
}
else{
const err = new Error('Opcion no valida, utiliza: mdLinks HELP');
return resolve(err);
}
}
else if(url != null && optionOne === '--stats' && optionTwo === '--validate'){
read(url)
.then((data)=>{
return convert(data,url);
})
.then((arrayObject)=>{
return validateLinks(arrayObject);
})
.then((objectValidated)=>{
return Promise.all(objectValidated);
})
.then((data) =>{
const objectStats = stats(data);
return broken(objectStats,data);
})
.then(statsBroken => resolve(statsBroken))
.catch((error)=>{
reject(error);
})
}
else{
const error = 'Error, deberias ingresar una ruta al menos o ingresa mdLinks help'
reject(error);
}
});
return comandos;
}