Headless Command
The headless command is simply a Template UI Command without UI.
Use APIs exported from "@kksh/api/headless"
.
Some APIs for rendering UI are removed in "@kksh/api/headless"
.
It’s useful for some simple tasks without needing to open a new page.
Run the project scaffolding command to create a new project with Worker Template Extension.
npm init kunkun@latest # choose the template
package.json
{ ..., "kunkun": { ... "identifier": "template-ext-headless", "permissions": [ "clipboard:write-text" ], "icon": { "type": "iconify", "value": "material-symbols:extensiontabler:code" }, "headlessCmds": [ { "name": "Template: Headless Command UUID", "main": "dist/index.js", "cmds": [] } ] }, ...}
Sample UUID Extension
This simple extension simply generates a UUID v4 and copies it to the clipboard.
Thus why "clipboard:write-text"
permission is required in package.json
.
HeadlessCommand
is the base class for headless commands.
import { clipboard, expose, HeadlessCommand, toast,} from "@kksh/api/headless";import { v4 as uuidv4 } from "uuid";
class UuidExt extends HeadlessCommand { async load() { const uuid = uuidv4(); return clipboard .writeText(uuid) .then(() => { toast.success(`Copied UUID: ${uuid}`); }) .catch((err) => { toast.error(`Failed to copy UUID: ${err}`); }); }}
expose(new UuidExt());
Publish
See Guide: Extension Publish for more details.