-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
34 lines (27 loc) · 783 Bytes
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* libs */
import fs from "node:fs";
import path from "node:path";
/* snippets */
import { snippets } from "./src";
// ========================================
// to ensure that the directory exists, creating it if necessary
function ensureDirectoryExists(directory) {
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory, { recursive: true });
}
}
// all snippets list
const snippetsList = [snippets];
// merge all snippets
const concatenedSnippets = Object.assign(
{},
...snippetsList.map((snippet) => {
return snippet;
}),
);
// convert to JSON
const json = JSON.stringify(concatenedSnippets);
// write to file
const distDirectory = "./dist";
ensureDirectoryExists(distDirectory);
fs.writeFileSync(path.join(distDirectory, "my-extension.code-snippets"), json);