| 
									
										
										
										
											2018-05-14 08:34:51 +01:00
										 |  |  | require('babel-register'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-20 19:20:16 +05:30
										 |  |  | const { getChallenges } = require('@freecodecamp/curriculum'); | 
					
						
							| 
									
										
										
										
											2018-05-14 08:34:51 +01:00
										 |  |  | const fs = require('fs'); | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							|  |  |  | const { Observable } = require('rx'); | 
					
						
							| 
									
										
										
										
											2018-08-31 16:04:04 +01:00
										 |  |  | const { dasherize } = require('../api-server/server/utils'); | 
					
						
							| 
									
										
										
										
											2018-05-14 08:34:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | let pathMap = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function createPathMigrationMap() { | 
					
						
							|  |  |  |   return new Promise(resolve => { | 
					
						
							| 
									
										
										
										
											2018-08-31 16:04:04 +01:00
										 |  |  |     Observable.of(getChallenges()) | 
					
						
							|  |  |  |       .map(blocks => { | 
					
						
							|  |  |  |         blocks.forEach(block => { | 
					
						
							|  |  |  |           const { name: blockName, superBlock, challenges } = block; | 
					
						
							|  |  |  |           if (!(dasherize(superBlock) in pathMap)) { | 
					
						
							|  |  |  |             pathMap[dasherize(superBlock)] = {}; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           if (!(dasherize(blockName) in pathMap[superBlock])) { | 
					
						
							|  |  |  |             pathMap[dasherize(superBlock)][ | 
					
						
							|  |  |  |               dasherize(blockName) | 
					
						
							|  |  |  |             ] = challenges.map(({ title, challengeType }) => ({ | 
					
						
							|  |  |  |               dashedName: dasherize(title), | 
					
						
							|  |  |  |               challengeType | 
					
						
							|  |  |  |             })); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       .subscribe(() => {}, console.error, () => { | 
					
						
							|  |  |  |         const migMap = Object.keys(pathMap) | 
					
						
							|  |  |  |           .filter(key => !key.includes('certificate')) | 
					
						
							|  |  |  |           .map(superBlock => { | 
					
						
							|  |  |  |             return Object.keys(pathMap[superBlock]) | 
					
						
							|  |  |  |               .map(block => { | 
					
						
							|  |  |  |                 return pathMap[superBlock][block].reduce( | 
					
						
							|  |  |  |                   (map, { dashedName, challengeType }) => ({ | 
					
						
							|  |  |  |                     ...map, | 
					
						
							|  |  |  |                     [dashedName]: | 
					
						
							|  |  |  |                       challengeType === 7 | 
					
						
							|  |  |  |                         ? `/${superBlock}/${block}` | 
					
						
							|  |  |  |                         : `/${superBlock}/${block}/${dashedName}` | 
					
						
							|  |  |  |                   }), | 
					
						
							|  |  |  |                   {} | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               .reduce( | 
					
						
							|  |  |  |                 (acc, current) => ({ | 
					
						
							|  |  |  |                   ...acc, | 
					
						
							|  |  |  |                   ...current | 
					
						
							|  |  |  |                 }), | 
					
						
							|  |  |  |                 {} | 
					
						
							|  |  |  |               ); | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |           .reduce( | 
					
						
							|  |  |  |             (acc, current) => ({ | 
					
						
							|  |  |  |               ...acc, | 
					
						
							|  |  |  |               ...current | 
					
						
							|  |  |  |             }), | 
					
						
							|  |  |  |             {} | 
					
						
							|  |  |  |           ); | 
					
						
							|  |  |  |         fs.writeFileSync( | 
					
						
							|  |  |  |           path.resolve( | 
					
						
							|  |  |  |             __dirname, | 
					
						
							|  |  |  |             '../api-server/server/resources/pathMigration.json' | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |           JSON.stringify(migMap, null, 2) | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         resolve(); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-05-14 08:34:51 +01:00
										 |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-31 16:04:04 +01:00
										 |  |  | exports.createPathMigrationMap = createPathMigrationMap; |