diff --git a/scripts/build.js b/scripts/build.js index 440ff76f4..a8e917c54 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -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
${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( diff --git a/scripts/localize.js b/scripts/localize.js index 88e270d6e..9cbb59a3b 100644 --- a/scripts/localize.js +++ b/scripts/localize.js @@ -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') + : '' + }` ); }); diff --git a/scripts/module.js b/scripts/module.js index de7be2f3d..cb63f931c 100644 --- a/scripts/module.js +++ b/scripts/module.js @@ -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); diff --git a/scripts/rollup.js b/scripts/rollup.js index d684f7d68..4fe1951a6 100644 --- a/scripts/rollup.js +++ b/scripts/rollup.js @@ -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] }); diff --git a/scripts/tdd.js b/scripts/tdd.js index 87f6d8610..64b18f078 100644 --- a/scripts/tdd.js +++ b/scripts/tdd.js @@ -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); } diff --git a/scripts/util.js b/scripts/util.js index 191b1f48c..538758603 100644 --- a/scripts/util.js +++ b/scripts/util.js @@ -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, diff --git a/scripts/web.js b/scripts/web.js index c66aeb53e..23af6fbeb 100644 --- a/scripts/web.js +++ b/scripts/web.js @@ -39,38 +39,43 @@ const unescapeHTML = str => '"': '"' }[tag] || tag) ); -const generateSnippetCard = (snippetList, snippetKey, addCornerTag = false) => `
-${addCornerTag ? `
`: ''} +const generateSnippetCard = ( + snippetList, + snippetKey, + addCornerTag = false +) => `
+${ + addCornerTag + ? `
` + : '' +} ${md - .render(`\n${addCornerTag ? snippetList[snippetKey[0] + '.md'] : snippetList[snippetKey[0]]}`) - .replace( - /

/g, '

') - .replace( - /
/m,
-    '
'
-  )
-  .replace(
-    /
([^\0]*?)<\/code><\/pre>/gm,
-    (match, p1) =>
-      `
${Prism.highlight(
-        unescapeHTML(p1),
-        Prism.languages.javascript
-      )}
` - ) - .replace(/<\/div>\s*
\s+
examples

/g, '

') + .replace( + /
/m,
+      '
'
+    )
+    .replace(
+      /
([^\0]*?)<\/code><\/pre>/gm,
+      (match, p1) =>
+        `
${Prism.highlight(
+          unescapeHTML(p1),
+          Prism.languages.javascript
+        )}
` + ) + .replace(/<\/div>\s*
\s+
examples
' + md .render(`\n${filteredGlossarySnippets[snippet[0]]}`)