KScript docs
EN

Projects and kscript.json

Project settings: kscript.json

kscript serve, kscript check, kscript fmt, kscript make and the editor read the nearest kscript.json in the folder they work on or a parent folder, so they behave the same from anywhere in the project. Every setting is optional:

JSON
{
  "name": "my-site",
  "kscript": "0.51.0",                             // the KScript release the project is written for (see below)
  "timezone": "Europe/London",                     // the zone stored dates are in (see docs/data.md); this is the default
  "standard": "kscript:recommended",               // lint rules and format settings to start from (see Standards)
  "packages": ["KScript.Terminal", "KScript.IO"],   // imported by every script in the project
  "extensions": ["extensions", "shared/**/*.kscript"], // where the project's extend files are (default: extensions/)
  "natives": ["natives"], // where the project's native types are, used without an import (default: natives/)
  "serve": {
    "root": ".",          // the site folder, relative to kscript.json
    "port": 8080,         // --port and --host on the command line still win
    "host": "localhost",
    "docs": true          // also serve the docs, with a page about this project (see docs/web.md)
  },
  "http": {
    "middleware": ["log"],                     // routes, middleware and their settings (see docs/http.md)
    "groups": { "api": ["cors", "throttle"] }
  },
  "lint": {
    "include": ["**/*.html", "**/*.md", "**/*.kscript"],  // what `kscript check` looks at
    "exclude": ["_templates", "node_modules", "drafts/**"], // never checked, on the command line or in the editor
    "rules": { "KS3003": "off", "KS4*": "error" },          // off, hint, info, warning or error, by code or prefix
    "warnings_as_errors": false                               // same as kscript check --warnings-as-errors
  },
  "test": {
    "include": ["tests/**/*.test.kscript"],  // what `kscript test` runs (default: **/*.test.kscript and **/*.test.ks.xml)
    "exclude": ["tests/slow"],
    "timeout": 10,                          // seconds per test, 0 for no limit
    "packages": ["KScript.Terminal"],       // imported by test files only
    "env": "test"                           // the environment tests run in, so kscript.test.json applies
  },
  "format": {
    "indent": 2,           // spaces per level, or "tab"; used by kscript fmt and Format Document
    "print_width": 80,      // the longest a line should be; longer lines are wrapped
    "rules": { "statement_per_line": false },  // any rule can be turned off
    "exclude": ["vendor"]  // see docs/formatting.md for every format setting
  },
  "app": {
    "main": "app.kscript",      // what `kscript run` and `kscript compile` start from (default: main.kscript, then index.kscript)
    "name": "My App",           // shown in the Dock, Start menu or launcher (default: the project's name)
    "id": "com.example.myapp",  // the macOS bundle id
    "version": "1.0.0",
    "icon": "icon.png",         // a .png, .ico or .icns, used for every platform
    "user_config": true         // lay the person's own config.json (KScript.Storage) over $config
  },
  "types": {
    "uuid": { "v": 4 },                     // arguments for every use of a built-in type (see Types and validation)
    "password": { "min": 12 }
  },
  "config": {
    "app": { "name": "Shop" },              // the app's own settings: $config.app.name
    "database": { "connections": { "main": { "url": "sqlite:data/shop.sqlite" } } }
  }
}
  • A pattern without a / (such as _templates or *.draft.html) matches a file or folder of that name anywhere. Otherwise it is matched against the path from kscript.json: * stays within a folder, ** spans folders, and a folder matches everything in it.
  • kscript names the KScript release the project is written for: an exact release such as "0.51.0", or "0.51" for the newest 0.51.x. Editors that fetch KScript for you, such as FlowIDE, run the project with that release; without it they use the latest one.
  • standard picks the standard the project's lint and format settings start from: kscript:recommended (the default), kscript:strict, or a standard file of your own that you can share between projects. Anything set in kscript.json itself wins over the standard. kscript check --print-config shows the result and where each setting came from.
  • rules changes how serious a diagnostic is (see the codes). The longest match wins, so "KS3*": "warning" with "KS3001": "error" keeps unknown elements as errors.
  • Comments and trailing commas are allowed. Unknown settings are reported as warnings rather than ignored silently, and the VS Code extension validates the file and completes its settings as you type.
  • format sets the style for kscript fmt and the editor's Format Document, and format.rules turns individual rules off. See Formatting for every setting and the ignore comments.
  • Inside a project, kscript make page about creates the page in the site root even when run from a subfolder.
  • config holds the app's own settings, read as $config; kscript.<env>.json and config.kscript beside kscript.json are laid over it (see Settings).
  • kscript serve never serves kscript.json, kscript.<env>.json, .env files, or config.* JSON files.
  • http configures route files, middleware, CORS, auth and rate limits for KScript.Http (see Routes, controllers and middleware).
  • types gives built-in types such as uuid, email and password the same arguments everywhere in the project. Arguments written where a type is used, such as uuid(v: 8), win (see Types and validation).
  • app.name (or name) also names the app's own folders for settings, data and caches (see App folders).
  • queue names the connections jobs wait on, the queues a worker checks and how long failed jobs are kept (see Queues and jobs).
  • app is read by kscript compile, which builds the script (often a desktop app) into a program for macOS, Windows and Linux (see Programs).