forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-node-modules.js
executable file
·57 lines (47 loc) · 1.49 KB
/
check-node-modules.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* @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';
var fs = require('fs');
var path = require('path');
var childProcess = require('child_process');
var PROJECT_ROOT = path.join(__dirname, '../../');
// tslint:disable:no-console
function checkNodeModules(logOutput, purgeIfStale) {
var yarnCheck = childProcess.spawnSync(
'yarn check --integrity', {shell: true, cwd: path.resolve(__dirname, '../..')});
var nodeModulesOK = yarnCheck.status === 0;
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...');
_deleteDir(path.join(PROJECT_ROOT, 'node_modules'));
}
}
return nodeModulesOK;
}
/**
* Custom implementation of recursive `rm` because we can't rely on the state of node_modules to
* pull in existing module.
*/
function _deleteDir(path) {
if (fs.existsSync(path)) {
var subpaths = fs.readdirSync(path);
subpaths.forEach(function(subpath) {
var curPath = path + '/' + subpath;
if (fs.lstatSync(curPath).isDirectory()) {
_deleteDir(curPath);
} else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}
module.exports = checkNodeModules;