Add version indicator

This commit is contained in:
osmarks 2018-10-06 10:49:12 +01:00
parent a1d6c273b3
commit 83f0dc76f1
3 changed files with 46 additions and 2 deletions

29
package-lock.json generated
View File

@ -1615,6 +1615,30 @@
"resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz",
"integrity": "sha1-l/tdlr/eiXMxPyDoKI75oWf6ZM4="
},
"gitlog": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/gitlog/-/gitlog-3.1.2.tgz",
"integrity": "sha512-e1g4ZuCWhyzzEzPnM5AJtGP4PLgN3NG8bE7mhPB6jkhvHlVQb0Wnue9e3+sV7J2+0V5RMsirvISFdwO0SIa0tA==",
"requires": {
"debug": "^3.1.0",
"lodash.assign": "^4.2.0"
},
"dependencies": {
"debug": {
"version": "3.2.5",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.5.tgz",
"integrity": "sha512-D61LaDQPQkxJ5AUM2mbSJRbPkNs/TmdmOeLAi1hgDkpDfIfetSrjmWhccwtuResSwMbACjx/xXQofvM9CE/aeg==",
"requires": {
"ms": "^2.1.1"
}
},
"ms": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
}
}
},
"glob-parent": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-3.1.0.tgz",
@ -2059,6 +2083,11 @@
"xtend": "~4.0.0"
}
},
"lodash.assign": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz",
"integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc="
},
"lodash.debounce": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz",

View File

@ -9,6 +9,7 @@
"cuid": "^2.1.4",
"express": "^4.16.3",
"express-ws": "^4.0.0",
"gitlog": "^3.1.2",
"level": "^4.0.0",
"ws": "^6.0.0"
},

View File

@ -4,6 +4,7 @@ const cors = require("cors")
const level = require("level")
const expressWS = require("express-ws")
const cuid = require("cuid")
const gitlog = require("gitlog")
const db = level("./db.level", {
valueEncoding: "json"
@ -38,8 +39,20 @@ const broadcast = (wss, msg, sender) => {
})
messageLog.unshift(toSend) // push to front for nice ordering
return toSend
}
// Get short-hash of last commit as version
const version = gitlog({
repo: __dirname + "/..", // this file is inside /src, and the repo stuff is outside of here
number: 1,
fields: [ "abbrevHash" ]
})[0].abbrevHash
// Featureset of this version
const features = [ "" ];
const clientCommands = {
open(message, sendBack, ctx) {
const channel = message.channel
@ -71,7 +84,7 @@ const clientCommands = {
sendBack({ log: messageLog.slice(start, end) })
},
message(message, sendBack, { wss, ws }) {
broadcast(wss, message, ws)
sendBack(broadcast(wss, message, ws))
}
}
@ -117,4 +130,5 @@ app.ws("/peer", (ws, req) => {
})
app.listen(parseInt(process.env.PORT) || 4567)
const port = parseInt(process.env.PORT) || 4567
app.listen(port, () => console.log("Skynet " + version, "listening on port " + port))