-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
39 lines (36 loc) · 1.09 KB
/
index.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
'use strict';
const yaml = require('js-yaml');
const localTags = require('./tags.json');
const cloudformationTags = build(localTags, yaml);
function build(localTags, yaml) {
function Model(name) {
return function (data) {
this.class = name;
this.name = name;
this.data = data;
};
}
function CustomYamlType(name, kind) {
const model = Model(name);
return new yaml.Type('!'+name, {
kind: kind,
instanceOf: model,
construct: function(data) {
return new model(data);
},
represent: function(ref, style) {
return ref.data;
}
});
}
let cloudformationTags = [];
Object.keys(localTags).map((kind) => localTags[kind].map((tag) => cloudformationTags.push(new CustomYamlType(tag, kind))));
return cloudformationTags;
}
module.exports.localTags = localTags;
module.exports.build = build;
module.exports.cloudformationTags = cloudformationTags;
module.exports.CLOUDFORMATION_SCHEMA = yaml.Schema.create(cloudformationTags);
module.exports.genSchema = function(yaml) {
return yaml.Schema.create(build(localTags, yaml));
};