Skip to content
CLI Overview

KosmoJS ships two binaries.

create-kosmo bootstraps a project - you run it once, through npm create kosmo.

kosmo does everything after that. It comes with @kosmojs/cli, a devDependency of every project, and package.json wires it to scripts so you rarely type the binary name:

ScriptCommandWhat it does
pnpm devkosmo serveDev server for every source folder
pnpm previewkosmo previewProduction build, served and rebuilt on change
pnpm buildkosmo buildProduction build
pnpm typecheckkosmo typechecktsc --noEmit per source folder, plus the project root
pnpm folderkosmo folderAdd a source folder to the project
pnpm sidecarkosmo sidecarAdd a sidecar folder - builds, serves no HTTP

All five run from the project root - the directory holding package.json.

-h / --help prints the full usage for either binary.

The commands ​

Scaffolding
create kosmoBootstrap a new project - run once
kosmo folderAdd a source folder to an existing project
kosmo sidecarAdd a sidecar folder - entry points, no HTTP
Running a project
kosmo serveDev server on kosmo.devHost, Vite + HMR, always client-rendered
kosmo previewProduction build served on kosmo.previewHost, rebuilt on change
kosmo buildProduction build only - dist/run.js plus a per-folder tree
kosmo typechecktsc --noEmit per source folder, plus the project root

Flags and prompts ​

npm create kosmo and kosmo folder take their answers as flags. Pass them all and the command just runs - no questions asked:

sh
pnpm folder --name admin --frontend react --backend hono

Leave a flag out and the command asks for it instead:

  • In a terminal, you get a prompt, and the command carries on with your answer.
  • Without a terminal - piped output (pnpm folder | tee setup.log), a CI script, a container, an agent sandbox - there is nobody to answer, so the command stops with an error. See the messages below.

So in scripts and CI, pass every flag up front. No terminal means nobody can answer, so a run that is missing a flag fails right away instead of waiting on a question.

When a command refuses to run ​

MessageCause
Unknown command; use one of folder, sidecar, serve, build, preview, typecheckTypo, or a command from another framework's CLI.
No source folders detectedNo src/*/kosmo.config.ts anywhere.
Some of the given names do not contain a valid KosmoJS source folderA named folder doesn't exist or has no config.
No folder name providedkosmo folder in CLI mode with no name positional - including the non-TTY case.
frontend is required: either provide --frontend <name> or --no-frontend flagNeither half of the pair was passed.
--frontend and --no-frontend are mutually exclusive; use only oneBoth halves were.
Target dir is not empty. Either remove dir contents or provide --overwrite flagcreate kosmo in CLI mode, non-empty target.
./src/<name> already exists. Either remove it or provide --overwrite flag.kosmo folder in CLI mode, folder taken.

Released under the MIT License.