| 
									
										
										
										
											2021-07-06 19:22:12 -05:00
										 |  |  | const { insertErms } = require('./insert-erms'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Builds a block
 | 
					
						
							|  |  |  | function getCodeBlock(label, content) { | 
					
						
							|  |  |  |   return `\`\`\`${label}
 | 
					
						
							|  |  |  | ${typeof content !== 'undefined' ? content : ''} | 
					
						
							| 
									
										
										
										
											2021-09-28 20:00:37 -07:00
										 |  |  | \`\`\`\n`; | 
					
						
							| 
									
										
										
										
											2021-07-06 19:22:12 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Builds a section
 | 
					
						
							|  |  |  | function getSeedSection(content, label) { | 
					
						
							|  |  |  |   return content | 
					
						
							|  |  |  |     ? `
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## --${label}-- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ${content}`
 | 
					
						
							|  |  |  |     : ''; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Build the base markdown for a step
 | 
					
						
							|  |  |  | function getStepTemplate({ | 
					
						
							|  |  |  |   challengeId, | 
					
						
							|  |  |  |   challengeSeeds, | 
					
						
							|  |  |  |   stepBetween, | 
					
						
							|  |  |  |   stepNum | 
					
						
							|  |  |  | }) { | 
					
						
							|  |  |  |   const seedTexts = Object.values(challengeSeeds) | 
					
						
							|  |  |  |     .map(({ contents, ext, editableRegionBoundaries }) => { | 
					
						
							| 
									
										
										
										
											2021-07-21 17:14:22 +01:00
										 |  |  |       let fullContents = contents; | 
					
						
							|  |  |  |       if (editableRegionBoundaries.length >= 2) { | 
					
						
							|  |  |  |         fullContents = insertErms(contents, editableRegionBoundaries); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-07-06 19:22:12 -05:00
										 |  |  |       return getCodeBlock(ext, fullContents); | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     .join('\n'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const seedHeads = Object.values(challengeSeeds) | 
					
						
							|  |  |  |     .filter(({ head }) => head) | 
					
						
							|  |  |  |     .map(({ ext, head }) => getCodeBlock(ext, head)) | 
					
						
							|  |  |  |     .join('\n'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const seedTails = Object.values(challengeSeeds) | 
					
						
							|  |  |  |     .filter(({ tail }) => tail) | 
					
						
							|  |  |  |     .map(({ ext, tail }) => getCodeBlock(ext, tail)) | 
					
						
							|  |  |  |     .join('\n'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const descStepNum = stepBetween ? stepNum + 1 : stepNum; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const stepDescription = `${ | 
					
						
							|  |  |  |     stepBetween ? 'new ' : '' | 
					
						
							|  |  |  |   }step ${descStepNum} instructions`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const seedChallengeSection = getSeedSection(seedTexts, 'seed-contents'); | 
					
						
							|  |  |  |   const seedHeadSection = getSeedSection(seedHeads, 'before-user-code'); | 
					
						
							|  |  |  |   const seedTailSection = getSeedSection(seedTails, 'after-user-code'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     `---
 | 
					
						
							|  |  |  | id: ${challengeId} | 
					
						
							| 
									
										
										
										
											2021-10-21 10:07:52 -07:00
										 |  |  | title: Step ${stepNum} | 
					
						
							| 
									
										
										
										
											2021-07-06 19:22:12 -05:00
										 |  |  | challengeType: 0 | 
					
						
							| 
									
										
										
										
											2021-10-21 10:07:52 -07:00
										 |  |  | dashedName: step-${stepNum} | 
					
						
							| 
									
										
										
										
											2021-07-06 19:22:12 -05:00
										 |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # --description-- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ${stepDescription} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # --hints-- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Test 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ${getCodeBlock('js')} | 
					
						
							|  |  |  | # --seed--` +
 | 
					
						
							|  |  |  |     seedChallengeSection + | 
					
						
							|  |  |  |     seedHeadSection + | 
					
						
							|  |  |  |     seedTailSection | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exports.getStepTemplate = getStepTemplate; |