From code
The commands are thin wrappers: the work is in plain async functions of @frigear-nu/cli that take options, return
what they did and throw typed errors. Use them in a script of your own, a project generator or another CLI.
pnpm add -D @frigear-nu/cli
Platforms
import { addPlatform, definePlatform, initPlatform, PlatformError } from '@frigear-nu/cli'
const display = definePlatform({
name: 'display',
template: 'gh:acme/templates/display#main',
scripts: { 'dev:<name>': 'pnpm --filter <dir> dev', '<name>:flash': 'pnpm --filter <dir> run flash' },
targets: { flash: { script: 'flash' } },
nextSteps: ({ appDir }) => [` plug in the display, then flash ${appDir}`],
})
try {
const added = await addPlatform({ cwd: process.cwd(), platform: display, name: 'lobby', install: false })
console.log(added.appDir, added.scripts.added, added.nextSteps)
await initPlatform({ cwd: process.cwd(), target: 'ios', app: 'mobile', args: ['--if-missing'] })
}
catch (error) {
if (error instanceof PlatformError && error.code === 'APP_EXISTS') { /* pick another name */ }
throw error
}
| Function | Does |
|---|---|
addPlatform(options) | What platform add does. platform is a name or a definePlatform definition. Returns the app's folder, package name, the scripts added and kept, and the next steps. |
initPlatform(options) | What platform init does. dryRun: true only works out the app and the command ({ kind: 'script' | 'exec', name, args }). |
definePlatform(definition) | Types a platform: the fields of Custom platforms, with nextSteps as a function of the new app, and detect(pkg) to recognise an app of the platform without a frigear.platform field. |
platformRegistry(rootPkg) | The built-in platforms and templates merged with a root package.json's frigear field. |
resolveAppsDir({ cwd, root, appsDir }) | The apps folder, as Where it works describes, and whether a workspace glob covers it. |
resolvePlatformApp(options), listWorkspaceApps(appsDir, registry) | Which app a target goes to; the apps of a folder with their platforms. |
BUILTIN_PLATFORMS, APP_TEMPLATES | The built-in definitions and template paths. |
A PlatformError has a code and, where there is a choice to make, the candidates:
| Code | When |
|---|---|
NO_WORKSPACE | No pnpm-workspace.yaml above cwd. |
OUTSIDE_ROOT | appsDir is outside the workspace. |
APP_EXISTS | The app's folder already has a package.json. |
UNKNOWN_PLATFORM, UNKNOWN_TEMPLATE | Not a known name; candidates lists the known ones. |
UNKNOWN_TARGET | The app's platform has no such target; candidates lists its targets. |
APP_NOT_FOUND, APP_AMBIGUOUS | No app, or several apps, for the target; candidates lists them. |
DOWNLOAD_FAILED | giget could not copy the template; cause is its error. |
Upgrades
import { upgradeWorkspace } from '@frigear-nu/cli'
const result = await upgradeWorkspace({ cwd: process.cwd(), only: ['auth'], dryRun: true })
upgradeWorkspace is what upgrade does, without the install: to sets target versions per package, only limits
the packages, and the result holds what changed and the report as Markdown. migrations lists the migrations the
CLI carries.
Environment files
import { prepareEnv } from '@frigear-nu/cli'
const results = await prepareEnv({ root: process.cwd(), secrets: { MY_TOKEN: 'hex:32', PIN: () => '1234' } })
prepareEnv is what prepare env does. It returns { file, created, generated } per .env
(file relative to root), and describeEnvResult(result) gives the line the command prints.
| Option | Purpose |
|---|---|
root | The workspace root. |
rootPkg | Its package.json, read from root when left out; its frigear.env applies before secrets. |
secrets | Variable name → a generator spec, a function returning the value, or false to skip a variable. Applied last. |
dirs | The folders whose subfolders are searched; default frigear.env.dirs, else apps and packages. |
dryRun | Work out the result and write nothing. |
generateSecret(key, generator) makes one value, resolveEnvConfig(rootPkg) gives the secrets and folders of a
package.json, and BUILTIN_SECRETS and DEFAULT_ENV_DIRS are the defaults.
Projects
resolveStarter, STARTERS and PLATFORMS are the starter table of init.