From 373223b95f04b1b4767266993ef1439c56fa1f34 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Sun, 25 Feb 2024 23:05:53 -0500 Subject: [PATCH] Added ETS snippets command to install built snippets to local vscode directory --- .bin/ets.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/.bin/ets.js b/.bin/ets.js index 2d10271..435d02b 100755 --- a/.bin/ets.js +++ b/.bin/ets.js @@ -54,6 +54,14 @@ program deploy(env); }); +program + .command("snippets") + .requiredOption("-t, --type ", "There are two sets of snippets, eluna: server side events and wowapi: used for building UIs for AIO/Addons", 'eluna') + .description("This installs snippets that enable shortcuts to generating code in vscode. The snippets are copied to the current vscode project directory prefixed by type") + .action(async ({type}) => { + installSnippets(type); + }); + program.parse(process.argv); /** @@ -348,6 +356,31 @@ function buildModules(luaDir, moduleDir, watch, liveReload) { } + /** + * This will install snippets into the current project + * @param {string} type - eluna | wowapi + */ + async function installSnippets(type) { + if(type !== 'eluna' && type !== 'wowapi') { + log.error("Invalid snippet type. Must be eluna or wowapi"); + process.exit(1); + } + + if(type === 'wowapi') { + log.error("wowapi snippets not yet implemented, in development add a comment to existing feature request to raise priority."); + process.exit(1); + } + + const snippetsFile = path.resolve(__dirname, `../dist/.vscode/${type}.code-snippets`); + const vscodeDir = path.resolve(process.cwd(), '.vscode'); + + if(!fs.existsSync(vscodeDir)) { + fs.mkdirSync(vscodeDir); + } + + fs.copyFileSync(snippetsFile, path.resolve(vscodeDir, `${type}.code-snippets`)); + } + /** * Get Environment Variable if found or return false. * @param {string} name