UNPKG

823 BJavaScriptView Raw
1'use strict';
2
3const YAML = require('js-yaml');
4const _ = require('lodash');
5
6const functionNames = [
7 'Ref',
8 'GetAtt'
9];
10
11const yamlType = (name, kind) => {
12 const functionName = _.includes(['Ref'], name) ? name : `Fn::${name}`;
13 return new YAML.Type(`!${name}`, {
14 kind,
15 construct: data => {
16 if (name === 'GetAtt') {
17 if (typeof data === 'string') {
18 const [first, ...tail] = data.split('.');
19 data = [first, tail.join('.')];
20 }
21 }
22 return { [functionName]: data };
23 }
24 });
25};
26
27const createSchema = () => {
28 const types = _.flatten(
29 _.map(functionNames, functionName =>
30 _.map(['mapping', 'scalar', 'sequence'], kind => yamlType(functionName, kind))
31 )
32 );
33 return YAML.Schema.create(types);
34};
35
36module.exports = {
37 schema: createSchema()
38};
\No newline at end of file