complete snippet template
This commit is contained in:
parent
ce284a8c03
commit
2d400f18ff
26
package-lock.json
generated
26
package-lock.json
generated
@ -648,6 +648,16 @@
|
||||
"integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==",
|
||||
"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": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
@ -706,8 +716,7 @@
|
||||
"graceful-fs": {
|
||||
"version": "4.2.3",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz",
|
||||
"integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ=="
|
||||
},
|
||||
"has": {
|
||||
"version": "1.0.3",
|
||||
@ -918,6 +927,14 @@
|
||||
"integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=",
|
||||
"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": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz",
|
||||
@ -1557,6 +1574,11 @@
|
||||
"integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==",
|
||||
"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": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz",
|
||||
|
@ -17,6 +17,7 @@
|
||||
"eslint": "^6.8.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"fs-extra": "^8.1.0",
|
||||
"yargs": "^15.1.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,34 @@
|
||||
const fs = require ('fs');
|
||||
/* eslint-disable no-sync */
|
||||
|
||||
const fs = require ('fs-extra');
|
||||
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');
|
||||
fs.mkdir (snipFolder);
|
||||
fs.copy (path.join (template, 'index.js'), path.join (snipFolder, 'index.js'));
|
||||
};
|
||||
fs.mkdir (snip_folder);
|
||||
fs.copy (template, snip_folder);
|
||||
}
|
||||
|
||||
exports.assert = (args) => {
|
||||
assert (args.length == 1);
|
||||
assert (typeof args[0] === 'string');
|
||||
assert ((/^[a-zA-Z]+$/u).test (args[0]));
|
||||
};
|
||||
/**
|
||||
* 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 };
|
||||
|
29
snippets/snippet/template/index.js
Normal file
29
snippets/snippet/template/index.js
Normal 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 };
|
0
snippets/snippet/template/template/deleteme
Normal file
0
snippets/snippet/template/template/deleteme
Normal file
Loading…
x
Reference in New Issue
Block a user