From 61c68baceec136f3932e88a7a9e2b873f6cc1b1f Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Sun, 25 Feb 2024 23:07:38 -0500 Subject: [PATCH] Added scripts for prepublish to build snippets file by type --- scripts/build-snippets.js | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 scripts/build-snippets.js diff --git a/scripts/build-snippets.js b/scripts/build-snippets.js new file mode 100755 index 0000000..878b26e --- /dev/null +++ b/scripts/build-snippets.js @@ -0,0 +1,40 @@ +#!/usr/bin/env node +const fs = require('fs-extra'); +const path = require('path'); + +/** + * This will combine all the snippets into the dist .vscode directory at publish time. + * @param {string} type + */ +async function buildSnippets(type) { + try { + const snippets = {}; + const snippetsDir = path.join(process.cwd(), 'snippets', type); + const files = await fs.readdir(snippetsDir); + + for (const file of files) { + if (file.endsWith('.code-snippets')) { + const content = await fs.readJson(path.join(snippetsDir, file)); + + Object.assign(snippets, content); + } + } + + const output = path.join(process.cwd(), 'dist', '.vscode'); + await fs.ensureDir(output); + await fs.writeJson(path.join(output, `${type}.code-snippets`),snippets, {spaces: 2}); + } catch (error) { + console.error('Error combining snippets:', error); + } +} + + +( async() => { +// Build Packaged Eluna snippets + await buildSnippets('eluna'); + // Build Package WoW API Snippets +})(); + + + +