chapterjs dev. Putting it online for everyone is two steps: build it, then start it on a machine that stays on. This page is the first step, and the reasons behind it.
Why a build
chapterjs dev runs your files as they are, reloads them on save, and keeps a broken file’s last working version. That is right while you write. In production, the opposite is right: nothing should change under the bot, and a broken file should never be online at all. So production runs a build: a snapshot of your bot, checked from top to bottom and compiled into one file. If a file can’t run, there is no build, and nothing goes online by mistake.
Run it
What it does
1
Checks the types
What your editor underlines, for the whole project at once, with the TypeScript of your project. One error stops the build:This is the moment the “no type to write” of the editor pays off: every mistake it could underline is caught here, before anything is online. The
typecheck script of your project runs the same check alone.2
Runs every file once
Each command, event, component, task and language file is loaded and checked, exactly as
chapterjs dev does when you save: a name Discord refuses, an option without description, two files that are the same command. Each broken file is reported, then the build stops.3
Compiles the bot
Everything becomes one JavaScript file,
.chapterjs/build/bot.js: your files, what they import from your project, and nothing that is not used. The names you wrote are kept, with a map back to your files, so that an error in production still says src/commands/warn.ts:12.4
Runs what it compiled
The compiled file is loaded once, as production will load it. A file that runs from
src/ but not once compiled stops the build.What is in the build, and what is not
The compiling is done by esbuild, which comes with ChapterJS: nothing to install, nothing to configure, and it is only loaded by
chapterjs build.
Points of attention
- The build is a snapshot. Once built, editing a file changes nothing until you build again.
chapterjs startreminds you when the sources changed since the build. - A build belongs to a version of ChapterJS. After updating the package, build again; a build from another version is refused with what to run.
- Keep TypeScript installed where you build. Without it, the build says
ℹ Types were not checkedand goes on: the first line of defense is gone.
Recap
chapterjs buildchecks the types, runs every file, compiles the bot into.chapterjs/build, and runs the result once.- Any invalid file fails the build; a failed build leaves nothing.
- Production runs the build, not your files.
Going online
Start the build on a machine that stays on, with the production application.
Guide: chapterjs build
The same, with every message.