mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-13 09:20:15 +08:00
Summary: @public We need to start using the `private-cli` for the new asset system. Note this is a breaking change! People will have to upgrade their workflows/scripts to start using the new cli. Otherwise we'd need to build a thin adapter that is aware of both APIs which is something we;d like to avoid. The major API changes are: - API is now `entry-file` based instead of `url` based. - /s/--out/--bundle-output - /s/--out/--sourcemap-output Also these parameters have no longer default values, you need to specify them. For instance, if you want to generate the sourcemaps you need to pass in the `--sourcemap-output` option Lastly, additional project roots or asset roots need to be specified on the `rn-cli.config.js`. Reviewed By: @frantic Differential Revision: D2533877 fb-gh-sync-id: a45f9095fdf9442a9106ea7bb6a6b7f651d25273
87 lines
2.0 KiB
JavaScript
87 lines
2.0 KiB
JavaScript
/**
|
|
* Copyright 2004-present Facebook. All Rights Reserved.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
var bundle = require('../private-cli/src/bundle/bundle');
|
|
var bundle_DEPRECATED = require('./bundle.js');
|
|
var Config = require('../private-cli/src/util/Config');
|
|
var fs = require('fs');
|
|
var generateAndroid = require('./generate-android.js');
|
|
var init = require('./init.js');
|
|
var install = require('./install.js');
|
|
var newLibrary = require('./new-library.js');
|
|
var runAndroid = require('./run-android.js');
|
|
var runPackager = require('./run-packager.js');
|
|
|
|
function printUsage() {
|
|
console.log([
|
|
'Usage: react-native <command>',
|
|
'',
|
|
'Commands:',
|
|
' start: starts the webserver',
|
|
' install: installs npm react components',
|
|
' bundle: builds the javascript bundle for offline use',
|
|
' new-library: generates a native library bridge',
|
|
' android: generates an Android project for your app'
|
|
].join('\n'));
|
|
process.exit(1);
|
|
}
|
|
|
|
function printInitWarning() {
|
|
console.log([
|
|
'Looks like React Native project already exists in the current',
|
|
'folder. Run this command from a different folder or remove node_modules/react-native'
|
|
].join('\n'));
|
|
process.exit(1);
|
|
}
|
|
|
|
function run() {
|
|
var args = process.argv.slice(2);
|
|
if (args.length === 0) {
|
|
printUsage();
|
|
}
|
|
|
|
switch (args[0]) {
|
|
case 'start':
|
|
runPackager();
|
|
break;
|
|
case 'install':
|
|
install.init();
|
|
break;
|
|
case 'bundle':
|
|
bundle(args, Config.get(__dirname)).done();
|
|
// bundle_DEPRECATED.init(args);
|
|
break;
|
|
case 'new-library':
|
|
newLibrary.init(args);
|
|
break;
|
|
case 'init':
|
|
printInitWarning();
|
|
break;
|
|
case 'android':
|
|
generateAndroid(
|
|
process.cwd(),
|
|
JSON.parse(fs.readFileSync('package.json', 'utf8')).name
|
|
);
|
|
break;
|
|
case 'run-android':
|
|
runAndroid();
|
|
break;
|
|
default:
|
|
console.error('Command `%s` unrecognized', args[0]);
|
|
printUsage();
|
|
}
|
|
// Here goes any cli commands we need to
|
|
}
|
|
|
|
if (require.main === module) {
|
|
run();
|
|
}
|
|
|
|
module.exports = {
|
|
run: run,
|
|
init: init,
|
|
};
|