2018-10-19 10:59:14 +01:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
const readdirp = require('readdirp-walk');
|
|
|
|
|
|
|
|
const guideRoot = path.resolve(__dirname, '../../../guide');
|
|
|
|
|
|
|
|
const allowedLangDirNames = [
|
|
|
|
'arabic',
|
|
|
|
'chinese',
|
|
|
|
'english',
|
|
|
|
'portuguese',
|
|
|
|
'russian',
|
|
|
|
'spanish'
|
|
|
|
];
|
|
|
|
|
|
|
|
function checkDirName(dirName, fullPath) {
|
|
|
|
if (dirName.replace(/(\s|\_)/, '') !== dirName) {
|
2018-10-19 11:10:46 +01:00
|
|
|
throw new Error(`
|
|
|
|
Invalid character found in '${dirName}', please use '-' for spaces
|
|
|
|
|
|
|
|
Found in:
|
|
|
|
${fullPath}
|
|
|
|
`);
|
2018-10-19 10:59:14 +01:00
|
|
|
}
|
|
|
|
if (dirName.toLowerCase() !== dirName) {
|
2018-10-19 11:10:46 +01:00
|
|
|
throw new Error(`
|
|
|
|
Upper case characters found in ${dirName}, all folder names must be lower case
|
|
|
|
|
|
|
|
Found in :
|
|
|
|
${fullPath}
|
|
|
|
`);
|
2018-10-19 10:59:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkFileName(fileName, fullPath) {
|
|
|
|
if (fileName !== 'index.md') {
|
|
|
|
throw new Error(
|
|
|
|
`${fileName} is not a valid file name, please use 'index.md'
|
2018-10-19 11:10:46 +01:00
|
|
|
|
|
|
|
Found in:
|
|
|
|
${fullPath}
|
|
|
|
`
|
2018-10-19 10:59:14 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkFile(file) {
|
|
|
|
const { stat, depth, name, fullPath } = file;
|
|
|
|
if (depth === 1) {
|
|
|
|
if (stat.isFile()) {
|
|
|
|
throw new Error(`${name} is not valid in the ${guideRoot} directory`);
|
|
|
|
}
|
|
|
|
if (!allowedLangDirNames.includes(name)) {
|
|
|
|
throw new Error(`${name} should not be in the ${guideRoot} directory`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (stat.isDirectory()) {
|
|
|
|
return checkDirName(name, fullPath);
|
|
|
|
}
|
|
|
|
return checkFileName(name, fullPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
readdirp({ root: guideRoot })
|
|
|
|
.on('data', checkFile)
|
|
|
|
.on('end', () => {
|
|
|
|
/* eslint-disable no-process-exit */
|
|
|
|
process.exit(0);
|
|
|
|
});
|