| 
									
										
										
										
											2021-02-18 11:46:29 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const { execSync } = require('child_process'); | 
					
						
							|  |  |  | const execa = require('execa'); | 
					
						
							|  |  |  | const logger = require('./logger'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2021-11-23 19:09:56 +01:00
										 |  |  |  * @param {string} path Path to directory (frontend, backend) | 
					
						
							| 
									
										
										
										
											2021-11-23 16:58:16 +01:00
										 |  |  |  * @param {Object} options | 
					
						
							|  |  |  |  * @param {boolean} options.useYarn Use yarn instead of npm | 
					
						
							| 
									
										
										
										
											2021-02-18 11:46:29 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-11-24 09:52:26 +01:00
										 |  |  | function runInstall(path, { useYarn } = {}) { | 
					
						
							| 
									
										
										
										
											2021-11-23 19:09:56 +01:00
										 |  |  |   return execa(useYarn ? 'yarn' : 'npm', ['install'], { | 
					
						
							|  |  |  |     cwd: path, | 
					
						
							|  |  |  |     stdin: 'ignore', | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-02-18 11:46:29 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-23 16:58:16 +01:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2021-11-23 19:09:56 +01:00
										 |  |  |  * @param {string} rootPath | 
					
						
							| 
									
										
										
										
											2021-11-23 16:58:16 +01:00
										 |  |  |  * @param {Object} options | 
					
						
							|  |  |  |  * @param {boolean} options.useYarn | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-11-24 09:52:26 +01:00
										 |  |  | function runApp(rootPath, { useYarn } = {}) { | 
					
						
							| 
									
										
										
										
											2021-11-23 16:58:16 +01:00
										 |  |  |   if (useYarn) { | 
					
						
							| 
									
										
										
										
											2021-02-18 11:46:29 +01:00
										 |  |  |     return execa('yarn', ['develop'], { | 
					
						
							|  |  |  |       stdio: 'inherit', | 
					
						
							|  |  |  |       cwd: rootPath, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |   return execa('npm', ['run', 'develop'], { | 
					
						
							|  |  |  |     stdio: 'inherit', | 
					
						
							|  |  |  |     cwd: rootPath, | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-02-18 11:46:29 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function initGit(rootPath) { | 
					
						
							|  |  |  |   try { | 
					
						
							|  |  |  |     await execa('git', ['init'], { | 
					
						
							|  |  |  |       cwd: rootPath, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } catch (err) { | 
					
						
							|  |  |  |     logger.warn(`Could not initialize a git repository`); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   try { | 
					
						
							|  |  |  |     await execa(`git`, [`add`, `-A`], { cwd: rootPath }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     execSync(`git commit -m "Create Strapi starter project"`, { | 
					
						
							|  |  |  |       cwd: rootPath, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } catch (err) { | 
					
						
							|  |  |  |     logger.warn(`Could not create initial git commit`); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |   runInstall, | 
					
						
							|  |  |  |   runApp, | 
					
						
							|  |  |  |   initGit, | 
					
						
							|  |  |  | }; |