Cleanup for scripts folder

This commit is contained in:
Angelos Chalaris
2018-11-10 14:55:31 +02:00
parent c1fe403bf0
commit 869ca8c13e
10 changed files with 130 additions and 148 deletions

View File

@ -18,19 +18,19 @@ const MODULE_NAME = '_30s';
const DIST = './dist';
// Regex for selecting code blocks
const codeRE = /```\s*js([\s\S]*?)```/;
// Read snippets, build packages
(async () => {
// Read snippets, build packages
(async() => {
// Start the timer of the script
console.time('Packager');
try {
const tagDatabase = fs.readFileSync('tag_database', 'utf8');
const nodeSnippets = tagDatabase.split('\n').filter(v => v.search(/:.*node/g) !== -1).map(v => v.slice(0,v.indexOf(':')));
const nodeSnippets = tagDatabase.split('\n').filter(v => v.search(/:.*node/g) !== -1).map(v => v.slice(0, v.indexOf(':')));
const snippets = fs.readdirSync(SNIPPETS_PATH);
const snippetExports = `module.exports = {${snippets.map(v => v.replace('.md', '')).join(',')}}`;
let requires = [];
let importData = '';
const archivedSnippets = fs.readdirSync(SNIPPETS_ARCHIVE_PATH).filter(v => v !== 'README.md');
const testExports = `module.exports = {${[...snippets,...archivedSnippets].map(v => v.replace('.md', '')).join(',')}}`;
const testExports = `module.exports = {${[...snippets, ...archivedSnippets].map(v => v.replace('.md', '')).join(',')}}`;
// Create `temp` and `dist` folders if they don't already exist.
if (!fs.existsSync(DIST)) fs.mkdirSync(DIST);
// Write `imports.js`
@ -43,7 +43,7 @@ const codeRE = /```\s*js([\s\S]*?)```/;
let code = snippetData.match(codeRE)[1].replace('\n', '');
if (nodeSnippets.includes(snippetName)) {
requires.push(code.match(/const.*=.*require\(([^\)]*)\);/g));
code = code.replace(/const.*=.*require\(([^\)]*)\);/g,'');
code = code.replace(/const.*=.*require\(([^\)]*)\);/g, '');
}
importData += code;
});
@ -67,7 +67,7 @@ const codeRE = /```\s*js([\s\S]*?)```/;
console.timeEnd('Packager');
process.exit(0);
}
// Write to the proper files and start the `rollup` script
const es5 = babel({
presets: ['@babel/preset-env']
@ -85,7 +85,7 @@ const codeRE = /```\s*js([\s\S]*?)```/;
file: `${DIST}/${MODULE_NAME}.esm.js`,
name: MODULE_NAME,
format: 'es'
});
});
// UMD ES5
const bundleES5 = await rollup({ input: IMPORTS, plugins: [es5] });
await bundleES5.write({
@ -115,4 +115,4 @@ const codeRE = /```\s*js([\s\S]*?)```/;
console.log(`${chalk.red('ERROR!')} During module creation: ${err}`);
process.exit(1);
}
})();
})();