@moku-labs/game 0.0.1 → 0.0.2

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,161 @@
1
+ import { l as Manifest } from "./types-DWILGrPn.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.
30
+ * Nothing here calls `process.exit`; the caller does.
31
+ *
32
+ * @param argv - The arguments after the script name.
33
+ * @param compile - The strings compiler, `compileStrings` of i18n.
34
+ * @param ui - Where the lines go. The branded console by default.
35
+ * @returns The exit code: `1` when the scan or the compile failed or `--check` found a difference, else `0`.
36
+ * @example
37
+ * ```ts
38
+ * await runCli(["--root", "src", "--manifest", "public/assets/manifest.json", "--check"], compileStrings);
39
+ * // 1 when public/assets/manifest.json is older than the files in src/features
40
+ * ```
41
+ */
42
+ declare function runCli(argv: string[], compile: StringsCompiler, ui?: ScanUi): Promise<number>;
43
+ //#endregion
44
+ //#region src/plugins/i18n/compile/compile.d.ts
45
+ /**
46
+ * What one compile produced.
47
+ */
48
+ type CompileReport = {
49
+ /** True when an output on disk differs from what the compile produced. */changed: boolean; /** Every locale a feature brought a file for, sorted. */
50
+ locales: readonly string[]; /** Every message key, sorted. */
51
+ keys: readonly string[]; /** One line per key a locale lacks. Nothing here stops a build. */
52
+ notes: readonly string[];
53
+ };
54
+ /**
55
+ * What one compile is told beyond its two paths.
56
+ */
57
+ type CompileOptions = {
58
+ /** True for a check run: nothing is written. */check?: boolean; /** Name of the folder that holds the features. Default `"features"`. */
59
+ features?: string;
60
+ };
61
+ /**
62
+ * Walks `features/*​/strings/<locale>.json` of a game, compiles every message and writes the
63
+ * generated modules: the types module `strings.ts` and one `strings.<locale>.ts` per locale. A
64
+ * check run writes nothing and only reports whether something would change.
65
+ *
66
+ * @param root - Game source root, the folder that holds the features.
67
+ * @param out - The generated directory the modules are written into.
68
+ * @param options - Whether this is a check run, and what the features folder is called.
69
+ * @returns Whether an output differed, the locales, the keys and the notes.
70
+ * @throws {Error} One error that lists every problem the compile found.
71
+ * @example
72
+ * ```ts
73
+ * const report = await compileStrings("src", "src/generated");
74
+ * // report.locales: ["en", "ru"], report.changed: true on the first run
75
+ * ```
76
+ */
77
+ declare function compileStrings(root: string, out: string, options?: CompileOptions): Promise<CompileReport>;
78
+ /**
79
+ * Tells whether the generated modules of a game are current, without writing anything. The
80
+ * `--check` run of `bun run assets:keys` covers the strings with it.
81
+ *
82
+ * @param root - Game source root, the folder that holds the features.
83
+ * @param out - The generated directory the modules live in.
84
+ * @returns True when nothing would change.
85
+ * @throws {Error} One error that lists every problem the compile found.
86
+ * @example
87
+ * ```ts
88
+ * await checkStrings("src", "src/generated"); // false when a message changed since the last run
89
+ * ```
90
+ */
91
+ declare function checkStrings(root: string, out: string): Promise<boolean>;
92
+ //#endregion
93
+ //#region src/plugins/assets/scan/emit.d.ts
94
+ /**
95
+ * Writes `manifest.json`: two-space JSON with a trailing newline, bundles sorted by name and
96
+ * files sorted by key.
97
+ *
98
+ * @param manifest - What the scan produced.
99
+ * @returns The text of the file.
100
+ * @example
101
+ * ```ts
102
+ * emitManifest({ version: 1, bundles: {} }); // '{\n "version": 1,\n "bundles": {}\n}\n'
103
+ * ```
104
+ */
105
+ declare function emitManifest(manifest: Manifest): string;
106
+ /**
107
+ * Writes `generated/assets.ts`: `AssetKey` over every kind, the narrower `FontKey` and `AudioKey`
108
+ * next to it, `BundleKey`, and the nine-slice table. A game commits this file, so `defineGame` can
109
+ * type `Sprite`, a text style, a sound, `defineBundles` and the `load` effect from it.
110
+ *
111
+ * @param manifest - What the scan produced.
112
+ * @returns The text of the module.
113
+ * @example
114
+ * ```ts
115
+ * emitKeys({ version: 1, bundles: {} });
116
+ * // the header, four unions that are all "never" and an empty nine-slice table
117
+ * ```
118
+ */
119
+ declare function emitKeys(manifest: Manifest): string;
120
+ //#endregion
121
+ //#region src/plugins/assets/scan/scan.d.ts
122
+ /**
123
+ * What one scan is told: where the features are and where the two generated files go.
124
+ */
125
+ type ScanOptions = {
126
+ /** Path of the game source root, the folder that holds the features. */root: string; /** Name of the folder that holds the features. Default `"features"`. */
127
+ features?: string; /** Path of the `manifest.json` to write. */
128
+ manifest: string; /** Path of the generated key module to write. */
129
+ keys: string; /** False for a check run: nothing is written. Default true. */
130
+ write?: boolean;
131
+ };
132
+ /**
133
+ * What a scan produced.
134
+ */
135
+ type ScanResult = {
136
+ /** The manifest, with bundles sorted by name and files sorted by key. */manifest: Manifest; /** The text of the generated key module. */
137
+ keysSource: string; /** True when an output on disk differs from what the scan produced. */
138
+ changed: boolean; /** One line per file the scan left out. Nothing here stops a build. */
139
+ notes: readonly string[];
140
+ };
141
+ /**
142
+ * Walks the features of a game and writes its two generated files: one bundle per feature, split
143
+ * by the optional `assets.ts` of that feature, every file keyed by the key rule. A check run
144
+ * (`write: false`) writes nothing and only reports whether something would change.
145
+ *
146
+ * @param options - The game source root, the two output paths and whether to write.
147
+ * @returns The manifest, the text of the key module and whether an output differed.
148
+ * @throws {Error} One error that lists every problem the scan found.
149
+ * @example
150
+ * ```ts
151
+ * const { manifest, changed } = await scanAssets({
152
+ * root: "src",
153
+ * manifest: "public/assets/manifest.json",
154
+ * keys: "src/generated/assets.ts"
155
+ * });
156
+ * // manifest.bundles.ui.files[0].key: "ui.button.primary", changed: true on the first run
157
+ * ```
158
+ */
159
+ declare function scanAssets(options: ScanOptions): Promise<ScanResult>;
160
+ //#endregion
161
+ export { type CompileOptions, type CompileReport, type ScanOptions, type ScanResult, type ScanUi, type StringsCompiler, type StringsReport, checkStrings, compileStrings, emitKeys, emitManifest, runCli, scanAssets };