forked from BochilTeam/database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
46 lines (40 loc) · 1.2 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
const fs = require('fs')
const path = require('path')
const assert = require('assert')
async function check() {
let base = path.join(__dirname, './')
let dir = await readdir(base)
dir.map(v => base + v)
let files = []
let dirnames = dir
while (dirnames.length !== 0) {
if (await isDirectory(dirnames[0])) {
let path = await readdir(dirnames[0])
path.filter(v => !v.endsWith('node_modules') && !v.startsWith('.')).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 {
await parse(file)
assert.ok(file)
console.log('Done checking', file)
} catch (e) {
assert.ok(e.length < 1, file + '\n\n' + e)
}
}
// console.log(process.argv0)
}
async function readdir(path) {
return await fs.readdirSync(path)
}
async function isDirectory(path) {
return await fs.statSync(path).isDirectory()
}
async function parse(path) {
return JSON.parse(await fs.readFileSync(path))
}
check()