KScript docs
EN

Programs: kscript compile

Introduction

When you share a script with someone, they shouldn't need to install kscript first. kscript compile turns a script into a program that runs on computers without kscript or .NET. It works for all three kinds of KScript:

  • A terminal script becomes a command-line program.
  • A desktop app (a script with a Window { } block) becomes a Mac .app, a Windows .exe with its icon, or a Linux program with a launcher entry.
  • A kscript serve site becomes a program that serves it.

To get started, compile a script:

CommandWhat it does
kscript compile hello.kscriptDist/linux-x64/hello on Linux, dist/mac-arm64/hello on an Apple Silicon Mac.

With no script, kscript compile builds the folder's main script, found the same way as kscript run: app.main in kscript.json, then main.kscript, then index.kscript. A script you name always wins over app.main. --name names the program and --out chooses the folder:

CommandWhat it does
kscript compileApp.main, or main.kscript, or index.kscript.
kscript compile tools/report.kscriptThis script, whatever app.main says.
kscript compile counter.kscript --name "Counter" --out buildA program called Counter, in build/.

When app.main names a script that doesn't exist, that's an error: kscript compile doesn't fall back to main.kscript, so a typo can't build the wrong program.

Each program is one file, except a Mac desktop app, which is an .app folder around one file. The program holds the script, the scripts it imports and every other file in its folder or project, such as data, pages and pictures, so import, @read_text and pages work as they do with kscript. The arguments a program is started with are the script's $args.

Edit this page on GitHub