KScript ドキュメント
JA

言語

英語から自動翻訳されています。原文は英語です。

プロジェクトと 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)
  "jit": true,                                     // run scripts on the JIT runtime too; false keeps kscript serve off it
  "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)
  "strict": false,                                 // true: every script is strict (see Strict types)
  "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)
    "main_function": "start",   // the function a script runs by itself after its top-level code (default: main)
    "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. Every kscript command in the project runs that release, downloading it the first time, and so do editors that fetch KScript for you, such as FlowIDE. kscript version pin 0.51 writes it, and kscript version unpin takes it out (see Switching versions). Without it, the project runs the computer's version.
  • jitは、インストール済みの kscript がリリースビルドのとき、プロジェクトをどこで実行するかを指定します。trueを指定すると、数秒かかるループを持つスクリプト向けに、スクリプトもJIT ランタイムで実行されます。falseは、kscript serveをインストール済みの kscript の中で実行し続けます。指定しない場合、kscript serveは JIT ランタイムで実行されますが、スクリプトは JIT ランタイムでは実行されません。--jit、--no-jit、KSCRIPT_JITがこれより優先されます。
  • 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.
  • strict: true は、プロジェクトのすべてのスクリプトを、それぞれが strict で始まるかのように strict にします。すべての値にチェッカーが証明できる型が必要で、型エラーは実行前にスクリプトを停止します。lint の重大度だけを変える kscript:strict 標準とは別物です。
  • 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.
  • コメントと末尾のカンマが使えます。不明な設定は黙って無視されず、警告として報告されます。VS Code拡張機能はファイルを検証し、入力中に設定を補完します。
  • formatはスタイルを設定します。これはkscript fmtとエディタのドキュメントの整形に使われます。format.rulesは個々のルールを無効にします。すべての設定と無視コメントについては整形を参照してください。
  • プロジェクト内では、kscript make page aboutはサブフォルダから実行しても、サイトのルートにページを作成します。
  • configにはアプリ独自の設定が入ります。これは$configとして読み込まれます。kscript.jsonの横にあるkscript.<env>.jsonとconfig.kscriptは、その上に重ねて適用されます(設定を参照)。
  • kscript serveはkscript.json、kscript.<env>.json、.envファイル、およびconfig.*のJSONファイルは配信しません。
  • httpは、KScript.Httpのルートファイル、ミドルウェア、CORS、認証、レート制限を設定します(ルート、コントローラー、ミドルウェアを参照)。
  • typesは、uuid、email、passwordなどの組み込み型に、プロジェクト全体で同じ引数を与えます。uuid(v: 8)のように型を使う場所に書かれた引数が優先されます(型と検証を参照)。
  • app.name(またはname)は、設定、データ、キャッシュ用に、アプリ独自のフォルダ名も定めます(アプリのフォルダを参照)。
  • queueは、ジョブが待機する接続先、ワーカーが確認するキュー、失敗したジョブを保持する期間を定めます(キューとジョブを参照)。
  • app は kscript compile によって読み込まれ、スクリプト(多くの場合デスクトップアプリ)を macOS、Windows、Linux 向けのプログラムにビルドします(プログラムを参照)。