| 
									
										
										
										
											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
										 |  |  |   padWithLeadingZeros, | 
					
						
							|  |  |  |   getExistingStepNums, | 
					
						
							| 
									
										
										
										
											2020-10-03 02:54:19 -07:00
										 |  |  |   getProjectPath, | 
					
						
							|  |  |  |   getArgValues | 
					
						
							| 
									
										
										
										
											2020-08-27 18:57:51 -07:00
										 |  |  | } = require('./utils'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const allStepsExist = (steps, stepsToFind) => | 
					
						
							|  |  |  |   stepsToFind.every(num => steps.includes(num)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const projectPath = getProjectPath(); | 
					
						
							| 
									
										
										
										
											2020-10-03 02:54:19 -07:00
										 |  |  | const args = getArgValues(process.argv); | 
					
						
							| 
									
										
										
										
											2020-08-27 18:57:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-27 20:29:49 +02:00
										 |  |  | const start = parseInt(args.start, 10); | 
					
						
							| 
									
										
										
										
											2020-08-27 18:57:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-27 20:29:49 +02:00
										 |  |  | if (!Number.isInteger(start) || start < 1) { | 
					
						
							|  |  |  |   throw 'Step not created. Start step must be greater than 0.'; | 
					
						
							| 
									
										
										
										
											2020-08-27 18:57:51 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-27 20:29:49 +02:00
										 |  |  | const end = start + 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:57:51 -07:00
										 |  |  | const existingSteps = getExistingStepNums(projectPath); | 
					
						
							|  |  |  | if (!allStepsExist(existingSteps, [start, end])) { | 
					
						
							| 
									
										
										
										
											2021-04-27 20:29:49 +02:00
										 |  |  |   throw `Step not created. Both start step, ${start}, and end step, ${end}, must exist`; | 
					
						
							| 
									
										
										
										
											2020-08-27 18:57:51 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 09:19:46 -06:00
										 |  |  | const challengeSeeds = getChallengeSeeds( | 
					
						
							| 
									
										
										
										
											2020-08-27 18:57:51 -07:00
										 |  |  |   `${projectPath}part-${padWithLeadingZeros(start)}.md` | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | createStepFile({ | 
					
						
							|  |  |  |   stepNum: start, | 
					
						
							|  |  |  |   projectPath, | 
					
						
							| 
									
										
										
										
											2021-03-31 09:19:46 -06:00
										 |  |  |   challengeSeeds, | 
					
						
							| 
									
										
										
										
											2020-08-27 18:57:51 -07:00
										 |  |  |   stepBetween: true | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | console.log(`Sucessfully added step between step #${start} and step #${end}`); | 
					
						
							|  |  |  | reorderSteps(); |