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.
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const chalk = require('chalk');
|
|
|
|
const formatBanner = require('./formatBanner');
|
|
|
|
const path = require('path');
|
|
|
|
const runServer = require('./runServer');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts the React Native Packager Server.
|
|
|
|
*/
|
2016-07-30 15:59:16 +00:00
|
|
|
function server(argv, config, args) {
|
2017-03-06 08:18:21 +00:00
|
|
|
args.projectRoots = args.projectRoots.concat(args.root);
|
2015-10-12 23:46:52 +00:00
|
|
|
|
|
|
|
console.log(formatBanner(
|
|
|
|
'Running packager on port ' + args.port + '.\n\n' +
|
|
|
|
'Keep this packager running while developing on any JS projects. ' +
|
|
|
|
'Feel free to close this tab and run your own packager instance if you ' +
|
|
|
|
'prefer.\n\n' +
|
|
|
|
'https://github.com/facebook/react-native', {
|
|
|
|
marginLeft: 1,
|
|
|
|
marginRight: 1,
|
|
|
|
paddingBottom: 1,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
'Looking for JS files in\n ',
|
|
|
|
chalk.dim(args.projectRoots.join('\n ')),
|
|
|
|
'\n'
|
|
|
|
);
|
|
|
|
|
|
|
|
process.on('uncaughtException', error => {
|
|
|
|
if (error.code === 'EADDRINUSE') {
|
|
|
|
console.log(
|
|
|
|
chalk.bgRed.bold(' ERROR '),
|
|
|
|
chalk.red('Packager can\'t listen on port', chalk.bold(args.port))
|
|
|
|
);
|
|
|
|
console.log('Most likely another process is already using this port');
|
|
|
|
console.log('Run the following command to find out which process:');
|
2016-12-01 01:01:00 +00:00
|
|
|
console.log('\n ', chalk.bold('lsof -i :' + args.port), '\n');
|
|
|
|
console.log('Then, you can either shut down the other process:');
|
2015-10-12 23:46:52 +00:00
|
|
|
console.log('\n ', chalk.bold('kill -9 <PID>'), '\n');
|
|
|
|
console.log('or run packager on different port.');
|
|
|
|
} else {
|
|
|
|
console.log(chalk.bgRed.bold(' ERROR '), chalk.red(error.message));
|
|
|
|
const errorAttributes = JSON.stringify(error);
|
|
|
|
if (errorAttributes !== '{}') {
|
|
|
|
console.error(chalk.red(errorAttributes));
|
|
|
|
}
|
|
|
|
console.error(chalk.red(error.stack));
|
|
|
|
}
|
|
|
|
console.log('\nSee', chalk.underline('http://facebook.github.io/react-native/docs/troubleshooting.html'));
|
|
|
|
console.log('for common problems and solutions.');
|
2016-09-08 22:53:15 +00:00
|
|
|
process.exit(11);
|
2015-10-12 23:46:52 +00:00
|
|
|
});
|
|
|
|
|
2016-07-30 15:59:16 +00:00
|
|
|
runServer(args, config, () => console.log('\nReact packager ready.\n'));
|
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,
|
|
|
|
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(),
|
2016-08-02 17:13:13 +00:00
|
|
|
}, {
|
|
|
|
command: '--assetExts [list]',
|
|
|
|
description: 'Specify any additional asset extentions to be used by the packager',
|
|
|
|
parse: (val) => val.split(','),
|
|
|
|
default: (config) => config.getAssetExts(),
|
2016-12-02 17:41:28 +00:00
|
|
|
}, {
|
|
|
|
command: '--platforms [list]',
|
|
|
|
description: 'Specify any additional platforms to be used by the packager',
|
|
|
|
parse: (val) => val.split(','),
|
|
|
|
default: (config) => config.getPlatforms(),
|
2017-01-13 05:03:57 +00:00
|
|
|
}, {
|
|
|
|
command: '--providesModuleNodeModules [list]',
|
|
|
|
description: 'Specify any npm packages that import dependencies with providesModule',
|
|
|
|
parse: (val) => val.split(','),
|
|
|
|
default: (config) => {
|
|
|
|
if (typeof config.getProvidesModuleNodeModules === 'function') {
|
|
|
|
return config.getProvidesModuleNodeModules();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
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',
|
|
|
|
}],
|
|
|
|
};
|