Hash :
0b539136
Author :
Date :
2020-01-06T14:39:45
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
"use strict";
const { parallel } = require('gulp');
const fs = require('fs');
const git = require('simple-git/promise')(__dirname);
// use the JSON file because this file is less susceptible to merge conflicts
const { languages } = require('../components.json');
/**
* Checks that no files have been modified by the build process.
*/
function gitChanges() {
return git.status().then(res => {
if (res.files.length > 0) {
console.log(res);
throw new Error('There are changes in the file system. Did you forget to run gulp?');
}
});
}
/**
* Checks that all languages have and example.
*/
async function hasExample() {
const exampleFiles = new Set(fs.readdirSync(__dirname + '/../examples'));
const ignore = new Set([
// these are libraries and not languages
'markup-templating',
't4-templating',
// this does alter some languages but it's mainly a library
'javadoclike',
// Regex doesn't have any classes supported by our themes and mainly extends other languages
'regex'
]);
/** @type {string[]} */
const missing = [];
for (const lang in languages) {
if (lang === 'meta') {
continue;
}
if (!exampleFiles.delete(`prism-${lang}.html`)) {
if (!ignore.has(lang)) {
missing.push(lang);
}
}
}
const errors = missing.map(id => `Missing example for ${id}.`);
for (const file of exampleFiles) {
errors.push(`The examples file "${file}" has no language associated with it.`);
}
if (errors.length) {
throw new Error(errors.join('\n'));
}
}
module.exports = {
premerge: parallel(gitChanges, hasExample)
};