Merge `rnpm config` with the `cli config`, step 1
Summary:
This is step one on merging the `rnpm` config with the `cli config`. The plan is to remove two sources of truth (rnpm package.json config and rn-cli Javascript config)
Rationale:
As of now, we have `rnpm` config, that used to live in the `local-cli/core/config/index.js` and the `rn-cli` config, living in `default.config.js` and `utils/Config.js`.
This PR moves all the things into one file, called `local-cli/core', simplifies things, enhances types (Config now has better types, added missing properties and fixed descriptions).
One notable addition is that users can now opt-in to override the commands that are loaded at the package level. Previously it was only possible to add a command by writing a plugin. Now, you can just tweak the `rn-cli.config.js`.
This is one of the several improvements I have on my roadmap, with better documentation for the CLI as well.
Closes https://github.com/facebook/react-native/pull/11564
Differential Revision: D4360095
fbshipit-source-id: feaec7c88df63e51cef1f9620c7eedeb738d3d00
2017-01-09 15:49:29 +00:00
|
|
|
/**
|
|
|
|
* 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 path = require('path');
|
|
|
|
const flatten = require('lodash').flatten;
|
|
|
|
|
|
|
|
const blacklist = require('../../packager/blacklist');
|
|
|
|
|
|
|
|
const android = require('./android');
|
|
|
|
const findAssets = require('./findAssets');
|
|
|
|
const ios = require('./ios');
|
|
|
|
const windows = require('./windows');
|
|
|
|
const wrapCommands = require('./wrapCommands');
|
|
|
|
const findPlugins = require('./findPlugins');
|
|
|
|
|
2017-01-31 11:35:00 +00:00
|
|
|
const findSymlinksPaths = require('../util/findSymlinksPaths');
|
|
|
|
const NODE_MODULES = path.resolve(__dirname, '..', '..', '..');
|
|
|
|
|
Merge `rnpm config` with the `cli config`, step 1
Summary:
This is step one on merging the `rnpm` config with the `cli config`. The plan is to remove two sources of truth (rnpm package.json config and rn-cli Javascript config)
Rationale:
As of now, we have `rnpm` config, that used to live in the `local-cli/core/config/index.js` and the `rn-cli` config, living in `default.config.js` and `utils/Config.js`.
This PR moves all the things into one file, called `local-cli/core', simplifies things, enhances types (Config now has better types, added missing properties and fixed descriptions).
One notable addition is that users can now opt-in to override the commands that are loaded at the package level. Previously it was only possible to add a command by writing a plugin. Now, you can just tweak the `rn-cli.config.js`.
This is one of the several improvements I have on my roadmap, with better documentation for the CLI as well.
Closes https://github.com/facebook/react-native/pull/11564
Differential Revision: D4360095
fbshipit-source-id: feaec7c88df63e51cef1f9620c7eedeb738d3d00
2017-01-09 15:49:29 +00:00
|
|
|
import type {ConfigT} from './index';
|
|
|
|
|
|
|
|
const getRNPMConfig = (folder) =>
|
|
|
|
// $FlowFixMe non-literal require
|
|
|
|
require(path.join(folder, './package.json')).rnpm || {};
|
|
|
|
|
|
|
|
const attachPackage = (command, pkg) => Array.isArray(command)
|
|
|
|
? command.map(cmd => attachPackage(cmd, pkg))
|
|
|
|
: { ...command, pkg };
|
|
|
|
|
2017-01-31 11:35:00 +00:00
|
|
|
const addSymlinkToRoots = (roots) =>
|
|
|
|
roots.concat(findSymlinksPaths(NODE_MODULES, roots));
|
|
|
|
|
Merge `rnpm config` with the `cli config`, step 1
Summary:
This is step one on merging the `rnpm` config with the `cli config`. The plan is to remove two sources of truth (rnpm package.json config and rn-cli Javascript config)
Rationale:
As of now, we have `rnpm` config, that used to live in the `local-cli/core/config/index.js` and the `rn-cli` config, living in `default.config.js` and `utils/Config.js`.
This PR moves all the things into one file, called `local-cli/core', simplifies things, enhances types (Config now has better types, added missing properties and fixed descriptions).
One notable addition is that users can now opt-in to override the commands that are loaded at the package level. Previously it was only possible to add a command by writing a plugin. Now, you can just tweak the `rn-cli.config.js`.
This is one of the several improvements I have on my roadmap, with better documentation for the CLI as well.
Closes https://github.com/facebook/react-native/pull/11564
Differential Revision: D4360095
fbshipit-source-id: feaec7c88df63e51cef1f9620c7eedeb738d3d00
2017-01-09 15:49:29 +00:00
|
|
|
/**
|
|
|
|
* Default configuration for the CLI.
|
|
|
|
*
|
|
|
|
* If you need to override any of this functions do so by defining the file
|
|
|
|
* `rn-cli.config.js` on the root of your project with the functions you need
|
|
|
|
* to tweak.
|
|
|
|
*/
|
|
|
|
const config: ConfigT = {
|
|
|
|
getProjectCommands() {
|
|
|
|
const appRoot = process.cwd();
|
|
|
|
const plugins = findPlugins([appRoot])
|
|
|
|
.map(pathToCommands => {
|
|
|
|
const name = pathToCommands.split(path.sep)[0];
|
|
|
|
|
|
|
|
return attachPackage(
|
|
|
|
// $FlowFixMe non-literal require
|
|
|
|
require(path.join(appRoot, 'node_modules', pathToCommands)),
|
|
|
|
// $FlowFixMe non-literal require
|
|
|
|
require(path.join(appRoot, 'node_modules', name, 'package.json'))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return flatten(plugins);
|
|
|
|
},
|
|
|
|
getProjectConfig() {
|
|
|
|
const folder = process.cwd();
|
|
|
|
const rnpm = getRNPMConfig(folder);
|
|
|
|
|
|
|
|
return Object.assign({}, rnpm, {
|
|
|
|
ios: ios.projectConfig(folder, rnpm.ios || {}),
|
|
|
|
android: android.projectConfig(folder, rnpm.android || {}),
|
|
|
|
windows: windows.projectConfig(folder, rnpm.windows || {}),
|
|
|
|
assets: findAssets(folder, rnpm.assets),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
getDependencyConfig(packageName) {
|
|
|
|
const folder = path.join(process.cwd(), 'node_modules', packageName);
|
|
|
|
const rnpm = getRNPMConfig(
|
|
|
|
path.join(process.cwd(), 'node_modules', packageName)
|
|
|
|
);
|
|
|
|
|
|
|
|
return Object.assign({}, rnpm, {
|
|
|
|
ios: ios.dependencyConfig(folder, rnpm.ios || {}),
|
|
|
|
android: android.dependencyConfig(folder, rnpm.android || {}),
|
|
|
|
windows: windows.dependencyConfig(folder, rnpm.windows || {}),
|
|
|
|
assets: findAssets(folder, rnpm.assets),
|
|
|
|
commands: wrapCommands(rnpm.commands),
|
|
|
|
params: rnpm.params || [],
|
|
|
|
});
|
|
|
|
},
|
|
|
|
getAssetExts() {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
getPlatforms() {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
getBlacklistRE() {
|
|
|
|
return blacklist();
|
|
|
|
},
|
|
|
|
getTransformModulePath() {
|
|
|
|
return require.resolve('../../packager/transformer');
|
|
|
|
},
|
|
|
|
getProjectRoots() {
|
|
|
|
const root = process.env.REACT_NATIVE_APP_ROOT;
|
|
|
|
if (root) {
|
2017-01-31 11:35:00 +00:00
|
|
|
return addSymlinkToRoots([path.resolve(root)]);
|
Merge `rnpm config` with the `cli config`, step 1
Summary:
This is step one on merging the `rnpm` config with the `cli config`. The plan is to remove two sources of truth (rnpm package.json config and rn-cli Javascript config)
Rationale:
As of now, we have `rnpm` config, that used to live in the `local-cli/core/config/index.js` and the `rn-cli` config, living in `default.config.js` and `utils/Config.js`.
This PR moves all the things into one file, called `local-cli/core', simplifies things, enhances types (Config now has better types, added missing properties and fixed descriptions).
One notable addition is that users can now opt-in to override the commands that are loaded at the package level. Previously it was only possible to add a command by writing a plugin. Now, you can just tweak the `rn-cli.config.js`.
This is one of the several improvements I have on my roadmap, with better documentation for the CLI as well.
Closes https://github.com/facebook/react-native/pull/11564
Differential Revision: D4360095
fbshipit-source-id: feaec7c88df63e51cef1f9620c7eedeb738d3d00
2017-01-09 15:49:29 +00:00
|
|
|
}
|
2017-01-31 11:35:00 +00:00
|
|
|
|
|
|
|
var roots;
|
Merge `rnpm config` with the `cli config`, step 1
Summary:
This is step one on merging the `rnpm` config with the `cli config`. The plan is to remove two sources of truth (rnpm package.json config and rn-cli Javascript config)
Rationale:
As of now, we have `rnpm` config, that used to live in the `local-cli/core/config/index.js` and the `rn-cli` config, living in `default.config.js` and `utils/Config.js`.
This PR moves all the things into one file, called `local-cli/core', simplifies things, enhances types (Config now has better types, added missing properties and fixed descriptions).
One notable addition is that users can now opt-in to override the commands that are loaded at the package level. Previously it was only possible to add a command by writing a plugin. Now, you can just tweak the `rn-cli.config.js`.
This is one of the several improvements I have on my roadmap, with better documentation for the CLI as well.
Closes https://github.com/facebook/react-native/pull/11564
Differential Revision: D4360095
fbshipit-source-id: feaec7c88df63e51cef1f9620c7eedeb738d3d00
2017-01-09 15:49:29 +00:00
|
|
|
if (__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli[\/\\]core$/)) {
|
|
|
|
// Packager is running from node_modules.
|
|
|
|
// This is the default case for all projects created using 'react-native init'.
|
2017-01-31 11:35:00 +00:00
|
|
|
roots = [path.resolve(__dirname, '../../../..')];
|
Merge `rnpm config` with the `cli config`, step 1
Summary:
This is step one on merging the `rnpm` config with the `cli config`. The plan is to remove two sources of truth (rnpm package.json config and rn-cli Javascript config)
Rationale:
As of now, we have `rnpm` config, that used to live in the `local-cli/core/config/index.js` and the `rn-cli` config, living in `default.config.js` and `utils/Config.js`.
This PR moves all the things into one file, called `local-cli/core', simplifies things, enhances types (Config now has better types, added missing properties and fixed descriptions).
One notable addition is that users can now opt-in to override the commands that are loaded at the package level. Previously it was only possible to add a command by writing a plugin. Now, you can just tweak the `rn-cli.config.js`.
This is one of the several improvements I have on my roadmap, with better documentation for the CLI as well.
Closes https://github.com/facebook/react-native/pull/11564
Differential Revision: D4360095
fbshipit-source-id: feaec7c88df63e51cef1f9620c7eedeb738d3d00
2017-01-09 15:49:29 +00:00
|
|
|
} else if (__dirname.match(/Pods[\/\\]React[\/\\]packager$/)) {
|
|
|
|
// React Native was installed using CocoaPods.
|
2017-01-31 11:35:00 +00:00
|
|
|
roots = [path.resolve(__dirname, '../../../..')];
|
Merge `rnpm config` with the `cli config`, step 1
Summary:
This is step one on merging the `rnpm` config with the `cli config`. The plan is to remove two sources of truth (rnpm package.json config and rn-cli Javascript config)
Rationale:
As of now, we have `rnpm` config, that used to live in the `local-cli/core/config/index.js` and the `rn-cli` config, living in `default.config.js` and `utils/Config.js`.
This PR moves all the things into one file, called `local-cli/core', simplifies things, enhances types (Config now has better types, added missing properties and fixed descriptions).
One notable addition is that users can now opt-in to override the commands that are loaded at the package level. Previously it was only possible to add a command by writing a plugin. Now, you can just tweak the `rn-cli.config.js`.
This is one of the several improvements I have on my roadmap, with better documentation for the CLI as well.
Closes https://github.com/facebook/react-native/pull/11564
Differential Revision: D4360095
fbshipit-source-id: feaec7c88df63e51cef1f9620c7eedeb738d3d00
2017-01-09 15:49:29 +00:00
|
|
|
} else {
|
2017-01-31 11:35:00 +00:00
|
|
|
roots = [path.resolve(__dirname, '../..')];
|
Merge `rnpm config` with the `cli config`, step 1
Summary:
This is step one on merging the `rnpm` config with the `cli config`. The plan is to remove two sources of truth (rnpm package.json config and rn-cli Javascript config)
Rationale:
As of now, we have `rnpm` config, that used to live in the `local-cli/core/config/index.js` and the `rn-cli` config, living in `default.config.js` and `utils/Config.js`.
This PR moves all the things into one file, called `local-cli/core', simplifies things, enhances types (Config now has better types, added missing properties and fixed descriptions).
One notable addition is that users can now opt-in to override the commands that are loaded at the package level. Previously it was only possible to add a command by writing a plugin. Now, you can just tweak the `rn-cli.config.js`.
This is one of the several improvements I have on my roadmap, with better documentation for the CLI as well.
Closes https://github.com/facebook/react-native/pull/11564
Differential Revision: D4360095
fbshipit-source-id: feaec7c88df63e51cef1f9620c7eedeb738d3d00
2017-01-09 15:49:29 +00:00
|
|
|
}
|
2017-01-31 11:35:00 +00:00
|
|
|
return addSymlinkToRoots(roots);
|
Merge `rnpm config` with the `cli config`, step 1
Summary:
This is step one on merging the `rnpm` config with the `cli config`. The plan is to remove two sources of truth (rnpm package.json config and rn-cli Javascript config)
Rationale:
As of now, we have `rnpm` config, that used to live in the `local-cli/core/config/index.js` and the `rn-cli` config, living in `default.config.js` and `utils/Config.js`.
This PR moves all the things into one file, called `local-cli/core', simplifies things, enhances types (Config now has better types, added missing properties and fixed descriptions).
One notable addition is that users can now opt-in to override the commands that are loaded at the package level. Previously it was only possible to add a command by writing a plugin. Now, you can just tweak the `rn-cli.config.js`.
This is one of the several improvements I have on my roadmap, with better documentation for the CLI as well.
Closes https://github.com/facebook/react-native/pull/11564
Differential Revision: D4360095
fbshipit-source-id: feaec7c88df63e51cef1f9620c7eedeb738d3d00
2017-01-09 15:49:29 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = config;
|