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(
'Examples',
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`;
}
};
if (util.isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) {
console.log(

View File

@ -28,9 +28,9 @@ locales.forEach(locale => {
existingData.indexOf(` => ${snippetHash}`) !== -1
? existingData
: existingData.replace(
locData[snippetName].hash,
`${locData[snippetName].hash} => ${snippetHash}`
);
locData[snippetName].hash,
`${locData[snippetName].hash} => ${snippetHash}`
);
hashChanges.push({
snippetName,
oldHash: locData[snippetName].hash.split(' => ')[0],
@ -57,6 +57,14 @@ locales.forEach(locale => {
fs.writeFileSync(
path.join(LOCALE_PATH, locale + '_log'),
`${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 chalk = require('chalk');
const util = require('./util');
if (
util.isTravisCI() && util.isNotTravisCronOrAPI()
) {
if (util.isTravisCI() && util.isNotTravisCronOrAPI()) {
console.log(
`${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
const toWrite = isNodeSnippet
? `${code
.replace(`const ${snippetName}`, `export const ${snippetName}`)
// Prevents errors from being thrown in browser environment
.replace('require(', 'typeof require !== "undefined" && require(')}`
.replace(`const ${snippetName}`, `export const ${snippetName}`)
// Prevents errors from being thrown in browser environment
.replace('require(', 'typeof require !== "undefined" && require(')}`
: `export ${code}`;
// Write data to the proper file
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 min = minify({ comments: false });
// Create the bundles
(async() => {
(async () => {
const bundle = await rollup({ input: INPUT_FILE });
const bundleES5 = await rollup({ input: INPUT_FILE, plugins: [es5] });
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 chalk = require('chalk');
const util = require('./util');
if (
util.isTravisCI() && util.isNotTravisCronOrAPI()
) {
if (util.isTravisCI() && util.isNotTravisCronOrAPI()) {
console.log(`${chalk.green('NOBUILD')} Testing terminated, not a cron job or a custom build!`);
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));
// Checks if current environment is Travis CI
const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env;
const isNotTravisCronOrAPI = () => process.env['TRAVIS_EVENT_TYPE'] !== 'cron' &&
process.env['TRAVIS_EVENT_TYPE'] !== 'api';
const isNotTravisCronOrAPI = () =>
process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['TRAVIS_EVENT_TYPE'] !== 'api';
// Creates a hash for a value using the SHA-256 algorithm.
const hashData = val =>
crypto
@ -140,16 +140,17 @@ const getTextualContent = str => {
}
return results[1];
};
const prepTaggedData = tagDbData => [...new Set(Object.entries(tagDbData).map(t => t[1][0]))]
.filter(v => v)
.sort(
(a, b) =>
capitalize(a, true) === 'Uncategorized'
? 1
: capitalize(b, true) === 'Uncategorized'
? -1
: a.localeCompare(b)
);
const prepTaggedData = tagDbData =>
[...new Set(Object.entries(tagDbData).map(t => t[1][0]))]
.filter(v => v)
.sort(
(a, b) =>
capitalize(a, true) === 'Uncategorized'
? 1
: capitalize(b, true) === 'Uncategorized'
? -1
: a.localeCompare(b)
);
module.exports = {
getMarkDownAnchor,
getFilesInDir,

View File

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