forked from Laboratoria/LIM018-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (38 loc) · 1.43 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
const {
existPath,
toAbsolutePath,
readDirectoriesAndFiles,
findLinks,
validateLinks,
stats,
brokenStats
} = require('./src/filesAndPaths.js');
const mdLinks = (path, options) => {
return new Promise((resolve, reject) => {
if (!existPath(path)) {
return reject(new Error('La ruta ingresada no existe, porfavor ingrese una ruta válida'));
}
const absolutePath = toAbsolutePath(path);
const directoriesDoc = readDirectoriesAndFiles(absolutePath); // array con paths de archivos .md
const resultOfOptions = [];
directoriesDoc.forEach(pathDoc => {
const linksInArray = findLinks(pathDoc);
if (options.validate === true && options.stats === true) {
return resultOfOptions.push(validateLinks(linksInArray).then((result) => brokenStats(stats(result), result)));
}
if (options.stats === true) {
return resultOfOptions.push(validateLinks(linksInArray).then((result) => stats(result)));
}
if (options.validate === true) {
// console.log(validateLinks(linksInArray), 'validatelinks');
return resultOfOptions.push(validateLinks(linksInArray).then(result => result));
}
return resultOfOptions.push(linksInArray);
});
resolve(Promise.all(resultOfOptions.flat()));
});
};
// mdLinks('directory', { validate: true })
// .then((res) => console.log(res, 'mdlinks'))
// .catch((e) => console.log(e.message));
module.exports = mdLinks;