Skip to content

Commit

Permalink
add: custom repo
Browse files Browse the repository at this point in the history
  • Loading branch information
darakuneko committed Sep 25, 2023
1 parent 3888af9 commit c961f21
Show file tree
Hide file tree
Showing 18 changed files with 453 additions and 225 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ Right Alt
Right GUI
```


Update Repository
Repository
-------
Clone again to the latest state.
You can add 5 fork repositories for QMK and Vial.
If you get an error like this, please update the repository.
```
error: branch 'x.x.x' not found.
Expand Down
41 changes: 21 additions & 20 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ const url = (path) => new URL(`${fwMakerUrl}${path}`).href
let isDockerUp = false
let skipCheckDocker = !fwMakerUrl.includes("127.0.0.1") ? !fwMakerUrl.includes("127.0.0.1") : false

const tagZeroFill2Int = (str) => {
const s = str
.replace(/\.(\d{1})\./, ".0$1.")
.replace(/\.(\d{2})$/, ".0$1")
.replace(/\.(\d{1})$/, ".00$1")
.replace(/\./g, "")
return parseInt(s)
}

const parseZeroLastDigit = (num) => parseInt(num.toString().slice(0, -1)) * 10

const fileAppend = (data, key, obj) => {
const buffer = fs.readFileSync(obj.path)
data.append(key, buffer, {
Expand Down Expand Up @@ -78,9 +67,11 @@ const responseStreamLog = async (res, mainWindow, channel) => {
}

const command = {
upImage: (mainWindow) => {
upImage: async (mainWindow) => {
if(!skipCheckDocker){
const res = spawn(appSpawn("docker compose build && docker compose up -d"), { shell: true })
const result = await appExe("docker images")
const cmd = result.stdout.match("gpk_fwmaker_0003") ? "docker compose start" : "docker compose build && docker compose up -d"
const res = spawn(appSpawn(cmd), { shell: true })
streamLog(res, mainWindow, true)
}
},
Expand All @@ -103,21 +94,19 @@ const command = {
tags: async () => {
const res = await instance(url('/tags/qmk')).catch(e => e)
if(res.status === 200) {
const dat = res.data
const limit = parseZeroLastDigit(tagZeroFill2Int(dat[0]) - 3000)
const tags = dat.filter(v => tagZeroFill2Int(v) >= limit)
return tags
return res.data
} else {
return []
}
},
build: async (dat, mainWindow) => {
const u = `/build/${dat.fw}`
const data = dat.fw === "qmk" ? {
const u = dat.fw === "QMK" || dat.fw === "Vial" ? `/build/${dat.fw.toLowerCase()}` : `/build/custom`
const data = dat.fw === "QMK" ? {
kb: dat.kb,
km: dat.km,
tag: dat.tag,
} : {
fw: dat.fw.toLowerCase(),
kb: dat.kb,
km: dat.km,
commit: dat.commit,
Expand Down Expand Up @@ -181,7 +170,19 @@ const command = {
return res.data
},
updateRepository: async (fw, mainWindow) => {
const res = await axios(url(`/update/repository/${fw}`), {responseType: 'stream'})
const res = await axios(url(`/update/repository/${fw.toLowerCase()}`), {responseType: 'stream'})
await responseStreamLog(res, mainWindow, "streamLog")
},
updateRepositoryCustom: async (obj, mainWindow) => {
const res = await axios({
url: url("/update/repository/custom"),
method: 'post',
responseType: 'stream',
data: {
id: obj.id.toLowerCase(),
url: obj.url
}
}).catch(e => {})
await responseStreamLog(res, mainWindow, "streamLog")
},
convertViaJson: async (file) => {
Expand Down
2 changes: 2 additions & 0 deletions gpk_fwmaker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ WORKDIR /root/vial-qmk

RUN make git-submodule

WORKDIR /root/custom_repository

COPY ./firmware-scripts/ /firmware-scripts

COPY ./server/ /server
Expand Down
1 change: 1 addition & 0 deletions gpk_fwmaker/compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
gpk_fwmaker:
build: .
image: gpk_fwmaker_0003
volumes:
- ~/GPKFW:/root/keyboards
tty: true
Expand Down
2 changes: 1 addition & 1 deletion gpk_fwmaker/server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gpk_fwmaker_sever",
"private": true,
"version": "0.0.1",
"version": "0.0.2",
"description": "GPK_FWMaker_Sever",
"author": "Daraku-Neko",
"dependencies": {
Expand Down
98 changes: 76 additions & 22 deletions gpk_fwmaker/server/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ const {cmd, streamError} = require('./command')
const app = express()
const multer = require("multer")

const server = app.listen(3000, async() =>console.log("Node.js is listening to PORT:" + server.address().port))
const server = app.listen(3000, async () => console.log("Node.js is listening to PORT:" + server.address().port))

const streamResponce = async (res, fn) => {
res.writeHead(200, { "Content-Type": "text/event-stream"})
const streamResponse = async (res, fn) => {
res.writeHead(200, {"Content-Type": "text/event-stream"})
await fn()
}

const bufferToJson = (buf) => JSON.parse(buf.toString())

const jsonToStr = (obj) => JSON.stringify(obj, null, 2)

app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())

app.get('/', async (req, res) => res.send('GPK FWMaker!'))
Expand All @@ -29,6 +29,35 @@ app.get('/update/repository/qmk', async (req, res) => await cmd.updateRepository

app.get('/update/repository/vial', async (req, res) => await cmd.updateRepositoryVial(res))

app.post('/update/repository/custom', async (req, res) => {
const fn = async () => {
try {
const id = req.body.id
const url = req.body.url
await cmd.updateRepositoryCustom(res, id, url)
} catch (e) {
streamError(res, e)
}
}
await streamResponse(res, fn)
})

app.post('/delete/repository/custom', async (req, res) => {
const fn = async () => {
try {
const id = req.body.id
await cmd.deleteRepositoryCustom(res, id)
} catch (e) {
streamError(res, e)
}
}
await streamResponse(res, fn)
})

app.get('/update/repository/qmk', async (req, res) => await cmd.updateRepositoryQmk(res))

app.get('/update/repository/vial', async (req, res) => await cmd.updateRepositoryVial(res))

app.post('/build/qmk', async (req, res) => {
const fn = async () => {
try {
Expand All @@ -44,9 +73,9 @@ app.post('/build/qmk', async (req, res) => {
streamError(res, e)
}
}
await streamResponce(res, fn)
await streamResponse(res, fn)
})

app.post('/build/vial', async (req, res) => {
const fn = async () => {
try {
Expand All @@ -58,23 +87,48 @@ app.post('/build/vial', async (req, res) => {
await cmd.checkoutVial(res, repo, commit)
await cmd.cpConfigsToVial(kbDir)
await cmd.buildVialFirmware(res, kb, km)
} catch (e) { streamError(res, e) }
} catch (e) {
streamError(res, e)
}
}

await streamResponce(res, fn)
await streamResponse(res, fn)
})



app.post('/build/custom', async (req, res) => {
const fn = async () => {
try {
const fw = req.body.fw
const kb = req.body.kb
const kbDir = kb.replace(/\/.*/g, "")
const km = req.body.km.replace(/:.*|flash/g, "")
const commit = req.body.commit
const obj = await cmd.checkoutCustom(res, fw, commit)
console.log("checkoutCustom")
await cmd.cpConfigsToCustom(obj.dir, kbDir)
console.log("cpConfigsToCustom")

await cmd.buildCustomFirmware(res, obj, kb, km)
} catch (e) {
streamError(res, e)
}
}

await streamResponse(res, fn)
})

app.post('/generate/qmk/file', async (req, res) => {
try {
const kb = req.body.kb
const kbL = kb.toLowerCase().replace(/-| /g,"_")
const kbL = kb.toLowerCase().replace(/-| /g, "_")
const kbDir = kbL.replace(/\/.*/g, "")
const mcu = req.body.mcu
const layout = req.body.layout
const user = req.body.user

const result = await cmd.generateQmkFile(kbL, mcu, layout, user)
const infoQmk = bufferToJson(await cmd.readQmkFile(kbDir, 'info.json'))
const infoQmk = bufferToJson(await cmd.readQmkFile(kbDir, 'info.json'))
infoQmk.keyboard_name = kb
infoQmk.manufacturer = user
infoQmk.maintainer = user
Expand All @@ -95,7 +149,7 @@ app.get('/generate/vial/id', async (req, res) => {
}
})

app.post('/convert/via/json', multer().fields([{ name: 'info' }, { name: 'kle' }]), async (req, res) => {
app.post('/convert/via/json', multer().fields([{name: 'info'}, {name: 'kle'}]), async (req, res) => {
try {
const info = bufferToJson(req.files['info'][0].buffer)
const kle = bufferToJson(req.files['kle'][0].buffer)
Expand Down Expand Up @@ -132,34 +186,34 @@ app.post('/convert/kle/qmk', multer().single('kle'), async (req, res) => {
try {
const params = JSON.parse(req.body.params)
const kb = params.kb
const fileKb = kb.toLowerCase().replace(/-| /g,"_")
const fileKb = kb.toLowerCase().replace(/-| /g, "_")
const kbDir = fileKb.replace(/\/.*/g, "")
const mcu = params.mcu
const layout = "fullsize_ansi"
const user = params.user
const vid = params.vid
const pid = params.pid
const option = params.option

const rows = params.rows.split(",")
const cols = params.cols.split(",")

const kle = bufferToJson(req.file.buffer)
const kleFileName = 'kle.json'
await cmd.writeFirmFiles(kleFileName, jsonToStr(kle))

await cmd.generateQmkFile(fileKb, mcu, layout, user)
await cmd.generateFirmFiles(kleFileName)

const vialFirm = bufferToJson(await cmd.readFirmFiles('vial.json'))
if(option === 2) {
if (option === 2) {
await cmd.write('/root/keyboards/via.json', jsonToStr(vialFirm))
res.send("finish!!")
return
}

const infoQmk = bufferToJson(await cmd.readQmkFile(fileKb, 'info.json'))
const infoFirm = bufferToJson(await cmd.readFirmFiles('info.json'))
const infoQmk = bufferToJson(await cmd.readQmkFile(fileKb, 'info.json'))
const infoFirm = bufferToJson(await cmd.readFirmFiles('info.json'))
infoQmk.keyboard_name = kb
infoQmk.manufacturer = user
infoQmk.maintainer = user
Expand All @@ -177,19 +231,19 @@ app.post('/convert/kle/qmk', multer().single('kle'), async (req, res) => {
await cmd.writeQmkFile(fileKb, 'info.json', jsonToStr(infoQmk))

let configQmk = await cmd.readQmkFile(fileKb, 'config.h')
if(option === 1){
if (option === 1) {
const configFirm = await cmd.readFirmFiles('config.h')
configQmk = configQmk + configFirm
}
await cmd.writeQmkFile(fileKb, 'config.h', configQmk)

const kbFirm = await cmd.readFirmFiles('kb.h')
await cmd.writeQmkFile(fileKb, `${fileKb}.h`, kbFirm)

const kmFirm = await cmd.readFirmFiles('keymap.c')
await cmd.writeQmkFile(fileKb, 'keymaps/default/keymap.c', kmFirm)

if(option === 1){
if (option === 1) {
vialFirm.name = kb
vialFirm.vendorId = vid
vialFirm.productId = pid
Expand Down
Loading

0 comments on commit c961f21

Please sign in to comment.