Optimized scripts
This commit is contained in:
@ -11,13 +11,11 @@ const util = require('./util');
|
|||||||
const SNIPPETS_PATH = './snippets';
|
const SNIPPETS_PATH = './snippets';
|
||||||
const SNIPPETS_ARCHIVE_PATH = './snippets_archive';
|
const SNIPPETS_ARCHIVE_PATH = './snippets_archive';
|
||||||
const STATIC_PARTS_PATH = './static-parts';
|
const STATIC_PARTS_PATH = './static-parts';
|
||||||
// Load helper functions (these are from existing snippets in 30 seconds of code!)
|
if(util.isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) {
|
||||||
const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env;
|
|
||||||
if(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!`);
|
console.log(`${chalk.green('NOBUILD')} README build terminated, parent commit is a Travis build!`);
|
||||||
process.exit(0);
|
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.log(`${chalk.green('ARCHIVE')} Cron job or custom build, building archive README!`);
|
||||||
console.time('Builder');
|
console.time('Builder');
|
||||||
let snippets = {};
|
let snippets = {};
|
||||||
@ -91,9 +89,6 @@ let startPart = '',
|
|||||||
output = '',
|
output = '',
|
||||||
tagDbData = {};
|
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');
|
console.time('Builder');
|
||||||
|
|
||||||
// Synchronously read all snippets from snippets folder and sort them as necessary (case-insensitive)
|
// Synchronously read all snippets from snippets folder and sort them as necessary (case-insensitive)
|
||||||
|
|||||||
@ -9,9 +9,8 @@ const fs = require('fs-extra');
|
|||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
// Load helper functions (these are from existing snippets in 30 seconds of code!)
|
const util = require('./util');
|
||||||
const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env;
|
if(util.isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) {
|
||||||
if(isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) {
|
|
||||||
console.log(`${chalk.green('NOBUILD')} Linting terminated, parent commit is a Travis build!`);
|
console.log(`${chalk.green('NOBUILD')} Linting terminated, parent commit is a Travis build!`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,9 +6,8 @@ const fs = require('fs-extra');
|
|||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
// Load helper functions (these are from existing snippets in 30 seconds of code!)
|
const util = require('./util');
|
||||||
const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env;
|
if(util.isTravisCI() && process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['TRAVIS_EVENT_TYPE'] !== 'api') {
|
||||||
if(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!`);
|
console.log(`${chalk.green('NOBUILD')} Module build terminated, not a cron job or a custom build!`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,7 @@ const fs = require('fs-extra'),
|
|||||||
path = require('path'),
|
path = require('path'),
|
||||||
chalk = require('chalk');
|
chalk = require('chalk');
|
||||||
const util = require('./util');
|
const util = require('./util');
|
||||||
// Load helper functions (these are from existing snippets in 30 seconds of code!)
|
if(util.isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) {
|
||||||
const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env;
|
|
||||||
if(isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) {
|
|
||||||
console.log(`${chalk.green('NOBUILD')} Tagging terminated, parent commit is a Travis build!`);
|
console.log(`${chalk.green('NOBUILD')} Tagging terminated, parent commit is a Travis build!`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,8 @@
|
|||||||
const fs = require('fs-extra'), path = require('path');
|
const fs = require('fs-extra'), path = require('path');
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
// Load helper functions (these are from existing snippets in 30 seconds of code!)
|
const util = require('./util');
|
||||||
const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env;
|
if(util.isTravisCI() && process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['TRAVIS_EVENT_TYPE'] !== 'api') {
|
||||||
if(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!`);
|
console.log(`${chalk.green('NOBUILD')} Testing terminated, not a cron job or a custom build!`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ const readSnippets = snippetsPath => {
|
|||||||
}
|
}
|
||||||
return snippets;
|
return snippets;
|
||||||
}
|
}
|
||||||
// Used in `readTags`
|
// Creates an object from pairs
|
||||||
const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {});
|
const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {});
|
||||||
// Load tag data from the database
|
// Load tag data from the database
|
||||||
const readTags = () => {
|
const readTags = () => {
|
||||||
@ -64,4 +64,6 @@ const optimizeNodes = (data, regexp, replacer) => {
|
|||||||
// Capitalizes the first letter of a string
|
// Capitalizes the first letter of a string
|
||||||
const capitalize = (str, lowerRest = false) =>
|
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));
|
||||||
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};
|
||||||
|
|||||||
@ -10,8 +10,6 @@ const fs = require('fs-extra'),
|
|||||||
minify = require('html-minifier').minify;
|
minify = require('html-minifier').minify;
|
||||||
const util = require('./util');
|
const util = require('./util');
|
||||||
var Prism = require('prismjs');
|
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 =>
|
const unescapeHTML = str =>
|
||||||
str.replace(
|
str.replace(
|
||||||
/&|<|>|'|"/g,
|
/&|<|>|'|"/g,
|
||||||
@ -24,7 +22,7 @@ const unescapeHTML = str =>
|
|||||||
'"': '"'
|
'"': '"'
|
||||||
}[tag] || tag)
|
}[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!`);
|
console.log(`${chalk.green('NOBUILD')} index build terminated, parent commit is a Travis build!`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
@ -57,8 +55,6 @@ let snippets = {},
|
|||||||
endPart = '',
|
endPart = '',
|
||||||
output = '',
|
output = '',
|
||||||
tagDbData = {};
|
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
|
// Start the timer of the script
|
||||||
console.time('Webber');
|
console.time('Webber');
|
||||||
// Synchronously read all snippets and sort them as necessary (case-insensitive)
|
// Synchronously read all snippets and sort them as necessary (case-insensitive)
|
||||||
|
|||||||
@ -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);
|
if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end);
|
||||||
return mid;
|
return mid;
|
||||||
};
|
};
|
||||||
module.exports = binarySearch;
|
module.exports = binarySearch;
|
||||||
Reference in New Issue
Block a user