| 
									
										
										
										
											2018-03-26 13:01:24 +01:00
										 |  |  | const crypto = require('crypto'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 18:22:52 +00:00
										 |  |  | function createChallengeNode(challenge, reporter) { | 
					
						
							| 
									
										
										
										
											2020-09-24 12:34:35 +02:00
										 |  |  |   // challengeType 11 is for video challenges (they only have instructions)
 | 
					
						
							|  |  |  |   // challengeType 7 is for certificates (they only have tests)
 | 
					
						
							| 
									
										
										
										
											2021-06-15 10:37:13 -05:00
										 |  |  |   // challengeType 12 is for CodeAlly/CodeRoad challenge
 | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // TODO: either handle empty descriptions inside Gatsby OR ensure that
 | 
					
						
							|  |  |  |   // description defaults to '' when creating challenges.
 | 
					
						
							|  |  |  |   // ditto for seeds and instructions.
 | 
					
						
							|  |  |  |   // create-md should, then, not create empty seed, description or instruction
 | 
					
						
							|  |  |  |   // sections.
 | 
					
						
							| 
									
										
										
										
											2020-04-21 17:19:22 -05:00
										 |  |  |   if ( | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  |     typeof challenge.description !== 'string' && | 
					
						
							| 
									
										
										
										
											2021-03-11 00:31:46 +05:30
										 |  |  |     challenge.challengeType !== 11 && | 
					
						
							| 
									
										
										
										
											2021-06-15 10:37:13 -05:00
										 |  |  |     challenge.challengeType !== 7 && | 
					
						
							|  |  |  |     challenge.challengeType !== 12 | 
					
						
							| 
									
										
										
										
											2020-04-21 17:19:22 -05:00
										 |  |  |   ) { | 
					
						
							| 
									
										
										
										
											2018-04-16 12:04:25 +01:00
										 |  |  |     reporter.warn(`
 | 
					
						
							| 
									
										
										
										
											2018-03-26 13:01:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-06 14:51:52 +01:00
										 |  |  |     ${challenge.title} has a description that will break things! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     `);
 | 
					
						
							| 
									
										
										
										
											2018-03-26 13:01:24 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-04-06 14:51:52 +01:00
										 |  |  |   const contentDigest = crypto | 
					
						
							|  |  |  |     .createHash('md5') | 
					
						
							|  |  |  |     .update(JSON.stringify(challenge)) | 
					
						
							|  |  |  |     .digest('hex'); | 
					
						
							|  |  |  |   const internal = { | 
					
						
							|  |  |  |     contentDigest, | 
					
						
							| 
									
										
										
										
											2020-09-24 12:34:35 +02:00
										 |  |  |     type: challenge.challengeType === 7 ? 'CertificateNode' : 'ChallengeNode' | 
					
						
							| 
									
										
										
										
											2018-04-06 14:51:52 +01:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* eslint-disable prefer-object-spread/prefer-object-spread */ | 
					
						
							|  |  |  |   return JSON.parse( | 
					
						
							|  |  |  |     JSON.stringify( | 
					
						
							|  |  |  |       Object.assign( | 
					
						
							|  |  |  |         {}, | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           children: [], | 
					
						
							|  |  |  |           parent: null, | 
					
						
							|  |  |  |           internal, | 
					
						
							|  |  |  |           sourceInstanceName: 'challenge' | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2020-09-24 20:19:40 +02:00
										 |  |  |         challenge | 
					
						
							| 
									
										
										
										
											2018-04-06 14:51:52 +01:00
										 |  |  |       ) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-03-26 13:01:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 18:22:52 +00:00
										 |  |  | exports.createChallengeNode = createChallengeNode; |