forked from Laboratoria/BOG005-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
62 lines (58 loc) · 2.99 KB
/
cli.js
File metadata and controls
62 lines (58 loc) · 2.99 KB
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
#!/usr/bin/env node
const chalk = require('chalk');
const figlet = require('figlet');
const {mdLinks} = require('./index.js');
const {statsLinks, validateStatsLinks} = require('./functions.js')
const userPath = process.argv[2]
const argvUser = process.argv
const cli = (route, argv)=>{
if(route === undefined || null){
console.log(chalk.bgYellow(" Ups!Enter a path ⚠ "))
} else if(argv.includes('--sv') || (argv.includes('--validate') ||argv.includes('--v')) && (argv.includes('--stats') ||argv.includes('--s')) ){
mdLinks(route, {validate: true})
.then((res)=>{
const validatelinks = validateStatsLinks(res)
console.table(validatelinks)
})
} else if (argv.includes('--validate') ||argv.includes('--v') ){
mdLinks( route, {validate : true})
.then((res) => {
if(res.length === 0){
return console.log(chalk.bgYellow.bold('no links found ⚠ '))
}
res.forEach((link)=> console.log(chalk.yellow.bold.italic('File > ' + link.file),chalk.magenta.bold.underline('Link > ' +link.href), chalk.bgMagenta.bold('Status > ' +link.status, link.OK), chalk.blue.bold('Text > ' +link.text)))} )
.catch((error) => console.error(chalk.bgRed.bold(error)))
} else if(argv.includes('--stats') ||argv.includes('--s')){
mdLinks(route)
.then((res) => {
const stats = statsLinks(res)
console.table(stats)
})
} else if( argv.includes('--help')){
console.log(chalk.bold.blue(figlet.textSync('Mdlinks', {
font: 'Big',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 100,
})));
console.log(chalk.blue.bold.italic('Options - Function'))
console.log(chalk.yellow.bold('-> mdLinks <Path>'),'\n', chalk.yellow('Show links with their text and path'))
console.log(chalk.green.bold('-> mdLinks <Path> --validate o --v'),'\n', chalk.green('Displays links with their text, path, status and "ok" or "fail" message'))
console.log(chalk.magenta.bold('-> mdLinks <Path> --stats o --s'),'\n', chalk.magenta('Shows the statistics of total links found and unique links.'))
console.log(chalk.cyan.bold('-> mdLinks <Path> --sv o --stats --validate o --validate --stats'),'\n', chalk.cyan('Shows the statistics of total links found and unique links and broken links.'))
} else if (argv.length === 3){
mdLinks(route)
.then((res) => {
if(res.length === 0){
return console.log(chalk.bgYellow.bold('no links found ⚠ '))
}
res.forEach((link)=> console.log(chalk.yellow.bold.italic('File > ' + link.file), chalk.magenta.bold.underline('Link > ' +link.href), chalk.blue.bold('Text > ' +link.text)))})
.catch((error) => console.error(chalk.bgRed.bold(error)))
} else if( !(argv.includes('--validate') ||argv.includes('--v')) && !(argv.includes('--stats') ||argv.includes('--s')) && !(argv.includes('--sv')) ){
console.log(chalk.bgYellow.bold(' 🥵 Enter a valid command'),'\n' , chalk.yellow.bold(' See the commands --help'))
}
}
cli(userPath, argvUser)
module.exports = {
cli
}