forked from Laboratoria/DEV004-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
81 lines (75 loc) · 2.51 KB
/
Copy pathcli.js
File metadata and controls
81 lines (75 loc) · 2.51 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env node
import chalk from 'chalk'
import { mdLinks } from './index.js'
// const chalk = new chalk({level: 2});
const ruta = process.argv[2]
const processArr = process.argv
if (!ruta) {
console.log('Please enter', chalk.bgBlue('--help'), 'to see options')
} else if (process.argv.includes('--help')) {
console.log(chalk.bgYellow('OPTIONS'))
console.log(chalk.bgBlue('<path> '), 'All links .md')
console.log(chalk.bgBlue('<path> --validate '), 'Links with status and msg')
console.log(chalk.bgBlue('<path> --stats '), 'Stats: Total and Unique links')
console.log(chalk.bgBlue('<path> --stats --validate'), 'Stats: Total, Unique and Broken links')
} else {
if (processArr[3] === '--validate') {
// console.log(true);
mdLinks(ruta, { validate: true })
.then((data) => {
// console.log(data);
data.forEach(element => {
console.log('')
console.log(chalk.bgBlue('Text: ', element.text))
console.log(chalk.cyan('Href: ', element.href))
console.log('File: ', element.file)
console.log(chalk.cyan('Status:'), (element.status))
console.log(chalk.cyanBright('Msg: ', element.msg))
})
})
.catch((error) => {
console.log(error)
})
}
if (processArr[3] === '--stats') {
// console.log(true);
mdLinks(ruta, { stats: true })
.then((data) => {
// console.log(data);
console.log(chalk.inverse('Total : '), data.total)
console.log(chalk.inverse('Unique: '), data.unique)
})
.catch((error) => {
console.log(error)
})
}
if (processArr[3] === '--stats' && processArr[4] === '--validate') {
// console.log(true);
mdLinks(ruta, { combo: true })
.then((data) => {
// console.log(data);
console.log(chalk.inverse('Broken: '), data.broken)
})
.catch((error) => {
console.log(error)
})
}
if (processArr.length === 3) {
// console.log('no validate');
mdLinks(ruta, { validate: false })
.then((data) => {
// console.log(data);
data.forEach(element => {
console.log('')
console.log(chalk.bgGray('Text: ', element.text))
console.log(chalk.cyan('Href: ', element.href))
console.log('File: ', element.file)
})
})
.catch((error) => {
console.log(error)
console.log(chalk.bgRed('TRY WITH:'))
console.log(chalk.bgBlue(' C:\\\\Users\\\\...\\\\example.md'))
})
}
}