Revert 5da0e135b6
It caused problems on Windows unfortunately and when we tried to fix it we got: https://github.com/facebook/react-native/issues/5159 Reverting to unblock people. In the future we'll do careful rc releases of the CLI. We should try to make the change again without breaking anyone, regardless of OS (OSX, Linux, Windows) or npm version.
This commit is contained in:
parent
d8830fb2b8
commit
521bd03f0a
|
@ -42,7 +42,6 @@ var spawn = require('child_process').spawn;
|
|||
var chalk = require('chalk');
|
||||
var prompt = require('prompt');
|
||||
var semver = require('semver');
|
||||
var os = require('os');
|
||||
|
||||
var CLI_MODULE_PATH = function() {
|
||||
return path.resolve(
|
||||
|
@ -84,16 +83,11 @@ if (cli) {
|
|||
switch (args[0]) {
|
||||
case 'init':
|
||||
if (args[1]) {
|
||||
var logLevel = '';
|
||||
if (process.argv.indexOf('--verbose') >= 0) {
|
||||
logLevel = 'verbose';
|
||||
} else if (process.argv.indexOf('--debug') >= 0) {
|
||||
logLevel = 'debug';
|
||||
}
|
||||
init(args[1], logLevel);
|
||||
var verbose = process.argv.indexOf('--verbose') >= 0;
|
||||
init(args[1], verbose);
|
||||
} else {
|
||||
console.error(
|
||||
'Usage: react-native init <ProjectName> [--debug|--verbose]'
|
||||
'Usage: react-native init <ProjectName> [--verbose]'
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
@ -129,17 +123,17 @@ function validatePackageName(name) {
|
|||
}
|
||||
}
|
||||
|
||||
function init(name, logLevel) {
|
||||
function init(name, verbose) {
|
||||
validatePackageName(name);
|
||||
|
||||
if (fs.existsSync(name)) {
|
||||
createAfterConfirmation(name, logLevel);
|
||||
createAfterConfirmation(name, verbose);
|
||||
} else {
|
||||
createProject(name, logLevel);
|
||||
createProject(name, verbose);
|
||||
}
|
||||
}
|
||||
|
||||
function createAfterConfirmation(name, logLevel) {
|
||||
function createAfterConfirmation(name, verbose) {
|
||||
prompt.start();
|
||||
|
||||
var property = {
|
||||
|
@ -152,7 +146,7 @@ function createAfterConfirmation(name, logLevel) {
|
|||
|
||||
prompt.get(property, function (err, result) {
|
||||
if (result.yesno[0] === 'y') {
|
||||
createProject(name, logLevel);
|
||||
createProject(name, verbose);
|
||||
} else {
|
||||
console.log('Project initialization canceled');
|
||||
process.exit();
|
||||
|
@ -160,7 +154,7 @@ function createAfterConfirmation(name, logLevel) {
|
|||
});
|
||||
}
|
||||
|
||||
function createProject(name, logLevel) {
|
||||
function createProject(name, verbose) {
|
||||
var root = path.resolve(name);
|
||||
var projectName = path.basename(root);
|
||||
|
||||
|
@ -186,35 +180,37 @@ function createProject(name, logLevel) {
|
|||
|
||||
console.log('Installing react-native package from npm...');
|
||||
|
||||
run(root, projectName, logLevel);
|
||||
if (verbose) {
|
||||
runVerbose(root, projectName);
|
||||
} else {
|
||||
run(root, projectName);
|
||||
}
|
||||
}
|
||||
|
||||
function run(root, projectName, logLevel) {
|
||||
var args = ['install', '--save'];
|
||||
if (logLevel === 'verbose') {
|
||||
args.push('--verbose');
|
||||
}
|
||||
args.push('react-native');
|
||||
var spawnArgs = {};
|
||||
if (logLevel === 'debug' || logLevel === 'verbose') {
|
||||
spawnArgs = {stdio: 'inherit'};
|
||||
}
|
||||
var proc;
|
||||
if (/^win/.test(process.platform)) {
|
||||
args.unshift('npm');
|
||||
args.unshift('/c');
|
||||
proc = spawn('cmd', args, spawnArgs);
|
||||
} else {
|
||||
proc = spawn('npm', args, spawnArgs);
|
||||
}
|
||||
function run(root, projectName) {
|
||||
exec('npm install --save react-native', function(e, stdout, stderr) {
|
||||
if (e) {
|
||||
console.log(stdout);
|
||||
console.error(stderr);
|
||||
console.error('`npm install --save react-native` failed');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
checkNodeVersion();
|
||||
|
||||
var cli = require(CLI_MODULE_PATH());
|
||||
cli.init(root, projectName);
|
||||
});
|
||||
}
|
||||
|
||||
function runVerbose(root, projectName) {
|
||||
var proc = spawn('npm', ['install', '--verbose', '--save', 'react-native'], {stdio: 'inherit'});
|
||||
proc.on('close', function (code) {
|
||||
if (code !== 0) {
|
||||
console.error('`npm install --save react-native` failed');
|
||||
return;
|
||||
}
|
||||
|
||||
checkNodeVersion();
|
||||
|
||||
cli = require(CLI_MODULE_PATH());
|
||||
cli.init(root, projectName);
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "react-native-cli",
|
||||
"version": "0.1.9",
|
||||
"version": "0.1.10",
|
||||
"license" : "BSD-3-Clause",
|
||||
"description": "The React Native CLI tools",
|
||||
"main": "index.js",
|
||||
|
|
Loading…
Reference in New Issue