feat: jacscript -> devicescript (#21)
This commit is contained in:
Родитель
7fc2edac04
Коммит
e52bdf8f4d
|
@ -50,9 +50,9 @@ This command will work in [GitHub codespaces](https://github.com/features/codesp
|
|||
jacdac devtools
|
||||
```
|
||||
|
||||
#### `jacscript devtools --jacscript <file>`
|
||||
#### `jacdac devtools --device-script <file>`
|
||||
|
||||
Starts the devtools web site and also watches/uploads the source of a given jacscript to the development web site. The dev web site will automatically compile and potentially deploy the jacscript program to a connected device.
|
||||
Starts the devtools web site and also watches/uploads the source of a given [DeviceScript](https://aka.ms/devicescript) to the development web site. The dev web site will automatically compile and potentially deploy the DeviceScript program to a connected device.
|
||||
|
||||
## Contributing
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
"dependencies": {
|
||||
"commander": "^9.4.1",
|
||||
"faye-websocket": "^0.11.4",
|
||||
"jacdac-ts": "^1.28.7"
|
||||
"jacdac-ts": "^1.29.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@semantic-release/exec": "^6.0.3",
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { readFileSync } from "fs"
|
||||
import {
|
||||
delay,
|
||||
JacscriptManagerCmd,
|
||||
DeviceScriptManagerCmd,
|
||||
JDBus,
|
||||
OutPipe,
|
||||
prettySize,
|
||||
sha256,
|
||||
SRV_JACSCRIPT_MANAGER,
|
||||
SRV_DEVICE_SCRIPT_MANAGER,
|
||||
toHex,
|
||||
} from "jacdac-ts"
|
||||
import { createTransports, TransportsOptions } from "./transports"
|
||||
|
@ -20,7 +20,7 @@ export async function deployCommand(
|
|||
const bytecode = readFileSync(file)
|
||||
const sha = await sha256([bytecode])
|
||||
|
||||
log(`jacscript bytecode ${prettySize(bytecode.length)}, ${toHex(sha)}`)
|
||||
log(`bytecode ${prettySize(bytecode.length)}, ${toHex(sha)}`)
|
||||
|
||||
const transports = createTransports(options)
|
||||
log(`starting bus...`)
|
||||
|
@ -34,14 +34,14 @@ export async function deployCommand(
|
|||
await delay(1000)
|
||||
|
||||
// deploy to services on bus
|
||||
const services = bus.services({ serviceClass: SRV_JACSCRIPT_MANAGER })
|
||||
log(`found ${services.length} jacscript managers`)
|
||||
const services = bus.services({ serviceClass: SRV_DEVICE_SCRIPT_MANAGER })
|
||||
log(`found ${services.length} managers`)
|
||||
|
||||
for (const service of services) {
|
||||
log(`deploy to ${service}`)
|
||||
await OutPipe.sendBytes(
|
||||
service,
|
||||
JacscriptManagerCmd.DeployBytecode,
|
||||
DeviceScriptManagerCmd.DeployBytecode,
|
||||
bytecode
|
||||
)
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ export async function devToolsCommand(
|
|||
trace?: string
|
||||
diagnostics?: boolean
|
||||
localhost?: boolean
|
||||
jacscript?: string
|
||||
deviceScript?: string
|
||||
} & TransportsOptions
|
||||
) {
|
||||
const {
|
||||
|
@ -80,7 +80,7 @@ export async function devToolsCommand(
|
|||
logging,
|
||||
diagnostics,
|
||||
localhost,
|
||||
jacscript: jacscriptFile,
|
||||
deviceScript: deviceScriptFile,
|
||||
} = options || {}
|
||||
const port = 8081
|
||||
const tcpPort = 8082
|
||||
|
@ -100,16 +100,18 @@ export async function devToolsCommand(
|
|||
// start http server
|
||||
const clients: WebSocket[] = []
|
||||
|
||||
// upload jacscript file is needed
|
||||
const sendJacscript = jacscriptFile
|
||||
// upload DeviceScript file is needed
|
||||
const sendDeviceScript = deviceScriptFile
|
||||
? () => {
|
||||
const source = fs.readFileSync(jacscriptFile, {
|
||||
const source = fs.readFileSync(deviceScriptFile, {
|
||||
encoding: "utf-8",
|
||||
})
|
||||
console.debug(`refresh jacscript (${prettySize(source.length)})`)
|
||||
console.debug(
|
||||
`refresh DeviceScript (${prettySize(source.length)})`
|
||||
)
|
||||
const msg = JSON.stringify({
|
||||
type: "source",
|
||||
channel: "jacscript",
|
||||
channel: "devicescript",
|
||||
source,
|
||||
})
|
||||
clients.forEach(c => c.send(msg))
|
||||
|
@ -172,7 +174,7 @@ export async function devToolsCommand(
|
|||
if (WebSocket.isWebSocket(request)) {
|
||||
const client = new WebSocket(request, socket, body)
|
||||
const sender = "ws" + randomDeviceId()
|
||||
let firstJacscript = false
|
||||
let firstDeviceScript = false
|
||||
// store sender id to deduped packet
|
||||
client[SENDER_FIELD] = sender
|
||||
clients.push(client)
|
||||
|
@ -181,9 +183,9 @@ export async function devToolsCommand(
|
|||
const { data } = event
|
||||
if (typeof data === "string") processMessage(data, sender)
|
||||
else processPacket(data, sender)
|
||||
if (!firstJacscript && sendJacscript) {
|
||||
firstJacscript = true
|
||||
sendJacscript()
|
||||
if (!firstDeviceScript && sendDeviceScript) {
|
||||
firstDeviceScript = true
|
||||
sendDeviceScript()
|
||||
}
|
||||
})
|
||||
client.on("close", () => removeClient(client))
|
||||
|
@ -252,10 +254,10 @@ export async function devToolsCommand(
|
|||
server.listen(port, listenHost)
|
||||
tcpServer.listen(tcpPort, listenHost)
|
||||
|
||||
if (sendJacscript) {
|
||||
console.debug(`watch ${jacscriptFile}`)
|
||||
fs.watch(jacscriptFile, async (eventType, filename) => {
|
||||
sendJacscript()
|
||||
if (sendDeviceScript) {
|
||||
console.debug(`watch ${deviceScriptFile}`)
|
||||
fs.watch(deviceScriptFile, async (eventType, filename) => {
|
||||
sendDeviceScript()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,14 +60,14 @@ async function mainCli() {
|
|||
"use localhost:8000 instead of the internet dashboard"
|
||||
)
|
||||
.option(
|
||||
"-j, --jacscript <string>",
|
||||
"upload and watch source of local jacscript file"
|
||||
"-j, --device-script <string>",
|
||||
"upload and watch source of local DeviceScript file"
|
||||
)
|
||||
.action(devToolsCommand)
|
||||
|
||||
createCommand("deploy")
|
||||
.description("deploy a jacscript program (as bytecode) to devices")
|
||||
.argument("<file>", "jacscript bytecode file")
|
||||
.description("deploy a DeviceScript program (as bytecode) to devices")
|
||||
.argument("<file>", "DeviceScript bytecode file")
|
||||
.option("-u, --usb", "listen to Jacdac over USB (requires usb)")
|
||||
.option(
|
||||
"-s, --serial",
|
||||
|
|
|
@ -2,8 +2,8 @@ import {
|
|||
JDBus,
|
||||
Packet,
|
||||
PACKET_REPORT,
|
||||
SRV_JACSCRIPT_MANAGER,
|
||||
JacscriptManagerCmd,
|
||||
SRV_DEVICE_SCRIPT_MANAGER,
|
||||
DeviceScriptManagerCmd,
|
||||
LoggerPriority,
|
||||
SRV_LOGGER,
|
||||
LoggerCmd,
|
||||
|
@ -35,8 +35,8 @@ export function enableLogging(bus: JDBus, logFn = logToConsole) {
|
|||
bus.minLoggerPriority = LoggerPriority.Debug
|
||||
bus.subscribe(PACKET_REPORT, (pkt: Packet) => {
|
||||
if (
|
||||
pkt.serviceClass === SRV_JACSCRIPT_MANAGER &&
|
||||
pkt.serviceCommand === JacscriptManagerCmd.LogMessage
|
||||
pkt.serviceClass === SRV_DEVICE_SCRIPT_MANAGER &&
|
||||
pkt.serviceCommand === DeviceScriptManagerCmd.LogMessage
|
||||
) {
|
||||
const [counter, flags, content] =
|
||||
pkt.jdunpack<[number, number, string]>("u8 u8 s")
|
||||
|
|
|
@ -3974,10 +3974,10 @@ issue-parser@^6.0.0:
|
|||
lodash.isstring "^4.0.1"
|
||||
lodash.uniqby "^4.7.0"
|
||||
|
||||
jacdac-ts@^1.28.7:
|
||||
version "1.28.7"
|
||||
resolved "https://registry.yarnpkg.com/jacdac-ts/-/jacdac-ts-1.28.7.tgz#e56290f6910cf5d0181be749ab3d32aa48831582"
|
||||
integrity sha512-zW13GhyHNN7VOAcbMLUUUNd90wXIALbum23WLbn1GkVOOlEbuQpVah8SRlGAsFmkPOzdYvz3Rc7BkDyjEGVttw==
|
||||
jacdac-ts@^1.29.0:
|
||||
version "1.29.0"
|
||||
resolved "https://registry.yarnpkg.com/jacdac-ts/-/jacdac-ts-1.29.0.tgz#b77cff28d137a2fd75eeb3b1895f759e98ba5fbb"
|
||||
integrity sha512-usEAgbqOlm4LTx3JLFCwozcj2w5GFgpOlivP1bICGkwrv53kbRX5NjnNADgkecRDOXF4ZeguAzHt2AW+CQtAGg==
|
||||
dependencies:
|
||||
"@types/node" "^17.0.41"
|
||||
"@types/w3c-web-serial" "^1.0.2"
|
||||
|
|
Загрузка…
Ссылка в новой задаче