Scripts linted

This commit is contained in:
Angelos Chalaris
2018-08-03 10:49:29 +03:00
parent 37da7ac424
commit d9593cdce5
13 changed files with 525 additions and 233 deletions

View File

@ -10,27 +10,34 @@ const util = require('../util');
const glossaryFiles = util.getFilesInDir('./glossary', true, ['keyword_database', 'README.md']);
const fileTitles = [];
const getGlossaryTermMarkdownBlock = (fileName) => {
const getGlossaryTermMarkdownBlock = fileName => {
let fileContent = fs.readFileSync(fileName, 'utf8');
let title = fileContent.match(/###[^\n]*/)[0].replace('### ', '').trim();
let title = fileContent
.match(/###[^\n]*/)[0]
.replace('### ', '')
.trim();
// let description = fileContent.replace(title, '').trim();
fileTitles.push(title);
return fileContent.trim() + "\n";
return fileContent.trim() + '\n';
};
const glossaryFilesContentReducer = (accumulator, currentFilename) => {
// handle first array item
if (accumulator === glossaryFiles[0]) {
return getGlossaryTermMarkdownBlock(accumulator) + "\n" + getGlossaryTermMarkdownBlock(currentFilename);
return (
getGlossaryTermMarkdownBlock(accumulator) +
'\n' +
getGlossaryTermMarkdownBlock(currentFilename)
);
}
return accumulator + "\n" + getGlossaryTermMarkdownBlock(currentFilename);
return accumulator + '\n' + getGlossaryTermMarkdownBlock(currentFilename);
};
const getTermLinkMarkdownBlock = (termTitle) => {
const getTermLinkMarkdownBlock = termTitle => {
let anchor = util.getMarkDownAnchor(termTitle);
return `* [\`${termTitle}\`](#${anchor})` + "\n";
return `* [\`${termTitle}\`](#${anchor})` + '\n';
};
const glossaryTableOfContentsReducer = (accumulator, currentFile) => {
@ -42,14 +49,10 @@ const glossaryTableOfContentsReducer = (accumulator, currentFile) => {
try {
const fileContents = glossaryFiles.reduce(glossaryFilesContentReducer);
const TOC = "## Table of Contents\n\n" + fileTitles.reduce(glossaryTableOfContentsReducer);
const README =
"# 30-seconds-of-code JavaScript Glossary\n\n" +
TOC +
"\n\n" +
fileContents;
fs.writeFileSync('glossary/README.md', README);
const TOC = '## Table of Contents\n\n' + fileTitles.reduce(glossaryTableOfContentsReducer);
const README = '# 30-seconds-of-code JavaScript Glossary\n\n' + TOC + '\n\n' + fileContents;
fs.writeFileSync('glossary/README.md', README);
} catch (err) {
console.log(`${chalk.red('ERROR!')} During glossary README generation: ${err}`);
process.exit(1);