complete basic cli
This commit is contained in:
parent
2d400f18ff
commit
709ab6ea35
40
index.js
40
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 ();
|
@ -7,9 +7,8 @@ const path = require ('path');
|
|||||||
* copies the full template to the current folder
|
* copies the full template to the current folder
|
||||||
*
|
*
|
||||||
* @param {string} folder folder to run in
|
* @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');
|
const template = path.join (__dirname, 'template');
|
||||||
fs.copy (template, folder);
|
fs.copy (template, folder);
|
||||||
}
|
}
|
||||||
@ -18,10 +17,9 @@ function run (folder, args) {
|
|||||||
* checks if the arguments meet the requirements
|
* checks if the arguments meet the requirements
|
||||||
*
|
*
|
||||||
* @param {string} folder folder to run in
|
* @param {string} folder folder to run in
|
||||||
* @param {Array} args function arguments
|
|
||||||
* @returns {boolean} true if arguments match requirements
|
* @returns {boolean} true if arguments match requirements
|
||||||
*/
|
*/
|
||||||
function assert (folder, args) {
|
function assert (folder) {
|
||||||
return (typeof folder === 'string')
|
return (typeof folder === 'string')
|
||||||
&& (fs.existsSync (folder));
|
&& (fs.existsSync (folder));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
const fs = require ('fs');
|
|
||||||
|
|
||||||
module.exports = async (folder) => {
|
|
||||||
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user