| 
									
										
										
										
											2018-09-06 15:24:49 +01:00
										 |  |  | require('dotenv').config(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 11:23:18 +01:00
										 |  |  | const { spawn } = require('child_process'); | 
					
						
							|  |  |  | const kill = require('tree-kill'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const spawnOpts = { | 
					
						
							|  |  |  |   stdio: 'inherit', | 
					
						
							|  |  |  |   shell: true | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const loopback = spawn( | 
					
						
							|  |  |  |   'cd', | 
					
						
							|  |  |  |   ['./api-server', '&&', 'node development-entry.js'], | 
					
						
							|  |  |  |   spawnOpts | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | const gatsby = spawn('cd', ['./client', '&&', 'npm run develop'], spawnOpts); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  | let cleanupCalled = false; | 
					
						
							| 
									
										
										
										
											2018-09-03 11:23:18 +01:00
										 |  |  | function cleanUp() { | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |   if (cleanupCalled) { | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   cleanupCalled = true; | 
					
						
							| 
									
										
										
										
											2018-09-03 11:23:18 +01:00
										 |  |  |   console.log(`
 | 
					
						
							|  |  |  |   Killing processes... | 
					
						
							|  |  |  |   `);
 | 
					
						
							|  |  |  |   const promises = [ | 
					
						
							|  |  |  |     kill(loopback.pid, 'SIGINT', () => Promise.resolve()), | 
					
						
							|  |  |  |     kill(gatsby.pid, 'SIGINT', () => Promise.resolve()) | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  |   return Promise.all(promises).then(() => { | 
					
						
							|  |  |  |     console.log(`
 | 
					
						
							|  |  |  |     All processes have exited | 
					
						
							|  |  |  |   `);
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | process.on('exit', cleanUp); | 
					
						
							|  |  |  | process.on('SIGINT', cleanUp); | 
					
						
							|  |  |  | process.on('SIGUSR1', cleanUp); | 
					
						
							|  |  |  | process.on('SIGUSR2', cleanUp); |