@cybermp-community/resource-builder 0.0.0-stage → 0.1.0

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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +303 -2
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/cli.js +584 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/index.d.ts +1040 -0
  7. package/dist/index.js +1 -0
  8. package/dist/run-CmhtmY2x.js +7018 -0
  9. package/dist/run-CmhtmY2x.js.map +1 -0
  10. package/package.json +64 -3
  11. package/schema/config.json +122 -0
  12. package/templates/project-default/Dockerfile +17 -0
  13. package/templates/project-default/README.md +57 -0
  14. package/templates/project-default/_dockerignore +26 -0
  15. package/templates/project-default/_gitignore +32 -0
  16. package/templates/project-default/addons/gamemode/browser/env.d.ts +1 -0
  17. package/templates/project-default/addons/gamemode/browser/index.html +12 -0
  18. package/templates/project-default/addons/gamemode/browser/package.json +21 -0
  19. package/templates/project-default/addons/gamemode/browser/src/App.vue +40 -0
  20. package/templates/project-default/addons/gamemode/browser/src/global.d.ts +7 -0
  21. package/templates/project-default/addons/gamemode/browser/src/main.ts +4 -0
  22. package/templates/project-default/addons/gamemode/browser/tsconfig.json +7 -0
  23. package/templates/project-default/addons/gamemode/browser/vite.config.ts +15 -0
  24. package/templates/project-default/addons/gamemode/client/src/global.d.ts +5 -0
  25. package/templates/project-default/addons/gamemode/client/src/index.ts +11 -0
  26. package/templates/project-default/addons/gamemode/client/tsconfig.json +4 -0
  27. package/templates/project-default/addons/gamemode/package.json +22 -0
  28. package/templates/project-default/addons/gamemode/resource.toml +12 -0
  29. package/templates/project-default/addons/gamemode/server/src/global.d.ts +5 -0
  30. package/templates/project-default/addons/gamemode/server/src/index.ts +13 -0
  31. package/templates/project-default/addons/gamemode/server/tsconfig.json +7 -0
  32. package/templates/project-default/addons/gamemode/shared/src/index.ts +2 -0
  33. package/templates/project-default/biome.json +43 -0
  34. package/templates/project-default/cybermp.config.json +6 -0
  35. package/templates/project-default/docker-compose.yml +19 -0
  36. package/templates/project-default/package.json +25 -0
  37. package/templates/project-default/pnpm-workspace.yaml +6 -0
  38. package/templates/project-default/server.toml +21 -0
  39. package/templates/project-default/tsconfig.json +7 -0
  40. package/templates/types.json +15 -0
  41. package/tsconfig.base.json +17 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CyberMP Community
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,304 @@
1
- # Temporary Holding Version
1
+ # @cybermp-community/resource-builder
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 project side of the [CyberMP resource toolchain](../../README.md): project
4
+ configuration, addon resolution from npm / GitHub / GitLab / URLs / local
5
+ paths, esbuild bundling, `server.toml` maintenance, redscript compilation,
6
+ server binaries and the `cybermp` CLI.
7
+
8
+ Requires Node.js 22 or newer.
9
+
10
+ ```bash
11
+ pnpm add -D @cybermp-community/resource-builder
12
+ pnpm exec cybermp --help
13
+ ```
14
+
15
+ An addon author does not need this package: the contract and the validator
16
+ live in [`@cybermp-community/addon`](../addon).
17
+
18
+ ## Quick start
19
+
20
+ ```bash
21
+ pnpm exec cybermp init my-project # render the project template
22
+ cd my-project
23
+ pnpm exec cybermp create addon hud # scaffold addons/hud
24
+ pnpm exec cybermp download # server binaries into .cybermp/mp
25
+ pnpm exec cybermp build # bundles, resources, server.toml
26
+ pnpm exec cybermp run # start the server
27
+ ```
28
+
29
+ ## Project layout
30
+
31
+ | Path | What it is |
32
+ | --- | --- |
33
+ | `cybermp.config.json` | Optional project configuration. Every key has a default. |
34
+ | `cybermp.lock.json` | Committed record of addons that did not come from npm (releases and local paths), with their sha256. |
35
+ | `server.toml` | The server configuration. **Always** at the project root (the server reads it from its working directory and has no path flag); the build rewrites its `resources` array and nothing else. |
36
+ | `resources/` | `resourcesDir` — what the server gets as `-rdir`. The build writes addon directories there and tracks which ones it owns in `built.json`. |
37
+ | `.cybermp/` | `workDir` — build state: compiler cache, unpacked release addons, `built.json` (which directories the build owns) and `.addons.json` (what was built). Deleting it between builds is safe; the build recreates it, except that it then no longer remembers which directories in `resourcesDir` it owns. |
38
+ | `addons/` | Local source addons, matched by `addons.local`. |
39
+
40
+ ## Configuration
41
+
42
+ `cybermp.config.json` is read from the project root; without it every default
43
+ applies. The key set is closed: an unknown key is `config.unknown-key`, and
44
+ `serverToml` / `build` are deliberately not project keys (the first is fixed,
45
+ the second lives in each addon's `package.json`).
46
+
47
+ ```json
48
+ {
49
+ "$schema": "./node_modules/@cybermp-community/resource-builder/schema/config.json",
50
+ "resourcesDir": "resources",
51
+ "workDir": ".cybermp",
52
+ "addons": {
53
+ "local": ["addons/*"],
54
+ "order": ["economy", "hud"],
55
+ "overrides": { "hud": { "cef_url": "http://localhost:5173" } },
56
+ "disabled": [],
57
+ "extraResources": []
58
+ },
59
+ "redscripts": {
60
+ "enabled": true,
61
+ "compilerVersion": "0.5.31",
62
+ "baseline": "core",
63
+ "output": "final_redscripts"
64
+ },
65
+ "server": { "platforms": ["linux"], "version": "v4.0.5-beta.2" }
66
+ }
67
+ ```
68
+
69
+ | Key | Type | Default | Meaning |
70
+ | --- | --- | --- | --- |
71
+ | `$schema` | string | — | Editor schema URL. Ignored by the build. |
72
+ | `resourcesDir` | string | `"resources"` | Directory passed to `-rdir`. Relative values resolve against the project root. |
73
+ | `workDir` | string | `".cybermp"` | Compiler cache, unpacked release addons and build records. Relative values resolve against the project root. |
74
+ | `addons.local` | string[] | `["addons/*"]` | Directory globs that resolve local source addons. Absolute globs and `..` segments are rejected. |
75
+ | `addons.order` | string[] | `[]` | Explicit load order by resource name. Addons not listed follow in dependency-graph order. |
76
+ | `addons.overrides` | object | `{}` | Manifest edits applied to the **materialized copy** (not `node_modules`), keyed by resource name. Only `cef_url`, `hotreload`, `use_game_natives`. |
77
+ | `addons.disabled` | string[] | `[]` | Addons kept installed but neither built nor listed in `server.toml`. The only way to switch one off. |
78
+ | `addons.extraResources` | string[] | `[]` | Hand-managed resources already in `resourcesDir`; copied into `server.toml` as they are. |
79
+ | `redscripts.enabled` | boolean | `true` | Whether `final_redscripts` is built at all. |
80
+ | `redscripts.compilerVersion` | string | `"0.5.31"` | Pinned `redscript-cli` version. `0.5.31` is the version that can read the shipped core baseline; `1.0.x` cannot. |
81
+ | `redscripts.platform` | `"win" \| "linux"` | — | Platform whose compiler and core baseline are used. Resolved as this field, then `server.platforms[0]`, then the host platform. |
82
+ | `redscripts.baseline` | string | `"core"` | `core` uses the downloaded core `final.redscripts`; `none` compiles with the core sources (needs `CYBERMP_REDSCRIPT_COMPILER`, because the pinned compiler requires `-b`); any other value is a path to a baseline file. |
83
+ | `redscripts.output` | string | `"final_redscripts"` | Resource name of the compiled scripts: one lowercase path segment, never a name the project already uses. |
84
+ | `server.platforms` | `("win" \| "linux")[]` | host platform | Server builds to keep downloaded. `download` installs all of them unless `--platform` is given. |
85
+ | `server.version` | string | latest release | Pinned server release tag. |
86
+
87
+ Precedence: CLI flags, then `cybermp.config.json`, then the `cybermp` field of
88
+ an addon's `package.json`, then the defaults.
89
+
90
+ ## Commands
91
+
92
+ ```
93
+ cybermp init [dir] [--template=<name>] [--types=<community|official>] [--pm=<pm>]
94
+ [--no-install] [--no-lint] [--force]
95
+ cybermp create addon <name> [dir] [--realms=<client,server,shared,browser>] [--shared]
96
+ [--types=<community|official>] [--no-install] [--pm=<pm>]
97
+ cybermp build [dir] [--filter=<resource>] [--no-browser] [--no-redscripts]
98
+ cybermp check [dir] [--no-redscripts]
99
+ cybermp add <spec> [dir] [--first|--before=<name>|--after=<name>] [--asset=<name|glob>]
100
+ [--copy] [--pm=<pm>]
101
+ cybermp remove <name-or-package> [dir] [--pm=<pm>]
102
+ cybermp list [dir]
103
+ cybermp install [dir] [--pm=<pm>]
104
+ cybermp update [name] [dir] [--to=<tag>]
105
+ cybermp download [dir] [--platform=<win|linux>] [--version=<tag>] [--latest]
106
+ cybermp run [dir] [--prod]
107
+ ```
108
+
109
+ `<dir>` is the project directory and defaults to the current directory.
110
+
111
+ | Command | What it does |
112
+ | --- | --- |
113
+ | `init` | Renders a project template (default `project-default`) into an empty directory, pins the type packages, runs `<pm> install` and prints the next steps. `--force` allows a non-empty directory; `--no-lint` leaves biome out; `--no-install` skips the install. |
114
+ | `create addon` | Scaffolds `addons/<name>` inside an existing project: package marker, `resource.toml`, one realm per `--realms` entry (`client,server` by default, `--shared` adds `shared`), each realm's `tsconfig.json` and type packages. Appends the addon to `addons.local`. |
115
+ | `build` | Resolves the project, builds local addons with esbuild, materializes every addon into `resourcesDir`, compiles `final_redscripts`, rewrites `server.toml` and writes `<workDir>/.addons.json`. |
116
+ | `check` | Validates without writing: every addon against the contract, and `server.toml`'s `resources` array against the order a build would write. Never resolves or downloads a compiler. |
117
+ | `add` | Installs one addon from `@scope/pkg[@range]`, `gh:owner/repo[@tag]`, `gl:group/repo[@tag]`, an `https://` archive URL or a local path; validates it and registers it in `addons.order`. A failed validation rolls the install back. |
118
+ | `remove` | Removes an npm dependency, a lock entry, or a local addon registered in `addons.local` (deleting its directory once no remaining glob matches it), and its `addons.order` entry. Accepts a resource name or an npm package name. |
119
+ | `list` | One row per installed addon: name, version, source, order position. |
120
+ | `install` | Runs the package manager's install and restores every release addon recorded in `cybermp.lock.json` (verifying its sha256). |
121
+ | `update` | Re-resolves releases to the latest tag (a pinned tag stays pinned unless `--to` is given) and recomputes the hash of local path addons. |
122
+ | `download` | Downloads the CyberMP server builds for `server.platforms` (or `--platform`) into `<workDir>/mp/<platform>`. `--version` and `--latest` are mutually exclusive. |
123
+ | `run` | Starts `<workDir>/mp/<platform>/cybermp-server -run -rdir=<resourcesDir>` with the project as its working directory; `--prod` sets `NODE_ENV=production`, otherwise `development`. A non-zero server exit becomes the CLI's exit code. |
124
+
125
+ Notes on the build flags:
126
+
127
+ - `--filter=<resource>` builds only the addon with that resource name. The
128
+ other addons stay in `server.toml`; only the selected one is rebuilt. A value
129
+ that names no resolved addon is `build.unknown-filter`, not a build that
130
+ quietly does nothing; a name that *is* resolved but sits in `addons.disabled`
131
+ is refused with the same code and a message that says the addon is disabled,
132
+ so a typo and a deliberate exclusion do not read alike.
133
+ - `--no-browser` skips the CEF build of local addons. A `browser/` directory a
134
+ previous build produced is kept, so the manifest and a local `cef_url` still
135
+ point at a UI instead of a missing directory.
136
+ - `--no-redscripts` skips the redscripts stage entirely: no compile, and
137
+ `final_redscripts` is left out of `server.toml`. `check --no-redscripts`
138
+ accepts a `resources` list without it.
139
+
140
+ Watch mode is not available in this release: `build --watch` is a usage error
141
+ (exit `2`) that says so, rather than building once and exiting as if it were
142
+ watching.
143
+
144
+ Values shared by several commands: `--pm` is one of `pnpm`, `npm`, `yarn` or
145
+ `bun` (default: detected from the project's `packageManager` field or lockfile;
146
+ when nothing is detected, `init` falls back to `pnpm` and the other commands to
147
+ `npm`); `--types` is `community` or `official` (`none` for `create addon` only;
148
+ default: the mixed set described under [Types](#types)); `--realms` is a
149
+ comma-separated subset of `client`, `server`, `shared`, `browser`. `add` positions
150
+ the addon in `addons.order` with `--first`, `--before=<name>` or
151
+ `--after=<name>`.
152
+
153
+ ## Exit codes and output
154
+
155
+ | Exit code | Meaning |
156
+ | --- | --- |
157
+ | `0` | Success. For `check`, no errors (warnings do not fail it). |
158
+ | `1` | Validation or build failure, or an internal error the CLI reports as `cybermp: <message>` on stderr. |
159
+ | `2` | Usage error: unknown command or option, a flag the command does not take, a bad flag value. The usage block is printed. |
160
+
161
+ Output contract, because CI reads it:
162
+
163
+ - `build` prints one line on stdout (`built N resources: ...`) and nothing else.
164
+ - `check` prints every issue on **stderr** as `<level> <code> <path>: <message>`
165
+ and its one-line summary on **stdout** (`checked <dir>: N errors, M warnings`),
166
+ so stderr stays pure diagnostics.
167
+ - Failures are `BuilderError`s: the message is `<code>: <human message>` and the
168
+ code is stable and machine-readable, shaped `area.reason` (`config.parse`,
169
+ `path.missing`, `manifest.legacy-files`, `compiler.integrity`, `server.download`,
170
+ …). Codes never change meaning between releases; messages may be reworded.
171
+
172
+ ## Addon sources
173
+
174
+ | Source | Syntax | What appears in the project |
175
+ | --- | --- | --- |
176
+ | npm | `@scope/pkg`, `@scope/pkg@1.2.0` | a dependency in `package.json`; resolution stays in the package manager's lockfile |
177
+ | release | `gh:owner/repo@v1.2.0`, `gl:group/repo@v1.2.0`, or a direct archive URL | an entry in `cybermp.lock.json`; unpacked into `<workDir>/addons/<name>/` |
178
+ | path | `./addons/hud`, `../shared-addon` | a glob in `addons.local`, no copying (`--copy` snapshots it to `./addons/<resource>`) |
179
+
180
+ For releases, the toolchain takes the single archive when the release ships
181
+ one; several archives require `--asset=<name|glob>`; none is an error with a
182
+ hint to pass a direct URL. `.zip` and `.tar.gz` are supported and must contain
183
+ `package.json` and `resource.toml` at the root. The resource name and version
184
+ always come from `package.json` inside the addon, never from the tag; a
185
+ mismatch with the tag is a warning. Two sources claiming one resource name is
186
+ an error.
187
+
188
+ `add` and `update` write `cybermp.config.json` only through its `addons` keys;
189
+ the rest of your configuration and comments are left alone.
190
+
191
+ ## The lock file
192
+
193
+ `cybermp.lock.json` is committed and covers everything npm's lockfile cannot:
194
+ release archives and local paths. npm addons are never recorded here — their
195
+ lockfile is the package manager's.
196
+
197
+ ```json
198
+ {
199
+ "version": 1,
200
+ "addons": {
201
+ "hud": {
202
+ "source": "release",
203
+ "resolved": "1.2.0",
204
+ "integrity": "sha256-…",
205
+ "url": "https://github.com/acme/cybermp-hud/releases/download/v1.2.0/cybermp-hud.zip",
206
+ "tag": "v1.2.0",
207
+ "pinned": true
208
+ },
209
+ "economy": {
210
+ "source": "path",
211
+ "resolved": "0.3.0",
212
+ "path": "addons/economy"
213
+ }
214
+ }
215
+ }
216
+ ```
217
+
218
+ Entries are keyed by **resource name**, serialized deterministically (sorted
219
+ keys, two-space indent), and verified on `install` and `build`: a release whose
220
+ archive no longer matches `integrity`, or whose unpacked copy is gone, fails
221
+ with a `cybermp install` hint instead of building something different from what
222
+ was locked. A key must be a usable, non-reserved resource name (`lock.parse`
223
+ otherwise), and it must equal the `cybermp.resource` of the package installed
224
+ under it (`addons.name-mismatch` otherwise) — the lock follows the resource the
225
+ project loads, and a hand-edited key cannot rename what the package ships. A
226
+ missing file is an empty lock.
227
+
228
+ ## Types
229
+
230
+ `init` and `create addon` pin type packages from
231
+ `templates/types.json`, which the typecheck gate (`scripts/types-smoke.mjs` in
232
+ this repository) verifies: it builds the smallest addon per realm, installs the
233
+ pinned package and runs `tsc --noEmit`, so a pin that does not compile fails the
234
+ gate. The default is the official `@cybermp/*` set for every realm.
235
+ `--types=community` pins the community set instead and refuses a realm the gate
236
+ recorded as `blocked` with `types.blocked` rather than substituting — today
237
+ `client`, because `@cybermp-community/client-types` 2.6.1 ships `.ts` sources
238
+ that fail typecheck (`TS2578` in `dist/precomputed/voice-chat.ts`, which
239
+ `skipLibCheck` cannot suppress). `--types=none` installs no package and leaves
240
+ `mp` declared as `unknown`.
241
+
242
+ ## Environment variables
243
+
244
+ | Variable | Used by | Effect |
245
+ | --- | --- | --- |
246
+ | `CYBERMP_REDSCRIPT_COMPILER` | `build` | Absolute path to a `redscript-cli` binary; skips the download and the pinned-digest check. |
247
+ | `CYBERMP_VERSION` | `download` | Server release tag when neither `--version` / `--latest` nor `server.version` names one. |
248
+ | `CYBERMP_DOWNLOAD_BASE` | `download` | Replaces the release download root (mirror or offline cache). |
249
+ | `GITHUB_TOKEN` | `add`, `install`, `update` | Authenticates GitHub API calls: private repositories and rate limits. |
250
+ | `GITLAB_TOKEN` | `add`, `install`, `update` | Same for GitLab. |
251
+ | `GITLAB_HOST` | `add`, `install`, `update` | GitLab host for `gl:` specs (default `gitlab.com`). |
252
+ | `NODE_ENV` | `run` | Not read from the parent: `run` sets it to `production` with `--prod`, `development` without. |
253
+
254
+ ## Build stages
255
+
256
+ 1. **State check** — npm dependencies and locked releases are resolved up
257
+ front, so a missing or unverifiable addon fails before anything is written.
258
+ 2. **Resolution** — local, npm and release addons, ordered by `requires`
259
+ (`addons.order` first, then graph order).
260
+ 3. **Cleanup** — only the directories recorded in `<workDir>/built.json` are
261
+ removed; a directory the build did not create is never deleted.
262
+ 4. **Local builds** — each source addon is bundled with esbuild (client `iife`,
263
+ server `cjs`, both `esnext`/`node22` by default) and its browser app is built
264
+ or copied.
265
+ 5. **Materialization** — every addon's manifest and referenced files are copied
266
+ into `resourcesDir`; a source addon's scripts come from the build.
267
+ 6. **Redscripts** — the core baseline is resolved and every addon's `.reds` are
268
+ compiled into `final_redscripts`. A flat name space means two addons with the
269
+ same `.reds` file name is an error (`redscripts.collision`, naming both
270
+ addons and both paths), not a silent overwrite.
271
+ 7. **`server.toml`** — the `resources` array becomes `final_redscripts` (when
272
+ built), then the ordered addons, then `addons.extraResources`. Everything
273
+ outside that array — comments, other keys, line endings — is preserved
274
+ byte-for-byte.
275
+
276
+ ## Programmatic API
277
+
278
+ The CLI is a thin wrapper; the same functions are exported for scripts:
279
+
280
+ ```ts
281
+ import { buildProject, checkProject, loadConfig } from '@cybermp-community/resource-builder';
282
+
283
+ const config = await loadConfig(process.cwd());
284
+ const report = await buildProject(config.root, { filter: 'hud' });
285
+ const result = await checkProject(config.root);
286
+ if (!result.ok) for (const issue of result.issues) console.error(issue.code, issue.message);
287
+ ```
288
+
289
+ `BuilderError` carries the same stable `code` the CLI prints. Resolution,
290
+ materialization, the lock file and the redscripts helpers are exported too.
291
+
292
+ ## Development
293
+
294
+ ```bash
295
+ pnpm --dir packages/resource-builder build # tsdown → dist/ (the CLI tests run dist/cli.js)
296
+ pnpm --dir packages/resource-builder test # vitest
297
+ ```
298
+
299
+ `prepublishOnly` runs exactly those two steps, building first because the CLI
300
+ suite spawns the published `dist/cli.js`.
301
+
302
+ ## License
303
+
304
+ MIT
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {}