35 lines
893 B
JavaScript
Raw Normal View History

2020-01-15 13:30:18 +01:00
/* eslint-disable no-sync */
const fs = require ('fs-extra');
2020-01-15 11:50:44 +01:00
const path = require ('path');
2020-01-15 11:40:33 +01:00
2020-01-15 13:30:18 +01:00
/**
* copies the full template to a new folder named after arg[0]
*
* @param {string} folder folder to run in
* @param {Array} args function arguments
*/
function run (folder, args) {
const snip_folder = path.join (folder, args[0]);
2020-01-15 11:50:44 +01:00
const template = path.join (__dirname, 'template');
2020-01-15 13:30:18 +01:00
fs.mkdir (snip_folder);
fs.copy (template, snip_folder);
}
/**
* 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) {
return (args.length === 1)
&& (typeof args[0] === 'string')
&& (/^[a-zA-Z]+$/u).test (args[0])
&& (typeof folder === 'string')
&& (fs.existsSync (folder));
}
module.exports = { run, assert };