Skip to content
Open

CLI #33

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .history/cli_20230907084925.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import mdLinks from "./index"

const [, , ...args] = process.argv
const route = args[1];
const validate = args.includes(--validate);
const stats = args[2].includes(--stats);
const option = { validate, stats };

mdLinks(route, option)
.then(()=>{
//si options es = = a validate
})
.catch((error)=>{
console.log(error)
})
15 changes: 15 additions & 0 deletions .history/cli_20230907084932.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import mdLinks from "./index"

const [, , ...args] = process.argv
const route = args[1];
const validate = args.includes(--validate);
const stats = args.includes(--stats);
const option = { validate, stats };

mdLinks(route, option)
.then(()=>{
//si options es = = a validate
})
.catch((error)=>{
console.log(error)
})
15 changes: 15 additions & 0 deletions .history/cli_20230907084958.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import mdLinks from "./index"

const [, , ...args] = process.argv
const route = args[1];
const validate = args.includes('--validate');
const stats = args.includes('--stats');
const option = { validate, stats };

mdLinks(route, option)
.then(()=>{
//si options es = = a validate
})
.catch((error)=>{
console.log(error)
})
17 changes: 17 additions & 0 deletions .history/cli_20230907085111.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import mdLinks from "./index"

const [, , ...args] = process.argv
console.log(args)
const route = args[0];
const validate = args.includes('--validate');
const stats = args.includes('--stats');
const option = { validate, stats };

mdLinks(route, option)
.then((result)=>{
//si options es = = a validate
console.log(result)
})
.catch((error)=>{
console.log(error)
})
17 changes: 17 additions & 0 deletions .history/cli_20230907085905.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import mdLinks from "./index"

const [, , ...args] = process.argv
console.log(args)
const route = args[0];
const validate = args.includes('--validate');
const stats = args.includes('--stats');
const option = { validate, stats };

mdLinks(route, option)
.then((result)=>{
//si options es = = a validate
console.log(result)
})
.catch((error)=>{
console.log(error)
})
17 changes: 17 additions & 0 deletions .history/cli_20230907090149.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import mdLinks from "./index.js"

const [, , ...args] = process.argv
console.log(args)
const route = args[0];
const validate = args.includes('--validate');
const stats = args.includes('--stats');
const option = { validate, stats };

mdLinks(route, option)
.then((result)=>{
//si options es = = a validate
console.log(result)
})
.catch((error)=>{
console.log(error)
})
17 changes: 17 additions & 0 deletions .history/cli_20230907090243.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import mdLinks from "./index.js"

const [, , ...args] = process.argv
console.log(args)
const route = args[0];
const validate = args.includes('--validate');
const stats = args.includes('--stats');
const option = { validate, stats };

mdLinks(route, option)
.then((result)=>{
//si options es = = a validate
console.log(result)
})
.catch((error)=>{
console.log(error)
})
17 changes: 17 additions & 0 deletions .history/cli_20230907121411.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {mdLink} from "./index.js"

const [, , ...args] = process.argv
console.log(args)
const route = args[0];
const validate = args.includes('--validate');
const stats = args.includes('--stats');
const option = { validate, stats };

mdLinks(route, option)
.then((result)=>{
//si options es = = a validate
console.log(result)
})
.catch((error)=>{
console.log(error)
})
17 changes: 17 additions & 0 deletions .history/cli_20230907121421.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {mdLinks} from "./index.js"

const [, , ...args] = process.argv
console.log(args)
const route = args[0];
const validate = args.includes('--validate');
const stats = args.includes('--stats');
const option = { validate, stats };

mdLinks(route, option)
.then((result)=>{
//si options es = = a validate
console.log(result)
})
.catch((error)=>{
console.log(error)
})
92 changes: 92 additions & 0 deletions .history/index_20230907085347.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//Promesa
//Callback resolve cuando la promesa se cumple
//Callback reject es cuando NO se cumple
//cree promesa pero se consume despues

import {
routeAbsolute,
routeValid,
isFiles,
fileDirectory,
filterMD,
fileToStringArray,
linkFinder,
validateLinks,
statsLinks,
statsBroken,
fusionStats,
} from "./fuctions.js";

