diff --git a/scripts/build.js b/scripts/build.js index 421d0e3e0..67173a631 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -11,13 +11,11 @@ const util = require('./util'); const SNIPPETS_PATH = './snippets'; const SNIPPETS_ARCHIVE_PATH = './snippets_archive'; const STATIC_PARTS_PATH = './static-parts'; -// Load helper functions (these are from existing snippets in 30 seconds of code!) -const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; -if(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(`${chalk.green('NOBUILD')} README build terminated, parent commit is a Travis build!`); process.exit(0); } -if(isTravisCI() && (process.env['TRAVIS_EVENT_TYPE'] === 'cron' || process.env['TRAVIS_EVENT_TYPE'] === 'api')){ +if(util.isTravisCI() && (process.env['TRAVIS_EVENT_TYPE'] === 'cron' || process.env['TRAVIS_EVENT_TYPE'] === 'api')){ console.log(`${chalk.green('ARCHIVE')} Cron job or custom build, building archive README!`); console.time('Builder'); let snippets = {}; @@ -91,9 +89,6 @@ let startPart = '', output = '', tagDbData = {}; -// Load helper functions (these are from existing snippets in 30 seconds of code!) -const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {}); - console.time('Builder'); // Synchronously read all snippets from snippets folder and sort them as necessary (case-insensitive) diff --git a/scripts/lint.js b/scripts/lint.js index d8140b8a4..69838bd3c 100644 --- a/scripts/lint.js +++ b/scripts/lint.js @@ -9,9 +9,8 @@ const fs = require('fs-extra'); const cp = require('child_process'); const path = require('path'); const chalk = require('chalk'); -// Load helper functions (these are from existing snippets in 30 seconds of code!) -const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; -if(isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) { +const util = require('./util'); +if(util.isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) { console.log(`${chalk.green('NOBUILD')} Linting terminated, parent commit is a Travis build!`); process.exit(0); } diff --git a/scripts/module.js b/scripts/module.js index 566c16568..0891f52b4 100644 --- a/scripts/module.js +++ b/scripts/module.js @@ -6,9 +6,8 @@ const fs = require('fs-extra'); const cp = require('child_process'); const path = require('path'); const chalk = require('chalk'); -// Load helper functions (these are from existing snippets in 30 seconds of code!) -const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; -if(isTravisCI() && process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['TRAVIS_EVENT_TYPE'] !== 'api') { +const util = require('./util'); +if(util.isTravisCI() && process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['TRAVIS_EVENT_TYPE'] !== 'api') { console.log(`${chalk.green('NOBUILD')} Module build terminated, not a cron job or a custom build!`); process.exit(0); } diff --git a/scripts/tag.js b/scripts/tag.js index 9b0371671..5ef2f535b 100644 --- a/scripts/tag.js +++ b/scripts/tag.js @@ -7,9 +7,7 @@ const fs = require('fs-extra'), path = require('path'), chalk = require('chalk'); const util = require('./util'); -// Load helper functions (these are from existing snippets in 30 seconds of code!) -const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; -if(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(`${chalk.green('NOBUILD')} Tagging terminated, parent commit is a Travis build!`); process.exit(0); } diff --git a/scripts/tdd.js b/scripts/tdd.js index 21151f199..0ade624d5 100644 --- a/scripts/tdd.js +++ b/scripts/tdd.js @@ -7,9 +7,8 @@ const fs = require('fs-extra'), path = require('path'); const child_process = require('child_process'); const chalk = require('chalk'); -// Load helper functions (these are from existing snippets in 30 seconds of code!) -const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; -if(isTravisCI() && process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['TRAVIS_EVENT_TYPE'] !== 'api') { +const util = require('./util'); +if(util.isTravisCI() && process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['TRAVIS_EVENT_TYPE'] !== 'api') { 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 7e7e41933..4df231829 100644 --- a/scripts/util.js +++ b/scripts/util.js @@ -23,7 +23,7 @@ const readSnippets = snippetsPath => { } return snippets; } -// Used in `readTags` +// Creates an object from pairs const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {}); // Load tag data from the database const readTags = () => { @@ -64,4 +64,6 @@ const optimizeNodes = (data, regexp, replacer) => { // Capitalizes the first letter of a string const capitalize = (str, lowerRest = false) => str.slice(0, 1).toUpperCase() + (lowerRest ? str.slice(1).toLowerCase() : str.slice(1)); -module.exports = {readSnippets, readTags, optimizeNodes, capitalize}; +// Checks if current environment is Travis CI +const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; +module.exports = {readSnippets, readTags, optimizeNodes, capitalize, objectFromPairs, isTravisCI}; diff --git a/scripts/web.js b/scripts/web.js index 61a3a2c47..692553b30 100644 --- a/scripts/web.js +++ b/scripts/web.js @@ -10,8 +10,6 @@ const fs = require('fs-extra'), minify = require('html-minifier').minify; const util = require('./util'); var Prism = require('prismjs'); - // Load helper functions (these are from existing snippets in 30 seconds of code!) -const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; const unescapeHTML = str => str.replace( /&|<|>|'|"/g, @@ -24,7 +22,7 @@ const unescapeHTML = str => '"': '"' }[tag] || tag) ); -if(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(`${chalk.green('NOBUILD')} index build terminated, parent commit is a Travis build!`); process.exit(0); } @@ -57,8 +55,6 @@ let snippets = {}, endPart = '', output = '', tagDbData = {}; -// Load helper functions (these are from existing snippets in 30 seconds of code!) -const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {}); // Start the timer of the script console.time('Webber'); // Synchronously read all snippets and sort them as necessary (case-insensitive) diff --git a/test/binarySearch/binarySearch.js b/test/binarySearch/binarySearch.js index 6813e1936..b352de700 100644 --- a/test/binarySearch/binarySearch.js +++ b/test/binarySearch/binarySearch.js @@ -5,4 +5,4 @@ if (arr[mid] > val) return binarySearch(arr, val, start, mid - 1); if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end); return mid; }; -module.exports = binarySearch; +module.exports = binarySearch; \ No newline at end of file