@viamrobotics/create-control
v0.3.0
Published
Scaffold a Svelte custom control UI for one model of a Viam module.
Readme
@viamrobotics/create-control
Scaffold a Svelte custom control UI for one model of a Viam module.
pnpm create @viamrobotics/control <model-name> <dir>
npm create @viamrobotics/control@latest <model-name> <dir><model-name> is the model's last segment (station) or its full triplet (acme:weather:station).
<dir> is where the control is written, relative to the module root. A * in it stands for the
model name, so '*_ui' gives station_ui/. The SDK's examples keep their controls flat in the
module root this way. There is no default, since where a control lives is the module author's
call.
Interactive mode
Run it with no arguments, or with -i, from the module root to add controls for several models at
once. It lists the models in meta.json with the ones that have no custom_control preselected,
asks for the directory pattern, shows the resulting paths, and scaffolds them after a confirmation.
A pattern that maps two models to one directory is asked again. A model whose directory is not
empty is reported and skipped, and the rest are still written.
What it writes
The template is copied into <dir>, with the template's svelte-control name replaced by
<model-name>-control. A non-empty target directory is never overwritten, and a directory outside
the module is refused since the tarball could not ship it.
meta.json
When a meta.json exists in the current directory and lists the model, its custom_control entry
is set to <dir>/dist/index.html. A full triplet matches the model field exactly. A short name
matches the last segment of model. If no model matches, or several share the short name, the file
is left alone and the CLI says so.
Module build
When that meta.json also has a build block, the CLI makes the module's build able to produce the
control on a host without Node, which is what Viam's cloud builders are. It sets build.setup to
./setup.sh, adds node and pnpm to build.darwin_deps, and writes setup.sh into the module
root unless one is there. The script installs Node 22 and pnpm on Linux and does nothing where both
exist. A build.setup that already names another command is left alone with a reminder that it has
to install them. A manifest without a build block is not touched.
Options
-i,--interactivestarts the interactive mode above. It takes no arguments.
Development flags
--sdk <spec>sets the@viamrobotics/post-message-sdkdependency in the scaffoldedpackage.json, for example--sdk file:../../sdk.--template <dir>copies a different template directory. Without it the packagedtemplate/is used, ortemplates/svelte-controlin a dev checkout.
Tests
pnpm test includes an end-to-end test that packs the SDK from this repo, scaffolds two models into
a temporary module, installs their dependencies from the registry, builds both, and checks the
single-file artifacts and the custom_control entries in meta.json. It needs the root package
built (dist/) and network access, and takes a few minutes at most.
