-
Notifications
You must be signed in to change notification settings - Fork 1
/
yaml-generate.js
52 lines (41 loc) · 1.28 KB
/
yaml-generate.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
44
45
46
47
48
49
50
51
52
const yaml = require('js-yaml');
const fs = require('fs');
const buildConstants = function(d) {
let built = d.reduce((p, c, i, a) => p + `const ${Object.keys(c)[0]} = ${c[Object.keys(c)[0]]}
`,'')
return built
}
const buildBindings = function(d) {
let built = d.reduce((p, c, i, a) => p + `case "${Object.keys(c)[0]}": ${c[Object.keys(c)[0]]}; break
`,'')
return built
}
const buildCommands = function(commands) {
let built = commands.reduce((p, c, i, a) => p + `const ${c} = function(d) => d
`,'')
return built
}
const buildInitialObjects = function(initialObjects) {
let built = initialObjects.reduce((p, c, i, a) => p + `let ${c} = {}
`,'')
return built
}
// Get document, or throw exception on error
try {
const doc = yaml.load(fs.readFileSync('specification.yaml', 'utf8'));
console.log(doc.htmlPrefix)
let constants = buildConstants(doc.constants)
console.log(constants)
let bindings = buildBindings(doc.keyBindingsKeys)
console.log(doc.keyBindingsPrefix)
console.log(bindings)
console.log(doc.keyBindingsPostfix)
let commands = buildCommands(doc.commands)
console.log(commands)
let initialObjects = buildInitialObjects(doc.initialObjects)
console.log(initialObjects)
console.log(doc.htmlPostfix)
//console.log(doc);
} catch (e) {
console.log(e);
}