| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  | const _ = require('lodash'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 envData = require('../../config/env.json'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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) { | 
					
						
							| 
									
										
										
										
											2020-12-17 15:02:56 +01:00
										 |  |  |     return await createChallenge(challengesDir, filePath, curriculumLocale); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | }; |