-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_keybindings.js
129 lines (114 loc) · 3.14 KB
/
generate_keybindings.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const fs = require('fs');
const cudef = require('./cudef')
const keybindings = []
const commands = []
const symbolMap = {}
function asString(val) {
const data = []
for (var i = 0; i < val.length; i++) {
var code = val.charCodeAt(i).toString(16);
if (code.length === 1) {
code = '000' + code
} else if(code.length === 2) {
code = '00' + code
} else if (code.length == 3) {
code = '0' + code
}
data.push(code)
}
return data.join('.')
}
const seen = {}
function makeIt(mod, defs) {
defs.forEach(function([kb, val, valShift]) {
if (val !== '') {
const k1 = {
key: mod.key + kb,
win: mod.win + kb,
mac: mod.mac + kb,
command: 'church-slavonic-keyboard:' + mod.title + kb,
when: 'editorTextFocus && cu.active'
}
if (seen[k1.command] === undefined) {
keybindings.push(k1)
commands.push({
command: k1.command,
title: 'CU Stroke: ' + mod.title + kb
})
seen[k1.command] = true
}
symbolMap[k1.command] = val;
}
if (valShift !== '') {
const k2 = {
key: mod.key + 'shift+' + kb,
win: mod.win + 'shift+' + kb,
mac: mod.mac + 'shift+' + kb,
command: 'church-slavonic-keyboard:' + mod.title + 'shift+' + kb,
when: 'editorTextFocus && cu.active'
}
if (seen[k2.command] === undefined) {
keybindings.push(k2)
commands.push({
command: k2.command,
title: 'CU Stroke: ' + mod.title + 'shift+' + kb
})
seen[k2.command] = true
}
symbolMap[k2.command] = valShift
}
})
}
makeIt({
title: '',
key: '',
win: '',
mac: '',
},
cudef.plain
)
makeIt({
title: 'meta+',
key: 'meta+',
win: 'ctrl+alt+',
mac: 'ctrl+alt+',
},
cudef.mod
)
makeIt({
title: 'dead',
key: '` ',
win: '` ',
mac: '` ',
}, cudef.deadPlain)
makeIt({
title: 'dead+meta+',
key: '` meta+',
win: '` ctrl+alt+',
mac: '` ctrl+atl+',
}, cudef.deadMod
)
keybindings.push({
key: 'meta+space',
mac: 'ctrl+alt+space',
win: 'ctrl+alt+space',
command: 'church-slavonic-toggle'
})
commands.push({
command: 'church-slavonic-toggle',
title: 'Church Slavonic Keyboard: Toggle'
})
var text = {
keybindings: JSON.stringify(keybindings, null, 4),
commands: JSON.stringify(commands, null, 4),
symbolMap: JSON.stringify(symbolMap, null, 4)
}
var template = fs.readFileSync('package.json.template').toString();
var expanded = template.
replace('{{keybindings}}', text.keybindings).
replace('{{commands}}', text.commands);
fs.writeFileSync('package.json', expanded)
var template = fs.readFileSync('symbol-map.js.template').toString();
var expanded = template.
replace('{{symbolMap}}', text.symbolMap)
fs.writeFileSync('symbol-map.js', expanded)