-
Notifications
You must be signed in to change notification settings - Fork 85
/
test.js
51 lines (44 loc) · 1.24 KB
/
test.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const fs = require('fs')
const path = require('path')
const assert = require('assert')
async function check() {
let base = path.join(__dirname, './')
let dir = readdir(base)
dir.map(v => base + v)
let files = []
let dirnames = dir
while (dirnames.length !== 0) {
if (isDirectory(dirnames[0]) && filter(dirnames[0])) {
let path = readdir(dirnames[0])
path.filter(filter).map(file => dirnames.push(dirnames[0] + '/' + file))
} else if (dirnames[0].endsWith('.json')) {
files.push(dirnames[0])
}
dirnames.shift()
}
for (let file of files) {
console.error('Checking', file)
try {
parse(file)
assert.ok(file)
console.log('Done checking', file)
} catch (e) {
assert.ok(e, file + '\n\n' + e)
if (e) process.exit(1)
}
}
// console.log(process.argv0)
}
function readdir(path) {
return fs.readdirSync(path)
}
function isDirectory(path) {
return fs.statSync(path).isDirectory()
}
function parse(path) {
return JSON.parse(fs.readFileSync(path))
}
function filter(fileName) {
return !fileName.startsWith('node_modules') && !fileName.startsWith('.')
}
check()