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
|
const childProcess = require('child_process')
const fs = require('fs')
const path = require('path')
const { parseKeymap } = require('./keymap')
const ZMK_PATH = path.join(__dirname, '..', '..', '..', 'zmk-config')
const KEYBOARD = 'dactyl'
function loadBehaviors() {
return JSON.parse(fs.readFileSync(path.join(__dirname, 'data', 'zmk-behaviors.json')))
}
function loadKeycodes() {
return JSON.parse(fs.readFileSync(path.join(__dirname, 'data', 'zmk-keycodes.json')))
}
function loadLayout (layout = 'LAYOUT') {
const layoutPath = path.join(ZMK_PATH, 'config', 'info.json')
return JSON.parse(fs.readFileSync(layoutPath)).layouts[layout].layout
}
function loadKeymap () {
const keymapPath = path.join(ZMK_PATH, 'config', 'keymap.json')
return JSON.parse(fs.readFileSync(keymapPath))
}
function exportKeymap (generatedKeymap, flash, callback) {
const keymapPath = path.join(ZMK_PATH, 'config')
fs.existsSync(keymapPath) || fs.mkdirSync(keymapPath)
fs.writeFileSync(path.join(keymapPath, 'keymap.json'), generatedKeymap.json)
fs.writeFileSync(path.join(keymapPath, `${KEYBOARD}.keymap`), generatedKeymap.code)
// Note: This isn't really helpful. In the QMK version I had this actually
// calling `make` and piping the output in realtime but setting up a ZMK dev
// environment proved to be more complex than I had patience for, so for now
// I'm writing changes to a zmk-config repo and counting on the predefined
// GitHub action to actually compile.
return childProcess.execFile('git', ['status'], { cwd: ZMK_PATH }, callback)
}
module.exports = {
loadBehaviors,
loadKeycodes,
loadLayout,
loadKeymap,
exportKeymap
}
|