-
Notifications
You must be signed in to change notification settings - Fork 139
/
validate-yaml.js
103 lines (95 loc) · 3.16 KB
/
validate-yaml.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const fs = require('fs');
const {load} = require('js-yaml');
const Joi = require('joi');
const permissionsSchema = Joi.object({
method: Joi.string().required(),
apps: Joi.array().items(Joi.string()),
args: Joi.array().items(Joi.any())
})
const moduleSchema = Joi.object({
module: Joi.string().required(),
scope: Joi.string().required(),
appName: Joi.string().required(),
group: Joi.string(),
manifest: Joi.string()
});
const subApp = Joi.object({
id: Joi.string().required().allow(''),
default: Joi.boolean(),
title: Joi.string(),
group: Joi.string(),
reload: Joi.string(),
permissions: [Joi.array().items(permissionsSchema), permissionsSchema],
section: Joi.string(),
navigate: Joi.string(),
sub_apps: Joi.array().items('#subApp')
});
const frontendSchema = Joi.object({
title: Joi.string(),
isBeta: Joi.boolean(),
isHidden: Joi.boolean(),
app_base: Joi.string(),
reload: Joi.string(),
section: Joi.string(),
paths: Joi.array().items(Joi.string()),
module: [Joi.string(), moduleSchema],
sub_apps: Joi.array().items(Joi.object({
id: Joi.string().required().allow(''),
default: Joi.boolean(),
title: Joi.string(),
group: Joi.string(),
reload: Joi.string(),
permissions: [Joi.array().items(permissionsSchema), permissionsSchema],
section: Joi.string(),
navigate: Joi.string(),
sub_apps: Joi.array().items(subApp)
}))
})
const schema = Joi.object({
disabled_on_prod: Joi.boolean(),
description: Joi.string(),
docs: Joi.string(),
mailing_list: Joi.string(),
title: Joi.string(),
api: Joi.object({
url: Joi.string(),
readonly: Joi.boolean(),
github: Joi.object({ owner: Joi.string(), repo: Joi.string(), path: Joi.string() }),
apiName: Joi.string(),
versions: [Joi.array().items(Joi.string()), Joi.string()],
isBeta: Joi.boolean(),
alias: Joi.array().items(Joi.string()),
subItems: Joi.object().pattern(/^/ ,Joi.object({
versions: [Joi.array().items(Joi.string()), Joi.string()],
url: Joi.string(),
readonly: Joi.boolean(),
github: Joi.object({ owner: Joi.string(), repo: Joi.string(), path: Joi.string() }),
title: Joi.string()
})),
tags: Joi.array().items(Joi.object({
value: Joi.string().required(),
title: Joi.string().required()
}))
}),
channel: Joi.string(),
deployment_repo: Joi.string(),
source_repo: Joi.string(),
frontend: frontendSchema,
top_level: Joi.boolean(),
permissions: [Joi.array().items(permissionsSchema), permissionsSchema],
productId: Joi.string(),
infoId: Joi.string()
})
const inputfile = 'main.yml';
const structure = load(fs.readFileSync(inputfile, { encoding: 'utf-8' }));
async function validate() {
Object.entries(structure).forEach(async ([ key, value ]) => {
try {
const result = await schema.validateAsync(value);
} catch (error) {
console.error(`Error in ${key} app definition.\n`, error)
process.exit(1)
}
})
}
validate()