[global-cli] react-native init [--debug|verbose]

`npm install` prints a lot of junk like gyp warnings
and the rest of the output is not super useful for
tracking progress.

Supress the output by default, show the output with
--debug, and show verbose output with --verbose.
This commit is contained in:
Martin Konicek 2016-01-05 16:48:38 +00:00
parent a5d82c2823
commit 6af7ae55b1
2 changed files with 23 additions and 14 deletions

View File

@ -83,11 +83,16 @@ if (cli) {
switch (args[0]) { switch (args[0]) {
case 'init': case 'init':
if (args[1]) { if (args[1]) {
var verbose = process.argv.indexOf('--verbose') >= 0; var logLevel = '';
init(args[1], verbose); if (process.argv.indexOf('--verbose') >= 0) {
logLevel = 'verbose';
} else if (process.argv.indexOf('--debug') >= 0) {
logLevel = 'debug';
}
init(args[1], logLevel);
} else { } else {
console.error( console.error(
'Usage: react-native init <ProjectName> [--verbose]' 'Usage: react-native init <ProjectName> [--debug|--verbose]'
); );
process.exit(1); process.exit(1);
} }
@ -123,17 +128,17 @@ function validatePackageName(name) {
} }
} }
function init(name, verbose) { function init(name, logLevel) {
validatePackageName(name); validatePackageName(name);
if (fs.existsSync(name)) { if (fs.existsSync(name)) {
createAfterConfirmation(name, verbose); createAfterConfirmation(name, logLevel);
} else { } else {
createProject(name, verbose); createProject(name, logLevel);
} }
} }
function createAfterConfirmation(name, verbose) { function createAfterConfirmation(name, logLevel) {
prompt.start(); prompt.start();
var property = { var property = {
@ -146,7 +151,7 @@ function createAfterConfirmation(name, verbose) {
prompt.get(property, function (err, result) { prompt.get(property, function (err, result) {
if (result.yesno[0] === 'y') { if (result.yesno[0] === 'y') {
createProject(name, verbose); createProject(name, logLevel);
} else { } else {
console.log('Project initialization canceled'); console.log('Project initialization canceled');
process.exit(); process.exit();
@ -154,7 +159,7 @@ function createAfterConfirmation(name, verbose) {
}); });
} }
function createProject(name, verbose) { function createProject(name, logLevel) {
var root = path.resolve(name); var root = path.resolve(name);
var projectName = path.basename(root); var projectName = path.basename(root);
@ -180,16 +185,20 @@ function createProject(name, verbose) {
console.log('Installing react-native package from npm...'); console.log('Installing react-native package from npm...');
run(root, projectName, verbose); run(root, projectName, logLevel);
} }
function run(root, projectName, verbose) { function run(root, projectName, logLevel) {
var args = ['install', '--save']; var args = ['install', '--save'];
if (verbose){ if (logLevel === 'verbose') {
args.push('--verbose'); args.push('--verbose');
} }
args.push('react-native'); args.push('react-native');
var proc = spawn('npm', args, {stdio: 'inherit'}); var spawnArgs = {};
if (logLevel === 'debug' || logLevel === 'verbose') {
spawnArgs = {stdio: 'inherit'};
}
var proc = spawn('npm', args, spawnArgs);
proc.on('close', function (code) { proc.on('close', function (code) {
if (code !== 0) { if (code !== 0) {
console.error('`npm install --save react-native` failed'); console.error('`npm install --save react-native` failed');

View File

@ -1,6 +1,6 @@
{ {
"name": "react-native-cli", "name": "react-native-cli",
"version": "0.1.7", "version": "0.1.8",
"license" : "BSD-3-Clause", "license" : "BSD-3-Clause",
"description": "The React Native CLI tools", "description": "The React Native CLI tools",
"main": "index.js", "main": "index.js",