-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvici.yml.js
57 lines (46 loc) · 1.32 KB
/
vici.yml.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
var _ = require('underscore')
var yaml = require('js-yaml')
var fs = require('fs')
module.exports = function (config) {
try {
var viciYmlPath = config.viciYmlPath
if (!config.callback) {
throw new Error('Missing config.callback')
}
if (_.isEmpty(viciYmlPath)) {
return config.callback('Missing config.viciYmlPath')
}
var viciYmlContent = fs.readFileSync(viciYmlPath, 'utf8')
var viciYml = yaml.safeLoad(viciYmlContent)
// validate config
if (_.isEmpty(viciYml)) {
return config.callback('vici yml is empty')
}
if (!_.isArray(viciYml.actions) ||
_.isEmpty(viciYml.actions)) {
return config.callback('actions should be a valid array')
}
var actionErrors = []
_.each(viciYml.actions,
function (action) {
if (_.isEmpty(action.name)) {
actionErrors.push('action.name need for ' +
JSON.stringify(action))
return
}
if (_.isEmpty(action.script)) {
actionErrors.push('action.script need for ' +
JSON.stringify(action))
return
}
}
)
if (!_.isEmpty(actionErrors)) {
return config.callback('Error parsing actions - ' +
JSON.stringify(actionErrors))
}
config.callback(null, viciYml)
} catch (err) {
config.callback(err)
}
}