snippeteer/index.js
2020-01-15 14:09:29 +01:00

41 lines
789 B
JavaScript

/* eslint-disable no-console */
/* eslint-disable global-require */
/* eslint-disable no-sync */
const { argv } = require ('yargs');
const path = require ('path');
const fs = require ('fs-extra');
const [
template,
...args
] = argv._;
/**
* main function
*/
function main () {
if (typeof template !== 'string') {
console.log ('please specify a template');
return;
}
if (
!fs.existsSync (path.join (__dirname, 'snippets', template))
|| !(/^[a-zA-Z]+$/u).test (template)
) {
console.log ('template does not exist');
return;
}
const snippet = require (`./snippets/${template}/index.js`);
if (!snippet.assert (process.cwd, args)) {
console.log ('snipped rejected arguments');
return;
}
snippet.run (process.cwd, args);
}
main ();