Merge branch 'master' into tdd.update
This commit is contained in:
@ -6,7 +6,12 @@
|
||||
const fs = require('fs-extra');
|
||||
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'])) {
|
||||
console.log(`${chalk.green('NOBUILD')} README build terminated, parent commit is a Travis build!`);
|
||||
process.exit(0);
|
||||
}
|
||||
const SNIPPETS_PATH = './snippets';
|
||||
const STATIC_PARTS_PATH = './static-parts';
|
||||
|
||||
|
||||
@ -9,7 +9,12 @@ 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'])) {
|
||||
console.log(`${chalk.green('NOBUILD')} Linting terminated, parent commit is a Travis build!`);
|
||||
process.exit(0);
|
||||
}
|
||||
const SNIPPETS_PATH = './snippets';
|
||||
const TEMP_PATH = './temp';
|
||||
|
||||
|
||||
80
scripts/module.js
Normal file
80
scripts/module.js
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
Builds the `_30s` module.
|
||||
*/
|
||||
// Load modules
|
||||
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') {
|
||||
console.log(`${chalk.green('NOBUILD')} Module build terminated, not a cron job or a custom build!`);
|
||||
process.exit(0);
|
||||
}
|
||||
// Set variables for paths
|
||||
const SNIPPETS_PATH = './snippets';
|
||||
const TEMP_PATH = './temp';
|
||||
const IMPORTS = './imports.js';
|
||||
// Regex for selecting code blocks
|
||||
const codeRE = /```\s*js([\s\S]*?)```/;
|
||||
// Start the timer of the script
|
||||
console.time('Module');
|
||||
// Load tag data from the database and snippets from their folder
|
||||
try {
|
||||
const tagDatabase = fs.readFileSync('tag_database', 'utf8');
|
||||
const snippets = fs.readdirSync(SNIPPETS_PATH);
|
||||
// Create `temp` folder if it doesn't already exist.
|
||||
if (!fs.existsSync(TEMP_PATH)) {
|
||||
fs.mkdirSync(TEMP_PATH);
|
||||
}
|
||||
// Write `imports.js`
|
||||
fs.writeFileSync(IMPORTS, '');
|
||||
let exportStr = 'export default {';
|
||||
// Read all snippets and store them appropriately
|
||||
for (const snippet of snippets) {
|
||||
const snippetData = fs.readFileSync(
|
||||
path.join(SNIPPETS_PATH, snippet),
|
||||
'utf8'
|
||||
);
|
||||
const snippetName = snippet.replace('.md', '');
|
||||
// Check if a snippet is Node-only
|
||||
const isNodeSnippet = tagDatabase
|
||||
.slice(tagDatabase.indexOf(snippetName) + snippetName.length + 1)
|
||||
.split('\n')[0]
|
||||
.includes('node');
|
||||
// Read `imports.js` and write the data
|
||||
const importData = fs.readFileSync(IMPORTS);
|
||||
fs.writeFileSync(
|
||||
IMPORTS,
|
||||
importData + `\nimport { ${snippetName} } from './temp/${snippetName}.js'`
|
||||
);
|
||||
exportStr += `${snippetName},`;
|
||||
// Find the code in each snippet
|
||||
const code = snippetData.match(codeRE)[1].replace('\n', '');
|
||||
// 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(')}`
|
||||
: `export ${code}`;
|
||||
// Write data to the proper file
|
||||
fs.writeFileSync(`${TEMP_PATH}/${snippetName}.js`, toWrite);
|
||||
}
|
||||
// Write to the proper files and start the `rollup` script
|
||||
exportStr += '}';
|
||||
fs.appendFileSync(IMPORTS, `\n${exportStr}`);
|
||||
cp.execSync('node ./scripts/rollup.js');
|
||||
// Clean up temporary data
|
||||
fs.removeSync(TEMP_PATH);
|
||||
fs.unlink(IMPORTS);
|
||||
// Log a success message
|
||||
console.log(`${chalk.green('SUCCESS!')} Snippet module built!`);
|
||||
// Log the time taken
|
||||
console.timeEnd('Module');
|
||||
} catch (err) {
|
||||
// Handle errors (hopefully not!)
|
||||
console.log(`${chalk.red('ERROR!')} During module creation: ${err}`);
|
||||
process.exit(1);
|
||||
}
|
||||
62
scripts/rollup.js
Normal file
62
scripts/rollup.js
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
Part of the process for building the `_30s` module.
|
||||
*/
|
||||
// Load modules
|
||||
const fs = require('fs-extra');
|
||||
const { rollup } = require('rollup');
|
||||
const babel = require('rollup-plugin-babel');
|
||||
const minify = require('rollup-plugin-babel-minify');
|
||||
// Set variables for paths
|
||||
const INPUT_FILE = './imports.js';
|
||||
const MODULE_NAME = '_30s';
|
||||
const DIST = './dist';
|
||||
// Create `dist` folder if not existing
|
||||
if (!fs.existsSync(DIST)) fs.mkdirSync(DIST);
|
||||
// Setup babel and minification
|
||||
const es5 = babel({ presets: [['env', { modules: false }]] });
|
||||
const min = minify({ comments: false });
|
||||
// Create the bundles
|
||||
(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] });
|
||||
const bundleES5Min = await rollup({
|
||||
input: INPUT_FILE,
|
||||
plugins: [es5, min]
|
||||
});
|
||||
|
||||
// UMD ES2017
|
||||
await bundle.write({
|
||||
file: `${DIST}/${MODULE_NAME}.js`,
|
||||
name: MODULE_NAME,
|
||||
format: 'umd'
|
||||
});
|
||||
|
||||
// UMD ES2017 minified
|
||||
await bundleMin.write({
|
||||
file: `${DIST}/${MODULE_NAME}.min.js`,
|
||||
name: MODULE_NAME,
|
||||
format: 'umd'
|
||||
});
|
||||
|
||||
// UMD ES5
|
||||
await bundleES5.write({
|
||||
file: `${DIST}/${MODULE_NAME}.es5.js`,
|
||||
name: MODULE_NAME,
|
||||
format: 'umd'
|
||||
});
|
||||
|
||||
// UMD ES5 min
|
||||
await bundleES5Min.write({
|
||||
file: `${DIST}/${MODULE_NAME}.es5.min.js`,
|
||||
name: MODULE_NAME,
|
||||
format: 'umd'
|
||||
});
|
||||
|
||||
// ESM ES2017
|
||||
await bundle.write({
|
||||
file: `${DIST}/${MODULE_NAME}.esm.js`,
|
||||
name: MODULE_NAME,
|
||||
format: 'es'
|
||||
});
|
||||
})();
|
||||
@ -6,6 +6,12 @@
|
||||
const fs = require('fs-extra'),
|
||||
path = require('path'),
|
||||
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'])) {
|
||||
console.log(`${chalk.green('NOBUILD')} Tagging terminated, parent commit is a Travis build!`);
|
||||
process.exit(0);
|
||||
}
|
||||
// Set variables for paths
|
||||
const snippetsPath = './snippets';
|
||||
// Set variables for script
|
||||
|
||||
@ -8,6 +8,12 @@ const fs = require('fs-extra'),
|
||||
chalk = require('chalk'),
|
||||
md = require('markdown-it')(),
|
||||
minify = require('html-minifier').minify;
|
||||
// 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'])) {
|
||||
console.log(`${chalk.green('NOBUILD')} index build terminated, parent commit is a Travis build!`);
|
||||
process.exit(0);
|
||||
}
|
||||
// Compile the mini.css framework and custom CSS styles, using `node-sass`.
|
||||
const sass = require('node-sass');
|
||||
sass.render(
|
||||
|
||||
Reference in New Issue
Block a user