| 
									
										
										
										
											2021-06-28 10:08:11 +02:00
										 |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-02 15:39:40 +02:00
										 |  |  | const _ = require('lodash'); | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-02 15:39:40 +02:00
										 |  |  | const envData = require('../../config/env.json'); | 
					
						
							| 
									
										
										
										
											2018-11-16 18:22:52 +00:00
										 |  |  | const { | 
					
						
							|  |  |  |   getChallengesForLang, | 
					
						
							| 
									
										
										
										
											2020-12-17 15:02:56 +01:00
										 |  |  |   createChallenge, | 
					
						
							| 
									
										
										
										
											2020-09-02 11:31:10 +02:00
										 |  |  |   challengesDir, | 
					
						
							| 
									
										
										
										
											2018-11-18 21:04:04 +03:00
										 |  |  |   getChallengesDirForLang | 
					
						
							| 
									
										
										
										
											2018-11-16 18:22:52 +00:00
										 |  |  | } = require('../../curriculum/getChallenges'); | 
					
						
							| 
									
										
										
										
											2021-03-26 00:43:43 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | const { curriculumLocale } = envData; | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  | exports.localeChallengesRootDir = getChallengesDirForLang(curriculumLocale); | 
					
						
							| 
									
										
										
										
											2018-11-16 18:22:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 11:31:10 +02:00
										 |  |  | exports.replaceChallengeNode = () => { | 
					
						
							|  |  |  |   return async function replaceChallengeNode(filePath) { | 
					
						
							| 
									
										
										
										
											2021-06-28 10:08:11 +02:00
										 |  |  |     // get the meta so that challengeOrder is accurate
 | 
					
						
							|  |  |  |     const blockNameRe = /\d\d-[-\w]+\/([^/]+)\//; | 
					
						
							| 
									
										
										
										
											2021-07-06 08:40:53 +02:00
										 |  |  |     const posix = path.normalize(filePath).split(path.sep).join(path.posix.sep); | 
					
						
							|  |  |  |     const blockName = posix.match(blockNameRe)[1]; | 
					
						
							| 
									
										
										
										
											2021-06-28 10:08:11 +02:00
										 |  |  |     const metaPath = path.resolve( | 
					
						
							|  |  |  |       __dirname, | 
					
						
							|  |  |  |       `../../curriculum/challenges/_meta/${blockName}/meta.json` | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     delete require.cache[require.resolve(metaPath)]; | 
					
						
							|  |  |  |     const meta = require(metaPath); | 
					
						
							|  |  |  |     return await createChallenge( | 
					
						
							|  |  |  |       challengesDir, | 
					
						
							|  |  |  |       filePath, | 
					
						
							|  |  |  |       curriculumLocale, | 
					
						
							|  |  |  |       meta | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-05-28 17:24:29 +02:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2019-02-18 19:32:49 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-11-16 18:22:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  | exports.buildChallenges = async function buildChallenges() { | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |   const curriculum = await getChallengesForLang(curriculumLocale); | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |   const superBlocks = Object.keys(curriculum); | 
					
						
							|  |  |  |   const blocks = superBlocks | 
					
						
							|  |  |  |     .map(superBlock => curriculum[superBlock].blocks) | 
					
						
							|  |  |  |     .reduce((blocks, superBlock) => { | 
					
						
							|  |  |  |       const currentBlocks = Object.keys(superBlock).map(key => superBlock[key]); | 
					
						
							|  |  |  |       return blocks.concat(_.flatten(currentBlocks)); | 
					
						
							|  |  |  |     }, []); | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 18:22:52 +00:00
										 |  |  |   const builtChallenges = blocks | 
					
						
							|  |  |  |     .filter(block => !block.isPrivate) | 
					
						
							| 
									
										
										
										
											2020-06-08 15:01:48 +02:00
										 |  |  |     .map(({ challenges }) => challenges) | 
					
						
							| 
									
										
										
										
											2018-11-16 18:22:52 +00:00
										 |  |  |     .reduce((accu, current) => accu.concat(current), []); | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |   return builtChallenges; | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  | }; |