| 
									
										
										
										
											2016-10-04 20:39:20 -07: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-05 23:37:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | var fs = require('fs'); | 
					
						
							|  |  |  | var path = require('path'); | 
					
						
							| 
									
										
										
										
											2017-09-21 15:39:43 +02:00
										 |  |  | var childProcess = require('child_process'); | 
					
						
							| 
									
										
										
										
											2015-06-05 23:37:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | var PROJECT_ROOT = path.join(__dirname, '../../'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-22 19:51:03 +02:00
										 |  |  | // tslint:disable:no-console
 | 
					
						
							| 
									
										
										
										
											2015-06-05 23:37:09 -07:00
										 |  |  | function checkNodeModules(logOutput, purgeIfStale) { | 
					
						
							| 
									
										
										
										
											2017-09-21 15:39:43 +02:00
										 |  |  |   var yarnCheck = childProcess.spawnSync( | 
					
						
							| 
									
										
										
										
											2017-11-03 00:11:34 +02:00
										 |  |  |       'yarn check --integrity', {shell: true, cwd: path.resolve(__dirname, '../..')}); | 
					
						
							| 
									
										
										
										
											2015-06-05 23:37:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 15:39:43 +02:00
										 |  |  |   var nodeModulesOK = yarnCheck.status === 0; | 
					
						
							| 
									
										
										
										
											2015-06-05 23:37:09 -07: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-13 01:01:33 +02:00
										 |  |  |       _deleteDir(path.join(PROJECT_ROOT, 'node_modules')); | 
					
						
							| 
									
										
										
										
											2015-06-05 23:37:09 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return nodeModulesOK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-01 09:19:03 -07: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 20:39:20 -07:00
										 |  |  |   if (fs.existsSync(path)) { | 
					
						
							| 
									
										
										
										
											2015-07-01 09:19:03 -07:00
										 |  |  |     var subpaths = fs.readdirSync(path); | 
					
						
							|  |  |  |     subpaths.forEach(function(subpath) { | 
					
						
							| 
									
										
										
										
											2016-10-04 20:39:20 -07:00
										 |  |  |       var curPath = path + '/' + subpath; | 
					
						
							|  |  |  |       if (fs.lstatSync(curPath).isDirectory()) { | 
					
						
							| 
									
										
										
										
											2015-07-01 09:19:03 -07:00
										 |  |  |         _deleteDir(curPath); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         fs.unlinkSync(curPath); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     fs.rmdirSync(path); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-05 23:37:09 -07:00
										 |  |  | module.exports = checkNodeModules; |