-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathvalidate-turtle.js
More file actions
38 lines (33 loc) · 1020 Bytes
/
validate-turtle.js
File metadata and controls
38 lines (33 loc) · 1020 Bytes
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
const fs = require('fs')
const Handlebars = require('handlebars')
const path = require('path')
const validate = require('turtle-validator/lib/validator')
const regex = /\\.(acl|ttl)$/i
const substitutions = {
webId: 'http://example.com/#me',
email: 'test@example.com',
name: 'Test test'
}
const files = recursiveFiles(path.join(__dirname, '../default-templates/'))
for (const file of files) {
const data = fs.readFileSync(file, 'utf8')
const template = Handlebars.compile(data)
validate(template(substitutions), feedback => {
if (feedback.errors.length > 0) {
throw new Error(`Validation error in ${file}: ${feedback.errors[0]}`)
}
})
}
function recursiveFiles (dir) {
const content = fs.readdirSync(dir)
return [].concat(...content.map(file => {
const fullPath = path.join(dir, file)
const stat = fs.statSync(fullPath)
if (stat.isDirectory()) {
return recursiveFiles(fullPath)
} else if (regex.test(file)) {
return [fullPath]
}
return []
}))
}