build: improve the environmental check and warnings

- we now correctly print errors even on old Node versions
- we print error messages even when node_modules are missing or messed up
- error messages looks better

Closes #5230
This commit is contained in:
Igor Minar 2015-11-14 08:10:31 -08:00 committed by Jeremy Elbourn
parent 1417e12f28
commit 7f783289ab
2 changed files with 56 additions and 11 deletions

View File

@ -1,5 +1,11 @@
'use strict';
// THIS CHECK SHOULD BE THE FIRST THING IN THIS FILE
// This is to ensure that we catch env issues before we error while requiring other dependencies.
require('./tools/check-environment')(
{requiredNpmVersion: '>=2.14.7 <3.0.0', requiredNodeVersion: '>=4.2.1 <5.0.0'});
var del = require('del');
var gulp = require('gulp');
var gulpPlugins = require('gulp-load-plugins')();
@ -26,8 +32,6 @@ var dartSdk = require('./tools/build/dart');
var browserProvidersConf = require('./browser-providers.conf.js');
require('./tools/check-environment')(
{requiredNpmVersion: '>=2.14.7', requiredNodeVersion: '>=4.2.1'});
var cliArgs = minimist(process.argv.slice(2));

View File

@ -1,7 +1,42 @@
var exec = require('child_process').exec;
var semver = require('semver');
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! !!!
!!! This file is special in that it must be able to execute with wrong Node version !!!
!!! or even when node_modules are missing. !!!
!!! !!!
!!! Do not depend on Node4+ features or presence of npm packages here. !!!
!!! !!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
var checkNodeModules = require('./npm/check-node-modules.js');
'use strict';
var exec = require('child_process').exec;
var checkNodeModules;
var semver;
var issues = [];
// coarse Node version check
if (process.version[1] !== '4') {
issues.push("Angular 2 build currently requires Node 4. Use nvm to update your node version.");
}
try {
semver = require('semver');
} catch(e) {
issues.push("Looks like you are missing some npm dependencies. Run: npm install");
}
// wrap in try/catch in case someone requires from within that file
try {
checkNodeModules = require('./npm/check-node-modules.js');
} catch(e) {
issues.push("Looks like you are missing some npm dependencies. Run: npm install");
throw e;
} finally {
// print warnings and move on, the next steps will likely fail, but hey, we warned them.
printWarning(issues);
}
function checkEnvironment(reqs) {
@ -26,14 +61,20 @@ function checkEnvironment(reqs) {
issues.push('Your node_modules directory is stale or out of sync with npm-shrinkwrap.json. Run: npm install');
}
if (issues.length) {
console.warn(Array(80).join('!'));
console.warn('Your environment is not in a good shape. Following issues were found:');
issues.forEach(function(issue) {console.warn(' - ' + issue)});
console.warn(Array(80).join('!'));
}
printWarning(issues);
});
}
function printWarning(issues) {
if (!issues.length) return;
console.warn('');
console.warn(Array(110).join('!'));
console.warn('!!! Your environment is not in a good shape. Following issues were found:');
issues.forEach(function(issue) {console.warn('!!! - ' + issue)});
console.warn(Array(110).join('!'));
console.warn('');
}
module.exports = checkEnvironment;