freeCodeCamp/tools/scripts/ci/ensure-guide-formatting.js
Stuart Taylor 2d3c2efa2a Feat: Ensure markdown formatting (#34547)
<!-- Please follow this checklist and put an x in each of the boxes, like this: [x]. It will ensure that our team takes your pull request seriously. -->

- [x] I have read [freeCodeCamp's contribution guidelines](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/CONTRIBUTING.md).
- [x] My pull request has a descriptive title (not a vague title like `Update index.md`)
- [x] My pull request targets the `master` branch of freeCodeCamp.

Closes #34535
2018-12-06 16:48:56 +05:30

35 lines
902 B
JavaScript

const readdirp = require('readdirp-walk');
const { has } = require('lodash');
const ora = require('ora');
const {
guideRoot,
checkGuideFile,
checkFrontmatter,
extractLangFromFileName
} = require('./md-testing-utils');
const spinner = ora('Checking guide markdown formatting').start();
const guideFrontmatterValidator = file => frontmatter => {
const hasLocale =
extractLangFromFileName(file) === 'english'
? true
: has(frontmatter, 'localeTitle');
const hasTitle = has(frontmatter, 'title');
return hasLocale && hasTitle;
};
readdirp({ root: guideRoot })
.on('data', file =>
Promise.all([
checkGuideFile(file),
checkFrontmatter(file, { validator: guideFrontmatterValidator(file) })
]).catch(err => {
console.error(err);
// eslint-disable-next-line no-process-exit
process.exit(1);
})
)
.on('end', () => spinner.stop());