* adding deploy command

* updated caniuse

* adding test file

* finish script

* cleaning up imports

* added samples

* wait for jacdac pipe ready before sending jacscript
This commit is contained in:
Peli de Halleux 2022-11-22 14:46:42 -08:00 коммит произвёл GitHub
Родитель eb3b6f8b3a
Коммит 25f0fad907
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 516 добавлений и 532 удалений

Просмотреть файл

@ -11,8 +11,8 @@
"scripts": {
"lint": "eslint src/**/*.ts",
"prettier": "prettier --write src/**/*.ts",
"build": "microbundle --no-compress",
"watch": "microbundle watch",
"build": "node node_modules/microbundle/dist/cli.js --no-compress",
"watch": "node node_modules/microbundle/dist/cli.js watch",
"devtools": "yarn build && node ./dist/cli.js devtools",
"devtools:serial": "yarn build && node ./dist/cli.js devtools --serial",
"devtools:usb": "yarn build && node ./dist/cli.js devtools --usb",
@ -37,31 +37,31 @@
},
"homepage": "https://github.com/microsoft/jacdac-cli#readme",
"dependencies": {
"commander": "^9.0.0",
"commander": "^9.4.1",
"faye-websocket": "^0.11.4",
"jacdac-ts": "^1.27.0"
"jacdac-ts": "^1.28.7"
},
"devDependencies": {
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"eslint": "^8.8.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.4",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"eslint": "^8.28.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-promise": "^6.1.1",
"microbundle": "^0.14.2",
"prettier": "^2.5.1",
"semantic-release": "^19.0.2",
"prettier": "^2.7.1",
"semantic-release": "^19.0.5",
"tslint-microsoft-contrib": "^6.2.0",
"typescript": "^4.5.5"
"typescript": "^4.9.3"
},
"optionalDependencies": {
"rpio": "^2.4.2",
"serialport": "^9.2.8",
"serialport": "^10.5.0",
"spi-device": "^3.1.2",
"usb": "^2.1.2"
"usb": "^2.5.2"
},
"files": [
"dist",

50
src/deploy.ts Normal file
Просмотреть файл

@ -0,0 +1,50 @@
import { readFileSync } from "fs"
import {
delay,
JacscriptManagerCmd,
JDBus,
OutPipe,
prettySize,
sha256,
SRV_JACSCRIPT_MANAGER,
toHex,
} from "jacdac-ts"
import { createTransports, TransportsOptions } from "./transports"
const log = console.log
export async function deployCommand(
file: string,
options: TransportsOptions = {}
) {
const bytecode = readFileSync(file)
const sha = await sha256([bytecode])
log(`jacscript bytecode ${prettySize(bytecode.length)}, ${toHex(sha)}`)
const transports = createTransports(options)
log(`starting bus...`)
const bus = new JDBus(transports, { client: false })
bus.start()
// connect to a bus
await bus.connect()
// allow devices to enumerate
await delay(1000)
// deploy to services on bus
const services = bus.services({ serviceClass: SRV_JACSCRIPT_MANAGER })
log(`found ${services.length} jacscript managers`)
for (const service of services) {
log(`deploy to ${service}`)
await OutPipe.sendBytes(
service,
JacscriptManagerCmd.DeployBytecode,
bytecode
)
}
process.exit(services.length > 0 ? 0 : -1)
}

Просмотреть файл

@ -172,6 +172,7 @@ export async function devToolsCommand(
if (WebSocket.isWebSocket(request)) {
const client = new WebSocket(request, socket, body)
const sender = "ws" + randomDeviceId()
let firstJacscript = false
// store sender id to deduped packet
client[SENDER_FIELD] = sender
clients.push(client)
@ -180,10 +181,13 @@ export async function devToolsCommand(
const { data } = event
if (typeof data === "string") processMessage(data, sender)
else processPacket(data, sender)
if (!firstJacscript && sendJacscript) {
firstJacscript = true
sendJacscript()
}
})
client.on("close", () => removeClient(client))
client.on("error", (ev: Error) => error(ev))
if (sendJacscript) sendJacscript()
}
})

Просмотреть файл

@ -4,6 +4,7 @@ import type { CommandOptions } from "commander"
import { devToolsCommand } from "./devtools"
import { parseCommand } from "./parse"
import { streamCommand } from "./stream"
import { deployCommand } from "./deploy"
const log = console.log
const error = console.error
@ -64,6 +65,21 @@ async function mainCli() {
)
.action(devToolsCommand)
createCommand("deploy")
.description("deploy a jacscript program (as bytecode) to devices")
.argument("<file>", "jacscript bytecode file")
.option("-u, --usb", "listen to Jacdac over USB (requires usb)")
.option(
"-s, --serial",
"listen to Jacdac over SERIAL (requires serialport)"
)
.option(
"-i, --spi",
"listen to Jacdac over SPI (requires rpio, experimental)"
)
.option("--devices <string>", "regular expression filter for devices")
.action(deployCommand)
await program.parseAsync(process.argv)
}

Просмотреть файл

@ -3,7 +3,6 @@ import {
JDBus,
printPacket,
Packet,
serializeToTrace,
isCancelError,
} from "jacdac-ts"
import { createTransports, TransportsOptions } from "./transports"

Двоичные данные
test/console.jacs Normal file

Двоичный файл не отображается.

8
test/console.ts Normal file
Просмотреть файл

@ -0,0 +1,8 @@
function testIt() {
const x = 7, y = 12
console.log("Hello world")
console.log("X is", x, "and Y is", y)
console.log("X=", x, "Y=", y)
}
testIt()

937
yarn.lock

Разница между файлами не показана из-за своего большого размера Загрузить разницу