complete snippet template

This commit is contained in:
Timo Hocker 2020-01-15 13:30:18 +01:00
parent ce284a8c03
commit 2d400f18ff
5 changed files with 84 additions and 13 deletions

26
package-lock.json generated
View File

@ -648,6 +648,16 @@
"integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==", "integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==",
"dev": true "dev": true
}, },
"fs-extra": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
"requires": {
"graceful-fs": "^4.2.0",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
},
"fs.realpath": { "fs.realpath": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@ -706,8 +716,7 @@
"graceful-fs": { "graceful-fs": {
"version": "4.2.3", "version": "4.2.3",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz",
"integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==", "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ=="
"dev": true
}, },
"has": { "has": {
"version": "1.0.3", "version": "1.0.3",
@ -918,6 +927,14 @@
"integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=",
"dev": true "dev": true
}, },
"jsonfile": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"requires": {
"graceful-fs": "^4.1.6"
}
},
"levn": { "levn": {
"version": "0.3.0", "version": "0.3.0",
"resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz",
@ -1557,6 +1574,11 @@
"integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==",
"dev": true "dev": true
}, },
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
},
"uri-js": { "uri-js": {
"version": "4.2.2", "version": "4.2.2",
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz",

View File

@ -17,6 +17,7 @@
"eslint": "^6.8.0" "eslint": "^6.8.0"
}, },
"dependencies": { "dependencies": {
"fs-extra": "^8.1.0",
"yargs": "^15.1.0" "yargs": "^15.1.0"
} }
} }

View File

@ -1,15 +1,34 @@
const fs = require ('fs'); /* eslint-disable no-sync */
const fs = require ('fs-extra');
const path = require ('path'); const path = require ('path');
exports.run = async (folder, args) => { /**
const snipFolder = path.join (folder, args[0]); * 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]);
const template = path.join (__dirname, 'template'); const template = path.join (__dirname, 'template');
fs.mkdir (snipFolder); fs.mkdir (snip_folder);
fs.copy (path.join (template, 'index.js'), path.join (snipFolder, 'index.js')); fs.copy (template, snip_folder);
}; }
exports.assert = (args) => { /**
assert (args.length == 1); * checks if the arguments meet the requirements
assert (typeof args[0] === 'string'); *
assert ((/^[a-zA-Z]+$/u).test (args[0])); * @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 };

View File

@ -0,0 +1,29 @@
/* eslint-disable no-sync */
const fs = require ('fs-extra');
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) {
const template = path.join (__dirname, 'template');
fs.copy (template, 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 (typeof folder === 'string')
&& (fs.existsSync (folder));
}
module.exports = { run, assert };