Custom platforms
The built-in platforms cover web, mobile and desktop. Anything else your project builds more than once, such as a wall
display, a kiosk or a point-of-sale terminal, can be a platform too. Then platform add copies it with its scripts,
and platform init runs its setup steps, the same way as for the built-ins.
Declare it
Platforms and templates go in the frigear field of the root package.json:
{
"frigear": {
"templates": {
"kiosk": "gh:acme/templates/kiosk#main"
},
"platforms": {
"display": {
"template": "kiosk",
"description": "A wall display",
"scripts": {
"dev:<name>": "pnpm --filter <dir> dev",
"<name>:flash": "pnpm --filter <dir> run flash"
},
"nextSteps": [" plug in the display, then: pnpm <name>:flash"],
"targets": {
"flash": { "description": "Write the image to the device", "script": "flash", "bin": ["kiosk-cli", "flash"] }
}
}
}
}
}
Then:
pnpx @frigear-nu/cli platform add display lobby # apps/lobby, with dev:lobby and lobby:flash
pnpx @frigear-nu/cli platform add display bar # apps/bar, with dev:bar and bar:flash
pnpx @frigear-nu/cli platform init flash --app bar
Fields
frigear.templates maps a template name to a giget source. Use the name in a
platform's template or in --template. A name of a built-in template (web, mobile, ...) replaces it.
Each entry of frigear.platforms:
| Field | Purpose |
|---|---|
template | A template name or a giget source. Without it, platform add needs --template. |
description | Shown by platform list. |
defaultAppName | The app's folder when no name is given; default: the platform's name. |
scripts | Root scripts added for each app. In keys and values <name> is the app's folder name and <dir> its path from the root (./apps/lobby). |
nextSteps | Lines printed after the app is added; <name>, <dir> and <package> are replaced. |
targets | What platform init <target> runs in an app of this platform: see below. |
A platform with a built-in's name (mobile, desktop, ...) is merged over it: set only the fields you want to change,
such as a template of your own, and keep the built-in's scripts and targets.
Each target:
| Field | Purpose |
|---|---|
script | A script of the app's package.json to run. |
bin | A binary of the app's dependencies and its first arguments, run when the app has no script of that name. |
args | Arguments added after the script or binary. Flags after -- on the command line come after these. |
aliases | Other names for the target, such as watchos for apple-watch. |
description | Shown by platform list. |
Without declaring it
platform add <name> --template <template> works for a platform that is not declared: it copies the template, renames
the package and records the platform, but adds no scripts and knows no targets. Declare the platform once you add a
second app of it.
In code
definePlatform takes the same fields, and nextSteps and detect may be functions there. See
From code.