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
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
2015-06-06 02:37:09 -04:00
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
2017-09-21 09:39:43 -04:00
|
|
|
var childProcess = require('child_process');
|
2015-06-06 02:37:09 -04:00
|
|
|
|
|
|
|
var PROJECT_ROOT = path.join(__dirname, '../../');
|
|
|
|
|
|
|
|
|
|
|
|
function checkNodeModules(logOutput, purgeIfStale) {
|
2017-09-21 09:39:43 -04:00
|
|
|
var yarnCheck = childProcess.spawnSync(
|
|
|
|
'./node_modules/.bin/yarn check --integrity',
|
|
|
|
{shell: true, cwd: path.resolve(__dirname, '../..')});
|
2015-06-06 02:37:09 -04:00
|
|
|
|
2017-09-21 09:39:43 -04:00
|
|
|
var nodeModulesOK = yarnCheck.status === 0;
|
2015-06-06 02:37:09 -04:00
|
|
|
if (nodeModulesOK) {
|
|
|
|
if (logOutput) console.log(':-) npm dependencies are looking good!');
|
|
|
|
} else {
|
|
|
|
if (logOutput) console.error(':-( npm dependencies are stale or in an in unknown state!');
|
|
|
|
if (purgeIfStale) {
|
|
|
|
if (logOutput) console.log(' purging...');
|
2016-05-12 19:01:33 -04:00
|
|
|
_deleteDir(path.join(PROJECT_ROOT, 'node_modules'));
|
2015-06-06 02:37:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodeModulesOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-01 12:19:03 -04:00
|
|
|
/**
|
|
|
|
* Custom implementation of recursive `rm` because we can't rely on the state of node_modules to
|
|
|
|
* pull in existing module.
|
|
|
|
*/
|
|
|
|
function _deleteDir(path) {
|
2016-10-04 23:39:20 -04:00
|
|
|
if (fs.existsSync(path)) {
|
2015-07-01 12:19:03 -04:00
|
|
|
var subpaths = fs.readdirSync(path);
|
|
|
|
subpaths.forEach(function(subpath) {
|
2016-10-04 23:39:20 -04:00
|
|
|
var curPath = path + '/' + subpath;
|
|
|
|
if (fs.lstatSync(curPath).isDirectory()) {
|
2015-07-01 12:19:03 -04:00
|
|
|
_deleteDir(curPath);
|
|
|
|
} else {
|
|
|
|
fs.unlinkSync(curPath);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fs.rmdirSync(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-06 02:37:09 -04:00
|
|
|
module.exports = checkNodeModules;
|