UNPKG

@mmote/niimblue-node

Version:

Headless clients for niimbluelib. Command line interface, simple REST server are also included.

80 lines (79 loc) 3.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const extra_typings_1 = require("@commander-js/extra-typings"); const niimbluelib_1 = require("@mmote/niimbluelib"); const server_1 = require("../server"); const worker_1 = require("./worker"); const intOption = (value) => { const parsed = parseInt(value, 10); if (isNaN(parsed) || parsed < 0) { throw new extra_typings_1.InvalidArgumentError("Integer required"); } return parsed; }; extra_typings_1.program.name("niimblue-cli"); extra_typings_1.program .command("info") .description("Printer information") .requiredOption("-d, --debug", "Debug information", false) .addOption(new extra_typings_1.Option("-t, --transport <type>", "Transport").makeOptionMandatory().choices(["ble", "serial"])) .requiredOption("-a, --address <string>", "Device bluetooth address/name or serial port name/path") .action(worker_1.cliPrinterInfo); extra_typings_1.program .command("scan") .description("Get available device list") .requiredOption("-n, --timeout <number>", "Timeout", intOption, 5000) .addOption(new extra_typings_1.Option("-t, --transport <type>", "Transport").makeOptionMandatory().choices(["ble", "serial"])) .action(worker_1.cliScan); extra_typings_1.program .command("print") .description("Prints image") .argument("<path>", "PNG image path") .requiredOption("-d, --debug", "Debug information", false) .addOption(new extra_typings_1.Option("-t, --transport <type>", "Transport").makeOptionMandatory().choices(["ble", "serial"])) .requiredOption("-a, --address <string>", "Device bluetooth address/name or serial port name/path") .addOption(new extra_typings_1.Option("-o, --print-direction <dir>", "Print direction").choices(["left", "top"])) .addOption(new extra_typings_1.Option("-p, --print-task <type>", "Print task").choices(niimbluelib_1.printTaskNames)) .requiredOption("-l, --label-type <type number>", "Label type", intOption, 1) .requiredOption("-q, --density <number>", "Density", intOption, 3) .requiredOption("-n, --quantity <number>", "Quantity", intOption, 1) .requiredOption("-x, --threshold <number>", "Threshold", intOption, 128) .option("-w, --label-width <number>", "Label width", intOption) .option("-h, --label-height <number>", "Label height", intOption) .addOption(new extra_typings_1.Option("-f, --image-fit <dir>", "Image fit while resizing (label-width and label-height must be set)").choices([ "contain", "cover", "fill", "inside", "outside", ])) .addOption(new extra_typings_1.Option("-m, --image-position <dir>", "Image position while resizing (label-width and label-height must be set)").choices([ "left", "top", "centre", "right top", "right", "right bottom", "bottom", "left bottom", "left top", ])) .action(worker_1.cliConnectAndPrintImageFile); extra_typings_1.program .command("server") .description("Start in server mode") .requiredOption("-d, --debug", "Debug information", false) .requiredOption("-c, --cors", "Enable CORS", false) .requiredOption("-p, --port <number>", "Listen port", intOption, 5000) .requiredOption("-h, --host <host>", "Listen hostname", "localhost") .action(server_1.cliStartServer); extra_typings_1.program .command("flash") .description("Flash firmware") .requiredOption("-d, --debug", "Debug information", false) .addOption(new extra_typings_1.Option("-t, --transport <type>", "Transport").makeOptionMandatory().choices(["ble", "serial"])) .requiredOption("-a, --address <string>", "Device bluetooth address/name or serial port name/path") .requiredOption("-f, --file <path>", "Firmware path") .requiredOption("-n, --new-version <version>", "New firmware version") .action(worker_1.cliFlashFirmware); extra_typings_1.program.parse();