@zkochan/pnpm
Version:
A fast implementation of npm install
61 lines (48 loc) • 1.5 kB
JavaScript
/**
* Copyright 2015 Google Inc. All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file or at
* https://github.com/firebase/superstatic/blob/master/LICENSE
*/
;
var fs = require('fs');
var _ = require('lodash');
var join = require('join-path');
var path = require('path');
var CONFIG_FILE = ['superstatic.json', 'firebase.json'];
module.exports = function(filename) {
if (_.isFunction(filename)) { return filename; }
filename = filename || CONFIG_FILE;
var configObject = {};
var config = {};
// From custom config data passed in
try {
configObject = JSON.parse(filename);
} catch (e) {
if (_.isPlainObject(filename)) {
configObject = filename;
filename = CONFIG_FILE;
}
}
if (_.isArray(filename)) {
filename = _.find(filename, function(name) {
return fs.existsSync(join(process.cwd(), name));
});
}
// Set back to default config file if stringified object is
// given as config. With this, we override values in the config file
if (_.isPlainObject(filename)) {
filename = CONFIG_FILE;
}
// A file name or array of file names
if (_.isString(filename) && _.endsWith(filename, 'json')) {
try {
config = JSON.parse(fs.readFileSync(path.resolve(filename)));
} catch (e) {
// do nothing
}
}
// Passing an object as the config value merges
// the config data
return _.assign(config, configObject);
};