| 
									
										
										
										
											2020-08-25 02:35:46 -07:00
										 |  |  | const fs = require('fs'); | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:57:51 -07:00
										 |  |  | const { | 
					
						
							|  |  |  |   reorderSteps, | 
					
						
							|  |  |  |   createStepFile, | 
					
						
							| 
									
										
										
										
											2021-03-31 09:19:46 -06:00
										 |  |  |   getChallengeSeeds, | 
					
						
							| 
									
										
										
										
											2020-08-27 18:57:51 -07:00
										 |  |  |   getProjectPath | 
					
						
							|  |  |  | } = require('./utils'); | 
					
						
							| 
									
										
										
										
											2020-08-25 02:35:46 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const getLastStepFileContent = () => { | 
					
						
							|  |  |  |   const filesArr = []; | 
					
						
							|  |  |  |   fs.readdirSync(projectPath).forEach(fileName => { | 
					
						
							|  |  |  |     if ( | 
					
						
							|  |  |  |       path.extname(fileName).toLowerCase() === '.md' && | 
					
						
							|  |  |  |       !fileName.endsWith('final.md') | 
					
						
							|  |  |  |     ) { | 
					
						
							|  |  |  |       filesArr.push(fileName); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const fileName = filesArr[filesArr.length - 1]; | 
					
						
							|  |  |  |   let lastStepFileNum = fileName.split('.')[0].split('-')[1]; | 
					
						
							|  |  |  |   lastStepFileNum = parseInt(lastStepFileNum, 10); | 
					
						
							|  |  |  |   if (filesArr.length !== lastStepFileNum) { | 
					
						
							|  |  |  |     throw `Error: The last file step is ${lastStepFileNum} and there are ${filesArr.length} files.`; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-27 18:57:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-25 02:35:46 -07:00
										 |  |  |   return { | 
					
						
							|  |  |  |     nextStepNum: lastStepFileNum + 1, | 
					
						
							| 
									
										
										
										
											2021-03-31 09:19:46 -06:00
										 |  |  |     challengeSeeds: getChallengeSeeds(projectPath + fileName) | 
					
						
							| 
									
										
										
										
											2020-08-25 02:35:46 -07:00
										 |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:57:51 -07:00
										 |  |  | const projectPath = getProjectPath(); | 
					
						
							| 
									
										
										
										
											2020-08-25 02:35:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 09:19:46 -06:00
										 |  |  | const { nextStepNum, challengeSeeds } = getLastStepFileContent(); | 
					
						
							| 
									
										
										
										
											2020-08-25 02:35:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 09:19:46 -06:00
										 |  |  | createStepFile({ stepNum: nextStepNum, projectPath, challengeSeeds }); | 
					
						
							| 
									
										
										
										
											2020-08-25 02:35:46 -07:00
										 |  |  | console.log(`Sucessfully added step #${nextStepNum}`); | 
					
						
							|  |  |  | reorderSteps(); |