| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  | require('dotenv').config(); | 
					
						
							| 
									
										
										
										
											2018-08-23 16:29:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 14:18:46 +01:00
										 |  |  | const { createFilePath } = require('gatsby-source-filesystem'); | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  | const { dasherize } = require('./utils'); | 
					
						
							|  |  |  | const { blockNameify } = require('./utils/blockNameify'); | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  | const { | 
					
						
							|  |  |  |   createChallengePages, | 
					
						
							|  |  |  |   createBlockIntroPages, | 
					
						
							| 
									
										
										
										
											2019-07-25 13:53:42 +05:30
										 |  |  |   createSuperBlockIntroPages | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  | } = require('./utils/gatsby'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const createByIdentityMap = { | 
					
						
							|  |  |  |   blockIntroMarkdown: createBlockIntroPages, | 
					
						
							|  |  |  |   superBlockIntroMarkdown: createSuperBlockIntroPages | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  | exports.onCreateNode = function onCreateNode({ node, actions, getNode }) { | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  |   const { createNodeField } = actions; | 
					
						
							|  |  |  |   if (node.internal.type === 'ChallengeNode') { | 
					
						
							|  |  |  |     const { tests = [], block, title, superBlock } = node; | 
					
						
							|  |  |  |     const slug = `/learn/${dasherize(superBlock)}/${dasherize( | 
					
						
							|  |  |  |       block | 
					
						
							|  |  |  |     )}/${dasherize(title)}`;
 | 
					
						
							|  |  |  |     createNodeField({ node, name: 'slug', value: slug }); | 
					
						
							|  |  |  |     createNodeField({ node, name: 'blockName', value: blockNameify(block) }); | 
					
						
							|  |  |  |     createNodeField({ node, name: 'tests', value: tests }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (node.internal.type === 'MarkdownRemark') { | 
					
						
							| 
									
										
										
										
											2019-02-04 03:46:27 +03:00
										 |  |  |     const slug = createFilePath({ node, getNode }); | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |     if (!slug.includes('LICENSE')) { | 
					
						
							| 
									
										
										
										
											2019-02-04 03:46:27 +03:00
										 |  |  |       const { | 
					
						
							|  |  |  |         frontmatter: { component = '' } | 
					
						
							|  |  |  |       } = node; | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |       createNodeField({ node, name: 'slug', value: slug }); | 
					
						
							| 
									
										
										
										
											2019-02-04 03:46:27 +03:00
										 |  |  |       createNodeField({ node, name: 'component', value: component }); | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 14:18:46 +01:00
										 |  |  | exports.createPages = function createPages({ graphql, actions }) { | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  |   const { createPage } = actions; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return new Promise((resolve, reject) => { | 
					
						
							|  |  |  |     // Query for all markdown 'nodes' and for the slug we previously created.
 | 
					
						
							|  |  |  |     resolve( | 
					
						
							|  |  |  |       graphql(`
 | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |           allChallengeNode( | 
					
						
							|  |  |  |             sort: { fields: [superOrder, order, challengeOrder] } | 
					
						
							|  |  |  |           ) { | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  |             edges { | 
					
						
							|  |  |  |               node { | 
					
						
							|  |  |  |                 block | 
					
						
							|  |  |  |                 challengeType | 
					
						
							|  |  |  |                 fields { | 
					
						
							|  |  |  |                   slug | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 id | 
					
						
							|  |  |  |                 order | 
					
						
							|  |  |  |                 required { | 
					
						
							|  |  |  |                   link | 
					
						
							|  |  |  |                   src | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |                 challengeOrder | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  |                 superBlock | 
					
						
							|  |  |  |                 superOrder | 
					
						
							|  |  |  |                 template | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           allMarkdownRemark { | 
					
						
							|  |  |  |             edges { | 
					
						
							|  |  |  |               node { | 
					
						
							|  |  |  |                 fields { | 
					
						
							|  |  |  |                   slug | 
					
						
							| 
									
										
										
										
											2018-10-23 14:18:46 +01:00
										 |  |  |                   nodeIdentity | 
					
						
							| 
									
										
										
										
											2019-02-04 03:46:27 +03:00
										 |  |  |                   component | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 frontmatter { | 
					
						
							|  |  |  |                   block | 
					
						
							|  |  |  |                   superBlock | 
					
						
							|  |  |  |                   title | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |                 htmlAst | 
					
						
							|  |  |  |                 id | 
					
						
							|  |  |  |                 excerpt | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       `).then(result => {
 | 
					
						
							|  |  |  |         if (result.errors) { | 
					
						
							|  |  |  |           console.log(result.errors); | 
					
						
							| 
									
										
										
										
											2018-10-23 14:18:46 +01:00
										 |  |  |           return reject(result.errors); | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Create challenge pages.
 | 
					
						
							|  |  |  |         result.data.allChallengeNode.edges.forEach( | 
					
						
							|  |  |  |           createChallengePages(createPage) | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Create intro pages
 | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |         result.data.allMarkdownRemark.edges.forEach(edge => { | 
					
						
							|  |  |  |           const { | 
					
						
							| 
									
										
										
										
											2018-10-23 14:18:46 +01:00
										 |  |  |             node: { frontmatter, fields } | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |           } = edge; | 
					
						
							| 
									
										
										
										
											2018-10-23 14:18:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |           if (!fields) { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2018-10-23 14:18:46 +01:00
										 |  |  |           const { slug, nodeIdentity } = fields; | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |           if (slug.includes('LICENCE')) { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           try { | 
					
						
							| 
									
										
										
										
											2018-10-23 14:18:46 +01:00
										 |  |  |             const pageBuilder = createByIdentityMap[nodeIdentity](createPage); | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |             return pageBuilder(edge); | 
					
						
							|  |  |  |           } catch (e) { | 
					
						
							|  |  |  |             console.log(`
 | 
					
						
							| 
									
										
										
										
											2018-10-23 14:18:46 +01:00
										 |  |  |             ident: ${nodeIdentity} does not belong to a function | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             ${frontmatter ? JSON.stringify(edge.node) : 'no frontmatter'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             `);
 | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2018-10-23 14:18:46 +01:00
										 |  |  |           return null; | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 14:18:46 +01:00
										 |  |  |         return null; | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  |       }) | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-31 02:26:43 +03:00
										 |  |  | exports.onCreateWebpackConfig = ({ plugins, actions }) => { | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  |   actions.setWebpackConfig({ | 
					
						
							|  |  |  |     node: { | 
					
						
							|  |  |  |       fs: 'empty' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     plugins: [ | 
					
						
							|  |  |  |       plugins.define({ | 
					
						
							|  |  |  |         HOME_PATH: JSON.stringify( | 
					
						
							|  |  |  |           process.env.HOME_PATH || 'http://localhost:3000' | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  |         STRIPE_PUBLIC_KEY: JSON.stringify(process.env.STRIPE_PUBLIC_KEY || ''), | 
					
						
							|  |  |  |         ROLLBAR_CLIENT_ID: JSON.stringify(process.env.ROLLBAR_CLIENT_ID || ''), | 
					
						
							| 
									
										
										
										
											2019-08-19 01:19:40 +05:30
										 |  |  |         ENVIRONMENT: JSON.stringify( | 
					
						
							|  |  |  |           process.env.FREECODECAMP_NODE_ENV || 'development' | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2018-12-01 11:23:08 +00:00
										 |  |  |         PAYPAL_SUPPORTERS: JSON.stringify(process.env.PAYPAL_SUPPORTERS || 404) | 
					
						
							| 
									
										
										
										
											2019-08-31 02:26:43 +03:00
										 |  |  |       }), | 
					
						
							|  |  |  |       new MonacoWebpackPlugin() | 
					
						
							| 
									
										
										
										
											2018-09-30 11:37:19 +01:00
										 |  |  |     ] | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exports.onCreateBabelConfig = ({ actions }) => { | 
					
						
							|  |  |  |   actions.setBabelPlugin({ | 
					
						
							|  |  |  |     name: '@babel/plugin-proposal-function-bind' | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   actions.setBabelPlugin({ | 
					
						
							|  |  |  |     name: '@babel/plugin-proposal-export-default-from' | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   actions.setBabelPlugin({ | 
					
						
							|  |  |  |     name: 'babel-plugin-transform-imports', | 
					
						
							|  |  |  |     options: { | 
					
						
							|  |  |  |       '@freecodecamp/react-bootstrap': { | 
					
						
							|  |  |  |         transform: '@freecodecamp/react-bootstrap/lib/${member}', | 
					
						
							|  |  |  |         preventFullImport: true | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       lodash: { | 
					
						
							|  |  |  |         transform: 'lodash/${member}', | 
					
						
							|  |  |  |         preventFullImport: true | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; |