diff --git a/index.js b/index.js index e69de29..05e97bc 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,40 @@ +/* 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 (); diff --git a/snippets/snippet/template/index.js b/snippets/snippet/template/index.js index dfc628b..87556c2 100644 --- a/snippets/snippet/template/index.js +++ b/snippets/snippet/template/index.js @@ -7,9 +7,8 @@ const path = require ('path'); * copies the full template to the current folder * * @param {string} folder folder to run in - * @param {Array} args function arguments */ -function run (folder, args) { +function run (folder) { const template = path.join (__dirname, 'template'); fs.copy (template, folder); } @@ -18,10 +17,9 @@ function run (folder, args) { * checks if the arguments meet the requirements * * @param {string} folder folder to run in - * @param {Array} args function arguments * @returns {boolean} true if arguments match requirements */ -function assert (folder, args) { +function assert (folder) { return (typeof folder === 'string') && (fs.existsSync (folder)); } diff --git a/snippets/vue/index.js b/snippets/vue/index.js deleted file mode 100644 index e5f1294..0000000 --- a/snippets/vue/index.js +++ /dev/null @@ -1,5 +0,0 @@ -const fs = require ('fs'); - -module.exports = async (folder) => { - -};