forked from Laboratoria/GDL004-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
40 lines (36 loc) · 1.57 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
const mdLink = require('./utils.js'),
process = require('process');
chalk = require('chalk');
//const argv = require('./yargs.js').argv;
const options = process.argv[3];
let pathUser= process.argv[2];
async function mdLinks(pathUser, options){
let pathFile = '';
let getLinks = '';
try {
pathFile = await mdLink.validateFile(pathUser);
console.log(chalk.bold.rgb(30, 166, 51).inverse('Correct File extension '));
getLinks = await mdLink.readFile(pathFile);
getLinksArray = await mdLink.getLinks(getLinks);
} catch (e) {
console.error(e);
}
if(options === '--stats'){
const stats = await mdLink.statsLinks(getLinksArray)
console.log({'TOTAL' : stats.TOTAL, 'UNIQUE': stats.UNIQUE});
} else if(options === '--validate'){
const wrongLinks = await mdLink.validateLinks(getLinksArray);
const getLinksText = await mdLink.getLinksText(pathFile)
const showLinksText= await mdLink.showLinksText(getLinksText)
const showStatus = await mdLink.getStatus(showLinksText);
console.log({'ok':showStatus,'bad':wrongLinks.wrongLinks});
} else if(options === '--validate--stats'){
const stats = await mdLink.statsLinks(getLinksArray)
console.log(stats);
} else {
const getLinksText = await mdLink.getLinksText(pathFile)
const showLinksText= await mdLink.showLinksText(getLinksText)
console.log(showLinksText);
}
}
mdLinks(pathUser, options)