-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset.js
executable file
·58 lines (50 loc) · 1.34 KB
/
dataset.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
52
53
54
55
56
57
58
#!/bin/env node
import fs from 'fs'
import path from 'path'
import inspector from 'schema-inspector'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const validation = {
type: 'object',
properties: {
name: { type: 'string', minLength: 5 },
providers: {
type: 'array',
minLength: 10,
items: {
type: 'object',
properties: {
name: { type: 'string', minLength: 3, someKeys: ['sendinblue', 'mailjet'] },
email: { type: 'string', pattern: 'email', optional: true },
form: { type: 'string', pattern: 'url', optional: true },
policy: { type: 'string', pattern: 'url', optional: true }
}
}
}
}
}
const validateFile = (file) => {
let jsonData = {}
try {
const data = fs.readFileSync(file, 'utf-8')
jsonData = JSON.parse(data)
} catch (e) {
console.log(e)
return false
}
const result = inspector.validate(validation, jsonData)
if (!result.valid) {
console.log(result.format())
return false
}
return true
}
const testJsonFile = (filePath) => {
if (validateFile(filePath) === false) {
process.exit(1)
} else {
console.log('file ' + path.parse(filePath).name + ' is valid')
}
}
testJsonFile(path.resolve(__dirname, '..', 'esp-abuse.json'))