From 134bef203c79fafadfa47afc6789e2aa86719f70 Mon Sep 17 00:00:00 2001 From: Nick Coutsos Date: Fri, 15 Apr 2022 12:21:45 -0400 Subject: Fix fontawesome icon keycodes --- application/keycodes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/keycodes.js b/application/keycodes.js index 743bc76..7a65f5b 100644 --- a/application/keycodes.js +++ b/application/keycodes.js @@ -18,10 +18,10 @@ function normalizeZmkKeycodes (keycodes) { const fnPattern = /^(.+?)\((code)\)$/ return keycodes.reduce((keycodes, keycode) => { - const { description, context, symbol } = keycode + const { description, context, symbol, faIcon } = keycode const aliases = keycode.names.filter(name => !name.match(fnPattern)) const fnCode = keycode.names.map(name => name.match(fnPattern)).filter(v => !!v)[0] - const base = { aliases, description, context, symbol: symbol || shortestAlias(aliases), params: [] } + const base = { aliases, description, context, faIcon, symbol: symbol || shortestAlias(aliases), params: [] } for (let code of aliases) { keycodes.push(Object.assign({}, base, { -- cgit v1.2.3 From 87a6bcb546dc72417658445c19cf573c62d2eee9 Mon Sep 17 00:00:00 2001 From: Nick Coutsos Date: Fri, 15 Apr 2022 12:36:38 -0400 Subject: Apparently fontawesome key symbols were always broken --- application/components/key-value.vue | 2 +- application/components/key.vue | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/application/components/key-value.vue b/application/components/key-value.vue index 776a37b..1bc6b10 100644 --- a/application/components/key-value.vue +++ b/application/components/key-value.vue @@ -5,7 +5,7 @@ @click.stop="onSelect({ target: $event.target, codeIndex: index, code: value, param })" > diff --git a/application/components/key.vue b/application/components/key.vue index dcc6972..1c135bb 100644 --- a/application/components/key.vue +++ b/application/components/key.vue @@ -140,15 +140,17 @@ export default { }, isSimple() { const [first] = this.normalized.params + const icon = get(first, 'source.faIcon') const symbol = get(first, 'source.symbol', get(first, 'source.code', '')) - const shortSymbol = symbol.length === 1 + const shortSymbol = !!icon || symbol.length === 1 const singleParam = this.normalized.params.length === 1 return singleParam && shortSymbol }, isComplex() { const [first] = this.normalized.params + const icon = get(first, 'source.faIcon') const symbol = get(first, 'source.symbol', get(first, 'value', '')) - const isLongSymbol = symbol.length > 4 + const isLongSymbol = !icon && symbol.length > 4 const isMultiParam = this.behaviourParams.length > 1 const isNestedParam = get(first, 'params', []).length > 0 -- cgit v1.2.3 From 140539893394e009fe33e94ec52515da84eb8bd7 Mon Sep 17 00:00:00 2001 From: Nick Coutsos Date: Fri, 15 Apr 2022 13:04:51 -0400 Subject: Get rid of arbitrary split keyboard formatting --- api/services/zmk/layout.js | 1 - 1 file changed, 1 deletion(-) diff --git a/api/services/zmk/layout.js b/api/services/zmk/layout.js index c914177..17bd7e4 100644 --- a/api/services/zmk/layout.js +++ b/api/services/zmk/layout.js @@ -36,7 +36,6 @@ function renderTable (layout, layer, opts={}) { (row[i] || []).length + columnSeparator.length + (useQuotes ? 2 : 0) // wrapping with quotes adds 2 characters - + (i === 6 ? 10 : 0) // sloppily add a little space between halves (right half starts at column 6) )) )) -- cgit v1.2.3 From 3c47217f698646fac6974a5d18ee007fb8e2ddf4 Mon Sep 17 00:00:00 2001 From: Nick Coutsos Date: Fri, 15 Apr 2022 19:48:40 -0400 Subject: Remove unused files --- application/data/keymap.json | 231 ------------------------------------------- application/data/layers.json | 56 ----------- application/data/layout.json | 62 ------------ 3 files changed, 349 deletions(-) delete mode 100644 application/data/keymap.json delete mode 100644 application/data/layers.json delete mode 100644 application/data/layout.json diff --git a/application/data/keymap.json b/application/data/keymap.json deleted file mode 100644 index c8678a6..0000000 --- a/application/data/keymap.json +++ /dev/null @@ -1,231 +0,0 @@ -{ - "keyboard": "handwired/dactyl_reduced", - "keymap": "default", - "layout": "LAYOUT", - "layers": [ - [ - "KC_TAB", - "KC_Q", - "KC_W", - "KC_E", - "KC_R", - "KC_T", - "KC_Y", - "KC_U", - "KC_I", - "KC_O", - "KC_P", - "KC_BSLS", - "KC_CAPS", - "KC_A", - "KC_S", - "KC_D", - "KC_F", - "KC_G", - "KC_H", - "KC_J", - "KC_K", - "KC_L", - "LT(2,KC_SCLN)", - "KC_QUOT", - "KC_LSPO", - "KC_Z", - "KC_X", - "KC_C", - "KC_V", - "KC_B", - "KC_N", - "KC_M", - "KC_COMM", - "KC_DOT", - "KC_SLSH", - "KC_RSPC", - "KC_LCTL", - "KC_LEFT", - "KC_RGHT", - "KC_DOWN", - "KC_UP", - "KC_LBRC", - "KC_LCTL", - "KC_BSPC", - "KC_RALT", - "KC_ESC", - "KC_LALT", - "KC_LGUI", - "MO(1)", - "KC_PGUP", - "KC_ENT", - "KC_SPC", - "MO(2)", - "KC_PGDN" - ], - [ - "KC_TRNS", - "KC_TRNS", - "KC_GRAVE", - "KC_MINS", - "KC_EQL", - "KC_TRNS", - "KC_LBRC", - "KC_7", - "KC_8", - "KC_9", - "KC_RBRC", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_KP_PLUS", - "KC_4", - "KC_5", - "KC_6", - "KC_KP_ASTERISK", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_KP_MINUS", - "KC_1", - "KC_2", - "KC_3", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_0", - "KC_DOT", - "KC_TRNS", - "KC_TRNS", - "KC_LCMD", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_LSHIFT", - "KC_TRNS" - ], - [ - "RESET", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "LCMD(KC_LBRC)", - "LCMD(LSFT(KC_LBRC))", - "LCMD(LSFT(KC_RBRC))", - "LCMD(KC_RBRC)", - "KC_TRNS", - "KC_TRNS", - "RGB_MODE_FORWARD", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_F8", - "KC_F9", - "KC_F7", - "LCMD(LALT(KC_GRAVE))", - "KC_TRNS", - "KC_TRNS", - "RGB_HUI", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC__VOLDOWN", - "KC__VOLUP", - "KC__MUTE", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS" - ], - [ - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_F7", - "KC_F8", - "KC_F9", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_F4", - "KC_F5", - "KC_F6", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_F1", - "KC_F2", - "KC_F3", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS", - "KC_TRNS" - ] - ] -} \ No newline at end of file diff --git a/application/data/layers.json b/application/data/layers.json deleted file mode 100644 index 3edf07b..0000000 --- a/application/data/layers.json +++ /dev/null @@ -1,56 +0,0 @@ -[ - { "code": "KC_TAB" }, - { "code": "KC_Q" }, - { "code": "KC_W" }, - { "code": "KC_E" }, - { "code": "KC_R" }, - { "code": "KC_T" }, - { "code": "KC_Y" }, - { "code": "KC_U" }, - { "code": "KC_I" }, - { "code": "KC_O" }, - { "code": "KC_P" }, - { "code": "KC_BSLS" }, - { "code": "KC_CAPS" }, - { "code": "KC_A" }, - { "code": "KC_S" }, - { "code": "KC_D" }, - { "code": "KC_F" }, - { "code": "KC_G" }, - { "code": "KC_H" }, - { "code": "KC_J" }, - { "code": "KC_K" }, - { "code": "KC_L" }, - { "code": "LT(2, KC_SCLN)" }, - { "code": "KC_QUOT" }, - { "code": "KC_LSPO" }, - { "code": "KC_Z" }, - { "code": "KC_X" }, - { "code": "KC_C" }, - { "code": "KC_V" }, - { "code": "KC_B" }, - { "code": "KC_N" }, - { "code": "KC_M" }, - { "code": "KC_COMM" }, - { "code": "KC_DOT" }, - { "code": "KC_SLSH" }, - { "code": "KC_RSPC" }, - { "code": "KC_LCTL" }, - { "code": "KC_LEFT" }, - { "code": "KC_RGHT" }, - { "code": "KC_DOWN" }, - { "code": "KC_UP" }, - { "code": "KC_LBRC" }, - { "code": "KC_LCTL" }, - { "code": "KC_BSPC" }, - { "code": "KC_RALT" }, - { "code": "KC_ESC" }, - { "code": "KC_LALT" }, - { "code": "KC_LGUI" }, - { "code": "MO(1)" }, - { "code": "KC_PGUP" }, - { "code": "KC_ENT" }, - { "code": "KC_SPC" }, - { "code": "MO(2)" }, - { "code": "KC_PGDN" } -] diff --git a/application/data/layout.json b/application/data/layout.json deleted file mode 100644 index 6095cd6..0000000 --- a/application/data/layout.json +++ /dev/null @@ -1,62 +0,0 @@ -[ - { "label": "L00", "row": 0, "col": 0, "x": 0, "y": 0.5 }, - { "label": "L01", "row": 0, "col": 1, "x": 1, "y": 0.5 }, - { "label": "L02", "row": 0, "col": 2, "x": 2, "y": 0.2 }, - { "label": "L03", "row": 0, "col": 3, "x": 3, "y": 0 }, - { "label": "L04", "row": 0, "col": 4, "x": 4, "y": 0.25 }, - { "label": "L05", "row": 0, "col": 5, "x": 5, "y": 0.25 }, - { "label": "R06", "row": 0, "col": 6, "x": 13, "y": 0.25 }, - { "label": "R07", "row": 0, "col": 7, "x": 14, "y": 0.25 }, - { "label": "R08", "row": 0, "col": 8, "x": 15, "y": 0 }, - { "label": "R09", "row": 0, "col": 9, "x": 16, "y": 0.2 }, - { "label": "R0A", "row": 0, "col": 10, "x": 17, "y": 0.5 }, - { "label": "R0B", "row": 0, "col": 11, "x": 18, "y": 0.5 }, - - { "label": "L10", "row": 1, "col": 0, "x": 0, "y": 1.5 }, - { "label": "L11", "row": 1, "col": 1, "x": 1, "y": 1.5 }, - { "label": "L12", "row": 1, "col": 2, "x": 2, "y": 1.2 }, - { "label": "L13", "row": 1, "col": 3, "x": 3, "y": 1 }, - { "label": "L14", "row": 1, "col": 4, "x": 4, "y": 1.25 }, - { "label": "L15", "row": 1, "col": 5, "x": 5, "y": 1.25 }, - { "label": "R16", "row": 1, "col": 6, "x": 13, "y": 1.25 }, - { "label": "R17", "row": 1, "col": 7, "x": 14, "y": 1.25 }, - { "label": "R18", "row": 1, "col": 8, "x": 15, "y": 1 }, - { "label": "R19", "row": 1, "col": 9, "x": 16, "y": 1.2 }, - { "label": "R1A", "row": 1, "col": 10, "x": 17, "y": 1.5 }, - { "label": "R1B", "row": 1, "col": 11, "x": 18, "y": 1.5 }, - - { "label": "L20", "row": 2, "col": 0, "x": 0, "y": 2.5 }, - { "label": "L21", "row": 2, "col": 1, "x": 1, "y": 2.5 }, - { "label": "L22", "row": 2, "col": 2, "x": 2, "y": 2.2 }, - { "label": "L23", "row": 2, "col": 3, "x": 3, "y": 2 }, - { "label": "L24", "row": 2, "col": 4, "x": 4, "y": 2.25 }, - { "label": "L25", "row": 2, "col": 5, "x": 5, "y": 2.25 }, - { "label": "R26", "row": 2, "col": 6, "x": 13, "y": 2.25 }, - { "label": "R27", "row": 2, "col": 7, "x": 14, "y": 2.25 }, - { "label": "R28", "row": 2, "col": 8, "x": 15, "y": 2 }, - { "label": "R29", "row": 2, "col": 9, "x": 16, "y": 2.2 }, - { "label": "R2A", "row": 2, "col": 10, "x": 17, "y": 2.5 }, - { "label": "R2B", "row": 2, "col": 11, "x": 18, "y": 2.5 }, - - { "label": "L32", "row": 3, "col": 2, "x": 2, "y": 3.2 }, - { "label": "L33", "row": 3, "col": 3, "x": 3, "y": 3 }, - { "label": "L34", "row": 3, "col": 4, "x": 4, "y": 3.25 }, - { "label": "R37", "row": 3, "col": 7, "x": 14, "y": 3.25 }, - { "label": "R38", "row": 3, "col": 8, "x": 15, "y": 3 }, - { "label": "R39", "row": 3, "col": 9, "x": 16, "y": 3.2 }, - - { "label": "L42", "row": 4, "col": 4, "x": 6.5, "y": 2, "r": 20, "rx": 4.5, "ry": 3 }, - { "label": "L43", "row": 4, "col": 5, "x": 7.5, "y": 2, "r": 20, "rx": 4.5, "ry": 3 }, - { "label": "R48", "row": 4, "col": 6, "x": 10.5, "y": 2, "r": -20, "rx": 14.5, "ry": 3 }, - { "label": "R49", "row": 4, "col": 7, "x": 11.5, "y": 2, "r": -20, "rx": 14.5, "ry": 3 }, - - { "label": "L40", "row": 5, "col": 3, "x": 5.5, "y": 3, "r": 20, "rx": 4.5, "ry": 3, "h": 2 }, - { "label": "L41", "row": 5, "col": 4, "x": 6.5, "y": 3, "r": 20, "rx": 4.5, "ry": 3, "h": 2 }, - { "label": "L44", "row": 5, "col": 5, "x": 7.5, "y": 3, "r": 20, "rx": 4.5, "ry": 3 }, - { "label": "R47", "row": 5, "col": 6, "x": 10.5, "y": 3, "r": -20, "rx": 14.5, "ry": 3 }, - { "label": "R4A", "row": 5, "col": 7, "x": 11.5, "y": 3, "r": -20, "rx": 14.5, "ry": 3, "h": 2 }, - { "label": "R4B", "row": 5, "col": 8, "x": 12.5, "y": 3, "r": -20, "rx": 14.5, "ry": 3, "h": 2 }, - - { "label": "L45", "row": 6, "col": 5, "x": 7.5, "y": 4, "r": 20, "rx": 4.5, "ry": 3 }, - { "label": "R46", "row": 6, "col": 6, "x": 10.5, "y": 4, "r": -20, "rx": 14.5, "ry": 3 } -] \ No newline at end of file -- cgit v1.2.3 From 134ed946aa6f6d617a16ff538814a848faa690d4 Mon Sep 17 00:00:00 2001 From: Nick Coutsos Date: Fri, 15 Apr 2022 19:49:36 -0400 Subject: Update screenshot and mention demo source --- README.md | 3 +++ editor-screenshot.png | Bin 292465 -> 169899 bytes 2 files changed, 3 insertions(+) diff --git a/README.md b/README.md index ae3b1d6..20a3f39 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ A browser app (plus NodeJS server) to edit ZMK keymaps. This is still in its infancy and doesn't yet support parsing existing ZMK keymaps which limits some kinds of functionality (mainly those involving custom/configured behaviours). +**Try it live!** Go to the [keymap-editor] and try it out with the built-in +[zmk-config-corne-demo] before setting up your own repo. + ![Screenshot](editor-screenshot.png) ## Features diff --git a/editor-screenshot.png b/editor-screenshot.png index 5d64bbf..86113cf 100644 Binary files a/editor-screenshot.png and b/editor-screenshot.png differ -- cgit v1.2.3 From 5fc92da78b10ab35ba57d28a0e1e2c547fa42e91 Mon Sep 17 00:00:00 2001 From: Nick Coutsos Date: Sat, 23 Apr 2022 18:30:58 -0400 Subject: Use cross-env to support Windows environments --- package-lock.json | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +- 2 files changed, 128 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 4437854..114ce43 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "axios": "^0.21.4", "body-parser": "^1.19.0", "cors": "^2.8.5", + "cross-env": "^7.0.3", "dotenv": "^10.0.0", "express": "^4.17.1", "express-ws": "^4.0.0", @@ -140,6 +141,36 @@ "node": ">= 0.10" } }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -356,6 +387,11 @@ "node": ">= 0.10" } }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + }, "node_modules/jsonwebtoken": { "version": "8.5.1", "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz", @@ -563,6 +599,14 @@ "node": ">= 0.8" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "engines": { + "node": ">=8" + } + }, "node_modules/path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", @@ -675,6 +719,25 @@ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "engines": { + "node": ">=8" + } + }, "node_modules/statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", @@ -727,6 +790,20 @@ "node": ">= 0.8" } }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/ws": { "version": "5.2.3", "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.3.tgz", @@ -831,6 +908,24 @@ "vary": "^1" } }, + "cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "requires": { + "cross-spawn": "^7.0.1" + } + }, + "cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "requires": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + } + }, "debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -991,6 +1086,11 @@ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + }, "jsonwebtoken": { "version": "8.5.1", "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz", @@ -1159,6 +1259,11 @@ "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" }, + "path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==" + }, "path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", @@ -1252,6 +1357,19 @@ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" }, + "shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==" + }, "statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", @@ -1286,6 +1404,14 @@ "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" }, + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "requires": { + "isexe": "^2.0.0" + } + }, "ws": { "version": "5.2.3", "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.3.tgz", diff --git a/package.json b/package.json index a68c1ff..aac6608 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "postinstall": "cd application && npm install", "start": "node index.js", - "dev": "ENABLE_DEV_SERVER=true node index.js", + "dev": "cross-env ENABLE_DEV_SERVER=true node index.js", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], @@ -16,6 +16,7 @@ "axios": "^0.21.4", "body-parser": "^1.19.0", "cors": "^2.8.5", + "cross-env": "^7.0.3", "dotenv": "^10.0.0", "express": "^4.17.1", "express-ws": "^4.0.0", -- cgit v1.2.3 From 69b3829df59b96db40155dbdf5adbf549164a6be Mon Sep 17 00:00:00 2001 From: Nick Coutsos Date: Sat, 23 Apr 2022 19:24:06 -0400 Subject: Fix missing config flags --- api/config.js | 26 ++++++++++++++++++++++++++ api/index.js | 9 +++++---- api/routes/application.js | 6 ++++-- api/services/github/auth.js | 15 ++++++++------- application/components/keyboard-picker.vue | 2 +- index.js | 7 +++---- 6 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 api/config.js diff --git a/api/config.js b/api/config.js new file mode 100644 index 0000000..ff9644f --- /dev/null +++ b/api/config.js @@ -0,0 +1,26 @@ +const process = require('process') +require('dotenv/config') + +const PORT = process.env.PORT || 8080 +const ENABLE_DEV_SERVER = process.env.ENABLE_DEV_SERVER +const ENABLE_GITHUB = process.env.ENABLE_GITHUB +const GITHUB_APP_NAME = process.env.GITHUB_APP_NAME +const GITHUB_APP_PRIVATE_KEY = process.env.GITHUB_APP_PRIVATE_KEY +const GITHUB_APP_ID = process.env.GITHUB_APP_ID +const GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID +const GITHUB_CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET +const GITHUB_OAUTH_CALLBACK_URL = process.env.GITHUB_OAUTH_CALLBACK_URL +const APP_BASE_URL = process.env.APP_BASE_URL + +module.exports = { + PORT, + ENABLE_DEV_SERVER, + ENABLE_GITHUB, + GITHUB_APP_NAME, + GITHUB_APP_PRIVATE_KEY, + GITHUB_APP_ID, + GITHUB_CLIENT_ID, + GITHUB_CLIENT_SECRET, + GITHUB_OAUTH_CALLBACK_URL, + APP_BASE_URL +} diff --git a/api/index.js b/api/index.js index d45471c..9c7e63c 100644 --- a/api/index.js +++ b/api/index.js @@ -1,9 +1,9 @@ -require('dotenv/config') const express = require('express') const bodyParser = require('body-parser') const cors = require('cors') const morgan = require('morgan') +const config = require('./config') const applicationInit = require('./routes/application') const keyboards = require('./routes/keyboards') @@ -14,14 +14,15 @@ app.use(cors({ origin: 'https://nickcoutsos.github.io' })) -if (process.env.ENABLE_DEV_SERVER) { +if (config.ENABLE_DEV_SERVER) { applicationInit(app) } app.use(morgan('dev')) -app.use(keyboards) -app.use('/github', require('./routes/github')) app.get('/health', (req, res) => res.sendStatus(200)) +app.use(keyboards) +config.ENABLE_GITHUB && app.use('/github', require('./routes/github')) + module.exports = app diff --git a/api/routes/application.js b/api/routes/application.js index 3ecac87..add60be 100644 --- a/api/routes/application.js +++ b/api/routes/application.js @@ -3,6 +3,8 @@ const path = require('path') const express = require('express') const expressWs = require('express-ws') +const config = require('../config') + const appDir = path.join(__dirname, '..', '..', 'application') function init (app) { @@ -12,8 +14,8 @@ function init (app) { cwd: appDir, env: Object.assign({}, process.env, { ENABLE_LOCAL: true, - ENABLE_GITHUB: true, - GITHUB_APP_NAME: process.env.GITHUB_APP_NAME, + ENABLE_GITHUB: config.ENABLE_GITHUB, + GITHUB_APP_NAME: config.GITHUB_APP_NAME, API_BASE_URL: 'http://localhost:8080', APP_BASE_URL: 'http://localhost:8080/application' }) diff --git a/api/services/github/auth.js b/api/services/github/auth.js index 175e5f7..fcb3ec4 100644 --- a/api/services/github/auth.js +++ b/api/services/github/auth.js @@ -3,12 +3,13 @@ const path = require('path') const jwt = require('jsonwebtoken') const api = require('./api') +const config = require('../../config') const pemPath = path.join(__dirname, '..', '..', '..', 'private-key.pem') -const privateKey = process.env.GITHUB_APP_PRIVATE_KEY || fs.readFileSync(pemPath) +const privateKey = config.GITHUB_APP_PRIVATE_KEY || fs.readFileSync(pemPath) function createAppToken () { - return jwt.sign({ iss: process.env.GITHUB_APP_ID }, privateKey, { + return jwt.sign({ iss: config.GITHUB_APP_ID }, privateKey, { algorithm: 'RS256', expiresIn: '10m' }) @@ -24,8 +25,8 @@ function createOauthFlowUrl () { const redirectUrl = new URL('https://github.com/login/oauth/authorize') redirectUrl.search = new URLSearchParams({ - client_id: process.env.GITHUB_CLIENT_ID, - redirect_uri: process.env.GITHUB_OAUTH_CALLBACK_URL, + client_id: config.GITHUB_CLIENT_ID, + redirect_uri: config.GITHUB_OAUTH_CALLBACK_URL, state: 'foo' }).toString() @@ -33,7 +34,7 @@ function createOauthFlowUrl () { } function createOauthReturnUrl (token) { - const url = new URL(process.env.APP_BASE_URL) + const url = new URL(config.APP_BASE_URL) url.search = new URLSearchParams({ token }).toString() return url.toString() } @@ -46,8 +47,8 @@ function getOauthToken (code) { Accept: 'application/json' }, data: { - client_id: process.env.GITHUB_CLIENT_ID, - client_secret: process.env.GITHUB_CLIENT_SECRET, + client_id: config.GITHUB_CLIENT_ID, + client_secret: config.GITHUB_CLIENT_SECRET, code } }) diff --git a/application/components/keyboard-picker.vue b/application/components/keyboard-picker.vue index c3b6383..dec3e37 100644 --- a/application/components/keyboard-picker.vue +++ b/application/components/keyboard-picker.vue @@ -41,7 +41,7 @@ export default { sourceChoices, source: onlySource || ( sourceChoices.find(source => source.id === selectedSource) - ? selectedSource.id + ? selectedSource : null ) } diff --git a/index.js b/index.js index 772caf4..95fcd8c 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ -const process = require('process') const api = require('./api') +const config = require('./api/config') -const PORT = process.env.PORT || 8080 -api.listen(PORT) -console.log('listening on', PORT) +api.listen(config.PORT) +console.log('listening on', config.PORT) -- cgit v1.2.3 From 260f0c6f3dc841cbe5fbf290d2b802e8acdb20b6 Mon Sep 17 00:00:00 2001 From: Nick Coutsos Date: Wed, 27 Apr 2022 18:45:59 -0400 Subject: Throw together a quick readme on building the web app --- application/README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 application/README.md diff --git a/application/README.md b/application/README.md new file mode 100644 index 0000000..6b967e1 --- /dev/null +++ b/application/README.md @@ -0,0 +1,57 @@ +# Keymap Editor - Web Application + +This is a single page application currently written in Vue (but I'm starting to +experiment with porting it to React) to integrate with the Keymap Editor API. + +It handles keyboard selection and rendering of parsed keymap data into a visual +editor. This application is _aware_ of some of the particulars of ZMK, but it +receives key bindings already parsed into a tree of values and parameters. + +## Building + +The easiest way to use this is the [hosted version](https://nickcoutsos.github.io/keymap-editor). +The second easiest is locally, served up via the API itself (in the repo root, +run `npm run dev` and open `http://localhost:8080` in your browser). + +If you must deploy this app to the web then you'll need to take care of building +it. This requires some configuration, as seen in the [config module](./config.js). + +All configuration is provided via environment variables. + +Variable | Description +------------------|------------- +`API_BASE_URL` | Fully qualified publicly accessible URL of the backend API. +`APP_BASE_URL` | Fully qualified publicly accessible URL of _this_ app. +`GITHUB_APP_NAME` | The app name (slug?) of the GitHub app integration (only required if using with GitHub). +`ENABLE_GITHUB` | Whether to enable fetching keyboard data from GitHub. Default is false, values `"1"`, `"on"`, `"yes"`, `"true"` are interpreted as `true`. +`ENABLE_LOCAL` | Whether to enable fetching keyboard data from locally. Default is false, values `"1"`, `"on"`, `"yes"`, `"true"` are interpreted as `true`. + +_Note: choosing to use the GitHub integration in your own environment isn't a +matter of flipping a switch, you will need to set up your own app in GitHub and +configure your API accordingly._ + +With these set you can run the npm build script, e.g. + +```bash +export API_BASE_URL=... +export APP_BASE_URL=... +export GITHUB_APP_NAME=... +export ENABLE_GITHUB=... +export ENABLE_LOCAL=... +npm run build +``` + +_(make sure you're in this directory, not the repository root!)_ + +This will have webpack produce bundles in the `dist/` directory which you can +deploy however you like. + +### Deploying to GitHub Pages + +On your GitHub repository's settings page, select _Pages_ in the sidebar. Pick a +branch you want to serve the app from (I use `pages`) and choose the `/ (root)` +directory. Check out that branch (I have another working repository locally for +this) locally, or make a new orphaned branch if such a branch doesn't exist, and +copy the contents of `dist/` to it. Commit and push to the GitHub remote. + +If you're not familiar with this it's worth reading up on the [GitHub Pages docs](https://docs.github.com/en/pages). \ No newline at end of file -- cgit v1.2.3