diff --git a/package.json b/package.json index b357514..a895b1d 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "spec:lint": "pnpm --filter @wifilabel/codegen spec:lint", "build": "turbo run build", "typecheck": "turbo run typecheck", - "lint": "eslint . && prettier --check . && pnpm spec:lint", + "lint": "eslint . && prettier --check . && pnpm spec:lint && node scripts/check-package-readmes.mjs", "test": "vitest run && pnpm test:c", "test:c": "cmake -S c -B c/build-host && cmake --build c/build-host && ctest --test-dir c/build-host --output-on-failure", "preview:labelary": "node scripts/preview-labelary.mjs" diff --git a/packages/epl2/CHANGELOG.md b/packages/epl2/CHANGELOG.md new file mode 100644 index 0000000..4c3e776 --- /dev/null +++ b/packages/epl2/CHANGELOG.md @@ -0,0 +1,9 @@ +# @wifilabel/epl2 + +## 0.1.1 + +### Patch Changes + +- Document each package on npm. +- Updated dependencies + - @wifilabel/printer-spec@0.1.1 diff --git a/packages/epl2/README.md b/packages/epl2/README.md new file mode 100644 index 0000000..bce0532 --- /dev/null +++ b/packages/epl2/README.md @@ -0,0 +1,39 @@ +# @wifilabel/epl2 + +A short EPL2 setup sequence, plus the bitmap wrappers the firmware uses for EPL `GW` and TSPL `BITMAP`. + +## Install + +```bash +npm install @wifilabel/epl2 +``` + +## Example + +```ts +import { epl } from "@wifilabel/epl2"; + +const setup = [ + epl.clearBuffer(), + epl.width(812), + epl.length(1218, 24), + epl.density(8), + epl.print(1), +].join(""); +``` + +Each call returns one command and a newline. `812` by `1218` is a 4 inch by 6 inch label at 203 dpi. A number outside the spec range throws. + +## What you get + +`clearBuffer`, `width`, `length`, `speed`, `density`, `bottomFirst`, `topFirst`, `queryConfig`, `print`, `graphicWrite`, and `tsplBitmap`. + +`graphicWrite` builds `N`, `GW`, and `P1` around a packed bitmap. `tsplBitmap` builds a TSPL job whose `SIZE` is fixed at 4x6 inches, the same helper the firmware uses. + +## Limits + +This is not a full EPL or TSPL language. There is no text, barcode, or font API. For ZPL, use [@wifilabel/zpl](https://www.npmjs.com/package/@wifilabel/zpl). Ranges come from [@wifilabel/printer-spec](https://www.npmjs.com/package/@wifilabel/printer-spec). + +Zebra, ZPL, and Link-OS are trademarks of Zebra Technologies Corporation. This project is not affiliated with, endorsed by, or sponsored by Zebra Technologies. + +Prefer a ready box? [wifilabel.com](https://wifilabel.com) diff --git a/packages/epl2/package.json b/packages/epl2/package.json index 8c73a49..f610af9 100644 --- a/packages/epl2/package.json +++ b/packages/epl2/package.json @@ -1,7 +1,18 @@ { "name": "@wifilabel/epl2", - "version": "0.1.0", - "description": "Small EPL2 builders for legacy desktop label printers.", + "version": "0.1.1", + "description": "EPL2 setup commands and a TSPL bitmap wrapper for desktop label printers.", + "keywords": [ + "epl2", + "epl", + "tspl", + "label-printer", + "thermal-printer" + ], + "homepage": "https://wifilabel.com/", + "bugs": { + "url": "https://github.com/WiFiLabel/label-toolkit/issues" + }, "license": "MIT", "author": "WiFiLabel ", "type": "module", diff --git a/packages/spec/CHANGELOG.md b/packages/spec/CHANGELOG.md new file mode 100644 index 0000000..d782909 --- /dev/null +++ b/packages/spec/CHANGELOG.md @@ -0,0 +1,7 @@ +# @wifilabel/printer-spec + +## 0.1.1 + +### Patch Changes + +- Document each package on npm. diff --git a/packages/spec/README.md b/packages/spec/README.md new file mode 100644 index 0000000..619798a --- /dev/null +++ b/packages/spec/README.md @@ -0,0 +1,39 @@ +# @wifilabel/printer-spec + +Typed ZPL commands, EPL2 commands, SGD settings, status layouts, and printer profiles. The YAML under `spec/` in the label-toolkit repo is the source. Codegen writes this package. + +## Install + +```bash +npm install @wifilabel/printer-spec +``` + +## Example + +```ts +import { printers, settingByKey, zplCommandById } from "@wifilabel/printer-spec"; + +const ids = printers.map((printer) => printer.id); +const printWidth = zplCommandById.PW; +const darkness = settingByKey["media.darkness"]; +``` + +## What you get + +`zplCommands`, `eplCommands`, `settings`, `statuses`, and `printers`, plus the lookup maps `zplCommandById`, `eplCommandById`, and `settingByKey`. + +Printer ids in this release: `gk420d`, `gx420d`, `lp2844`, `lp2844-z`, `zd410`, `zd420`, `zd421`, `zp450`. + +Edit the YAML in the [label-toolkit repo](https://github.com/WiFiLabel/label-toolkit/tree/main/spec), then run codegen. Do not hand-edit the generated TypeScript or the JSON under `packages/spec/data/`. + +The YAML shape is described at . + +## Limits + +This package does not build printer bytes. Use [@wifilabel/zpl](https://www.npmjs.com/package/@wifilabel/zpl) or [@wifilabel/epl2](https://www.npmjs.com/package/@wifilabel/epl2) for that. + +A printer field with `verified: false` is a starting point, not a measurement from that model. Read `notes` before you lock dpi, width, or top speed. + +Zebra, ZPL, and Link-OS are trademarks of Zebra Technologies Corporation. This project is not affiliated with, endorsed by, or sponsored by Zebra Technologies. + +Prefer a ready box? [wifilabel.com](https://wifilabel.com) diff --git a/packages/spec/package.json b/packages/spec/package.json index f1b8cd4..f64faf5 100644 --- a/packages/spec/package.json +++ b/packages/spec/package.json @@ -1,7 +1,19 @@ { "name": "@wifilabel/printer-spec", - "version": "0.1.0", - "description": "Generated command, SGD, status, and printer profiles for thermal label printers.", + "version": "0.1.1", + "description": "ZPL, EPL2, SGD, status, and printer profiles for thermal label printers.", + "keywords": [ + "zpl", + "epl2", + "sgd", + "zebra", + "label-printer", + "thermal-printer" + ], + "homepage": "https://wifilabel.com/", + "bugs": { + "url": "https://github.com/WiFiLabel/label-toolkit/issues" + }, "license": "MIT", "author": "WiFiLabel ", "type": "module", diff --git a/packages/transport-box/CHANGELOG.md b/packages/transport-box/CHANGELOG.md new file mode 100644 index 0000000..c4c2807 --- /dev/null +++ b/packages/transport-box/CHANGELOG.md @@ -0,0 +1,9 @@ +# @wifilabel/box-client + +## 0.1.1 + +### Patch Changes + +- Document each package on npm. +- Updated dependencies + - @wifilabel/transport@0.1.1 diff --git a/packages/transport-box/README.md b/packages/transport-box/README.md new file mode 100644 index 0000000..5e2ddfe --- /dev/null +++ b/packages/transport-box/README.md @@ -0,0 +1,37 @@ +# @wifilabel/box-client + +A stub client for a WiFiLabel box on the local network. `write` holds bytes, and `read` posts them to the box. + +## Install + +```bash +npm install @wifilabel/box-client +``` + +## Example + +```ts +import { BoxClient } from "@wifilabel/box-client"; + +const bytes = new Uint8Array([0x7e, 0x48, 0x49]); +const box = BoxClient.connect("http://192.168.1.20"); +await box.write(bytes); +const reply = await box.read(4000); +const info = await box.info(); +``` + +`read` POSTs the pending bytes to `/api/raw` and returns the body. `info` GETs `/api/info`. + +## What you get + +`BoxClient.connect` runs the address through `boxOrigin` first. The host has to be a private IPv4 address, a local IPv6 address, or `wifilabel-*.local`. The scheme has to be `http://`. A username, a password, or a public hostname throws. + +Requests set `targetAddressSpace: "local"` so Chrome can show the local-network prompt. + +## Limits + +The client is the stub. The box has to serve those routes. The contract is . + +It uses the same `write` / `read` / `close` shape as [@wifilabel/transport](https://www.npmjs.com/package/@wifilabel/transport). USB from the browser is [@wifilabel/webusb](https://www.npmjs.com/package/@wifilabel/webusb). + +Prefer a ready box? [wifilabel.com](https://wifilabel.com) diff --git a/packages/transport-box/package.json b/packages/transport-box/package.json index 3d479c4..8e2499a 100644 --- a/packages/transport-box/package.json +++ b/packages/transport-box/package.json @@ -1,7 +1,16 @@ { "name": "@wifilabel/box-client", - "version": "0.1.0", + "version": "0.1.1", "description": "Stub client for a WiFiLabel box on the local network.", + "keywords": [ + "label-printer", + "print-server", + "thermal-printer" + ], + "homepage": "https://wifilabel.com/", + "bugs": { + "url": "https://github.com/WiFiLabel/label-toolkit/issues" + }, "license": "MIT", "author": "WiFiLabel ", "type": "module", diff --git a/packages/transport-webusb/CHANGELOG.md b/packages/transport-webusb/CHANGELOG.md new file mode 100644 index 0000000..e8a6db4 --- /dev/null +++ b/packages/transport-webusb/CHANGELOG.md @@ -0,0 +1,9 @@ +# @wifilabel/webusb + +## 0.1.1 + +### Patch Changes + +- Document each package on npm. +- Updated dependencies + - @wifilabel/transport@0.1.1 diff --git a/packages/transport-webusb/README.md b/packages/transport-webusb/README.md new file mode 100644 index 0000000..4316222 --- /dev/null +++ b/packages/transport-webusb/README.md @@ -0,0 +1,39 @@ +# @wifilabel/webusb + +Open a USB label printer from Chrome or Edge and use it as a [`Transport`](https://www.npmjs.com/package/@wifilabel/transport). + +## Install + +```bash +npm install @wifilabel/webusb +``` + +## Example + +```ts +import { requestPrinter, WebUsbTransport } from "@wifilabel/webusb"; + +const bytes = new Uint8Array([0x7e, 0x48, 0x49]); +const device = await requestPrinter(navigator.usb); +const transport = await WebUsbTransport.open(device); +await transport.write(bytes); +const chunk = await transport.read(2000); +``` + +`bytes` here is `~HI`. There is no public constructor. `open` claims the bulk in and out endpoints. + +## What you get + +`requestPrinter` filters on Zebra's vendor id (`0x0a5f`) or USB printer class `0x07`. `permittedDevices` lists devices this origin already may use. `watchUsb` subscribes to connect and disconnect. `webUsbSupport` reports when `navigator.usb` is missing. `guidanceForUsbError` maps a failed claim to a short note for the current operating system. + +The same browser flow is on . + +## Limits + +Safari and Firefox do not implement WebUSB. The page has to be a secure context, https or localhost. On Windows the Zebra driver can keep the interface, so the claim fails until that driver lets go. Use `guidanceForUsbError` for the text this package shows. It does not swap the OS driver for you. + +Build the bytes with [@wifilabel/zpl](https://www.npmjs.com/package/@wifilabel/zpl) or [@wifilabel/epl2](https://www.npmjs.com/package/@wifilabel/epl2). + +Zebra, ZPL, and Link-OS are trademarks of Zebra Technologies Corporation. This project is not affiliated with, endorsed by, or sponsored by Zebra Technologies. + +Prefer a ready box? [wifilabel.com](https://wifilabel.com) diff --git a/packages/transport-webusb/package.json b/packages/transport-webusb/package.json index 8722231..626dba5 100644 --- a/packages/transport-webusb/package.json +++ b/packages/transport-webusb/package.json @@ -1,7 +1,18 @@ { "name": "@wifilabel/webusb", - "version": "0.1.0", - "description": "WebUSB transport for thermal label printers. Chromium only.", + "version": "0.1.1", + "description": "WebUSB transport for USB label printers. Chrome and Edge only.", + "keywords": [ + "webusb", + "zebra", + "zpl", + "label-printer", + "thermal-printer" + ], + "homepage": "https://wifilabel.com/", + "bugs": { + "url": "https://github.com/WiFiLabel/label-toolkit/issues" + }, "license": "MIT", "author": "WiFiLabel ", "type": "module", diff --git a/packages/transport/CHANGELOG.md b/packages/transport/CHANGELOG.md new file mode 100644 index 0000000..b87f451 --- /dev/null +++ b/packages/transport/CHANGELOG.md @@ -0,0 +1,7 @@ +# @wifilabel/transport + +## 0.1.1 + +### Patch Changes + +- Document each package on npm. diff --git a/packages/transport/README.md b/packages/transport/README.md new file mode 100644 index 0000000..46b7569 --- /dev/null +++ b/packages/transport/README.md @@ -0,0 +1,35 @@ +# @wifilabel/transport + +A `write` / `read` / `close` pipe for one label-printer session, a mock that scripts the replies, and a helper that reads until the line goes quiet. + +## Install + +```bash +npm install @wifilabel/transport +``` + +## Example + +```ts +import { decodeLatin1, encodeAscii, MockTransport, readUntilQuiet } from "@wifilabel/transport"; + +const transport = new MockTransport(["ok"]); +await transport.write(encodeAscii("~HI")); +const reply = decodeLatin1(await readUntilQuiet(transport)); +``` + +`MockTransport` records each write and returns the next scripted response on the following read. An empty read after that lets `readUntilQuiet` stop. + +## What you get + +`Transport` is three methods. `write` takes a `Uint8Array`. `read(timeoutMs)` resolves with bytes, or an empty array when that timeout elapsed with nothing new. `close` ends the session. + +`readUntilQuiet` keeps calling `read` until a timeout comes back empty after some data, or the overall budget runs out. Defaults are 2000 ms total and 200 ms of quiet. + +`encodeAscii` copies a string into bytes. A code point above 255 throws. `decodeLatin1` turns bytes back into a string. + +## Limits + +No USB and no sockets. Those adapters are [@wifilabel/webusb](https://www.npmjs.com/package/@wifilabel/webusb) and [@wifilabel/box-client](https://www.npmjs.com/package/@wifilabel/box-client). Command text comes from [@wifilabel/zpl](https://www.npmjs.com/package/@wifilabel/zpl) or [@wifilabel/epl2](https://www.npmjs.com/package/@wifilabel/epl2). + +Prefer a ready box? [wifilabel.com](https://wifilabel.com) diff --git a/packages/transport/package.json b/packages/transport/package.json index b95192d..bb3d84a 100644 --- a/packages/transport/package.json +++ b/packages/transport/package.json @@ -1,7 +1,15 @@ { "name": "@wifilabel/transport", - "version": "0.1.0", + "version": "0.1.1", "description": "Byte transport interface for thermal printer sessions. No network and no USB driver.", + "keywords": [ + "label-printer", + "thermal-printer" + ], + "homepage": "https://wifilabel.com/", + "bugs": { + "url": "https://github.com/WiFiLabel/label-toolkit/issues" + }, "license": "MIT", "author": "WiFiLabel ", "type": "module", diff --git a/packages/zpl/CHANGELOG.md b/packages/zpl/CHANGELOG.md new file mode 100644 index 0000000..0b6afd8 --- /dev/null +++ b/packages/zpl/CHANGELOG.md @@ -0,0 +1,10 @@ +# @wifilabel/zpl + +## 0.1.1 + +### Patch Changes + +- Document each package on npm. +- Updated dependencies + - @wifilabel/printer-spec@0.1.1 + - @wifilabel/transport@0.1.1 diff --git a/packages/zpl/README.md b/packages/zpl/README.md new file mode 100644 index 0000000..4c526e8 --- /dev/null +++ b/packages/zpl/README.md @@ -0,0 +1,45 @@ +# @wifilabel/zpl + +Functions that return ZPL and SGD text, and parsers for `~HI`, `~HS`, and `^HQES`. + +## Install + +```bash +npm install @wifilabel/zpl +``` + +## Example + +```ts +import { sgd, zpl } from "@wifilabel/zpl"; + +const setup = [ + zpl.setDarkness(15), + zpl.mediaType("direct"), + zpl.mediaTracking("gap"), + zpl.printWidth(812), + zpl.labelLength(1218), + zpl.calibrate(), + zpl.saveSettings(), +].join(""); + +const readDarkness = sgd.get("media.darkness"); +``` + +`setup` and `readDarkness` are strings. Send them with a transport you already have. `queryPrinter(transport)` runs a short script of those queries and returns a `PrinterSnapshot`. `parseHostStatus` reads a `~HS` reply. + +## What you get + +`zpl` covers darkness, speed, media type, tracking, width, length, tear-off, calibrate, save, factory reset, restart, a test label, and `graphicField`. `sgd` is `get`, `set`, and `do`. `factoryReset` and `restart` throw unless you pass `{ confirm: true }`. + +Runtime dependencies are [@wifilabel/printer-spec](https://www.npmjs.com/package/@wifilabel/printer-spec) and [@wifilabel/transport](https://www.npmjs.com/package/@wifilabel/transport). Nothing else. + +## Limits + +Nothing here opens USB or a socket. Pair it with [@wifilabel/webusb](https://www.npmjs.com/package/@wifilabel/webusb), [@wifilabel/box-client](https://www.npmjs.com/package/@wifilabel/box-client), or your own `Transport`. + +Some numbers in the spec are still `verified: false`. The builder will emit them. That does not mean the value was measured on your printer. + +Zebra, ZPL, and Link-OS are trademarks of Zebra Technologies Corporation. This project is not affiliated with, endorsed by, or sponsored by Zebra Technologies. + +Prefer a ready box? [wifilabel.com](https://wifilabel.com) diff --git a/packages/zpl/package.json b/packages/zpl/package.json index e0b568a..7d1cf46 100644 --- a/packages/zpl/package.json +++ b/packages/zpl/package.json @@ -1,7 +1,19 @@ { "name": "@wifilabel/zpl", - "version": "0.1.0", - "description": "ZPL and SGD builders and status parsers for thermal label printers. Zero runtime dependencies outside the WiFiLabel spec packages.", + "version": "0.1.1", + "description": "Build and parse ZPL and SGD for Zebra label printers.", + "keywords": [ + "zpl", + "zebra", + "sgd", + "label-printer", + "thermal-printer", + "host-status" + ], + "homepage": "https://wifilabel.com/", + "bugs": { + "url": "https://github.com/WiFiLabel/label-toolkit/issues" + }, "license": "MIT", "author": "WiFiLabel ", "type": "module", diff --git a/scripts/check-package-readmes.mjs b/scripts/check-package-readmes.mjs new file mode 100644 index 0000000..efa6b0f --- /dev/null +++ b/scripts/check-package-readmes.mjs @@ -0,0 +1,37 @@ +import { existsSync, readFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); +const homepage = "https://wifilabel.com/"; +const packages = [ + "packages/spec", + "packages/zpl", + "packages/epl2", + "packages/transport", + "packages/transport-webusb", + "packages/transport-box", +]; + +let failed = false; + +for (const dir of packages) { + const pkgPath = join(root, dir, "package.json"); + const readmePath = join(root, dir, "README.md"); + const pkg = JSON.parse(readFileSync(pkgPath, "utf8")); + const readme = existsSync(readmePath) ? readFileSync(readmePath, "utf8") : ""; + const problems = []; + if (!readme.includes(`# ${pkg.name}`)) problems.push("README.md is missing the package heading"); + if (pkg.homepage !== homepage) { + problems.push(`homepage is ${JSON.stringify(pkg.homepage)}`); + } + if (!Array.isArray(pkg.keywords) || pkg.keywords.length === 0) { + problems.push("keywords is empty"); + } + if (problems.length > 0) { + failed = true; + console.error(`${pkg.name ?? dir}: ${problems.join("; ")}`); + } +} + +if (failed) process.exit(1);