forked from Laboratoria/SAP009-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
32 lines (29 loc) · 801 Bytes
/
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
#!/usr/bin/env node
const {mdLinks}= require('./index.js');
const { chalk }= require('chalk');
const caminhoArquivo = process.argv[2];
console.log(process.argv);
const options ={
validate: process.argv.includes('--validate'),
}
mdLinks(caminhoArquivo, options)
.then((links) => {
links.forEach((link) => {
let status = link.status;
if(status === 'Fail'){
status = chalk.red(status);
}
const saida = formatarSaida(caminhoArquivo, options, link);
process.stdout.write(saida);
});
})
.catch((erro) => {
console.error(erro);
});
function formatarSaida (caminhoArquivo, options, link){
if (!options.validate){
return `${link.url} | ${caminhoArquivo}\n`;
} else{
return `${link.status} | ${link.url} | ${caminhoArquivo}\n`;
}
};