export function mdLinks(path, options) {
return new Promise((resolve, reject) => {
//Calcula la ruta absoluta a partir de la ruta proporcionada
const routeA = routeAbsolute(path);
//Verifica si la ruta es válida usando la función
if (routeValid(routeA) === false) {
//Si no es válida, se rechaza
reject("Route invalid");
}
//Dependiendo de si la ruta representa un archivo o un directorio,
//se crea un arreglo llamado arrayAllFile que contendrá rutas de archivos.
let arrayAllFile = []; //contiene todos los archivos
if (isFiles(routeA) === true) {
arrayAllFile.push(routeA);
} else {
arrayAllFile = fileDirectory(routeA);
}

const mdFiltro = filterMD(arrayAllFile);
if (mdFiltro.length === 0) reject("Does not have MD files");
let contentMD = fileToStringArray(mdFiltro);

const theSameLinks = linkFinder(contentMD);

//constante donde vamos a gusradar las promesa
const arrayPromes = [];
if (options.validate === true && options.stats === false) {
theSameLinks.forEach((element) => {
arrayPromes.push(validateLinks(element));
});
Promise.all(arrayPromes)
.then((resposes) => {
resolve(resposes);
})
.catch((errors) => {
console.log("errors");
});
} else if (options.validate === false && options.stats === false) {
resolve(theSameLinks);

// theSameLinks.forEach((element) => {
5// console.log(element);
});
} else if (options.validate === false && options.stats === true) {
const totalLinks = fusionStats(theSameLinks);
const totalstats = statsLinks(theSameLinks);

resolve({
total: totalLinks,
unique: totalstats,
});
} else if (options.validate === true && options.stats === true) {
const totalLinks = fusionStats(theSameLinks);
const totalstats = statsLinks(theSameLinks);
const totalBroken = statsBroken(theSameLinks);
resolve({
total: totalLinks,
unique: totalstats,
broken: totalBroken,
});
}
});
}

// Consumir la promesa
//links para función de links

mdLinks("./README.md", {
validate: true,
stats: true,
}).then((links) => {
console.log("keeping promise!", links);
});
92 changes: 92 additions & 0 deletions .history/index_20230907085436.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//Promesa
//Callback resolve cuando la promesa se cumple
//Callback reject es cuando NO se cumple
//cree promesa pero se consume despues

import {
routeAbsolute,
routeValid,
isFiles,
fileDirectory,
filterMD,
fileToStringArray,
linkFinder,
validateLinks,
statsLinks,
statsBroken,
fusionStats,
} from "./fuctions.js";

export function mdLinks(path, options) {
return new Promise((resolve, reject) => {
//Calcula la ruta absoluta a partir de la ruta proporcionada
const routeA = routeAbsolute(path);
//Verifica si la ruta es válida usando la función
if (routeValid(routeA) === false) {
//Si no es válida, se rechaza
reject("Route invalid");
}
//Dependiendo de si la ruta representa un archivo o un directorio,
//se crea un arreglo llamado arrayAllFile que contendrá rutas de archivos.
let arrayAllFile = []; //contiene todos los archivos
if (isFiles(routeA) === true) {
arrayAllFile.push(routeA);
} else {
arrayAllFile = fileDirectory(routeA);
}

const mdFiltro = filterMD(arrayAllFile);
if (mdFiltro.length === 0) reject("Does not have MD files");
let contentMD = fileToStringArray(mdFiltro);

const theSameLinks = linkFinder(contentMD);

//constante donde vamos a gusradar las promesa
const arrayPromes = [];
if (options.validate === true && options.stats === false) {
theSameLinks.forEach((element) => {
arrayPromes.push(validateLinks(element));
});
Promise.all(arrayPromes)
.then((resposes) => {
resolve(resposes);
})
.catch((errors) => {
console.log("errors");
});
} else if (options.validate === false && options.stats === false) {
resolve(theSameLinks);

/*theSameLinks.forEach((element) => {
console.log(element);
});*/
} else if (options.validate === false && options.stats === true) {
const totalLinks = fusionStats(theSameLinks);
const totalstats = statsLinks(theSameLinks);

resolve({
total: totalLinks,
unique: totalstats,
});
} else if (options.validate === true && options.stats === true) {
const totalLinks = fusionStats(theSameLinks);
const totalstats = statsLinks(theSameLinks);
const totalBroken = statsBroken(theSameLinks);
resolve({
total: totalLinks,
unique: totalstats,
broken: totalBroken,
});
}
});
}

// Consumir la promesa
//links para función de links

mdLinks("./README.md", {
validate: true,
stats: true,
}).then((links) => {
console.log("keeping promise!", links);
});
Loading