Skip to content

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

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

They read distDir, devPort and previewPort from it, and refuse to start if any is missing.

-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
Running a project
kosmo serveDev server on devPort, Vite + HMR, always client-rendered
kosmo previewProduction build served on previewPort, rebuilt on change
kosmo buildProduction build only - dist/run.js plus a per-folder tree
kosmo typechecktsc --noEmit per source folder, plus an opt-in root run

Interactive vs CLI mode

The two scaffolding commands - npm create kosmo and kosmo folder - each have an interactive flow and a flag-driven one.

InvocationMode
Any flag passedCLI
No flags, stdout is a terminalInteractive
No flags, stdout is not a terminalCLI, with an empty flag set

There is no partial prompting. Once you are in CLI mode, anything you left out must have a default, or the command errors out.

-q / --quiet suppresses CLI mode's output. Errors still print.

The non-terminal case

This is the one that surprises people, and it has nothing to do with how you typed the command. The prompts disappear whenever stdout is not a terminal:

  • piping the output - pnpm folder admin | tee setup.log
  • running it from a setup or CI script
  • running it in a container or an agent sandbox with no terminal attached

So the same invocation that prompts in your shell becomes a CLI-mode run with no flags. It fails on the first required value rather than hanging on a question nobody can answer.

That is deliberate: a scaffolder blocked on an invisible prompt is worse than one that tells you which flag is missing.

When a command refuses to run

MessageCause
package.json does not exist or some of distDir / devPort / previewPort is not setNot in the project root, or some of listed key(s) are missing.
Invalid command, use one of folder, 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.