thrunium 0.0.0-stage → 1.2.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,192 @@
1
- # Temporary Holding Version
1
+ # Thrunium
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The official Thrungames game engine — a single-file, dependency-free browser
4
+ game library.
5
+
6
+ ## Usage
7
+
8
+ ```html
9
+ <script src="https://cdn.thrungames.com/thrunium/v1.1.0/thrunium.js"></script>
10
+ <!-- or the minified build (with a source map): -->
11
+ <script src="https://cdn.thrungames.com/thrunium/v1.1.0/thrunium.min.js"></script>
12
+ <script>
13
+ var v = new THRUNIUM.Vector(10, 10);
14
+ </script>
15
+ ```
16
+
17
+ The [CDN image](#cdn-image) serves the files at its root (`/thrunium.js`,
18
+ `/thrunium.min.js`). The CDN maps them under `/thrunium/v<version>/`, and
19
+ `https://cdn.thrungames.com/thrunium/versions.json` lists the published versions.
20
+
21
+ The engine attaches itself to the global `THRUNIUM` namespace. It has no runtime
22
+ dependencies. The source is TypeScript in `src/`; `npm run build` bundles it with
23
+ esbuild into a classic (non-module) script, `dist/thrunium.js` (readable) and
24
+ `dist/thrunium.min.js` plus `dist/thrunium.min.js.map` (minified). Both start
25
+ with a `/*! THRUNIUM v<version> | (c) Infobits ApS | MIT License */` banner and target ES2017.
26
+
27
+ > The `Storage` user-token members (`reqToken`, `userToken`, `timeout`,
28
+ > `loginPopup`, `accessRequested`, `_options`, `setReqToken`, `reqUserToken`,
29
+ > `_receiveMessage`, `request`) are work in progress: they talk to endpoints that no
30
+ > longer exist and will change when authentication is added.
31
+
32
+ ## Package and CLI
33
+
34
+ The engine is also on npm as `thrunium` (Node 24 or newer):
35
+
36
+ ```bash
37
+ npx thrunium init my-game # new TypeScript project; add --js for JavaScript
38
+ cd my-game && pnpm install && pnpm dev
39
+ ```
40
+
41
+ ```ts
42
+ import { Game } from 'thrunium';
43
+ ```
44
+
45
+ `exports` in `package.json`:
46
+
47
+ | Import | Gives you |
48
+ |---|---|
49
+ | `thrunium` | the engine as an ES module, with types |
50
+ | `thrunium/thrunium.js` | the readable classic script |
51
+ | `thrunium/thrunium.min.js` | the minified classic script |
52
+ | `thrunium/package.json` | the package manifest |
53
+
54
+ Commands (`thrunium --help`, `--version`):
55
+
56
+ | Command | Options |
57
+ |---|---|
58
+ | `thrunium dev` | `--port <n>` (default 3000, tries the next 10 ports if busy), `--host <name>` (default `localhost`), `--no-open` |
59
+ | `thrunium build` | `--out <dir>` (default `dist`), `--engine cdn\|bundle` |
60
+ | `thrunium init [dir]` | `--js` (TypeScript by default); the folder must be empty |
61
+
62
+ `dev` never uses the CDN. For a project with a module entry
63
+ (`<script type="module" src=...>` importing `thrunium`), `build` has two engine
64
+ modes. `cdn` (the default) adds a script tag for
65
+ `https://cdn.thrungames.com/thrunium/v<version>/thrunium.min.js` with a `sha384`
66
+ integrity hash, pinned to the installed version. It fails, and leaves the output
67
+ folder alone, if that version is not on the CDN or the CDN's file differs from
68
+ the installed one (for example with `npm link` or local changes). `bundle` copies
69
+ `thrunium.min.js` next to the game. Set `"thrunium": { "engine": "bundle" }` in
70
+ the game's `package.json` to make it the default; `--engine` wins. A script-tag
71
+ folder (no module entry) keeps its own Thrunium tag: `build` copies it unchanged,
72
+ without a CDN check, and `--engine bundle` is an error. The
73
+ `THRUNIUM_CDN_URL` environment variable replaces the CDN base URL (for tests).
74
+ See `docs/guides/getting-started.md` and `docs/guides/dev-and-build.md` for the full guides.
75
+
76
+ The release stages the npm package after the CDN publish succeeds, from the
77
+ tarball inside the scanned image. Prereleases (`1.2.0-rc.1`) go under the `next`
78
+ dist-tag, stable versions under `latest`. It needs the `NPM_TOKEN` Actions secret:
79
+ an npm granular token with "Read and write (stage only)" on `thrunium` and no
80
+ organization access. npm does not let CI tokens publish directly, so the version
81
+ goes live only when a maintainer approves it with 2FA:
82
+
83
+ ```bash
84
+ npm stage list thrunium # the id is also in the release log
85
+ npm stage approve <id> --otp <code>
86
+ ```
87
+
88
+ It refuses to stage if `license` is missing from `package.json`.
89
+
90
+ ## Development
91
+
92
+ Requires Node 24.
93
+
94
+ ```bash
95
+ npm ci
96
+ npm run build # dist/thrunium.js, dist/thrunium.min.js, source map
97
+ npm test # typecheck + build + unit and bundle tests, 90% line coverage
98
+ npm run coverage # unit and bundle tests with coverage (after a build)
99
+ npm run test:browser # real-Chromium tests (builds first)
100
+ npm run test:games # smoke-tests the sibling game repos against the built engine
101
+ ```
102
+
103
+ `VERSION=1.2.3 npm run build` stamps another version into the banner and
104
+ `THRUNIUM.version`; it defaults to `version` in `package.json` and must look like
105
+ `1.2.3` or `1.2.3-rc.1`.
106
+
107
+ `test:games` needs the game repositories checked out next to this one. Set
108
+ `GAMES_ENGINE_FILE` to point it at a different engine file (for example a 1.0.0
109
+ copy) to compare behavior.
110
+
111
+ Browser tests use Playwright's Chromium, or the system Chromium when
112
+ `CHROME_BIN` is set (as on the arm64 CI runner, where `--no-sandbox` is added
113
+ because it runs as root). Without `CHROME_BIN`, `test:browser` and `test:games`
114
+ need Playwright's Chromium installed once with `npx playwright-core install chromium`.
115
+
116
+ ## Docs
117
+
118
+ `VERSION=1.2.3 npm run docs` writes the versioned docs to `dist/docs/`: guides from
119
+ `docs/guides/` (listed in `docs/guides.json`) and one reference page per part of the
120
+ `THRUNIUM` global, generated from the doc comments in `src/`. It fails if a public
121
+ member has no description. The release image carries them at `/usr/share/thrunium/docs`
122
+ (never served over HTTP) and the release publishes them to the CDN next to the JS.
123
+
124
+ ## CDN image
125
+
126
+ The engine is distributed as a hardened static image serving the file over HTTP.
127
+
128
+ ```bash
129
+ docker build --build-arg VERSION=1.1.0 -t thrunium-game-engine:dev .
130
+
131
+ docker run --read-only --tmpfs /tmp \
132
+ --cap-drop ALL --security-opt no-new-privileges \
133
+ -p 8080:8080 thrunium-game-engine:dev
134
+ ```
135
+
136
+ `VERSION` is required and is stamped into the bundle. The image builds the
137
+ bundle in a Node 24 stage and serves only the output.
138
+
139
+ The hardening flags above are supplied by the operator and cannot be baked into
140
+ the image — run it this way in every environment.
141
+
142
+ | Route | Response |
143
+ |---|---|
144
+ | `GET /thrunium.js` | the engine, `Cache-Control: public, max-age=3600`, CORS `*` |
145
+ | `GET /thrunium.min.js` | the minified engine, same headers |
146
+ | `GET /thrunium.min.js.map` | its source map (`application/json`), same headers |
147
+ | `GET /healthz` | `200 ok` |
148
+ | anything else | `404` |
149
+
150
+ The container listens on **8080** as **UID 101**. It never runs as root.
151
+
152
+ ## Releases
153
+
154
+ Publishing a release on Forgejo builds the image for `linux/arm64` (the
155
+ cluster's architecture), scans it, and pushes it to Scaleway Container
156
+ Registry:
157
+
158
+ ```
159
+ rg.fr-par.scw.cloud/infobits/thrunium-game-engine:<version>
160
+ rg.fr-par.scw.cloud/infobits/thrunium-game-engine:latest
161
+ ```
162
+
163
+ The release tag must match the `version` in `package.json`, or the workflow
164
+ fails before building.
165
+
166
+ It then publishes the image's files to the `infobits-thrunium-cdn` bucket, which
167
+ `cdn.thrungames.com` serves, so a release needs no deploy step:
168
+
169
+ | CDN path | Holds |
170
+ |---|---|
171
+ | `/thrunium/v<version>/` | that version, never changed once published |
172
+ | `/thrunium/v<major>/`, `/thrunium/v<major>.<minor>/` | the newest release in that range |
173
+ | `/thrunium/latest/` | the newest release |
174
+ | `/thrunium/versions.json` (also `/thrunium/`) | JSON list of versions, aliases and files |
175
+
176
+ Prereleases (`1.2.0-rc.1`) get an exact-version path but never an alias.
177
+ Publishing a version again is a no-op if its files are unchanged, and fails if
178
+ they differ. To publish an already-released version (for example, one released
179
+ before the bucket existed), dispatch `publish-cdn.yml` with its version:
180
+
181
+ ```bash
182
+ fj actions dispatch publish-cdn.yml main -I version=1.1.0
183
+ ```
184
+
185
+ Both workflows need the `THRUNIUM_CDN_ACCESS_KEY` and `THRUNIUM_CDN_SECRET_KEY`
186
+ Actions secrets.
187
+
188
+ ## License
189
+
190
+ MIT, see [LICENSE](LICENSE). The names "Thrunium" and "ThrunGames" are
191
+ trademarks of Infobits ApS: [TRADEMARKS.md](TRADEMARKS.md) explains how you
192
+ can use them.