Other languages are translated automatically from English.
kscript make commands
kscript make <type> <name> makes a file where the project keeps that kind of file, and makes any folder it needs. Scripts are written in the project's format (.kscript unless make.syntax in kscript.json says xml). kscript make --list prints this list, and kscript make <type> --help prints one entry.
Every type comes from a template. kscript make templates copies them to the project's _templates folder, where you can change what they make or add types of your own. Add --dry-run to any command to see what it would make, and --force to replace a file. In a new project, make route name=users runs kscript make route users (see Projects).
A native type in natives/: a value of your own, like email or handle, that its validator checks wherever it is used and that can be written without quotes. Every script in the project can use it without an import
A migration in database/migrations to write by hand: steps that change the tables, run by kscript db migrate. kscript db diff writes one from the models instead
A route, added to routes.kscript (or api.kscript with --api), with its controller made if it's missing
Option
Description
--method
The HTTP method: get (the default), post, put, patch, delete, options or any
--api
Add it to api.kscript, served under /api with JSON errors, instead of routes.kscript
--to
The controller function that answers it, such as people.list. By default the path picks it: users gives users.index, users/{id} gives users.show, and --method post gives users.store
--controller
The controller to use or make, such as admin/users (default: the path without its {parameters})
--action
The controller function (default from the method: index or show, store, update, destroy)
--resource
Add Resource(path: …, to: …) for index, show, store, update and destroy, and make a resource controller
--view
Answer with this view (made in views/ if it's missing) instead of a controller
--name
A name for @route('name')
--where
Rules for the parameters, such as "id: int"
Example
Shell
kscript make route users
kscript make route "users/{id}" --where "id: int"
kscript make route users --method post --api
kscript make route people --resource --api
kscript make route about --view about
kscript make route reports/export --to reports.export
kscript make controller <name> [--resource] [--model Post] [--actions index,export]
A controller in controllers/: functions that answer routes
Option
Description
--resource
Write index, show, store, update and destroy, for Resource(path: /people, to: people)
--model
Fill the resource actions in with a model's records (Post->paginate, ->find_or_fail, ->create, ->update and ->delete); implies --resource
--actions
The functions to write, comma separated (default index)
Example
Shell
kscript make controller people --resource
kscript make controller reports --actions index,export
kscript make controller admin/users --resource
kscript make controller posts --model Post
kscript make type <Name> [--fields "name: string, stars: int from stargazers_count"] [--sample data/repo.json]
A type in types/ that checks data and turns it into a record (API responses, JSON files, request bodies)
Option
Description
--fields
The fields, comma separated, as name: type, with ? for optional, = for a default and from for another key. Default: name: string
--sample
Take the fields from a saved example of the data instead
Example
Shell
kscript make type Repo --fields "name: string, stars: int from stargazers_count, topics: string[] = []"
kscript make type Order --sample data/order.json
A native type in natives/: a value of your own, like email or handle, that its validator checks wherever it is used and that can be written without quotes. Every script in the project can use it without an import
Option
Description
--base
The type it is made from: string, int, float, number, a native type such as email, url, domain, slug or country, or another of your types (default string)
--pattern
A regex the whole value must match, such as "/^[A-Z]{3}-\d{4}$/i"
--min
The smallest number, or the shortest text or list
--max
The largest number, or the longest text or list
--one-of
The only values allowed, comma separated
--not
Values that are never allowed, comma separated
--normalize
An expression that tidies the value, as $value, before it is checked, such as "$value->trim()->upper()"
--validate
Any other check, with the message to show when it fails: "test, 'message'"
Example
Shell
kscript make native Sku --pattern '/^[A-Z]{3}-\d{4}$/' --normalize '$value->trim()->upper()'
kscript make native Percent --base int --min 0 --max 100
kscript make native CompanySite --base url --validate '$value.host->ends_with("example.com"), "Use a company site"'
kscript make native Username --base handle --max 16 --not @admin,@root
kscript make model <Name> [--fields "name: string, email: email"] [--timestamps] [--soft-deletes] [--component] [--policy] [--migration] [--controller] [--seeder] [--all]
A model in models/: a type whose records are kept in a database table, with a query builder (User->where(...))
Option
Description
--fields
The fields, comma separated, as name: type, with ? for optional and = for a default. Default: name: string
--timestamps
Extend Timestamps: created_at and updated_at, set when records are saved
--soft-deletes
Extend SoftDeletes: mark records deleted instead of removing them, so they can be restored
--component
Also create a component that takes a row of this model as record
--policy
Also create its policy in policies/, which @can and @authorize ask
--migration
Also write the migration that makes its table, with kscript db diff
--controller
Also create a resource controller filled in with the model (kscript make controller --model)
--seeder
Also create a seeder in database/seeders that makes some of its records
--all
All of --component, --policy, --migration, --controller and --seeder
Example
Shell
kscript make model User --fields "name: string, email: email, password: password" --timestamps
kscript make model BlogPost --fields "title: string, body: string, published: bool = false" --soft-deletes
kscript make model Note --fields "title: string, body: string" --component
kscript make model Post --fields "title: string, body: string" --timestamps --all
A migration in database/migrations to write by hand: steps that change the tables, run by kscript db migrate. kscript db diff writes one from the models instead
Example
Shell
kscript make migration add_bio_to_users
kscript make migration backfill_slugs
kscript make extension <type> [--methods api_date,is_payday]
Methods added to a type, such as date or list, in extensions/: every script in the project gets them
Option
Description
--methods
The methods to start with, comma separated. Each returns $this until you fill it in
Example
Shell
kscript make extension date --methods api_date,is_payday
kscript make extension text/string --methods slug
kscript make extension list --methods second