David Aurelio edf1774945 Resolve path at callsite rather than in Config.loadFile
Summary:
Resolve path at callsite rather than in `Config.loadFile`

`Config.loadFile` should not expose unexpected behavior as joining paths together. This moves that responsibility to the call site. `path.resolve` returns the second argument if it is an absolute path.

Reviewed By: bestander

Differential Revision: D4986130

fbshipit-source-id: c80a588ffa86011bcd5a2c393ad5d6eedc6c61ae
2017-05-03 06:51:47 -07:00

51 lines
1.3 KiB
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
'use strict';
const Config = require('../util/Config');
const defaultConfig = require('./default.config');
const minimist = require('minimist');
const path = require('path');
import type {CommandT} from '../commands';
import type {ConfigT} from '../util/Config';
export type RNConfig = {
...ConfigT,
/**
* Returns an array of project commands used by the CLI to load
*/
getProjectCommands(): Array<CommandT>,
/**
* Returns project config from the current working directory
*/
getProjectConfig(): Object,
/**
* Returns dependency config from <node_modules>/packageName
*/
getDependencyConfig(pkgName: string): Object,
};
/**
* Loads the CLI configuration
*/
function getCliConfig(): RNConfig {
const cliArgs = minimist(process.argv.slice(2));
const config = cliArgs.config != null
? Config.loadFile(path.resolve(__dirname, cliArgs.config))
: Config.findOptional(__dirname);
return {...defaultConfig, ...config};
}
module.exports = getCliConfig();