NPM version check for tip (#1193)

* Implemented a version check of npm to give a soft tip during the install procedure
and fixed gitignore

* Moved NPM check to method, it is only executed when you use NPM and the version is < 3.

* Minor formatting tweaks

* Simplify the code

* Remove unnecessary change
This commit is contained in:
Mo Binni
2017-02-24 15:25:18 -05:00
committed by Joe Haddad
parent 93f7aeff1c
commit 3b5434ca35
2 changed files with 26 additions and 1 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
.idea/
.vscode/
node_modules/
build
.DS_Store

View File

@@ -152,6 +152,7 @@ function install(dependencies, verbose, callback) {
command = 'yarnpkg';
args = [ 'add', '--exact'].concat(dependencies);
} else {
checkNpmVersion();
command = 'npm';
args = ['install', '--save', '--save-exact'].concat(dependencies);
}
@@ -173,7 +174,10 @@ function run(root, appName, version, verbose, originalDirectory, template) {
var allDependencies = ['react', 'react-dom', packageToInstall];
console.log('Installing packages. This might take a couple minutes.');
console.log('Installing ' + chalk.cyan('react, react-dom, ' + packageName) + '...');
console.log(
'Installing ' + chalk.cyan('react') + ', ' + chalk.cyan('react-dom') +
', and ' + chalk.cyan(packageName) + '...'
);
console.log();
install(allDependencies, verbose, function(code, command, args) {
@@ -230,6 +234,25 @@ function getPackageName(installPackage) {
return installPackage;
}
function checkNpmVersion() {
var isNpm2 = false;
try {
var npmVersion = execSync('npm --version').toString();
isNpm2 = semver.lt(npmVersion, '3.0.0');
} catch (err) {
return;
}
if (!isNpm2) {
return;
}
console.log(chalk.yellow('It looks like you are using npm 2.'));
console.log(chalk.yellow(
'We suggest using npm 3 or Yarn for faster install times ' +
'and less disk space usage.'
));
console.log();
}
function checkNodeVersion(packageName) {
var packageJsonPath = path.resolve(
process.cwd(),