forked from Laboratoria/DEV007-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdLinks.js
28 lines (23 loc) · 886 Bytes
/
mdLinks.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
// importar librerías
import chalk from 'chalk';
// importar funciones
import {
getFilesRecursively, processMarkdownFile, processMarkdownFileWithStatus,
} from './functions.js';
// FUNCIÓN PRINCIPAL DE ENLACE
export default function mdLinks(path, options) {
console.log(chalk.bold.italic('The path you provided was: ') + chalk.bgBlue(path));
const filesArray = getFilesRecursively(path);
if (filesArray.length === 0) {
return Promise.reject(new Error(chalk.bgRedBright.bold(' No .md file found ')));
}
const promises = filesArray.map((file) => { // array de promesas
if (options === false) {
return processMarkdownFile(file);
} if (options === true) {
return processMarkdownFileWithStatus(file);
}
return Promise.reject(new Error(chalk.bgRedBright.bold(' The option you chose is not valid ')));
});
return Promise.all(promises);
}