2016-10-04 23:39:20 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2015-11-14 11:10:31 -05:00
|
|
|
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
!!! !!!
|
|
|
|
!!! 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. !!!
|
|
|
|
!!! !!!
|
|
|
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2015-06-06 02:37:09 -04:00
|
|
|
var exec = require('child_process').exec;
|
2015-11-14 11:10:31 -05:00
|
|
|
var checkNodeModules;
|
|
|
|
var semver;
|
|
|
|
var issues = [];
|
|
|
|
|
|
|
|
// coarse Node version check
|
2016-09-19 14:40:08 -04:00
|
|
|
if (+process.version[1] < 5) {
|
2017-01-27 01:30:42 -05:00
|
|
|
issues.push('Angular build currently requires Node 5+. Use nvm to update your node version.');
|
2015-11-14 11:10:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
semver = require('semver');
|
2016-10-04 23:39:20 -04:00
|
|
|
} catch (e) {
|
|
|
|
issues.push('Looks like you are missing some npm dependencies. Run: npm install');
|
2015-11-14 11:10:31 -05:00
|
|
|
}
|
|
|
|
|
2016-01-21 17:15:32 -05:00
|
|
|
if (issues.length) {
|
|
|
|
printWarning(issues);
|
2016-10-04 23:39:20 -04:00
|
|
|
console.error(
|
|
|
|
'Your environment doesn\'t provide the prerequisite dependencies.\n' +
|
|
|
|
'Please fix the issues listed above and then rerun the gulp command.\n' +
|
|
|
|
'Check out https://github.com/angular/angular/blob/master/DEVELOPER.md for more info.');
|
2016-01-21 17:15:32 -05:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2015-11-14 11:10:31 -05:00
|
|
|
// wrap in try/catch in case someone requires from within that file
|
|
|
|
try {
|
|
|
|
checkNodeModules = require('./npm/check-node-modules.js');
|
2016-10-04 23:39:20 -04:00
|
|
|
} catch (e) {
|
|
|
|
issues.push('Looks like you are missing some npm dependencies. Run: npm install');
|
2015-11-14 11:10:31 -05:00
|
|
|
throw e;
|
|
|
|
} finally {
|
|
|
|
// print warnings and move on, the next steps will likely fail, but hey, we warned them.
|
|
|
|
printWarning(issues);
|
|
|
|
}
|
2015-06-06 02:37:09 -04:00
|
|
|
|
|
|
|
function checkEnvironment(reqs) {
|
2017-02-22 23:55:25 -05:00
|
|
|
exec('npm --version', function(npmErr, npmStdout) {
|
|
|
|
exec('yarn --version', function(yarnErr, yarnStdout) {
|
|
|
|
var foundNodeVersion = process.version;
|
|
|
|
var foundNpmVersion = semver.clean(npmStdout);
|
|
|
|
var foundYarnVersion = !yarnErr && semver.clean(yarnStdout);
|
|
|
|
var issues = [];
|
|
|
|
|
|
|
|
|
|
|
|
if (!semver.satisfies(foundNodeVersion, reqs.requiredNodeVersion)) {
|
|
|
|
issues.push(
|
|
|
|
'You are running unsupported node version. Found: ' + foundNodeVersion + ' Expected: ' +
|
|
|
|
reqs.requiredNodeVersion + '. Use nvm to update your node version.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!semver.satisfies(foundNpmVersion, reqs.requiredNpmVersion)) {
|
|
|
|
issues.push(
|
|
|
|
'You are running unsupported npm version. Found: ' + foundNpmVersion + ' Expected: ' +
|
|
|
|
reqs.requiredNpmVersion + '. Run: npm update -g npm');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yarnErr) {
|
|
|
|
issues.push(
|
|
|
|
'You don\'t have yarn globally installed. This is required if you want to work on ' +
|
|
|
|
'certain areas, such as `aio/` and `integration/`. Installation instructions: ' +
|
|
|
|
'https://yarnpkg.com/lang/en/docs/install/');
|
|
|
|
} else if (!semver.satisfies(foundYarnVersion, reqs.requiredYarnVersion)) {
|
|
|
|
issues.push(
|
|
|
|
'You are running unsupported yarn version. Found: ' + foundYarnVersion + ' Expected: ' +
|
|
|
|
reqs.requiredYarnVersion + '. This is required if you want to work on ' +
|
|
|
|
'certain areas, such as `aio/` and `integration/`. See: ' +
|
|
|
|
'https://yarnpkg.com/lang/en/docs/install/');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!checkNodeModules()) {
|
|
|
|
issues.push(
|
|
|
|
'Your node_modules directory is stale or out of sync with npm-shrinkwrap.json. Run: npm install');
|
|
|
|
}
|
|
|
|
|
|
|
|
printWarning(issues);
|
|
|
|
})
|
2015-06-06 02:37:09 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-14 11:10:31 -05:00
|
|
|
function printWarning(issues) {
|
|
|
|
if (!issues.length) return;
|
|
|
|
|
|
|
|
console.warn('');
|
2016-09-19 14:40:08 -04:00
|
|
|
console.warn('!'.repeat(110));
|
2015-11-14 11:10:31 -05:00
|
|
|
console.warn('!!! Your environment is not in a good shape. Following issues were found:');
|
2016-10-04 23:39:20 -04:00
|
|
|
issues.forEach(function(issue) { console.warn('!!! - ' + issue); });
|
2016-09-19 14:40:08 -04:00
|
|
|
console.warn('!'.repeat(110));
|
2015-11-14 11:10:31 -05:00
|
|
|
console.warn('');
|
2016-05-25 22:54:34 -04:00
|
|
|
|
|
|
|
if (process.env.CI) {
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2015-11-14 11:10:31 -05:00
|
|
|
}
|
|
|
|
|
2015-06-06 02:37:09 -04:00
|
|
|
|
|
|
|
module.exports = checkEnvironment;
|