Run a script ($args holds the arguments; --env picks kscript.staging.json, .env.staging...). The word run can be left out. With no script, or a folder, it runs the main script: app.main in kscript.json, then main.kscript, then index.kscript.
Rebuild everything the project makes from its code (the agent docs, the OpenAPI file http.openapi.file names, and more as packages add to it) each time a file changes, until Ctrl+C. kscript serve and the editor (on save) do the same.
Start a new project, or generate a file: a route (added to the routes file), controller, request, middleware, view, mail, page, component, stylesheet, model, type, enum, window, config, test and more. kscript make --list shows them all, with their options.
Copy a model a package ships, such as User, Guest or Ownable, into your models folder to change it, or write the migration for the database queue's tables or the database sessions table.
Run a script ($args holds the arguments; --env picks kscript.staging.json, .env.staging...). The word run can be left out. With no script, or a folder, it runs the main script: app.main in kscript.json, then main.kscript, then index.kscript.
Option
Description
--env name
The environment for $config: lays kscript.<name>.json over kscript.json, reads .env.<name> and sets KSCRIPT_ENV.
--debug
Run the script in the terminal debugger: it pauses before the first statement (or at each --break line), then steps a line at a time and prints variables.
--break line
Run the script in the debugger and pause at this line of it, or at file:line in another script. Give it once for each breakpoint.
Examples
Command
What it does
kscript hello.kscript Joan
Runs hello.kscript with Joan as its first argument ($args[0]).
kscript run hello.kscript Joan
The same, with the command written out.
kscript run
Runs the project's main script: app.main in kscript.json, or main.kscript, or index.kscript.
kscript . Joan
Runs this folder's main script with Joan as $args[0].
kscript --env staging deploy.kscript
Runs deploy.kscript with the staging settings (kscript.staging.json and .env.staging).
kscript --debug --break 12 basket.kscript
Runs basket.kscript in the debugger, pausing at line 12.
Rebuild everything the project makes from its code (the agent docs, the OpenAPI file http.openapi.file names, and more as packages add to it) each time a file changes, until Ctrl+C. kscript serve and the editor (on save) do the same.
Option
Description
--once
Build once and stop.
--check
Write nothing; fail if anything is out of date (for CI).
Examples
Command
What it does
kscript watch
Keeps the project's generated files up to date as you save.
kscript watch --check
Also checks each file you save and prints its problems.
Serve pages, and routes.kscript / api.kscript routes.
Option
Description
--docker | --no-docker
Launch the project's Compose service or serve locally. serve.docker sets the default.
--migrate
Apply pending database migrations before the server starts.
--no-reload
Disable automatic browser reload when site source or assets change. Production and compiled sites never inject the reload script.
--port, -p N
The port to listen on (default 8080, or serve.port in kscript.json).
--host H
The address to listen on: localhost (default), 0.0.0.0 or * for every address.
--env name
The environment for $config.
--with-docs
Also serve the docs on localhost, with a page about this project: its conventions, routes, and the functions, types and constants its scripts declare. serve.docs in kscript.json turns it on by default; --no-docs turns it off. Never for compiled programs or the production environment.
--docs-port N
The port for the docs (default 4180, or a free one if that is in use).
--with-worker
Also run a queue worker in the server's process, for working on a site: it runs the jobs routes dispatch, including on the memory connection.
--with-scheduler
Also run the schedule file's tasks at their times, as kscript schedule work does, while the server runs.
Examples
Command
What it does
kscript serve
Serves the project on http://localhost:8080, reloading as you save.
kscript serve site --port 3000
Serves the site folder on port 3000.
kscript serve --with-docs
Also serves these docs, with a page about your project, on a second port.
kscript serve --with-worker
Also runs a queue worker, so queued jobs run while you work.
kscript serve --with-worker --with-scheduler
Also runs the scheduled tasks, and a worker for the jobs they dispatch.
Open these docs: a local website with every package, element, command and method, and examples you can run.
Option
Description
--port, -p N
The port to serve the docs on (default 4180, or a free port if that one is taken).
--syntax kscript|xml
Show examples as .kscript or XML (default: the project's make.syntax, else .kscript).
--no-open
Don't open a browser; just print the address.
--project
Write .kscript/docs/project.md, the docs of this project's own code (its conventions, routes, functions and types). From then on kscript watch, kscript serve and saving in the editor keep it up to date.
--export-to folder
Write the whole docs site into a folder as plain files that work offline: open its index.html in a browser, no server or network needed. Search works; examples can't run, so each one carries a hidden placeholder for a runner of your own.
--published
With --export-to: a copy for a website, read as the product's documentation: no playground, no "Edit this page on GitHub" links, and no notes about how it was made.
--hide list
With --export-to: pages and reference entries to leave out, with every link to them, separated by commas: playground, /guide/editor, /reference/methods/* (every page under a path), /reference/ai#ask (one entry), or edit-links.
--config file
With --export-to: a JSON file that shapes the copy, with published, hide, pages (replace a page with your Markdown), before and after (add Markdown under a page's title or at its end), files (a folder of pictures and other files to copy in), versions, stylesheet and syntax.
--versions url
With --export-to: a JSON list of published versions, {"latest": "0.55.0", "versions": [...]}, that turns the version in the header into a picker. Each version's copy is a folder named after it, side by side.
--stylesheet url
With --export-to: a stylesheet to load after the docs' own, so they match the site they're put on.
Examples
Command
What it does
kscript docs
Opens these docs in your browser.
kscript docs replace
Opens them at the search results for replace.
kscript docs --syntax xml
Shows the examples in XML.
kscript docs --project
Writes .kscript/docs/project.md about this project's own code, and keeps it up to date.
kscript docs --export-to kscript-docs
Writes the docs into the kscript-docs folder, to read offline or put on any web server.
kscript make project [folder] [--template web|api|fullstack|bare] [--db sqlite] [--auth] [--docker] [--examples]
kscript make <type> <name> [--key value]
kscript make auth [--passkeys] [--origin URL] [--rp-id DOMAIN] [--api]
kscript make --list
Start a new project, or generate a file: a route (added to the routes file), controller, request, middleware, view, mail, page, component, stylesheet, model, type, enum, window, config, test and more. kscript make --list shows them all, with their options.
Option
Description
--list
Every type of file kscript make can make, with its options and examples. kscript make <type> --help shows one.
--template name
kscript make project: web (the default), api (a JSON API), fullstack (pages and their API) or bare. With no options at a terminal, a setup wizard asks.
--examples
Add the optional Notes example to a fullstack project.
-n, --no-interaction
kscript make project: ask nothing, and take the defaults.
--syntax kscript|xml
Write .kscript (the default) or .ks.xml files.
--dry-run
Show what would be made, and make nothing.
--force
Replace a file that is already there.
--key value
Values for the template, such as --resource or --fields "name: string".
--model Name
kscript make controller: fill the resource actions in with the model's records (Post->paginate, ->find_or_fail, ->create, ->update, ->delete).
kscript make model: also make its policy, the migration for its table (with kscript db diff), a resource controller for it, a seeder, or all of them with --component.
Examples
Command
What it does
kscript make project my-site
Makes a new project in my-site, asking what it needs.
kscript make project shop --template api --db postgres --docker
Makes an API project on Postgres, with Docker files.
kscript make route users --api
Adds an API route for users and its controller.
kscript make controller people --resource
Makes a controller with the index, show, store, update and destroy actions.
kscript make model Post --fields "title: string" --all
Makes the Post model with its policy, migration, controller, seeder and component.
kscript make mail welcome --vars name
Makes views/mail/welcome.html, an email's view for @send_mail.
Copy a model a package ships, such as User, Guest or Ownable, into your models folder to change it, or write the migration for the database queue's tables or the database sessions table.
Option
Description
--syntax kscript|xml
Write a .kscript (the default) or .ks.xml file.
--force
Replace the project's copy with the package's again.
--dry-run
Show where the copy would go, and write nothing.
--dir <folder>
Use the project in this folder instead of the current one.
--connection <name>
With queue: the database queue connection whose tables to write (default: database).
Examples
Command
What it does
kscript publish
Lists the models and mixins the packages ship, and which ones the project has its own copy of.
kscript publish User
Copies KScript.Auth's User model to models/user.kscript.
kscript publish queue
Writes the migration that makes the database queue's tables, so kscript db migrate makes them.
kscript publish sessions
Writes the migration for the table database sessions are kept in, and sets http.auth.sessions to database.