forked from Laboratoria/DEV010-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (52 loc) · 2.09 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
const { mdLinks } = require('./lib/mdLinks.js');
const isLinkValid = require('./lib/validateLinks.js');
// eslint-disable-next-line
const colors = require('colors');
// eslint-disable-next-line
const { Table } = require('console-table-printer');
const directoryPath = ('D:/Proyectos/DEV010-md-links/examples');
// mdLinks('examples/ejemplo1.md')
// .then((links) => {
// console.log(links);
// const linkPromises = links.map((link) => isLinkValid(link));
// return Promise.all(linkPromises);
// })
mdLinks(directoryPath)
.then((links) => {
console.log(links);
const linkPromises = links.map((link) => isLinkValid(link));
return Promise.all(linkPromises);
})
.then((linksWithStatus) => {
const table = new Table(); // Crea una nueva tabla
// Configura el formato de las columnas
table.addColumn({ name: 'Index', alignment: 'left', color: 'white', format: colors.white });
table.addColumn({ name: 'Text', alignment: 'left', color: 'cyan', format: colors.cyan });
table.addColumn({ name: 'URL', alignment: 'left', color: 'magenta', format: colors.magenta });
table.addColumn({ name: 'Validate', alignment: 'left', color: 'green', format: colors.green });
table.addColumn({ name: 'Status', alignment: 'left', color: 'yellow', format: colors.yellow });
linksWithStatus.forEach((link, index) => {
const rowData = {
Index: index + 1,
Text: link.text,
URL: link.href,
Validate: link.isValid ? 'True' : 'False',
Status: link.status !== undefined ? `${link.status} ${link.statusText}` : '404 Not Found',
};
if (!link.href) {
rowData.Status = 'N/A';
}
// if (link.status === 404) {
// rowData.Estado = '404 Not Found';
// } else if (!link.href) {
// rowData.Estado = 'N/A';
// } else {
// rowData.Estado = link.status !== undefined ? `${link.status} ${link.statusText}` : 'N/A';
// }
table.addRow(rowData); // Agrega una fila a la tabla
});
table.printTable(); // Imprime la tabla
})
.catch((error) => {
console.error(error);
});