Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | 1x 1x 1x 10x 1x 1x 1x 1x 1x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x |
import {mdLinks} from './mdLinks'
// import {optionValidate} from './utils1'
// const validate = require('./index');
import {optionValidate} from './utils1'
// import {linksStats, uniqueStats, brokenStats} from './stats.js';
const prueba = [
{
href: 'https://es.wikipedia.org/wiki/Ada_Lovelace',
text: 'https://es.wikipedia.org/wiki/Ada_Lovelace',
file: 'C:\\Users\\HP\\MD-links\\LIM013-fe-md-links\\prueba1.md',
status: 200,
statusText: 'OK'
},
{
href: 'https://es.wikipedia.org/wiki/%C3%81ngela_Ruiz_Robles',
text: 'https://es.wikipedia.org/wiki/%C3%81ngela_Ruiz_Rob',
file: 'C:\\Users\\HP\\MD-links\\LIM013-fe-md-links\\prueba1.md',
status: 200,
statusText: 'OK'
},
{
href: 'https://es.wikipedia.org/wiki/Grace_Murray_Hopper',
text: 'https://es.wikipedia.org/wiki/Grace_Murray_Hopper',
file: 'C:\\Users\\HP\\MD-links\\LIM013-fe-md-links\\prueba1.md',
status: 200,
statusText: 'OK'
},
{
href: 'https://es.wikipedia.org/wiki/Hedy_Lamarr',
text: 'https://es.wikipedia.org/wiki/Hedy_Lamarr',
file: 'C:\\Users\\HP\\MD-links\\LIM013-fe-md-links\\prueba1.md',
status: 200,
statusText: 'OK'
},
{
href: 'https://es.wikipedia.org/wiki/Mary_Allen_Wilkes',
text: 'https://es.wikipedia.org/wiki/Mary_Allen_Wilkes',
file: 'C:\\Users\\HP\\MD-links\\LIM013-fe-md-links\\prueba1.md',
status: 200,
statusText: 'OK'
},
{
href: 'https://es.wikipedia.org/wiki/Katherine_Johnson',
text: 'https://es.wikipedia.org/wiki/Katherine_Johnson',
file: 'C:\\Users\\HP\\MD-links\\LIM013-fe-md-links\\prueba1.md',
status: 200,
statusText: 'OK'
},
{
href: 'https://es.wikipedia.org/wiki/Steve_Shirley',
text: 'https://es.wikipedia.org/wiki/Steve_Shirley',
file: 'C:\\Users\\HP\\MD-links\\LIM013-fe-md-links\\prueba1.md',
status: 200,
statusText: 'OK'
},
{
href: 'https://es.wikipedia.org/wiki/Margaret_Hamilton_(cient%C3%ADfica)',
text: 'https://es.wikipedia.org/wiki/Margaret_Hamilton_(c',
file: 'C:\\Users\\HP\\MD-links\\LIM013-fe-md-links\\prueba1.md',
status: 200,
statusText: 'OK'
},
{
href: 'https://es.wikipedia.org/wiki/Carol_Shaw',
text: 'https://es.wikipedia.org/wiki/Carol_Shaw',
file: 'C:\\Users\\HP\\MD-links\\LIM013-fe-md-links\\prueba1.md',
status: 200,
statusText: 'OK'
},
{
href: '#1-Estudiante-de-Laboratoria',
text: '#1-Estudiante-de-Laboratoria',
file: 'C:\\Users\\HP\\MD-links\\LIM013-fe-md-links\\prueba1.md',
status: 500,
statusText: 'FAIL'
},
{
href: '#1-Estudiante-de-Laboratoria',
text: '#1-Estudiante-de-Laboratoria',
file: 'C:\\Users\\HP\\MD-links\\LIM013-fe-md-links\\prueba1.md',
status: 500,
statusText: 'FAIL'
}
]
export const optionStats = (arrLinks) => {
const totalLinks = arrLinks.length;
const uniqueLinks = new Set(arrLinks.map((element) => element.href)).size;
Iif (totalLinks === 0) {
return 'Is 0 Links in this path! !';
}
const statsTemplate = `
Mostrar Stats:
Total: ${totalLinks}
Unique: ${uniqueLinks}
`;
return statsTemplate;
};
// console.log(optionStats(prueba));
export const statsValidate = (arrLinks) => {
const totalLinks = arrLinks.length;
const uniqueLinks = new Set(arrLinks.map((element) => element.href)).size;
const brokenLinks = arrLinks.filter(href => href.status >= 400).length;
// const brokenLinks = arrLinks.filter(link => link.status >= 400).length;
const statsValidateTemplate = `
Mostrar Stats Validate
Total: ${totalLinks}
Unique: ${uniqueLinks}
Broken: ${brokenLinks}
`;
return statsValidateTemplate;
};
// console.log(statsValidate(prueba));
const warning = `
Need to insert:
md-links <path-to-file> [valid arguments]
*****************Valid Arguments*****************
- md-links <path-to-file> --validate --stats
- md-links <path-to-file> -v -s
- md-links <path-to-file> --validate
- md-links <path-to-file> --stats
*************************************************
`;
const route = process.argv[2]; // segundo argumento
const validate = process.argv.indexOf('--validate');
const optValidate = process.argv.indexOf('-v');// tercer argumento
const stats = process.argv.indexOf('--stats');
const optStats = process.argv.indexOf('-s'); // cuarto argumento
// const combinado=process.argv.indexOf('-v -s')//quinta opcion
const helps = process.argv.indexOf('--help');
// const args = process.argv[2];
// let options= process.argv[3];
// console.log('route',args);
// console.log('options',options);
const funcionCli = (route) => {
Eif (helps >= 0 || route === undefined) {
console.log(warning);
}
Iif (route) {
if ((stats >= 0 || optStats >= 0) && (validate >= 0 || optValidate >= 0)) {
return mdLinks(route, { validate: true })
.then((links) => console.log(statsValidate(links)))
.catch((error) => console.log(error));
}
if (validate >= 0 || optValidate >= 0) {
return mdLinks(route, { validate: true })
// .then((links) => console.log(optionValidate(links)))
.then((links) =>links.forEach(link =>console.log(link.file, link.href, link.statusText, link.status, link.text)))
.catch((error) => console.log(warning));
}
if (stats >= 0 || optStats >= 0) {
return mdLinks(route, { validate: false })
.then((links) => console.log(optionStats(links)))
.catch((error) => console.error(error));
} else {
return mdLinks(route, { validate: false })
// .then((links) => console.log(links))
.then((links) =>links.forEach(link =>console.log(link.href,link.file,link.text)))
.catch((error) => console.error('Error'));
}
}
};
funcionCli(route);
// console.log(process.argv);
// console.log('probando funcionCli', funcionCli('README.md','--stats'))
// funcionCli('./prueba').then((res) => console.log('este',res));
// console.log(funcionCli('README.md')) |