2018-04-06 14:51:52 +01:00
|
|
|
const path = require('path');
|
2018-04-08 21:04:30 +01:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
|
2018-04-06 14:51:52 +01:00
|
|
|
const { dasherize } = require('./utils');
|
|
|
|
const { blockNameify } = require('./utils/blockNameify');
|
2018-04-17 15:24:17 +01:00
|
|
|
const { createChallengePages, createIntroPages } = require('./utils/gatsby');
|
2018-04-06 14:51:52 +01:00
|
|
|
|
|
|
|
exports.onCreateNode = function onCreateNode({ node, boundActionCreators }) {
|
|
|
|
const { createNodeField } = boundActionCreators;
|
|
|
|
if (node.internal.type === 'ChallengeNode') {
|
|
|
|
const { tests = [], block, title, superBlock } = node;
|
|
|
|
|
|
|
|
const slug = `/${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 });
|
|
|
|
}
|
2018-04-12 17:20:52 +01:00
|
|
|
|
|
|
|
if (node.internal.type === 'MarkdownRemark') {
|
2018-04-16 12:04:25 +01:00
|
|
|
const { frontmatter: { block, superBlock } } = node;
|
2018-04-12 17:20:52 +01:00
|
|
|
|
2018-05-18 11:59:12 +01:00
|
|
|
let slug = `/${dasherize(superBlock)}`;
|
|
|
|
|
|
|
|
// Without this condition the slug for superblocks ends up as something like
|
|
|
|
// "/apis-and-microservice/undefined" and what we want instead is just
|
|
|
|
// "/apis-and-microservice"
|
|
|
|
if (typeof block !== 'undefined') {
|
|
|
|
slug = slug + `/${dasherize(block)}`;
|
|
|
|
}
|
2018-04-12 17:20:52 +01:00
|
|
|
|
|
|
|
createNodeField({ node, name: 'slug', value: slug });
|
|
|
|
}
|
2018-04-06 14:51:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.createPages = ({ graphql, boundActionCreators }) => {
|
|
|
|
const { createPage } = boundActionCreators;
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2018-05-18 14:54:21 +01:00
|
|
|
// Query for all markdown 'nodes' and for the slug we previously created.
|
2018-04-06 14:51:52 +01:00
|
|
|
resolve(
|
|
|
|
graphql(`
|
|
|
|
{
|
|
|
|
allChallengeNode(sort: { fields: [superOrder, order, suborder] }) {
|
|
|
|
edges {
|
|
|
|
node {
|
2018-04-17 15:24:17 +01:00
|
|
|
block
|
2018-04-06 14:51:52 +01:00
|
|
|
challengeType
|
2018-04-17 15:24:17 +01:00
|
|
|
fields {
|
|
|
|
slug
|
|
|
|
}
|
2018-04-06 14:51:52 +01:00
|
|
|
id
|
2018-04-17 15:24:17 +01:00
|
|
|
order
|
2018-04-11 14:40:43 +01:00
|
|
|
required {
|
|
|
|
link
|
|
|
|
raw
|
|
|
|
src
|
|
|
|
}
|
2018-04-17 15:24:17 +01:00
|
|
|
suborder
|
|
|
|
superBlock
|
|
|
|
superOrder
|
2018-04-11 14:40:43 +01:00
|
|
|
template
|
2018-04-06 14:51:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-12 17:20:52 +01:00
|
|
|
allMarkdownRemark {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
fields {
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
frontmatter {
|
|
|
|
block
|
|
|
|
superBlock
|
|
|
|
title
|
|
|
|
}
|
|
|
|
html
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-06 14:51:52 +01:00
|
|
|
}
|
|
|
|
`).then(result => {
|
|
|
|
if (result.errors) {
|
|
|
|
console.log(result.errors);
|
|
|
|
reject(result.errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create challenge pages.
|
2018-04-17 15:24:17 +01:00
|
|
|
result.data.allChallengeNode.edges.forEach(
|
|
|
|
createChallengePages(createPage)
|
|
|
|
);
|
2018-04-06 14:51:52 +01:00
|
|
|
|
2018-04-12 17:20:52 +01:00
|
|
|
// Create intro pages
|
2018-04-17 15:24:17 +01:00
|
|
|
result.data.allMarkdownRemark.edges.forEach(
|
|
|
|
createIntroPages(createPage)
|
|
|
|
);
|
2018-04-12 17:20:52 +01:00
|
|
|
|
2018-04-06 14:51:52 +01:00
|
|
|
return;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
2018-04-08 21:04:30 +01:00
|
|
|
|
2018-04-09 00:11:35 +01:00
|
|
|
const generateBabelConfig = require('gatsby/dist/utils/babel-config');
|
|
|
|
|
|
|
|
exports.modifyWebpackConfig = ({ config, stage }) => {
|
|
|
|
const program = {
|
|
|
|
directory: __dirname,
|
|
|
|
browserslist: ['> 1%', 'last 2 versions', 'IE >= 9']
|
|
|
|
};
|
|
|
|
|
|
|
|
return generateBabelConfig(program, stage).then(babelConfig => {
|
|
|
|
config.removeLoader('js').loader('js', {
|
|
|
|
test: /\.jsx?$/,
|
2018-05-21 13:28:22 +01:00
|
|
|
/* eslint-disable max-len */
|
2018-04-09 00:11:35 +01:00
|
|
|
exclude: modulePath => {
|
|
|
|
return (
|
|
|
|
/node_modules/.test(modulePath) &&
|
2018-05-21 13:28:22 +01:00
|
|
|
!(/(ansi-styles|chalk|strict-uri-encode|react-freecodecamp-search)/).test(
|
|
|
|
modulePath
|
|
|
|
)
|
2018-04-09 00:11:35 +01:00
|
|
|
);
|
|
|
|
},
|
2018-05-21 13:28:22 +01:00
|
|
|
/* eslint-enable max-len*/
|
2018-04-09 00:11:35 +01:00
|
|
|
loader: 'babel',
|
|
|
|
query: babelConfig
|
|
|
|
});
|
2018-04-08 21:04:30 +01:00
|
|
|
config.plugin('CopyWebpackPlugin', CopyWebpackPlugin, [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
from: path.resolve(__dirname, './node_modules/monaco-editor/min/vs'),
|
|
|
|
to: 'vs'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]);
|
2018-04-09 00:11:35 +01:00
|
|
|
});
|
2018-04-08 21:04:30 +01:00
|
|
|
};
|
2018-05-18 14:54:21 +01:00
|
|
|
/* eslint-disable prefer-object-spread/prefer-object-spread */
|
|
|
|
exports.modifyBabelrc = ({ babelrc }) =>
|
|
|
|
Object.assign({}, babelrc, {
|
|
|
|
plugins: babelrc.plugins.concat([
|
|
|
|
[
|
2018-05-21 13:28:22 +01:00
|
|
|
'transform-es2015-arrow-functions',
|
2018-05-18 14:54:21 +01:00
|
|
|
'transform-imports',
|
2018-05-24 19:45:38 +01:00
|
|
|
'transform-function-bind',
|
2018-05-18 14:54:21 +01:00
|
|
|
{
|
|
|
|
'react-bootstrap': {
|
|
|
|
transform: 'react-bootstrap/lib/${member}',
|
|
|
|
preventFullImport: true
|
|
|
|
},
|
|
|
|
lodash: {
|
|
|
|
transform: 'lodash/${member}',
|
|
|
|
preventFullImport: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
])
|
|
|
|
});
|