Merge pull request #3580 from exponentjs/cli-version-check

[CLI] Make `react-native init` check your Node version
This commit is contained in:
Felix Oghină 2015-10-23 11:57:25 +01:00
commit 864fdd1ebd
2 changed files with 31 additions and 1 deletions

View File

@ -39,7 +39,9 @@ var fs = require('fs');
var path = require('path');
var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var chalk = require('chalk');
var prompt = require('prompt');
var semver = require('semver');
var CLI_MODULE_PATH = function() {
return path.resolve(
@ -50,6 +52,15 @@ var CLI_MODULE_PATH = function() {
);
};
var REACT_NATIVE_PACKAGE_JSON_PATH = function() {
return path.resolve(
process.cwd(),
'node_modules',
'react-native',
'package.json'
);
};
checkForVersionArgument();
var cli;
@ -185,6 +196,8 @@ function run(root, projectName) {
process.exit(1);
}
checkNodeVersion();
var cli = require(CLI_MODULE_PATH());
cli.init(root, projectName);
});
@ -203,6 +216,21 @@ function runVerbose(root, projectName) {
});
}
function checkNodeVersion() {
var packageJson = require(REACT_NATIVE_PACKAGE_JSON_PATH());
if (!packageJson.engines || !packageJson.engines.node) {
return;
}
if (!semver.satisfies(process.version, packageJson.engines.node)) {
console.error(chalk.red(
'You are currently running Node %s but React Native requires %s. ' +
'Please use a supported version of Node.'
),
process.version,
packageJson.engines.node);
}
}
function checkForVersionArgument() {
if (process.argv.indexOf('-v') >= 0 || process.argv.indexOf('--version') >= 0) {
var pjson = require('./package.json');

View File

@ -13,6 +13,8 @@
"react-native": "index.js"
},
"dependencies": {
"prompt": "^0.2.14"
"chalk": "^1.1.1",
"prompt": "^0.2.14",
"semver": "^5.0.3"
}
}