snippeteer/index.js
2020-01-15 15:43:23 +01:00

44 lines
833 B
JavaScript

#!/usr/bin/env node
/* 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`);
const folder = process.cwd ();
if (!snippet.assert (folder, args)) {
console.log ('snipped rejected arguments');
return;
}
snippet.run (folder, args);
}
main ();