(filePath, contents)
| 15 | } |
| 16 | |
| 17 | function parse(filePath, contents) { |
| 18 | // Auto-parse JSON |
| 19 | if (filePath.endsWith('.json') || filePath.endsWith('.tfstate')) { |
| 20 | return jc.parse(contents) |
| 21 | } else if (filePath.endsWith('.yml') || filePath.endsWith('.yaml')) { |
| 22 | const options = { |
| 23 | filename: filePath, |
| 24 | } |
| 25 | let result = loadYaml(contents.toString(), options) |
| 26 | if (result.error && result.error.name === 'YAMLException') { |
| 27 | _.merge(options, { schema: cloudformationSchema }) |
| 28 | result = loadYaml(contents.toString(), options) |
| 29 | } |
| 30 | if (result.error) { |
| 31 | throw result.error |
| 32 | } |
| 33 | return result.data |
| 34 | } |
| 35 | return contents.toString().trim() |
| 36 | } |
| 37 | |
| 38 | export default parse |
no test coverage detected
searching dependent graphs…