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 chalk = require('chalk');
|
||||||
var prompt = require('prompt');
|
var prompt = require('prompt');
|
||||||
var semver = require('semver');
|
var semver = require('semver');
|
||||||
var os = require('os');
|
|
||||||
|
|
||||||
var CLI_MODULE_PATH = function() {
|
var CLI_MODULE_PATH = function() {
|
||||||
return path.resolve(
|
return path.resolve(
|
||||||
|
@ -84,16 +83,11 @@ if (cli) {
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case 'init':
|
case 'init':
|
||||||
if (args[1]) {
|
if (args[1]) {
|
||||||
var logLevel = '';
|
var verbose = process.argv.indexOf('--verbose') >= 0;
|
||||||
if (process.argv.indexOf('--verbose') >= 0) {
|
init(args[1], verbose);
|
||||||
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> [--debug|--verbose]'
|
'Usage: react-native init <ProjectName> [--verbose]'
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
@ -129,17 +123,17 @@ function validatePackageName(name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(name, logLevel) {
|
function init(name, verbose) {
|
||||||
validatePackageName(name);
|
validatePackageName(name);
|
||||||
|
|
||||||
if (fs.existsSync(name)) {
|
if (fs.existsSync(name)) {
|
||||||
createAfterConfirmation(name, logLevel);
|
createAfterConfirmation(name, verbose);
|
||||||
} else {
|
} else {
|
||||||
createProject(name, logLevel);
|
createProject(name, verbose);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createAfterConfirmation(name, logLevel) {
|
function createAfterConfirmation(name, verbose) {
|
||||||
prompt.start();
|
prompt.start();
|
||||||
|
|
||||||
var property = {
|
var property = {
|
||||||
|
@ -152,7 +146,7 @@ function createAfterConfirmation(name, logLevel) {
|
||||||
|
|
||||||
prompt.get(property, function (err, result) {
|
prompt.get(property, function (err, result) {
|
||||||
if (result.yesno[0] === 'y') {
|
if (result.yesno[0] === 'y') {
|
||||||
createProject(name, logLevel);
|
createProject(name, verbose);
|
||||||
} else {
|
} else {
|
||||||
console.log('Project initialization canceled');
|
console.log('Project initialization canceled');
|
||||||
process.exit();
|
process.exit();
|
||||||
|
@ -160,7 +154,7 @@ function createAfterConfirmation(name, logLevel) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createProject(name, logLevel) {
|
function createProject(name, verbose) {
|
||||||
var root = path.resolve(name);
|
var root = path.resolve(name);
|
||||||
var projectName = path.basename(root);
|
var projectName = path.basename(root);
|
||||||
|
|
||||||
|
@ -186,35 +180,37 @@ function createProject(name, logLevel) {
|
||||||
|
|
||||||
console.log('Installing react-native package from npm...');
|
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) {
|
function run(root, projectName) {
|
||||||
var args = ['install', '--save'];
|
exec('npm install --save react-native', function(e, stdout, stderr) {
|
||||||
if (logLevel === 'verbose') {
|
if (e) {
|
||||||
args.push('--verbose');
|
console.log(stdout);
|
||||||
|
console.error(stderr);
|
||||||
|
console.error('`npm install --save react-native` failed');
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
args.push('react-native');
|
|
||||||
var spawnArgs = {};
|
checkNodeVersion();
|
||||||
if (logLevel === 'debug' || logLevel === 'verbose') {
|
|
||||||
spawnArgs = {stdio: 'inherit'};
|
var cli = require(CLI_MODULE_PATH());
|
||||||
}
|
cli.init(root, projectName);
|
||||||
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 runVerbose(root, projectName) {
|
||||||
|
var proc = spawn('npm', ['install', '--verbose', '--save', 'react-native'], {stdio: 'inherit'});
|
||||||
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');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkNodeVersion();
|
|
||||||
|
|
||||||
cli = require(CLI_MODULE_PATH());
|
cli = require(CLI_MODULE_PATH());
|
||||||
cli.init(root, projectName);
|
cli.init(root, projectName);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "react-native-cli",
|
"name": "react-native-cli",
|
||||||
"version": "0.1.9",
|
"version": "0.1.10",
|
||||||
"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",
|
||||||
|
|
Loading…
Reference in New Issue