forked from Laboratoria/DEV004-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
95 lines (71 loc) · 3.28 KB
/
cli.js
File metadata and controls
95 lines (71 loc) · 3.28 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
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
#! /usr/bin/env node
import { resolvePlugin } from "@babel/core";
import chalk from 'chalk';
import { statsTotal, brokenStats, uniqueStats, mdLinks } from "./index.js"
const filePath = process.argv[2];
// mdLinks(filePath, { validate: true })
// .then(info => {
// console.log(info)
// })
// .catch(err => {
// console.log(err)
// })
//Checar options.
if (process.argv[2] === undefined) {
console.log("Por favor ingrese una ruta o escriba --help");
} else if (process.argv[3] === undefined) {
mdLinks(filePath, { validate: false })
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
}
else if (process.argv[2] === "--help") {
console.log(chalk.bold.cyan(`Para validar los links de tu(s) archivo(s), puedes usar las siguientes opciones:
--validate: Revisa si tu(s) link(s) funciona o no,
--stats: Te dará la cantidad total de links y cantidad de links unicos,
--validate--stats: Te dará la cantidad total de links,cantidad de links unicos
y cantidad de links rotos"`));
} else {
mdLinks(filePath, { validate: true })
.then((res) => {
const total = `Total: ${statsTotal(res)}`;
const unique = `Unique: ${uniqueStats(res)}`;
const broken = `Broken: ${brokenStats(res)}`;
const election1 = process.argv[4] === "--stats" && process.argv[3] === "--validate";
const election2 = process.argv[4] === "--validate" && process.argv[3] === "--stats";
const election3 = process.argv[3] === "--validate" && process.argv[4] === undefined;
if (election1 || election2) {
console.log(chalk.bgCyan.black("Cargando Links: "));
console.log(chalk.bold.magenta(`${total}\n${unique}\n${broken}`));
} else if (process.argv[3] === "--stats") {
console.log(chalk.bgCyan.black("Cargando Links: "));
console.log(chalk.bold.yellow(`${total}\n${unique}`));
} else if (election3) {
console.log(res);
} else {
console.log(chalk.bold.blueBright(`Escribe "md-links --help" para mayor informacion de tus links"
`));
}
})
}
// mdLinks(filePath, {validate: true})
// .then((res) => {
// const total = `Total: ${statsTotal(res)}`;
// const unique = `Unique: ${uniqueStats(res)}`;
// const broken = `Broquen: ${brokenStats(res)}`;
// const election1 = fp.argv[4] === "--stats" && fp.argv[3] === "--validate";
// const election2 = fp.argv[4] === "--validate" && fp.argv[3] === "--stats";
// const election3 = fp.argv[3] === "--validate" && fp.argv[4] === undefined;
// if (election1 || election2) {
// console.log(`${total}\n${unique}\n${broken}`);
// } else if (fp.argv[3] === "--stats") {
// console.log(`${total}\n${unique}`);
// } else if (election3) {
// console.log(res);
// } else {
// console.log("Escribir una opcion");
// }
// })