Linted scripts

This commit is contained in:
Angelos Chalaris
2018-09-22 14:10:33 +03:00
parent b4de123e43
commit d3cf5a392a
7 changed files with 70 additions and 60 deletions

View File

@ -21,10 +21,10 @@ const makeExamples = data => {
misc.collapsible( misc.collapsible(
'Examples', 'Examples',
data.slice(data.lastIndexOf('```js'), data.lastIndexOf('```')) + data.slice(data.lastIndexOf('```js'), data.lastIndexOf('```')) +
data.slice(data.lastIndexOf('```')) data.slice(data.lastIndexOf('```'))
); );
return `${data}\n<br>${misc.link('⬆ Back to top', misc.anchor('Table of Contents'))}\n\n`; return `${data}\n<br>${misc.link('⬆ Back to top', misc.anchor('Table of Contents'))}\n\n`;
} };
if (util.isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) { if (util.isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) {
console.log( console.log(

View File

@ -28,9 +28,9 @@ locales.forEach(locale => {
existingData.indexOf(` => ${snippetHash}`) !== -1 existingData.indexOf(` => ${snippetHash}`) !== -1
? existingData ? existingData
: existingData.replace( : existingData.replace(
locData[snippetName].hash, locData[snippetName].hash,
`${locData[snippetName].hash} => ${snippetHash}` `${locData[snippetName].hash} => ${snippetHash}`
); );
hashChanges.push({ hashChanges.push({
snippetName, snippetName,
oldHash: locData[snippetName].hash.split(' => ')[0], oldHash: locData[snippetName].hash.split(' => ')[0],
@ -57,6 +57,14 @@ locales.forEach(locale => {
fs.writeFileSync( fs.writeFileSync(
path.join(LOCALE_PATH, locale + '_log'), path.join(LOCALE_PATH, locale + '_log'),
`${new Date()}\nHash changes: ${hashChanges.length}\n${ `${new Date()}\nHash changes: ${hashChanges.length}\n${
hashChanges.length ? hashChanges.map(v => `Snippet name: ${v.snippetName}\n Old hash: ${v.oldHash}\n New hash: ${v.newHash}\n`).join('\n') : ''}` hashChanges.length
? hashChanges
.map(
v =>
`Snippet name: ${v.snippetName}\n Old hash: ${v.oldHash}\n New hash: ${v.newHash}\n`
)
.join('\n')
: ''
}`
); );
}); });

View File

@ -7,9 +7,7 @@ const cp = require('child_process');
const path = require('path'); const path = require('path');
const chalk = require('chalk'); const chalk = require('chalk');
const util = require('./util'); const util = require('./util');
if ( if (util.isTravisCI() && util.isNotTravisCronOrAPI()) {
util.isTravisCI() && util.isNotTravisCronOrAPI()
) {
console.log( console.log(
`${chalk.green('NOBUILD')} Module build terminated, not a cron job or a custom build!` `${chalk.green('NOBUILD')} Module build terminated, not a cron job or a custom build!`
); );
@ -55,9 +53,9 @@ try {
// Store the data to be written // Store the data to be written
const toWrite = isNodeSnippet const toWrite = isNodeSnippet
? `${code ? `${code
.replace(`const ${snippetName}`, `export const ${snippetName}`) .replace(`const ${snippetName}`, `export const ${snippetName}`)
// Prevents errors from being thrown in browser environment // Prevents errors from being thrown in browser environment
.replace('require(', 'typeof require !== "undefined" && require(')}` .replace('require(', 'typeof require !== "undefined" && require(')}`
: `export ${code}`; : `export ${code}`;
// Write data to the proper file // Write data to the proper file
fs.writeFileSync(`${TEMP_PATH}/${snippetName}.js`, toWrite); fs.writeFileSync(`${TEMP_PATH}/${snippetName}.js`, toWrite);

View File

@ -16,7 +16,7 @@ if (!fs.existsSync(DIST)) fs.mkdirSync(DIST);
const es5 = babel({ presets: [['env', { modules: false }]] }); const es5 = babel({ presets: [['env', { modules: false }]] });
const min = minify({ comments: false }); const min = minify({ comments: false });
// Create the bundles // Create the bundles
(async() => { (async () => {
const bundle = await rollup({ input: INPUT_FILE }); const bundle = await rollup({ input: INPUT_FILE });
const bundleES5 = await rollup({ input: INPUT_FILE, plugins: [es5] }); const bundleES5 = await rollup({ input: INPUT_FILE, plugins: [es5] });
const bundleMin = await rollup({ input: INPUT_FILE, plugins: [min] }); const bundleMin = await rollup({ input: INPUT_FILE, plugins: [min] });

View File

@ -9,9 +9,7 @@ const fs = require('fs-extra'),
const childProcess = require('child_process'); const childProcess = require('child_process');
const chalk = require('chalk'); const chalk = require('chalk');
const util = require('./util'); const util = require('./util');
if ( if (util.isTravisCI() && util.isNotTravisCronOrAPI()) {
util.isTravisCI() && util.isNotTravisCronOrAPI()
) {
console.log(`${chalk.green('NOBUILD')} Testing terminated, not a cron job or a custom build!`); console.log(`${chalk.green('NOBUILD')} Testing terminated, not a cron job or a custom build!`);
process.exit(0); process.exit(0);
} }

View File

@ -102,8 +102,8 @@ const capitalize = (str, lowerRest = false) =>
str.slice(0, 1).toUpperCase() + (lowerRest ? str.slice(1).toLowerCase() : str.slice(1)); str.slice(0, 1).toUpperCase() + (lowerRest ? str.slice(1).toLowerCase() : str.slice(1));
// Checks if current environment is Travis CI // Checks if current environment is Travis CI
const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env;
const isNotTravisCronOrAPI = () => process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && const isNotTravisCronOrAPI = () =>
process.env['TRAVIS_EVENT_TYPE'] !== 'api'; process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['TRAVIS_EVENT_TYPE'] !== 'api';
// Creates a hash for a value using the SHA-256 algorithm. // Creates a hash for a value using the SHA-256 algorithm.
const hashData = val => const hashData = val =>
crypto crypto
@ -140,16 +140,17 @@ const getTextualContent = str => {
} }
return results[1]; return results[1];
}; };
const prepTaggedData = tagDbData => [...new Set(Object.entries(tagDbData).map(t => t[1][0]))] const prepTaggedData = tagDbData =>
.filter(v => v) [...new Set(Object.entries(tagDbData).map(t => t[1][0]))]
.sort( .filter(v => v)
(a, b) => .sort(
capitalize(a, true) === 'Uncategorized' (a, b) =>
? 1 capitalize(a, true) === 'Uncategorized'
: capitalize(b, true) === 'Uncategorized' ? 1
? -1 : capitalize(b, true) === 'Uncategorized'
: a.localeCompare(b) ? -1
); : a.localeCompare(b)
);
module.exports = { module.exports = {
getMarkDownAnchor, getMarkDownAnchor,
getFilesInDir, getFilesInDir,

View File

@ -39,38 +39,43 @@ const unescapeHTML = str =>
'&quot;': '"' '&quot;': '"'
}[tag] || tag) }[tag] || tag)
); );
const generateSnippetCard = (snippetList, snippetKey, addCornerTag = false) => `<div class="card code-card"> const generateSnippetCard = (
${addCornerTag ? `<div class="corner ${ snippetList,
snippetKey[1].includes('advanced') snippetKey,
? 'advanced' addCornerTag = false
: snippetKey[1].includes('beginner') ) => `<div class="card code-card">
? 'beginner' ${
: 'intermediate' addCornerTag
}"></div>`: ''} ? `<div class="corner ${
snippetKey[1].includes('advanced')
? 'advanced'
: snippetKey[1].includes('beginner')
? 'beginner'
: 'intermediate'
}"></div>`
: ''
}
${md ${md
.render(`\n${addCornerTag ? snippetList[snippetKey[0] + '.md'] : snippetList[snippetKey[0]]}`) .render(`\n${addCornerTag ? snippetList[snippetKey[0] + '.md'] : snippetList[snippetKey[0]]}`)
.replace( .replace(/<h3/g, `<div class="section card-content"><h4 id="${snippetKey[0].toLowerCase()}"`)
/<h3/g, .replace(/<\/h3>/g, '</h4>')
`<div class="section card-content"><h4 id="${snippetKey[0].toLowerCase()}"` .replace(
) /<pre><code class="language-js">/m,
.replace(/<\/h3>/g, '</h4>') '</div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre><code class="language-js">'
.replace( )
/<pre><code class="language-js">/m, .replace(
'</div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre><code class="language-js">' /<pre><code class="language-js">([^\0]*?)<\/code><\/pre>/gm,
) (match, p1) =>
.replace( `<pre class="language-js">${Prism.highlight(
/<pre><code class="language-js">([^\0]*?)<\/code><\/pre>/gm, unescapeHTML(p1),
(match, p1) => Prism.languages.javascript
`<pre class="language-js">${Prism.highlight( )}</pre>`
unescapeHTML(p1), )
Prism.languages.javascript .replace(/<\/div>\s*<pre class="/g, '</div><pre class="section card-code ')
)}</pre>` .replace(
) /<\/pre>\s+<pre class="/g,
.replace(/<\/div>\s*<pre class="/g, '</div><pre class="section card-code ') '</pre><label class="collapse">examples</label><pre class="section card-examples '
.replace( )}
/<\/pre>\s+<pre class="/g,
'</pre><label class="collapse">examples</label><pre class="section card-examples '
)}
</div>`; </div>`;
const filterSnippets = (snippetList, excludedFiles) => const filterSnippets = (snippetList, excludedFiles) =>
Object.keys(snippetList) Object.keys(snippetList)
@ -286,7 +291,7 @@ try {
// Generate glossary snippets from md files // Generate glossary snippets from md files
for (let snippet of Object.entries(filteredGlossarySnippets)) for (let snippet of Object.entries(filteredGlossarySnippets))
glossaryOutput += glossaryOutput +=
'<div class="card code-card"><div class="section card-content">' + '<div class="card code-card"><div class="section card-content">' +
md md
.render(`\n${filteredGlossarySnippets[snippet[0]]}`) .render(`\n${filteredGlossarySnippets[snippet[0]]}`)