-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
43 lines (32 loc) · 1.11 KB
/
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
35
36
37
38
39
40
41
42
43
const fs = require('fs');
const source = require('./source.json')
const surfaces = require('./source/surfaces.json')
const actionsBlocks = require('./source/actions-blocks.json')
const inputBlocks = require('./source/input-blocks.json')
const miscBlocks = require('./source/misc-blocks.json')
const sectionBlocks = require('./source/section-blocks.json')
const contextBlocks = require('./source/context-blocks.json')
const snippets = surfaces
.concat(actionsBlocks)
.concat(inputBlocks)
.concat(miscBlocks)
.concat(sectionBlocks)
.concat(contextBlocks)
function createSnippetBody(inputBody) {
const stringifiedBody = JSON.stringify(inputBody, null, 4)
outputBody = []
stringifiedBody.split("\n").forEach(line => {
const formattedLine = line.replace(/"/g, '\"').replace(/ /g, "\t")
outputBody.push(formattedLine)
})
return outputBody
}
const output = {}
snippets.forEach(snippet => {
output[snippet.name] = {
prefix: snippet.name.toLowerCase(),
body: createSnippetBody(snippet.body)
}
})
fs.writeFileSync('snippets.json', JSON.stringify(output, null, 4))
console.log("Build complete")