@moku-labs/game 0.0.1 → 0.0.3

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.
@@ -0,0 +1,213 @@
1
+ import { l as Manifest } from "./types-DgwbzDLP.mjs";
2
+
3
+ //#region src/plugins/assets/scan/cli.d.ts
4
+ /**
5
+ * The part of the branded console the scanner writes through. A `BrandConsole` fits it, and a
6
+ * test passes a recorder instead.
7
+ */
8
+ type ScanUi = {
9
+ /** Writes one neutral line. */info(message: string): void; /** Writes one warning line. */
10
+ warn(message: string): void; /** Writes one error line. */
11
+ error(message: string, cause?: unknown): void;
12
+ };
13
+ /** What one strings compile reports back. `CompileReport` of i18n has this shape. */
14
+ type StringsReport = {
15
+ /** True when an output on disk differs from what the compile produced. */changed: boolean; /** Every locale a feature brought a file for, sorted. */
16
+ locales: readonly string[]; /** Every message key, sorted. */
17
+ keys: readonly string[]; /** One line per key a locale lacks. Nothing here stops a build. */
18
+ notes: readonly string[];
19
+ };
20
+ /**
21
+ * Compiles the feature strings of a root into a folder, or checks them in a check run.
22
+ * `compileStrings` of i18n fits it, and a test passes a stub instead.
23
+ */
24
+ type StringsCompiler = (root: string, out: string, options: {
25
+ check: boolean;
26
+ }) => Promise<StringsReport>;
27
+ /**
28
+ * Runs the asset key scanner: walk the features, write the manifest and the key module, then
29
+ * compile the feature strings next to the key module, or check that all of it is current. With
30
+ * `--pack <dir>` it packs the art for production on the same scan (`--no-cache` for a cold run).
31
+ * Nothing here calls `process.exit`; the caller does.
32
+ *
33
+ * @param argv - The arguments after the script name.
34
+ * @param compile - The strings compiler, `compileStrings` of i18n.
35
+ * @param ui - Where the lines go. The branded console by default.
36
+ * @returns The exit code: `1` when the scan, the compile or the pack failed or `--check` found a
37
+ * difference, else `0`.
38
+ * @example
39
+ * ```ts
40
+ * await runCli(["--root", "src", "--manifest", "public/assets/manifest.json", "--check"], compileStrings);
41
+ * // 1 when public/assets/manifest.json is older than the files in src/features
42
+ *
43
+ * await runCli(["--root", "src", "--keys", "src/generated/assets.ts", "--pack", "dist/assets"], compileStrings);
44
+ * // 0, and dist/assets holds the pages, the loose files and the packed manifest.json
45
+ * ```
46
+ */
47
+ declare function runCli(argv: string[], compile: StringsCompiler, ui?: ScanUi): Promise<number>;
48
+ //#endregion
49
+ //#region src/plugins/i18n/compile/compile.d.ts
50
+ /**
51
+ * What one compile produced.
52
+ */
53
+ type CompileReport = {
54
+ /** True when an output on disk differs from what the compile produced. */changed: boolean; /** Every locale a feature brought a file for, sorted. */
55
+ locales: readonly string[]; /** Every message key, sorted. */
56
+ keys: readonly string[]; /** One line per key a locale lacks. Nothing here stops a build. */
57
+ notes: readonly string[];
58
+ };
59
+ /**
60
+ * What one compile is told beyond its two paths.
61
+ */
62
+ type CompileOptions = {
63
+ /** True for a check run: nothing is written. */check?: boolean; /** Name of the folder that holds the features. Default `"features"`. */
64
+ features?: string;
65
+ };
66
+ /**
67
+ * Walks `features/*​/strings/<locale>.json` of a game, compiles every message and writes the
68
+ * generated modules: the types module `strings.ts` and one `strings.<locale>.ts` per locale. A
69
+ * check run writes nothing and only reports whether something would change.
70
+ *
71
+ * @param root - Game source root, the folder that holds the features.
72
+ * @param out - The generated directory the modules are written into.
73
+ * @param options - Whether this is a check run, and what the features folder is called.
74
+ * @returns Whether an output differed, the locales, the keys and the notes.
75
+ * @throws {Error} One error that lists every problem the compile found.
76
+ * @example
77
+ * ```ts
78
+ * const report = await compileStrings("src", "src/generated");
79
+ * // report.locales: ["en", "ru"], report.changed: true on the first run
80
+ * ```
81
+ */
82
+ declare function compileStrings(root: string, out: string, options?: CompileOptions): Promise<CompileReport>;
83
+ /**
84
+ * Tells whether the generated modules of a game are current, without writing anything. The
85
+ * `--check` run of `bun run assets:keys` covers the strings with it.
86
+ *
87
+ * @param root - Game source root, the folder that holds the features.
88
+ * @param out - The generated directory the modules live in.
89
+ * @returns True when nothing would change.
90
+ * @throws {Error} One error that lists every problem the compile found.
91
+ * @example
92
+ * ```ts
93
+ * await checkStrings("src", "src/generated"); // false when a message changed since the last run
94
+ * ```
95
+ */
96
+ declare function checkStrings(root: string, out: string): Promise<boolean>;
97
+ //#endregion
98
+ //#region src/plugins/assets/scan/emit.d.ts
99
+ /**
100
+ * Writes `manifest.json`: two-space JSON with a trailing newline, bundles sorted by name, pages
101
+ * by id and files by key. The version is written as given: `1` from the scanner, `2` from the
102
+ * packer.
103
+ *
104
+ * @param manifest - What the scan produced.
105
+ * @returns The text of the file.
106
+ * @example
107
+ * ```ts
108
+ * emitManifest({ version: 1, bundles: {} }); // '{\n "version": 1,\n "bundles": {}\n}\n'
109
+ * ```
110
+ */
111
+ declare function emitManifest(manifest: Manifest): string;
112
+ /**
113
+ * Writes `generated/assets.ts`: `AssetKey` over every kind, the narrower `FontKey` and `AudioKey`
114
+ * next to it, `BundleKey`, and the nine-slice table. A game commits this file, so `defineGame` can
115
+ * type `Sprite`, a text style, a sound, `defineBundles` and the `load` effect from it.
116
+ *
117
+ * @param manifest - What the scan produced.
118
+ * @returns The text of the module.
119
+ * @example
120
+ * ```ts
121
+ * emitKeys({ version: 1, bundles: {} });
122
+ * // the header, four unions that are all "never" and an empty nine-slice table
123
+ * ```
124
+ */
125
+ declare function emitKeys(manifest: Manifest): string;
126
+ //#endregion
127
+ //#region src/plugins/assets/scan/pack/pack.d.ts
128
+ /**
129
+ * What one pack is told: where the sources are, what the scan found and where everything goes.
130
+ */
131
+ type PackOptions = {
132
+ /** Path of the game source root: the `path` of every file of `manifest` is relative to it. */root: string; /** The manifest the scan produced (version 1, loose files). */
133
+ manifest: Manifest; /** The pack folder. It belongs to the command: created, written and pruned. */
134
+ out: string; /** Where the packed manifest (version 2) goes. */
135
+ manifestFile: string; /** The cache folder, or `false` for a run that neither reads nor writes the cache. */
136
+ cache: string | false;
137
+ };
138
+ /**
139
+ * What a pack wrote.
140
+ */
141
+ type PackResult = {
142
+ /** The packed manifest, version 2, as written. */manifest: Manifest; /** How many atlas pages the pack folder holds. */
143
+ pages: number; /** How many textures stayed files of their own. */
144
+ loose: number; /** The bytes of every file the manifest references. */
145
+ bytes: number; /** How many of the pages were replayed from the cache. */
146
+ cacheHits: number;
147
+ };
148
+ /**
149
+ * Packs the art of a game for production: per bundle, the textures of the `fx` group and of the
150
+ * `main` group go onto WebP atlas pages (2048 px at most, 2 px padding and border, never trimmed
151
+ * or rotated), a texture with a side above 512 px and a group of one stay loose files, fonts and
152
+ * sounds are copied, every file name carries the hash of its bytes, and the packed manifest
153
+ * (version 2) names it all. Nothing is written while a problem is open; afterwards the pack folder
154
+ * holds exactly what the manifest references, plus `manifest.json`. Two runs on the same tree and
155
+ * the same `sharp` write the same bytes.
156
+ *
157
+ * @param options - The sources, the scanned manifest, the pack folder, the manifest file, the cache.
158
+ * @returns The packed manifest and what was written.
159
+ * @throws {Error} One error that lists every problem, when `sharp` is missing, or when the pack
160
+ * folder holds the sources.
161
+ * @example
162
+ * ```ts
163
+ * // After `scanAssets` read the features of the game. `cache: false` skips the cache.
164
+ * const { manifest, pages, cacheHits } = await packAssets({
165
+ * root: "src", manifest: scanned, cache: "node_modules/.cache/moku-game-pack",
166
+ * out: "dist/assets", manifestFile: "dist/assets/manifest.json"
167
+ * });
168
+ * // manifest.version: 2; on a second run with the same art, cacheHits equals pages
169
+ * ```
170
+ */
171
+ declare function packAssets(options: PackOptions): Promise<PackResult>;
172
+ //#endregion
173
+ //#region src/plugins/assets/scan/scan.d.ts
174
+ /**
175
+ * What one scan is told: where the features are and where the two generated files go.
176
+ */
177
+ type ScanOptions = {
178
+ /** Path of the game source root, the folder that holds the features. */root: string; /** Name of the folder that holds the features. Default `"features"`. */
179
+ features?: string; /** Path of the `manifest.json` to write. */
180
+ manifest: string; /** Path of the generated key module to write. */
181
+ keys: string; /** False for a check run: nothing is written. Default true. */
182
+ write?: boolean;
183
+ };
184
+ /**
185
+ * What a scan produced.
186
+ */
187
+ type ScanResult = {
188
+ /** The manifest, with bundles sorted by name and files sorted by key. */manifest: Manifest; /** The text of the generated key module. */
189
+ keysSource: string; /** True when an output on disk differs from what the scan produced. */
190
+ changed: boolean; /** One line per file the scan left out. Nothing here stops a build. */
191
+ notes: readonly string[];
192
+ };
193
+ /**
194
+ * Walks the features of a game and writes its two generated files: one bundle per feature, split
195
+ * by the optional `assets.ts` of that feature, every file keyed by the key rule. A check run
196
+ * (`write: false`) writes nothing and only reports whether something would change.
197
+ *
198
+ * @param options - The game source root, the two output paths and whether to write.
199
+ * @returns The manifest, the text of the key module and whether an output differed.
200
+ * @throws {Error} One error that lists every problem the scan found.
201
+ * @example
202
+ * ```ts
203
+ * const { manifest, changed } = await scanAssets({
204
+ * root: "src",
205
+ * manifest: "public/assets/manifest.json",
206
+ * keys: "src/generated/assets.ts"
207
+ * });
208
+ * // manifest.bundles.ui.files[0].key: "ui.button.primary", changed: true on the first run
209
+ * ```
210
+ */
211
+ declare function scanAssets(options: ScanOptions): Promise<ScanResult>;
212
+ //#endregion
213
+ export { type CompileOptions, type CompileReport, type PackOptions, type PackResult, type ScanOptions, type ScanResult, type ScanUi, type StringsCompiler, type StringsReport, checkStrings, compileStrings, emitKeys, emitManifest, packAssets, runCli, scanAssets };