serverless/lib/utils/getServerlessConfigFile.js
2017-12-19 20:14:39 +11:00

35 lines
992 B
JavaScript

'use strict';
const _ = require('lodash');
const BbPromise = require('bluebird');
const path = require('path');
const fileExists = require('./fs/fileExists');
const readFile = require('./fs/readFile');
const getServerlessConfigFile = _.memoize((servicePath) => {
const jsonPath = path.join(servicePath, 'serverless.json');
const ymlPath = path.join(servicePath, 'serverless.yml');
const yamlPath = path.join(servicePath, 'serverless.yaml');
const jsPath = path.join(servicePath, 'serverless.js');
return BbPromise.props({
json: fileExists(jsonPath),
yml: fileExists(ymlPath),
yaml: fileExists(yamlPath),
js: fileExists(jsPath)
}).then((exists) => {
if (exists.json) {
return readFile(jsonPath);
} else if (exists.yml) {
return readFile(ymlPath);
} else if (exists.yaml) {
return readFile(yamlPath);
} else if (exists.js) {
return require(jsPath);
}
return '';
});
});
module.exports = getServerlessConfigFile;