mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
25 lines
536 B
JavaScript
25 lines
536 B
JavaScript
'use strict';
|
|
|
|
const YAML = require('js-yaml');
|
|
const fse = require('./fse');
|
|
|
|
function readFileSync(filePath) {
|
|
let contents;
|
|
|
|
// Read file
|
|
contents = fse.readFileSync(filePath);
|
|
|
|
// Auto-parse JSON
|
|
if (filePath.endsWith('.json')) {
|
|
contents = JSON.parse(contents);
|
|
} else if (filePath.endsWith('.yml') || filePath.endsWith('.yaml')) {
|
|
contents = YAML.load(contents.toString(), { filename: filePath });
|
|
} else {
|
|
contents = contents.toString().trim();
|
|
}
|
|
|
|
return contents;
|
|
}
|
|
|
|
module.exports = readFileSync;
|