2015-10-12 23:46:52 +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.
|
2017-05-17 11:56:02 +00:00
|
|
|
*
|
|
|
|
* @flow
|
2015-10-12 23:46:52 +00:00
|
|
|
*/
|
2017-05-17 11:56:02 +00:00
|
|
|
|
2015-10-12 23:46:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const runServer = require('./runServer');
|
|
|
|
|
2017-05-17 11:56:02 +00:00
|
|
|
import type {RNConfig} from '../core';
|
|
|
|
import type {ConfigT} from '../util/Config';
|
|
|
|
import type {Args as RunServerArgs} from './runServer';
|
|
|
|
|
2015-10-12 23:46:52 +00:00
|
|
|
/**
|
|
|
|
* Starts the React Native Packager Server.
|
|
|
|
*/
|
2017-05-17 11:56:02 +00:00
|
|
|
function server(argv: mixed, config: RNConfig, allArgs: Object) {
|
|
|
|
const {root, ...args} = allArgs;
|
|
|
|
args.projectRoots = args.projectRoots.concat(root);
|
2015-10-12 23:46:52 +00:00
|
|
|
|
2017-03-31 09:10:00 +00:00
|
|
|
const startedCallback = logReporter => {
|
|
|
|
logReporter.update({
|
|
|
|
type: 'initialize_packager_started',
|
|
|
|
port: args.port,
|
|
|
|
projectRoots: args.projectRoots,
|
|
|
|
});
|
2015-10-12 23:46:52 +00:00
|
|
|
|
2017-03-31 09:10:00 +00:00
|
|
|
process.on('uncaughtException', error => {
|
|
|
|
logReporter.update({
|
|
|
|
type: 'initialize_packager_failed',
|
|
|
|
port: args.port,
|
|
|
|
error,
|
|
|
|
});
|
2015-10-12 23:46:52 +00:00
|
|
|
|
2017-03-31 09:10:00 +00:00
|
|
|
process.exit(11);
|
|
|
|
});
|
|
|
|
};
|
2015-10-12 23:46:52 +00:00
|
|
|
|
2017-03-31 09:10:00 +00:00
|
|
|
const readyCallback = logReporter => {
|
|
|
|
logReporter.update({
|
|
|
|
type: 'initialize_packager_done',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:56:02 +00:00
|
|
|
/* $FlowFixMe: we would have either to invariant() everything, or to
|
|
|
|
* auto-generate CLI args Flow types. */
|
|
|
|
const runServerArgs: RunServerArgs = args;
|
|
|
|
/* $FlowFixMe: ConfigT shouldn't be extendable. */
|
|
|
|
const configT: ConfigT = config;
|
|
|
|
runServer(runServerArgs, configT, startedCallback, readyCallback);
|
2015-10-12 23:46:52 +00:00
|
|
|
}
|
|
|
|
|
2016-07-30 15:59:16 +00:00
|
|
|
module.exports = {
|
|
|
|
name: 'start',
|
|
|
|
func: server,
|
|
|
|
description: 'starts the webserver',
|
|
|
|
options: [{
|
|
|
|
command: '--port [number]',
|
|
|
|
default: 8081,
|
2017-05-17 11:56:02 +00:00
|
|
|
parse: (val: string) => Number(val),
|
2016-07-30 15:59:16 +00:00
|
|
|
}, {
|
|
|
|
command: '--host [string]',
|
|
|
|
default: '',
|
|
|
|
}, {
|
|
|
|
command: '--root [list]',
|
|
|
|
description: 'add another root(s) to be used by the packager in this project',
|
2017-05-17 11:56:02 +00:00
|
|
|
parse: (val: string) => val.split(',').map(root => path.resolve(root)),
|
2016-07-30 15:59:16 +00:00
|
|
|
default: [],
|
|
|
|
}, {
|
|
|
|
command: '--projectRoots [list]',
|
|
|
|
description: 'override the root(s) to be used by the packager',
|
2017-05-17 11:56:02 +00:00
|
|
|
parse: (val: string) => val.split(','),
|
|
|
|
default: (config: ConfigT) => config.getProjectRoots(),
|
2016-08-02 17:13:13 +00:00
|
|
|
}, {
|
|
|
|
command: '--assetExts [list]',
|
2017-05-04 12:06:27 +00:00
|
|
|
description: 'Specify any additional asset extensions to be used by the packager',
|
2017-05-17 11:56:02 +00:00
|
|
|
parse: (val: string) => val.split(','),
|
|
|
|
default: (config: ConfigT) => config.getAssetExts(),
|
2017-05-04 12:06:27 +00:00
|
|
|
}, {
|
|
|
|
command: '--sourceExts [list]',
|
|
|
|
description: 'Specify any additional source extensions to be used by the packager',
|
2017-05-17 11:56:02 +00:00
|
|
|
parse: (val: string) => val.split(','),
|
|
|
|
default: (config: ConfigT) => config.getSourceExts(),
|
2016-12-02 17:41:28 +00:00
|
|
|
}, {
|
|
|
|
command: '--platforms [list]',
|
|
|
|
description: 'Specify any additional platforms to be used by the packager',
|
2017-05-17 11:56:02 +00:00
|
|
|
parse: (val: string) => val.split(','),
|
|
|
|
default: (config: ConfigT) => config.getPlatforms(),
|
2017-01-13 05:03:57 +00:00
|
|
|
}, {
|
|
|
|
command: '--providesModuleNodeModules [list]',
|
|
|
|
description: 'Specify any npm packages that import dependencies with providesModule',
|
2017-05-17 11:56:02 +00:00
|
|
|
parse: (val: string) => val.split(','),
|
|
|
|
default: (config: RNConfig) => {
|
2017-01-13 05:03:57 +00:00
|
|
|
if (typeof config.getProvidesModuleNodeModules === 'function') {
|
|
|
|
return config.getProvidesModuleNodeModules();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2017-06-13 16:11:57 +00:00
|
|
|
}, {
|
|
|
|
command: '--max-workers [number]',
|
|
|
|
description: 'Specifies the maximum number of workers the worker-pool ' +
|
|
|
|
'will spawn for transforming files. This defaults to the number of the ' +
|
|
|
|
'cores available on your machine.',
|
|
|
|
parse: (workers: string) => Number(workers),
|
2016-07-30 15:59:16 +00:00
|
|
|
}, {
|
|
|
|
command: '--skipflow',
|
|
|
|
description: 'Disable flow checks'
|
|
|
|
}, {
|
|
|
|
command: '--nonPersistent',
|
|
|
|
description: 'Disable file watcher'
|
|
|
|
}, {
|
|
|
|
command: '--transformer [string]',
|
2016-09-12 22:11:22 +00:00
|
|
|
description: 'Specify a custom transformer to be used'
|
2016-07-30 15:59:16 +00:00
|
|
|
}, {
|
|
|
|
command: '--reset-cache, --resetCache',
|
|
|
|
description: 'Removes cached files',
|
2017-03-31 01:14:28 +00:00
|
|
|
}, {
|
|
|
|
command: '--custom-log-reporter-path, --customLogReporterPath [string]',
|
|
|
|
description: 'Path to a JavaScript file that exports a log reporter as a replacement for TerminalReporter',
|
2016-07-30 15:59:16 +00:00
|
|
|
}, {
|
|
|
|
command: '--verbose',
|
|
|
|
description: 'Enables logging',
|
2017-06-12 23:06:36 +00:00
|
|
|
}, {
|
|
|
|
command: '--https',
|
|
|
|
description: 'Enables https connections to the server',
|
|
|
|
}, {
|
|
|
|
command: '--key [path]',
|
|
|
|
description: 'Path to custom SSL key',
|
|
|
|
}, {
|
|
|
|
command: '--cert [path]',
|
|
|
|
description: 'Path to custom SSL cert',
|
2016-07-30 15:59:16 +00:00
|
|
|
}],
|
|
|
|
};
|