KScript Dokumentation
DE

Sprache

Automatisch aus dem Englischen übersetzt; das englische Original ist maßgeblich.

Projekte und kscript.json

Projekteinstellungen: kscript.json

kscript serve, kscript check, kscript fmt, kscript make und der Editor lesen die nächste kscript.json im Ordner, in dem sie arbeiten, oder in einem übergeordneten Ordner, damit sie sich überall im Projekt gleich verhalten. Jede Einstellung ist 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" } } }
  }
}
  • Ein Muster ohne / (etwa _templates oder *.draft.html) passt auf eine Datei oder einen Ordner dieses Namens überall. Andernfalls wird es mit dem Pfad ab kscript.json verglichen: * bleibt innerhalb eines Ordners, ** umfasst mehrere Ordner, und ein Ordner passt auf alles darin.
  • 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 wählt den Standard, von dem die Einstellungen lint und format des Projekts ausgehen: kscript:recommended (der Standard), kscript:strict oder eine eigene Standarddatei, die du zwischen Projekten teilen kannst. Was in kscript.json selbst gesetzt ist, hat Vorrang vor dem Standard. kscript check --print-config zeigt das Ergebnis und woher jede Einstellung stammt.
  • rules ändert, wie schwerwiegend eine Diagnose ist (siehe die Codes). Die längste Übereinstimmung gewinnt, daher behält "KS3*": "warning" mit "KS3001": "error" unbekannte Elemente als Fehler bei.
  • Kommentare und nachgestellte Kommas sind erlaubt. Unbekannte Einstellungen werden als Warnungen gemeldet und nicht stillschweigend ignoriert. Die VS-Code-Erweiterung prüft die Datei und ergänzt die Einstellungen beim Tippen.
  • format legt den Stil für kscript fmt und das Dokument-Formatieren des Editors fest, und format.rules schaltet einzelne Regeln aus. Alle Einstellungen und die Ignorier-Kommentare findest du unter Formatierung.
  • Innerhalb eines Projekts erstellt kscript make page about die Seite im Site-Stammverzeichnis, auch wenn du den Befehl aus einem Unterordner ausführst.
  • config enthält die eigenen Einstellungen der App, gelesen als $config; kscript.<env>.json und config.kscript neben kscript.json werden darüber gelegt (siehe Einstellungen).
  • kscript serve liefert niemals kscript.json-, kscript.<env>.json- und .env-Dateien oder config.*-JSON-Dateien aus.
  • http konfiguriert Routendateien, Middleware, CORS, Authentifizierung und Ratenbegrenzungen für KScript.Http (siehe Routen, Controller und Middleware).
  • types legt für eingebaute Typen wie uuid, email und password im ganzen Projekt dieselben Argumente fest. Argumente, die dort angegeben werden, wo ein Typ verwendet wird, etwa uuid(v: 8), haben Vorrang (siehe Typen und Validierung).
  • app.name (oder name) benennt außerdem die eigenen Ordner der App für Einstellungen, Daten und Caches (siehe App-Ordner).
  • queue legt die Verbindungen fest, auf die Jobs warten, die Warteschlangen, die ein Worker prüft, und wie lange fehlgeschlagene Jobs aufbewahrt werden (siehe Warteschlangen und Jobs).
  • app wird von kscript compile gelesen, das das Skript (oft eine Desktop-App) zu einem Programm für macOS, Windows und Linux baut (siehe Programme).