1 | 'use strict';
|
2 |
|
3 | const YAML = require('js-yaml');
|
4 | const _ = require('lodash');
|
5 |
|
6 | const functionNames = [
|
7 | 'Ref',
|
8 | 'GetAtt'
|
9 | ];
|
10 |
|
11 | const 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 |
|
27 | const 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 |
|
36 | module.exports = {
|
37 | schema: createSchema()
|
38 | }; |
\ | No newline at end of file |