snippeteer/index.js

44 lines
833 B
JavaScript
Raw Normal View History

2020-01-15 14:14:54 +01:00
#!/usr/bin/env node
2020-01-15 14:09:29 +01:00
/* 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`);
2020-01-15 15:43:23 +01:00
const folder = process.cwd ();
2020-01-15 14:09:29 +01:00
2020-01-15 14:46:10 +01:00
if (!snippet.assert (folder, args)) {
2020-01-15 14:09:29 +01:00
console.log ('snipped rejected arguments');
return;
}
2020-01-15 14:46:10 +01:00
snippet.run (folder, args);
2020-01-15 14:09:29 +01:00
}
main ();