complete snippet template
This commit is contained in:
		| @@ -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
									
								
							
		Reference in New Issue
	
	Block a user