* fix: handle missing solutions correctly Rather than creating an [[]] the parser now creates [] which isEmpty(). This makes the test suite check the next challenge for a solution. In addition, the logic for testing solutions was fixed. * chore: update snapshots * test: build new superblock in node.js-tests CI * test: allow forward slash in superblock slug * fix: borked tests oops * test: ignore duplicated projects * fix: i did not break these shaun did :) * fix: idIndex is index of id not id Co-authored-by: Nicholas Carrigan <nhcarrigan@gmail.com>
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
const { isEmpty } = require('lodash');
|
|
const { root } = require('mdast-builder');
|
|
const visitChildren = require('unist-util-visit-children');
|
|
|
|
const { editableRegionMarker } = require('./add-seed');
|
|
const getAllBetween = require('./utils/between-headings');
|
|
const { getFileVisitor } = require('./utils/get-file-visitor');
|
|
const { splitOnThematicBreak } = require('./utils/split-on-thematic-break');
|
|
|
|
function validateMarkers({ value }) {
|
|
const lines = value.split('\n');
|
|
if (lines.some(line => line.match(RegExp(editableRegionMarker))))
|
|
throw Error(
|
|
'--fcc-editable-region-- should only appear in the --seed-contents--\n' +
|
|
'section, not in --solutions--'
|
|
);
|
|
}
|
|
|
|
function createPlugin() {
|
|
return function transformer(tree, file) {
|
|
const solutionArrays = splitOnThematicBreak(
|
|
getAllBetween(tree, `--solutions--`)
|
|
);
|
|
const solutions = [];
|
|
|
|
solutionArrays.forEach(nodes => {
|
|
const solution = {};
|
|
const solutionTree = root(nodes);
|
|
const visitForContents = visitChildren(
|
|
getFileVisitor(solution, 'contents', validateMarkers)
|
|
);
|
|
|
|
visitForContents(solutionTree);
|
|
if (!isEmpty(solution)) solutions.push(Object.values(solution));
|
|
});
|
|
|
|
file.data = {
|
|
...file.data,
|
|
solutions: solutions
|
|
};
|
|
};
|
|
}
|
|
|
|
module.exports = createPlugin;
|