Skip to content

Commit

Permalink
Moved NPM check to method, it is only executed when you use NPM and t…
Browse files Browse the repository at this point in the history
…he version is < 3.
  • Loading branch information
Mo Binni committed Feb 24, 2017
1 parent c5cbee8 commit 97f49f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
.vscode/
node_modules/
build
Expand Down
34 changes: 19 additions & 15 deletions packages/create-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,6 @@ function createApp(name, verbose, version, template) {
);
console.log();

// Check npm version
var npmVersionProc = spawn.sync('npm', ['--version']),
npmVersion = npmVersionProc.stdout;
if (npmVersion) {
var recommendVersion = semver.lt(npmVersion.toString(), '3.0.0');
if (recommendVersion) {
console.log(
chalk.green(
'Tip: It looks like you are using npm 2.\n' +
'We suggest using npm 3 or Yarn for faster install times and less disk space usage.'
)
);
}
}

var packageJson = {
name: appName,
version: '0.1.0',
Expand Down Expand Up @@ -167,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);
}
Expand Down Expand Up @@ -245,6 +231,24 @@ function getPackageName(installPackage) {
return installPackage;
}

function checkNpmVersion() {
// Check npm version
var npmVersionProc = spawn.sync('npm', ['--version']),
npmVersion = npmVersionProc.stdout;

if (npmVersion) {
var recommendVersion = semver.lt(npmVersion.toString(), '3.0.0');
if (recommendVersion) {
console.log(
chalk.green(
'Tip: It looks like you are using npm 2.\n' +
'We suggest using npm 3 or Yarn for faster install times and less disk space usage.'
)
);
}
}
}

function checkNodeVersion(packageName) {
var packageJsonPath = path.resolve(
process.cwd(),
Expand Down

0 comments on commit 97f49f9

Please sign in to comment.