-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·52 lines (44 loc) · 1.28 KB
/
index.js
File metadata and controls
executable file
·52 lines (44 loc) · 1.28 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
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const jsonlint = require('jsonlint')
const args = process.argv.slice(2)
const check = String.fromCharCode(0x2713)
const cross = String.fromCharCode(0x2717)
const inputFolder = args[0]
if (!inputFolder) {
console.error('Usage: jsonlint-tree <folder>')
process.exit(1)
}
const folder = path.resolve(inputFolder)
let passed = 0
let failed = 0
fs.readdir(folder, { recursive: true, withFileTypes: true }, (err, entries) => {
if (err) throw err
const files = entries
.filter(entry => entry.isFile())
.map(entry => path.join(entry.path, entry.name))
for (const file of files) {
if (file.endsWith('.json')) {
fs.readFile(file, 'utf8', (err, data) => {
if (err) throw err
try {
jsonlint.parse(data)
console.log(check, file)
passed++
}
catch (e) {
failed++
console.error(cross, file, `\n\t${e.toString().split('\n').join('\n\t')}`)
}
if (passed+failed === files.length) {
console.log('\n')
console.log(' ', check, passed, 'valid files')
console.log(' ', cross, failed, 'invalid files')
console.log('\n')
process.exit(failed)
}
})
}
}
})