Merge rnpm cli into react-native

Summary:
This is an initial step of rewriting the CLI interface to use `rnpm` one (commander, plugins etc.).

It's scope is to move all existing commands to use rnpm CLI interface, so that we get plugins, flags and our existing ecosystem working out of the box.

<s>This is still WIP and some of the commands are left commented out.</s>

For the `config` of `rnpm` (functions get info about project and dependency), <s>I am thinking we can merge them with</s> we decided to merge it with [`default.config.js`](e57683e420/local-cli/default.config.js (L33)), so they are available on the `new Config()` [instance](e57683e420/local-cli/cliEntry.js (L59)) (which means we don't have to change anything and current plugins, like runIOS and runAndroid can just start using it [w/o depending on any extra argument](https://github.com/grabbou/react-native/blob/e57683e420210749a5a6b802b4e
Closes https://github.com/facebook/react-native/pull/7899

Differential Revision: D3613193

Pulled By: bestander

fbshipit-source-id: 09a072f3b21e5239dfcd8da88a205bd28dc5d037
This commit is contained in:
Mike Grabowski
2016-07-30 08:59:16 -07:00
committed by Facebook Github Bot
parent a37d5a825e
commit e8b508144f
127 changed files with 1158 additions and 1389 deletions

View File

@@ -10,82 +10,14 @@
const chalk = require('chalk');
const formatBanner = require('./formatBanner');
const parseCommandLine = require('../util/parseCommandLine');
const path = require('path');
const Promise = require('promise');
const runServer = require('./runServer');
/**
* Starts the React Native Packager Server.
*/
function server(argv, config) {
return new Promise((resolve, reject) => {
_server(argv, config, resolve, reject);
});
}
function _server(argv, config, resolve, reject) {
const args = parseCommandLine([{
command: 'port',
default: 8081,
type: 'string',
}, {
command: 'host',
default: '',
type: 'string',
}, {
command: 'root',
type: 'string',
description: 'add another root(s) to be used by the packager in this project',
}, {
command: 'projectRoots',
type: 'string',
description: 'override the root(s) to be used by the packager',
},{
command: 'assetRoots',
type: 'string',
description: 'specify the root directories of app assets'
}, {
command: 'skipflow',
description: 'Disable flow checks'
}, {
command: 'nonPersistent',
description: 'Disable file watcher'
}, {
command: 'transformer',
type: 'string',
default: null,
description: 'Specify a custom transformer to be used'
}, {
command: 'resetCache',
description: 'Removes cached files',
default: false,
}, {
command: 'reset-cache',
description: 'Removes cached files',
default: false,
}, {
command: 'verbose',
description: 'Enables logging',
default: false,
}]);
args.projectRoots = args.projectRoots
? argToArray(args.projectRoots)
: config.getProjectRoots();
if (args.root) {
const additionalRoots = argToArray(args.root);
additionalRoots.forEach(root => {
args.projectRoots.push(path.resolve(root));
});
}
args.assetRoots = args.assetRoots
? argToArray(args.assetRoots).map(dir =>
path.resolve(process.cwd(), dir)
)
: config.getAssetRoots();
function server(argv, config, args) {
args.projectRoots = args.projectRoots.concat(args.root);
console.log(formatBanner(
'Running packager on port ' + args.port + '.\n\n' +
@@ -130,25 +62,50 @@ function _server(argv, config, resolve, reject) {
process.exit(1);
});
// TODO: remove once we deprecate this arg
if (args.resetCache) {
console.log(
'Please start using `--reset-cache` instead. ' +
'We\'ll deprecate this argument soon.'
);
}
startServer(args, config);
runServer(args, config, () => console.log('\nReact packager ready.\n'));
}
function startServer(args, config) {
runServer(args, config, () =>
console.log('\nReact packager ready.\n')
);
}
function argToArray(arg) {
return Array.isArray(arg) ? arg : arg.split(',');
}
module.exports = server;
module.exports = {
name: 'start',
func: server,
description: 'starts the webserver',
options: [{
command: '--port [number]',
default: 8081,
parse: (val) => Number(val),
}, {
command: '--host [string]',
default: '',
}, {
command: '--root [list]',
description: 'add another root(s) to be used by the packager in this project',
parse: (val) => val.split(',').map(root => path.resolve(root)),
default: [],
}, {
command: '--projectRoots [list]',
description: 'override the root(s) to be used by the packager',
parse: (val) => val.split(','),
default: (config) => config.getProjectRoots(),
}, {
command: '--assetRoots [list]',
description: 'specify the root directories of app assets',
parse: (val) => val.split(',').map(dir => path.resolve(process.cwd(), dir)),
default: (config) => config.getAssetRoots(),
}, {
command: '--skipflow',
description: 'Disable flow checks'
}, {
command: '--nonPersistent',
description: 'Disable file watcher'
}, {
command: '--transformer [string]',
default: require.resolve('../../packager/transformer'),
description: 'Specify a custom transformer to be used (absolute path)'
}, {
command: '--reset-cache, --resetCache',
description: 'Removes cached files',
}, {
command: '--verbose',
description: 'Enables logging',
}],
};