-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b15b2f1
commit 25fd989
Showing
13 changed files
with
110 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const express = require('express') | ||
const bodyParser = require('body-parser') | ||
|
||
const applicationInit = require('./routes/application') | ||
const keyboards = require('./routes/keyboards') | ||
|
||
const app = express() | ||
|
||
app.use(bodyParser.json()) | ||
applicationInit(app) | ||
app.use(keyboards) | ||
|
||
module.exports = app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const childProcess = require('child_process') | ||
const path = require('path') | ||
const express = require('express') | ||
const expressWs = require('express-ws') | ||
|
||
const appDir = path.join(__dirname, '..', '..', 'application') | ||
|
||
function init (app) { | ||
expressWs(app) | ||
|
||
childProcess.execFile('npm', ['run', 'build-watch'], { cwd: appDir }, err => { | ||
console.error(err) | ||
console.error('Application serving failed') | ||
process.exit(1) | ||
}) | ||
|
||
app.get('/', (req, res) => res.redirect('/application')) | ||
app.use('/application', express.static(path.join(appDir, 'dist'))) | ||
|
||
const subscribers = [] | ||
app.ws('/console', (ws, req) => { | ||
const { remoteAddress } = req.connection | ||
subscribers.push(ws) | ||
|
||
console.info(`[${new Date()}] [${remoteAddress}] connected`) | ||
|
||
ws.onerror = err => { | ||
console.error(`[${new Date()}] [${remoteAddress}]`, err) | ||
} | ||
|
||
ws.onclose = () => { | ||
console.info(`[${new Date()}] [${remoteAddress}] disconnected`) | ||
const index = subscribers.indexOf(ws) | ||
subscribers.splice(index, 1) | ||
} | ||
}) | ||
} | ||
|
||
module.exports = init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const { Router } = require('express') | ||
const zmk = require('../services/zmk/zmk') | ||
|
||
const firmwares = { zmk } | ||
const router = Router() | ||
|
||
function addFirmwareLibrary(req, res, next) { | ||
|
||
if (!('firmware' in req.query)) { | ||
return res.status(400).json({ | ||
error: 'Must include "firmware" query parameter' | ||
}) | ||
} | ||
|
||
if (!firmwares[req.query.firmware]) { | ||
return res.status(400).json({ | ||
error: `Unknown firmware "${req.query.firmware}"` | ||
}) | ||
} | ||
|
||
req.firmware = firmwares[req.query.firmware] | ||
next() | ||
} | ||
|
||
router.get('/behaviors', addFirmwareLibrary, (req, res) => res.json(req.firmware.loadBehaviors())) | ||
router.get('/keycodes', addFirmwareLibrary, (req, res) => res.json(req.firmware.loadKeycodes())) | ||
router.get('/layout', addFirmwareLibrary, (req, res) => res.json(req.firmware.loadLayout())) | ||
router.get('/keymap', addFirmwareLibrary, (req, res) => res.json(req.firmware.loadKeymap())) | ||
router.post('/keymap', addFirmwareLibrary, (req, res) => { | ||
const keymap = req.body | ||
const layout = req.firmware.loadLayout() | ||
const generatedKeymap = req.firmware.generateKeymap(layout, keymap) | ||
const exportStdout = req.firmware.exportKeymap(generatedKeymap, 'flash' in req.query, err => { | ||
if (err) { | ||
res.status(500).send(err) | ||
return | ||
} | ||
|
||
res.send() | ||
}) | ||
|
||
// exportStdout.stdout.on('data', data => { | ||
// for (let sub of subscribers) { | ||
// sub.send(data) | ||
// } | ||
// }) | ||
}) | ||
|
||
module.exports = router |
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,6 @@ | ||
const childProcess = require('child_process') | ||
const process = require('process') | ||
const express = require('express') | ||
const expressWs = require('express-ws') | ||
const bodyParser = require('body-parser') | ||
const zmk = require('./zmk') | ||
|
||
const app = express() | ||
const subscribers = [] | ||
expressWs(app) | ||
app.use(bodyParser.json()) | ||
|
||
childProcess.execFile('npm', ['run', 'build-watch'], { cwd: './application' }, err => { | ||
console.error(err) | ||
console.error('Application serving failed') | ||
process.exit(1) | ||
}) | ||
|
||
const firmwares = { zmk } | ||
|
||
function addFirmwareLibrary(req, res, next) { | ||
|
||
if (!('firmware' in req.query)) { | ||
return res.status(400).json({ | ||
error: 'Must include "firmware" query parameter' | ||
}) | ||
} | ||
|
||
if (!firmwares[req.query.firmware]) { | ||
return res.status(400).json({ | ||
error: `Unknown firmware "${req.query.firmware}"` | ||
}) | ||
} | ||
|
||
req.firmware = firmwares[req.query.firmware] | ||
next() | ||
} | ||
|
||
app.get('/', (req, res) => res.redirect('/application')) | ||
app.use('/application', express.static('application/dist')) | ||
app.get('/behaviors', addFirmwareLibrary, (req, res) => res.json(req.firmware.loadBehaviors())) | ||
app.get('/keycodes', addFirmwareLibrary, (req, res) => res.json(req.firmware.loadKeycodes())) | ||
app.get('/layout', addFirmwareLibrary, (req, res) => res.json(req.firmware.loadLayout())) | ||
app.get('/keymap', addFirmwareLibrary, (req, res) => res.json(req.firmware.loadKeymap())) | ||
app.post('/keymap', addFirmwareLibrary, (req, res) => { | ||
const keymap = req.body | ||
const layout = req.firmware.loadLayout() | ||
const generatedKeymap = req.firmware.generateKeymap(layout, keymap) | ||
const exportStdout = req.firmware.exportKeymap(generatedKeymap, 'flash' in req.query, err => { | ||
if (err) { | ||
res.status(500).send(err) | ||
return | ||
} | ||
|
||
res.send() | ||
}) | ||
|
||
exportStdout.stdout.on('data', data => { | ||
for (let sub of subscribers) { | ||
sub.send(data) | ||
} | ||
}) | ||
}) | ||
|
||
app.ws('/console', (ws, req) => { | ||
const { remoteAddress } = req.connection | ||
subscribers.push(ws) | ||
|
||
console.info(`[${new Date()}] [${remoteAddress}] connected`) | ||
|
||
ws.onerror = err => { | ||
console.error(`[${new Date()}] [${remoteAddress}]`, err) | ||
} | ||
|
||
ws.onclose = () => { | ||
console.info(`[${new Date()}] [${remoteAddress}] disconnected`) | ||
const index = subscribers.indexOf(ws) | ||
subscribers.splice(index, 1) | ||
} | ||
}) | ||
const api = require('./api') | ||
|
||
const PORT = process.env.PORT || 8080 | ||
app.listen(PORT) | ||
api.listen(PORT) | ||
console.log('listening on', PORT) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters