@puzzle-ui/i18n 0.0.0-stage → 0.16.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.
- package/README.md +94 -2
- package/ai/instructions.md +141 -0
- package/ai/manifest.json +10 -0
- package/dist/LICENSE +21 -0
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/adapters/next.cjs +11 -0
- package/dist/adapters/next.cjs.map +1 -0
- package/dist/adapters/next.d.cts +7 -0
- package/dist/adapters/next.d.ts +7 -0
- package/dist/adapters/next.js +10 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/adapters/react-router.cjs +13 -0
- package/dist/adapters/react-router.cjs.map +1 -0
- package/dist/adapters/react-router.d.cts +10 -0
- package/dist/adapters/react-router.d.ts +10 -0
- package/dist/adapters/react-router.js +12 -0
- package/dist/adapters/react-router.js.map +1 -0
- package/dist/adapters/request.cjs +67 -0
- package/dist/adapters/request.cjs.map +1 -0
- package/dist/adapters/request.d.cts +16 -0
- package/dist/adapters/request.d.ts +16 -0
- package/dist/adapters/request.js +65 -0
- package/dist/adapters/request.js.map +1 -0
- package/dist/adapters/tanstack.cjs +13 -0
- package/dist/adapters/tanstack.cjs.map +1 -0
- package/dist/adapters/tanstack.d.cts +10 -0
- package/dist/adapters/tanstack.d.ts +10 -0
- package/dist/adapters/tanstack.js +12 -0
- package/dist/adapters/tanstack.js.map +1 -0
- package/dist/ai/index.cjs +205 -0
- package/dist/ai/index.cjs.map +1 -0
- package/dist/ai/index.d.cts +75 -0
- package/dist/ai/index.d.ts +75 -0
- package/dist/ai/index.js +195 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/review.cjs +319 -0
- package/dist/ai/review.cjs.map +1 -0
- package/dist/ai/review.d.cts +91 -0
- package/dist/ai/review.d.ts +91 -0
- package/dist/ai/review.js +315 -0
- package/dist/ai/review.js.map +1 -0
- package/dist/cli/bin.cjs +10 -0
- package/dist/cli/bin.cjs.map +1 -0
- package/dist/cli/bin.d.cts +1 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +12 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/index.cjs +310 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +7 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.js +309 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/compiler/index.cjs +218 -0
- package/dist/compiler/index.cjs.map +1 -0
- package/dist/compiler/index.d.cts +18 -0
- package/dist/compiler/index.d.ts +18 -0
- package/dist/compiler/index.js +210 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/typescript.cjs +251 -0
- package/dist/compiler/typescript.cjs.map +1 -0
- package/dist/compiler/typescript.d.cts +27 -0
- package/dist/compiler/typescript.d.ts +27 -0
- package/dist/compiler/typescript.js +247 -0
- package/dist/compiler/typescript.js.map +1 -0
- package/dist/compiler/vite.cjs +94 -0
- package/dist/compiler/vite.cjs.map +1 -0
- package/dist/compiler/vite.d.cts +13 -0
- package/dist/compiler/vite.d.ts +13 -0
- package/dist/compiler/vite.js +92 -0
- package/dist/compiler/vite.js.map +1 -0
- package/dist/content/index.cjs +156 -0
- package/dist/content/index.cjs.map +1 -0
- package/dist/content/index.d.cts +75 -0
- package/dist/content/index.d.ts +75 -0
- package/dist/content/index.js +151 -0
- package/dist/content/index.js.map +1 -0
- package/dist/content/sanity.cjs +74 -0
- package/dist/content/sanity.cjs.map +1 -0
- package/dist/content/sanity.d.cts +19 -0
- package/dist/content/sanity.d.ts +19 -0
- package/dist/content/sanity.js +73 -0
- package/dist/content/sanity.js.map +1 -0
- package/dist/devtools/index.cjs +77 -0
- package/dist/devtools/index.cjs.map +1 -0
- package/dist/devtools/index.d.cts +29 -0
- package/dist/devtools/index.d.ts +29 -0
- package/dist/devtools/index.js +75 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/format.cjs +17 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.d.cts +9 -0
- package/dist/format.d.ts +9 -0
- package/dist/format.js +13 -0
- package/dist/format.js.map +1 -0
- package/dist/index.cjs +20 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/locale.cjs +158 -0
- package/dist/locale.cjs.map +1 -0
- package/dist/locale.d.cts +42 -0
- package/dist/locale.d.ts +42 -0
- package/dist/locale.js +155 -0
- package/dist/locale.js.map +1 -0
- package/dist/react/index.cjs +239 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +105 -0
- package/dist/react/index.d.ts +105 -0
- package/dist/react/index.js +238 -0
- package/dist/react/index.js.map +1 -0
- package/dist/routing/index.cjs +381 -0
- package/dist/routing/index.cjs.map +1 -0
- package/dist/routing/index.d.cts +44 -0
- package/dist/routing/index.d.ts +44 -0
- package/dist/routing/index.js +380 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/runtime.cjs +261 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +74 -0
- package/dist/runtime.d.ts +74 -0
- package/dist/runtime.js +257 -0
- package/dist/runtime.js.map +1 -0
- package/dist/seo/index.cjs +212 -0
- package/dist/seo/index.cjs.map +1 -0
- package/dist/seo/index.d.cts +52 -0
- package/dist/seo/index.d.ts +52 -0
- package/dist/seo/index.js +209 -0
- package/dist/seo/index.js.map +1 -0
- package/dist/seo/origin.cjs +27 -0
- package/dist/seo/origin.cjs.map +1 -0
- package/dist/seo/origin.js +26 -0
- package/dist/seo/origin.js.map +1 -0
- package/dist/seo/sitemap.cjs +74 -0
- package/dist/seo/sitemap.cjs.map +1 -0
- package/dist/seo/sitemap.d.cts +16 -0
- package/dist/seo/sitemap.d.ts +16 -0
- package/dist/seo/sitemap.js +72 -0
- package/dist/seo/sitemap.js.map +1 -0
- package/dist/sources/index.cjs +227 -0
- package/dist/sources/index.cjs.map +1 -0
- package/dist/sources/index.d.cts +41 -0
- package/dist/sources/index.d.ts +41 -0
- package/dist/sources/index.js +222 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/node.cjs +50 -0
- package/dist/sources/node.cjs.map +1 -0
- package/dist/sources/node.d.cts +5 -0
- package/dist/sources/node.d.ts +5 -0
- package/dist/sources/node.js +49 -0
- package/dist/sources/node.js.map +1 -0
- package/package.json +256 -4
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { findMissingTranslationKeys, findUnusedTranslationKeys, generateCatalogTypes, validateCatalogs } from "../compiler/index.js";
|
|
2
|
+
import { parseJsonCatalog } from "../sources/index.js";
|
|
3
|
+
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
4
|
+
import { basename, resolve } from "node:path";
|
|
5
|
+
// src/cli/index.ts
|
|
6
|
+
var CliUsageError = class extends Error {
|
|
7
|
+
exitCode = 2;
|
|
8
|
+
};
|
|
9
|
+
const defaultOutput = {
|
|
10
|
+
stdout: (message) => process.stdout.write(`${message}\n`),
|
|
11
|
+
stderr: (message) => process.stderr.write(`${message}\n`),
|
|
12
|
+
cwd: process.cwd()
|
|
13
|
+
};
|
|
14
|
+
const usage = `Puzzle Multilingual CLI
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
puzzle-i18n init [directory] [--default-locale <locale>] [--locales <list>]
|
|
18
|
+
puzzle-i18n validate [catalog-directory] [--default-locale <locale>] [--config <file>]
|
|
19
|
+
puzzle-i18n generate-types [catalog-file] [--out <file>] [--locale <locale>] [--config <file>]
|
|
20
|
+
puzzle-i18n scan [source-directory] [--catalog <file>] [--callees <names>] [--config <file>]
|
|
21
|
+
puzzle-i18n --help
|
|
22
|
+
puzzle-i18n --version
|
|
23
|
+
|
|
24
|
+
Catalog validation reads one <locale>.json file per locale from the directory.
|
|
25
|
+
Without overrides, validate, generate-types, and scan read puzzle-i18n.config.json.
|
|
26
|
+
Source scanning checks static t("key") and translate("key") calls.`;
|
|
27
|
+
const parseOption = (args, option) => {
|
|
28
|
+
const index = args.indexOf(option);
|
|
29
|
+
if (index < 0) return;
|
|
30
|
+
const value = args[index + 1];
|
|
31
|
+
if (!value || value.startsWith("--")) throw new CliUsageError(`Expected a value after ${option}.`);
|
|
32
|
+
if (args.lastIndexOf(option) !== index) throw new CliUsageError(`Option ${option} can only be provided once.`);
|
|
33
|
+
return value;
|
|
34
|
+
};
|
|
35
|
+
const getPositionals = (args, valueOptions) => {
|
|
36
|
+
const positionals = [];
|
|
37
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
38
|
+
const arg = args[index];
|
|
39
|
+
if (!arg) continue;
|
|
40
|
+
if (arg.startsWith("--")) {
|
|
41
|
+
if (!valueOptions.includes(arg)) throw new CliUsageError(`Unknown option "${arg}".`);
|
|
42
|
+
const value = args[index + 1];
|
|
43
|
+
if (!value || value.startsWith("--")) throw new CliUsageError(`Expected a value after ${arg}.`);
|
|
44
|
+
index += 1;
|
|
45
|
+
} else positionals.push(arg);
|
|
46
|
+
}
|
|
47
|
+
return positionals;
|
|
48
|
+
};
|
|
49
|
+
const readPackageVersion = async () => {
|
|
50
|
+
const packageJsonUrl = new URL("../../package.json", import.meta.url);
|
|
51
|
+
const contents = await readFile(packageJsonUrl, "utf8");
|
|
52
|
+
const parsed = JSON.parse(contents);
|
|
53
|
+
if (typeof parsed !== "object" || parsed === null || !("version" in parsed) || typeof parsed.version !== "string") throw new Error("Package metadata does not contain a string version.");
|
|
54
|
+
return parsed.version;
|
|
55
|
+
};
|
|
56
|
+
const validateCommand = async (args, output) => {
|
|
57
|
+
const config = await readProjectConfig(args, output);
|
|
58
|
+
const [directory, ...extraPositionals] = getPositionals(args, ["--default-locale", "--config"]);
|
|
59
|
+
const catalogDirectory = directory ?? config?.catalogDirectory;
|
|
60
|
+
const defaultLocale = parseOption(args, "--default-locale") ?? config?.defaultLocale;
|
|
61
|
+
if (!catalogDirectory || extraPositionals.length > 0 || !defaultLocale) throw new CliUsageError("validate requires a catalog directory and defaultLocale from config or --default-locale.");
|
|
62
|
+
const absoluteDirectory = resolve(output.cwd, catalogDirectory);
|
|
63
|
+
const files = (await readdir(absoluteDirectory, { withFileTypes: true })).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).sort((left, right) => left.name.localeCompare(right.name));
|
|
64
|
+
if (files.length === 0) throw new Error(`No JSON catalogs were found in "${absoluteDirectory}".`);
|
|
65
|
+
const foundLocales = new Set(files.map((file) => basename(file.name, ".json")));
|
|
66
|
+
const missingLocales = config?.locales.filter((locale) => !foundLocales.has(locale)) ?? [];
|
|
67
|
+
if (missingLocales.length > 0) {
|
|
68
|
+
missingLocales.forEach((locale) => output.stderr(`[missing-locale] ${locale}: expected catalog "${locale}.json" in "${absoluteDirectory}".`));
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
const catalogs = {};
|
|
72
|
+
for (const file of files) {
|
|
73
|
+
const locale = basename(file.name, ".json");
|
|
74
|
+
const content = await readFile(resolve(absoluteDirectory, file.name), "utf8");
|
|
75
|
+
catalogs[locale] = parseJsonCatalog(content, locale);
|
|
76
|
+
}
|
|
77
|
+
const issues = validateCatalogs({
|
|
78
|
+
catalogs,
|
|
79
|
+
defaultLocale
|
|
80
|
+
});
|
|
81
|
+
if (issues.length > 0) {
|
|
82
|
+
for (const issue of issues) {
|
|
83
|
+
const location = issue.key ? ` ${issue.key}` : "";
|
|
84
|
+
output.stderr(`[${issue.code}] ${issue.locale}${location}: ${issue.message}`);
|
|
85
|
+
}
|
|
86
|
+
return 1;
|
|
87
|
+
}
|
|
88
|
+
output.stdout(`Catalogs are valid (${files.length} locales).`);
|
|
89
|
+
return 0;
|
|
90
|
+
};
|
|
91
|
+
const generateTypesCommand = async (args, output) => {
|
|
92
|
+
const config = await readProjectConfig(args, output);
|
|
93
|
+
const [file, ...extraPositionals] = getPositionals(args, [
|
|
94
|
+
"--out",
|
|
95
|
+
"--type-name",
|
|
96
|
+
"--locale",
|
|
97
|
+
"--config"
|
|
98
|
+
]);
|
|
99
|
+
const outputFile = parseOption(args, "--out");
|
|
100
|
+
const typeName = parseOption(args, "--type-name") ?? "Messages";
|
|
101
|
+
const localeArg = parseOption(args, "--locale");
|
|
102
|
+
const locale = localeArg ? canonicalizeLocale(localeArg) : config?.defaultLocale;
|
|
103
|
+
const catalogFile = file ?? (config && locale ? resolve(output.cwd, config.catalogDirectory, `${locale}.json`) : void 0);
|
|
104
|
+
const declarationFile = outputFile ?? (config ? "messages.d.ts" : void 0);
|
|
105
|
+
if (!catalogFile || extraPositionals.length > 0 || !declarationFile) throw new CliUsageError("generate-types requires a catalog file and --out, or a valid project config.");
|
|
106
|
+
const inputPath = resolve(output.cwd, catalogFile);
|
|
107
|
+
const outputPath = resolve(output.cwd, declarationFile);
|
|
108
|
+
const catalogLocale = canonicalizeLocale(basename(inputPath).replace(/\.json$/, ""));
|
|
109
|
+
const catalog = parseJsonCatalog(await readFile(inputPath, "utf8"), catalogLocale);
|
|
110
|
+
const declarations = generateCatalogTypes(catalog, typeName);
|
|
111
|
+
await writeFile(outputPath, declarations, "utf8");
|
|
112
|
+
output.stdout(`Generated ${outputPath}.`);
|
|
113
|
+
return 0;
|
|
114
|
+
};
|
|
115
|
+
const SOURCE_EXTENSION = /\.(?:tsx?|jsx?|mts|cts|mjs|cjs)$/;
|
|
116
|
+
const IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
117
|
+
".git",
|
|
118
|
+
".next",
|
|
119
|
+
".turbo",
|
|
120
|
+
"build",
|
|
121
|
+
"coverage",
|
|
122
|
+
"dist",
|
|
123
|
+
"node_modules"
|
|
124
|
+
]);
|
|
125
|
+
const collectSourceFiles = async (directory) => {
|
|
126
|
+
const files = [];
|
|
127
|
+
const visit = async (currentDirectory) => {
|
|
128
|
+
const entries = await readdir(currentDirectory, { withFileTypes: true });
|
|
129
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
130
|
+
const path = resolve(currentDirectory, entry.name);
|
|
131
|
+
if (entry.isDirectory()) {
|
|
132
|
+
if (!IGNORED_DIRECTORIES.has(entry.name)) await visit(path);
|
|
133
|
+
} else if (entry.isFile() && SOURCE_EXTENSION.test(entry.name)) files.push(path);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
await visit(directory);
|
|
137
|
+
return files;
|
|
138
|
+
};
|
|
139
|
+
const scanCommand = async (args, output) => {
|
|
140
|
+
const config = await readProjectConfig(args, output);
|
|
141
|
+
const [directory, ...extraPositionals] = getPositionals(args, [
|
|
142
|
+
"--catalog",
|
|
143
|
+
"--callees",
|
|
144
|
+
"--config"
|
|
145
|
+
]);
|
|
146
|
+
const configuredDirectories = directory ? [directory] : config?.sourceDirectories;
|
|
147
|
+
const catalogFile = parseOption(args, "--catalog") ?? (config ? resolve(output.cwd, config.catalogDirectory, `${config.defaultLocale}.json`) : void 0);
|
|
148
|
+
const callees = parseOption(args, "--callees")?.split(",").map((callee) => callee.trim()).filter(Boolean);
|
|
149
|
+
if (!configuredDirectories || configuredDirectories.length === 0 || extraPositionals.length > 0 || !catalogFile) throw new CliUsageError("scan requires a source directory and catalog file, or a valid project config.");
|
|
150
|
+
const sourceFiles = [...new Set((await Promise.all(configuredDirectories.map((sourceDirectory) => collectSourceFiles(resolve(output.cwd, sourceDirectory))))).flat())];
|
|
151
|
+
if (sourceFiles.length === 0) throw new Error(`No supported source files were found in "${configuredDirectories.join(", ")}".`);
|
|
152
|
+
const absoluteCatalogFile = resolve(output.cwd, catalogFile);
|
|
153
|
+
const catalog = parseJsonCatalog(await readFile(absoluteCatalogFile, "utf8"), basename(absoluteCatalogFile).replace(/\.json$/, ""));
|
|
154
|
+
const { extractTranslationKeys } = await import("../compiler/typescript.js");
|
|
155
|
+
const usedKeys = /* @__PURE__ */ new Set();
|
|
156
|
+
const diagnostics = [];
|
|
157
|
+
for (const file of sourceFiles) {
|
|
158
|
+
const result = extractTranslationKeys(await readFile(file, "utf8"), {
|
|
159
|
+
fileName: file,
|
|
160
|
+
callees
|
|
161
|
+
});
|
|
162
|
+
result.keys.forEach((key) => usedKeys.add(key));
|
|
163
|
+
diagnostics.push(...result.diagnostics.map((diagnostic) => `[${diagnostic.code}] ${diagnostic.file}:${diagnostic.line}:${diagnostic.column}: ${diagnostic.message}`));
|
|
164
|
+
}
|
|
165
|
+
const missing = findMissingTranslationKeys(catalog, usedKeys);
|
|
166
|
+
const unused = findUnusedTranslationKeys(catalog, usedKeys);
|
|
167
|
+
diagnostics.push(...missing.map((key) => `[missing-key] ${key}: referenced but absent from catalog.`), ...unused.map((key) => `[unused-key] ${key}: catalog key is not referenced in source.`));
|
|
168
|
+
if (diagnostics.length > 0) {
|
|
169
|
+
diagnostics.forEach(output.stderr);
|
|
170
|
+
return 1;
|
|
171
|
+
}
|
|
172
|
+
output.stdout(`Source scan passed (${sourceFiles.length} files, ${usedKeys.size} translation keys).`);
|
|
173
|
+
return 0;
|
|
174
|
+
};
|
|
175
|
+
const canonicalizeLocale = (locale) => {
|
|
176
|
+
try {
|
|
177
|
+
const [canonical] = Intl.getCanonicalLocales(locale);
|
|
178
|
+
if (!canonical) throw new Error();
|
|
179
|
+
return canonical;
|
|
180
|
+
} catch {
|
|
181
|
+
throw new CliUsageError(`Invalid BCP 47 locale "${locale}".`);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const isObjectRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
185
|
+
const readProjectConfig = async (args, output) => {
|
|
186
|
+
const configArg = parseOption(args, "--config");
|
|
187
|
+
const configPath = resolve(output.cwd, configArg ?? "puzzle-i18n.config.json");
|
|
188
|
+
let contents;
|
|
189
|
+
try {
|
|
190
|
+
contents = await readFile(configPath, "utf8");
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (configArg === void 0 && typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") return;
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
let parsed;
|
|
196
|
+
try {
|
|
197
|
+
parsed = JSON.parse(contents);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
throw new Error(`Could not parse i18n config "${configPath}": ${error instanceof Error ? error.message : String(error)}`);
|
|
200
|
+
}
|
|
201
|
+
if (!isObjectRecord(parsed)) throw new Error(`i18n config "${configPath}" must contain a JSON object.`);
|
|
202
|
+
const defaultLocale = typeof parsed.defaultLocale === "string" ? canonicalizeLocale(parsed.defaultLocale) : void 0;
|
|
203
|
+
const locales = Array.isArray(parsed.locales) && parsed.locales.every((locale) => typeof locale === "string") ? parsed.locales.map(canonicalizeLocale) : void 0;
|
|
204
|
+
const catalogDirectory = typeof parsed.catalogDirectory === "string" && parsed.catalogDirectory.trim() ? parsed.catalogDirectory : void 0;
|
|
205
|
+
const sourceDirectories = Array.isArray(parsed.sourceDirectories) && parsed.sourceDirectories.length > 0 && parsed.sourceDirectories.every((directory) => typeof directory === "string" && directory.trim()) ? parsed.sourceDirectories : void 0;
|
|
206
|
+
if (!defaultLocale || !locales || new Set(locales).size !== locales.length || !locales.includes(defaultLocale) || !catalogDirectory || !sourceDirectories) throw new Error(`i18n config "${configPath}" must define a defaultLocale included in locales, catalogDirectory, and non-empty sourceDirectories.`);
|
|
207
|
+
return Object.freeze({
|
|
208
|
+
defaultLocale,
|
|
209
|
+
locales: Object.freeze(locales),
|
|
210
|
+
catalogDirectory,
|
|
211
|
+
sourceDirectories: Object.freeze(sourceDirectories)
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
const detectFramework = async (directory) => {
|
|
215
|
+
let contents;
|
|
216
|
+
try {
|
|
217
|
+
contents = await readFile(resolve(directory, "package.json"), "utf8");
|
|
218
|
+
} catch (error) {
|
|
219
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") return "generic";
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
const parsed = JSON.parse(contents);
|
|
223
|
+
if (!isObjectRecord(parsed)) throw new Error("package.json must contain a JSON object.");
|
|
224
|
+
const dependencies = [
|
|
225
|
+
parsed.dependencies,
|
|
226
|
+
parsed.devDependencies,
|
|
227
|
+
parsed.optionalDependencies
|
|
228
|
+
].filter(isObjectRecord);
|
|
229
|
+
const hasDependency = (name) => dependencies.some((items) => Object.hasOwn(items, name));
|
|
230
|
+
if (hasDependency("next")) return "next";
|
|
231
|
+
if (hasDependency("@tanstack/react-start") || hasDependency("@tanstack/react-router")) return "tanstack";
|
|
232
|
+
if (hasDependency("react-router")) return "react-router";
|
|
233
|
+
return hasDependency("react") ? "react" : "generic";
|
|
234
|
+
};
|
|
235
|
+
const fileExists = async (path) => {
|
|
236
|
+
try {
|
|
237
|
+
await readFile(path);
|
|
238
|
+
return true;
|
|
239
|
+
} catch (error) {
|
|
240
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") return false;
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
const initCommand = async (args, output) => {
|
|
245
|
+
const [directoryArg, ...extraPositionals] = getPositionals(args, ["--default-locale", "--locales"]);
|
|
246
|
+
const defaultLocale = canonicalizeLocale(parseOption(args, "--default-locale") ?? "en");
|
|
247
|
+
const localeOption = parseOption(args, "--locales");
|
|
248
|
+
const localeInputs = localeOption === void 0 ? [defaultLocale] : localeOption.split(",").map((locale) => locale.trim());
|
|
249
|
+
if (extraPositionals.length > 0) throw new CliUsageError("init accepts at most one target directory.");
|
|
250
|
+
if (localeInputs.length === 0 || localeInputs.some((locale) => !locale)) throw new CliUsageError("--locales must be a comma-separated locale list.");
|
|
251
|
+
const locales = localeInputs.map(canonicalizeLocale);
|
|
252
|
+
if (new Set(locales).size !== locales.length) throw new CliUsageError("--locales must not contain duplicate locales.");
|
|
253
|
+
if (!locales.includes(defaultLocale)) throw new CliUsageError(`The default locale "${defaultLocale}" must be included in --locales.`);
|
|
254
|
+
const directory = resolve(output.cwd, directoryArg ?? ".");
|
|
255
|
+
const localeDirectory = resolve(directory, "locales");
|
|
256
|
+
const framework = await detectFramework(directory);
|
|
257
|
+
const configPath = resolve(directory, "puzzle-i18n.config.json");
|
|
258
|
+
const catalogPaths = locales.map((locale) => resolve(localeDirectory, `${locale}.json`));
|
|
259
|
+
const existingFiles = [];
|
|
260
|
+
for (const path of [configPath, ...catalogPaths]) if (await fileExists(path)) existingFiles.push(path);
|
|
261
|
+
if (existingFiles.length > 0) throw new Error(`Initialization would overwrite existing files: ${existingFiles.join(", ")}.`);
|
|
262
|
+
const config = {
|
|
263
|
+
framework,
|
|
264
|
+
defaultLocale,
|
|
265
|
+
locales,
|
|
266
|
+
catalogDirectory: "./locales",
|
|
267
|
+
sourceDirectories: ["./src"]
|
|
268
|
+
};
|
|
269
|
+
const catalog = { common: { greeting: "Hello {name}" } };
|
|
270
|
+
await mkdir(localeDirectory, { recursive: true });
|
|
271
|
+
await writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`, {
|
|
272
|
+
encoding: "utf8",
|
|
273
|
+
flag: "wx"
|
|
274
|
+
});
|
|
275
|
+
for (const path of catalogPaths) await writeFile(path, `${JSON.stringify(catalog, null, 2)}\n`, {
|
|
276
|
+
encoding: "utf8",
|
|
277
|
+
flag: "wx"
|
|
278
|
+
});
|
|
279
|
+
output.stdout(`Initialized Puzzle Multilingual for ${framework} with ${locales.length} locale(s).`);
|
|
280
|
+
return 0;
|
|
281
|
+
};
|
|
282
|
+
const runI18nCli = async (args, output = {}) => {
|
|
283
|
+
const io = {
|
|
284
|
+
...defaultOutput,
|
|
285
|
+
...output
|
|
286
|
+
};
|
|
287
|
+
try {
|
|
288
|
+
const [command, ...commandArgs] = args;
|
|
289
|
+
if (!command || command === "--help" || command === "-h") {
|
|
290
|
+
io.stdout(usage);
|
|
291
|
+
return 0;
|
|
292
|
+
}
|
|
293
|
+
if (command === "--version" || command === "-v") {
|
|
294
|
+
io.stdout(`@puzzle-ui/i18n ${await readPackageVersion()}`);
|
|
295
|
+
return 0;
|
|
296
|
+
}
|
|
297
|
+
if (command === "validate") return await validateCommand(commandArgs, io);
|
|
298
|
+
if (command === "generate-types") return await generateTypesCommand(commandArgs, io);
|
|
299
|
+
if (command === "scan") return await scanCommand(commandArgs, io);
|
|
300
|
+
if (command === "init") return await initCommand(commandArgs, io);
|
|
301
|
+
throw new CliUsageError(`Unknown command "${command}".`);
|
|
302
|
+
} catch (error) {
|
|
303
|
+
io.stderr(error instanceof Error ? error.message : String(error));
|
|
304
|
+
return error instanceof CliUsageError ? error.exitCode : 1;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
export { runI18nCli };
|
|
308
|
+
|
|
309
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/cli/index.ts"],"sourcesContent":["import { mkdir, readdir, readFile, writeFile } from \"node:fs/promises\";\nimport { basename, resolve } from \"node:path\";\n\nimport {\n findMissingTranslationKeys,\n findUnusedTranslationKeys,\n generateCatalogTypes,\n validateCatalogs,\n} from \"../compiler\";\nimport { parseJsonCatalog } from \"../sources\";\n\ninterface CliOutput {\n stdout(message: string): void;\n stderr(message: string): void;\n cwd: string;\n}\n\nclass CliUsageError extends Error {\n readonly exitCode = 2;\n}\n\nconst defaultOutput: CliOutput = {\n stdout: (message) => process.stdout.write(`${message}\\n`),\n stderr: (message) => process.stderr.write(`${message}\\n`),\n cwd: process.cwd(),\n};\n\nconst usage = `Puzzle Multilingual CLI\n\nUsage:\n puzzle-i18n init [directory] [--default-locale <locale>] [--locales <list>]\n puzzle-i18n validate [catalog-directory] [--default-locale <locale>] [--config <file>]\n puzzle-i18n generate-types [catalog-file] [--out <file>] [--locale <locale>] [--config <file>]\n puzzle-i18n scan [source-directory] [--catalog <file>] [--callees <names>] [--config <file>]\n puzzle-i18n --help\n puzzle-i18n --version\n\nCatalog validation reads one <locale>.json file per locale from the directory.\nWithout overrides, validate, generate-types, and scan read puzzle-i18n.config.json.\nSource scanning checks static t(\"key\") and translate(\"key\") calls.`;\n\nconst parseOption = (\n args: readonly string[],\n option: string,\n): string | undefined => {\n const index = args.indexOf(option);\n\n if (index < 0) {\n return undefined;\n }\n\n const value = args[index + 1];\n\n if (!value || value.startsWith(\"--\")) {\n throw new CliUsageError(`Expected a value after ${option}.`);\n }\n\n if (args.lastIndexOf(option) !== index) {\n throw new CliUsageError(`Option ${option} can only be provided once.`);\n }\n\n return value;\n};\n\nconst rejectUnknownOptions = (\n args: readonly string[],\n allowed: readonly string[],\n): void => {\n for (const arg of args) {\n if (arg.startsWith(\"--\") && !allowed.includes(arg)) {\n throw new CliUsageError(`Unknown option \"${arg}\".`);\n }\n }\n};\n\nconst getPositionals = (\n args: readonly string[],\n valueOptions: readonly string[],\n): string[] => {\n const positionals: string[] = [];\n\n for (let index = 0; index < args.length; index += 1) {\n const arg = args[index];\n\n if (!arg) {\n continue;\n }\n\n if (arg.startsWith(\"--\")) {\n if (!valueOptions.includes(arg)) {\n throw new CliUsageError(`Unknown option \"${arg}\".`);\n }\n\n const value = args[index + 1];\n\n if (!value || value.startsWith(\"--\")) {\n throw new CliUsageError(`Expected a value after ${arg}.`);\n }\n\n index += 1;\n } else {\n positionals.push(arg);\n }\n }\n\n return positionals;\n};\n\nconst readPackageVersion = async (): Promise<string> => {\n const packageJsonUrl = new URL(\"../../package.json\", import.meta.url);\n const contents = await readFile(packageJsonUrl, \"utf8\");\n const parsed: unknown = JSON.parse(contents);\n\n if (\n typeof parsed !== \"object\" ||\n parsed === null ||\n !(\"version\" in parsed) ||\n typeof parsed.version !== \"string\"\n ) {\n throw new Error(\"Package metadata does not contain a string version.\");\n }\n\n return parsed.version;\n};\n\nconst validateCommand = async (\n args: readonly string[],\n output: CliOutput,\n): Promise<number> => {\n const config = await readProjectConfig(args, output);\n const positionals = getPositionals(args, [\"--default-locale\", \"--config\"]);\n const [directory, ...extraPositionals] = positionals;\n const catalogDirectory =\n directory ?? config?.catalogDirectory;\n const defaultLocale =\n parseOption(args, \"--default-locale\") ?? config?.defaultLocale;\n\n if (\n !catalogDirectory ||\n extraPositionals.length > 0 ||\n !defaultLocale\n ) {\n throw new CliUsageError(\n \"validate requires a catalog directory and defaultLocale from config or --default-locale.\",\n );\n }\n\n const absoluteDirectory = resolve(output.cwd, catalogDirectory);\n const files = (await readdir(absoluteDirectory, { withFileTypes: true }))\n .filter((entry) => entry.isFile() && entry.name.endsWith(\".json\"))\n .sort((left, right) => left.name.localeCompare(right.name));\n\n if (files.length === 0) {\n throw new Error(`No JSON catalogs were found in \"${absoluteDirectory}\".`);\n }\n\n const foundLocales = new Set(\n files.map((file) => basename(file.name, \".json\")),\n );\n const missingLocales =\n config?.locales.filter((locale) => !foundLocales.has(locale)) ?? [];\n\n if (missingLocales.length > 0) {\n missingLocales.forEach((locale) =>\n output.stderr(\n `[missing-locale] ${locale}: expected catalog \"${locale}.json\" in \"${absoluteDirectory}\".`,\n ),\n );\n return 1;\n }\n\n const catalogs: Record<string, ReturnType<typeof parseJsonCatalog>> = {};\n\n for (const file of files) {\n const locale = basename(file.name, \".json\");\n const content = await readFile(resolve(absoluteDirectory, file.name), \"utf8\");\n catalogs[locale] = parseJsonCatalog(content, locale);\n }\n\n const issues = validateCatalogs({ catalogs, defaultLocale });\n\n if (issues.length > 0) {\n for (const issue of issues) {\n const location = issue.key ? ` ${issue.key}` : \"\";\n output.stderr(`[${issue.code}] ${issue.locale}${location}: ${issue.message}`);\n }\n\n return 1;\n }\n\n output.stdout(`Catalogs are valid (${files.length} locales).`);\n return 0;\n};\n\nconst generateTypesCommand = async (\n args: readonly string[],\n output: CliOutput,\n): Promise<number> => {\n const config = await readProjectConfig(args, output);\n const positionals = getPositionals(args, [\n \"--out\",\n \"--type-name\",\n \"--locale\",\n \"--config\",\n ]);\n const [file, ...extraPositionals] = positionals;\n const outputFile = parseOption(args, \"--out\");\n const typeName = parseOption(args, \"--type-name\") ?? \"Messages\";\n const localeArg = parseOption(args, \"--locale\");\n const locale = localeArg\n ? canonicalizeLocale(localeArg)\n : config?.defaultLocale;\n const catalogFile = file ??\n (config && locale\n ? resolve(output.cwd, config.catalogDirectory, `${locale}.json`)\n : undefined);\n const declarationFile = outputFile ?? (config ? \"messages.d.ts\" : undefined);\n\n if (!catalogFile || extraPositionals.length > 0 || !declarationFile) {\n throw new CliUsageError(\n \"generate-types requires a catalog file and --out, or a valid project config.\",\n );\n }\n\n const inputPath = resolve(output.cwd, catalogFile);\n const outputPath = resolve(output.cwd, declarationFile);\n const catalogLocale = canonicalizeLocale(\n basename(inputPath).replace(/\\.json$/, \"\"),\n );\n const catalog = parseJsonCatalog(\n await readFile(inputPath, \"utf8\"),\n catalogLocale,\n );\n const declarations = generateCatalogTypes(catalog, typeName);\n\n await writeFile(outputPath, declarations, \"utf8\");\n output.stdout(`Generated ${outputPath}.`);\n return 0;\n};\n\nconst SOURCE_EXTENSION = /\\.(?:tsx?|jsx?|mts|cts|mjs|cjs)$/;\nconst IGNORED_DIRECTORIES = new Set([\n \".git\",\n \".next\",\n \".turbo\",\n \"build\",\n \"coverage\",\n \"dist\",\n \"node_modules\",\n]);\n\nconst collectSourceFiles = async (directory: string): Promise<string[]> => {\n const files: string[] = [];\n\n const visit = async (currentDirectory: string): Promise<void> => {\n const entries = await readdir(currentDirectory, { withFileTypes: true });\n\n for (const entry of entries.sort((left, right) =>\n left.name.localeCompare(right.name),\n )) {\n const path = resolve(currentDirectory, entry.name);\n\n if (entry.isDirectory()) {\n if (!IGNORED_DIRECTORIES.has(entry.name)) {\n await visit(path);\n }\n } else if (entry.isFile() && SOURCE_EXTENSION.test(entry.name)) {\n files.push(path);\n }\n }\n };\n\n await visit(directory);\n return files;\n};\n\nconst scanCommand = async (\n args: readonly string[],\n output: CliOutput,\n): Promise<number> => {\n const config = await readProjectConfig(args, output);\n const positionals = getPositionals(args, [\n \"--catalog\",\n \"--callees\",\n \"--config\",\n ]);\n const [directory, ...extraPositionals] = positionals;\n const configuredDirectories = directory\n ? [directory]\n : config?.sourceDirectories;\n const catalogFile =\n parseOption(args, \"--catalog\") ??\n (config\n ? resolve(\n output.cwd,\n config.catalogDirectory,\n `${config.defaultLocale}.json`,\n )\n : undefined);\n const callees = parseOption(args, \"--callees\")\n ?.split(\",\")\n .map((callee) => callee.trim())\n .filter(Boolean);\n\n if (\n !configuredDirectories ||\n configuredDirectories.length === 0 ||\n extraPositionals.length > 0 ||\n !catalogFile\n ) {\n throw new CliUsageError(\n \"scan requires a source directory and catalog file, or a valid project config.\",\n );\n }\n\n const sourceFiles = [\n ...new Set(\n (\n await Promise.all(\n configuredDirectories.map((sourceDirectory) =>\n collectSourceFiles(resolve(output.cwd, sourceDirectory)),\n ),\n )\n ).flat(),\n ),\n ];\n\n if (sourceFiles.length === 0) {\n throw new Error(\n `No supported source files were found in \"${configuredDirectories.join(\", \")}\".`,\n );\n }\n\n const absoluteCatalogFile = resolve(output.cwd, catalogFile);\n const catalog = parseJsonCatalog(\n await readFile(absoluteCatalogFile, \"utf8\"),\n basename(absoluteCatalogFile).replace(/\\.json$/, \"\"),\n );\n const { extractTranslationKeys } = await import(\"../compiler/typescript\");\n const usedKeys = new Set<string>();\n const diagnostics: string[] = [];\n\n for (const file of sourceFiles) {\n const result = extractTranslationKeys(await readFile(file, \"utf8\"), {\n fileName: file,\n callees,\n });\n\n result.keys.forEach((key) => usedKeys.add(key));\n diagnostics.push(\n ...result.diagnostics.map(\n (diagnostic) =>\n `[${diagnostic.code}] ${diagnostic.file}:${diagnostic.line}:${diagnostic.column}: ${diagnostic.message}`,\n ),\n );\n }\n\n const missing = findMissingTranslationKeys(catalog, usedKeys);\n const unused = findUnusedTranslationKeys(catalog, usedKeys);\n diagnostics.push(\n ...missing.map((key) => `[missing-key] ${key}: referenced but absent from catalog.`),\n ...unused.map((key) => `[unused-key] ${key}: catalog key is not referenced in source.`),\n );\n\n if (diagnostics.length > 0) {\n diagnostics.forEach(output.stderr);\n return 1;\n }\n\n output.stdout(\n `Source scan passed (${sourceFiles.length} files, ${usedKeys.size} translation keys).`,\n );\n return 0;\n};\n\nconst canonicalizeLocale = (locale: string): string => {\n try {\n const [canonical] = Intl.getCanonicalLocales(locale);\n\n if (!canonical) {\n throw new Error();\n }\n\n return canonical;\n } catch {\n throw new CliUsageError(`Invalid BCP 47 locale \"${locale}\".`);\n }\n};\n\nconst isObjectRecord = (\n value: unknown,\n): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\ninterface I18nCliConfig {\n defaultLocale: string;\n locales: readonly string[];\n catalogDirectory: string;\n sourceDirectories: readonly string[];\n}\n\nconst readProjectConfig = async (\n args: readonly string[],\n output: CliOutput,\n): Promise<I18nCliConfig | undefined> => {\n const configArg = parseOption(args, \"--config\");\n const configPath = resolve(\n output.cwd,\n configArg ?? \"puzzle-i18n.config.json\",\n );\n let contents: string;\n\n try {\n contents = await readFile(configPath, \"utf8\");\n } catch (error) {\n if (\n configArg === undefined &&\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return undefined;\n }\n\n throw error;\n }\n\n let parsed: unknown;\n\n try {\n parsed = JSON.parse(contents);\n } catch (error) {\n throw new Error(\n `Could not parse i18n config \"${configPath}\": ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n\n if (!isObjectRecord(parsed)) {\n throw new Error(`i18n config \"${configPath}\" must contain a JSON object.`);\n }\n\n const defaultLocale =\n typeof parsed.defaultLocale === \"string\"\n ? canonicalizeLocale(parsed.defaultLocale)\n : undefined;\n const locales = Array.isArray(parsed.locales) &&\n parsed.locales.every((locale) => typeof locale === \"string\")\n ? parsed.locales.map(canonicalizeLocale)\n : undefined;\n const catalogDirectory =\n typeof parsed.catalogDirectory === \"string\" &&\n parsed.catalogDirectory.trim()\n ? parsed.catalogDirectory\n : undefined;\n const sourceDirectories =\n Array.isArray(parsed.sourceDirectories) &&\n parsed.sourceDirectories.length > 0 &&\n parsed.sourceDirectories.every(\n (directory) => typeof directory === \"string\" && directory.trim(),\n )\n ? parsed.sourceDirectories as string[]\n : undefined;\n\n if (\n !defaultLocale ||\n !locales ||\n new Set(locales).size !== locales.length ||\n !locales.includes(defaultLocale) ||\n !catalogDirectory ||\n !sourceDirectories\n ) {\n throw new Error(\n `i18n config \"${configPath}\" must define a defaultLocale included in locales, catalogDirectory, and non-empty sourceDirectories.`,\n );\n }\n\n return Object.freeze({\n defaultLocale,\n locales: Object.freeze(locales),\n catalogDirectory,\n sourceDirectories: Object.freeze(sourceDirectories),\n });\n};\n\nconst detectFramework = async (directory: string): Promise<string> => {\n let contents: string;\n\n try {\n contents = await readFile(resolve(directory, \"package.json\"), \"utf8\");\n } catch (error) {\n if (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return \"generic\";\n }\n\n throw error;\n }\n\n const parsed: unknown = JSON.parse(contents);\n\n if (!isObjectRecord(parsed)) {\n throw new Error(\"package.json must contain a JSON object.\");\n }\n\n const dependencies = [\n parsed.dependencies,\n parsed.devDependencies,\n parsed.optionalDependencies,\n ].filter(isObjectRecord);\n const hasDependency = (name: string): boolean =>\n dependencies.some((items) => Object.hasOwn(items, name));\n\n if (hasDependency(\"next\")) {\n return \"next\";\n }\n\n if (\n hasDependency(\"@tanstack/react-start\") ||\n hasDependency(\"@tanstack/react-router\")\n ) {\n return \"tanstack\";\n }\n\n if (hasDependency(\"react-router\")) {\n return \"react-router\";\n }\n\n return hasDependency(\"react\") ? \"react\" : \"generic\";\n};\n\nconst fileExists = async (path: string): Promise<boolean> => {\n try {\n await readFile(path);\n return true;\n } catch (error) {\n if (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return false;\n }\n\n throw error;\n }\n};\n\nconst initCommand = async (\n args: readonly string[],\n output: CliOutput,\n): Promise<number> => {\n const positionals = getPositionals(args, [\n \"--default-locale\",\n \"--locales\",\n ]);\n const [directoryArg, ...extraPositionals] = positionals;\n const defaultLocale = canonicalizeLocale(\n parseOption(args, \"--default-locale\") ?? \"en\",\n );\n const localeOption = parseOption(args, \"--locales\");\n const localeInputs = localeOption === undefined\n ? [defaultLocale]\n : localeOption.split(\",\").map((locale) => locale.trim());\n\n if (extraPositionals.length > 0) {\n throw new CliUsageError(\"init accepts at most one target directory.\");\n }\n\n if (localeInputs.length === 0 || localeInputs.some((locale) => !locale)) {\n throw new CliUsageError(\"--locales must be a comma-separated locale list.\");\n }\n\n const locales = localeInputs.map(canonicalizeLocale);\n\n if (new Set(locales).size !== locales.length) {\n throw new CliUsageError(\"--locales must not contain duplicate locales.\");\n }\n\n if (!locales.includes(defaultLocale)) {\n throw new CliUsageError(\n `The default locale \"${defaultLocale}\" must be included in --locales.`,\n );\n }\n\n const directory = resolve(output.cwd, directoryArg ?? \".\");\n const localeDirectory = resolve(directory, \"locales\");\n const framework = await detectFramework(directory);\n const configPath = resolve(directory, \"puzzle-i18n.config.json\");\n const catalogPaths = locales.map((locale) =>\n resolve(localeDirectory, `${locale}.json`),\n );\n const existingFiles: string[] = [];\n\n for (const path of [configPath, ...catalogPaths]) {\n if (await fileExists(path)) {\n existingFiles.push(path);\n }\n }\n\n if (existingFiles.length > 0) {\n throw new Error(\n `Initialization would overwrite existing files: ${existingFiles.join(\", \")}.`,\n );\n }\n\n const config = {\n framework,\n defaultLocale,\n locales,\n catalogDirectory: \"./locales\",\n sourceDirectories: [\"./src\"],\n };\n const catalog = {\n common: {\n greeting: \"Hello {name}\",\n },\n };\n\n await mkdir(localeDirectory, { recursive: true });\n await writeFile(configPath, `${JSON.stringify(config, null, 2)}\\n`, {\n encoding: \"utf8\",\n flag: \"wx\",\n });\n\n for (const path of catalogPaths) {\n await writeFile(path, `${JSON.stringify(catalog, null, 2)}\\n`, {\n encoding: \"utf8\",\n flag: \"wx\",\n });\n }\n\n output.stdout(\n `Initialized Puzzle Multilingual for ${framework} with ${locales.length} locale(s).`,\n );\n return 0;\n};\n\nexport const runI18nCli = async (\n args: readonly string[],\n output: Partial<CliOutput> = {},\n): Promise<number> => {\n const io: CliOutput = { ...defaultOutput, ...output };\n\n try {\n const [command, ...commandArgs] = args;\n\n if (!command || command === \"--help\" || command === \"-h\") {\n io.stdout(usage);\n return 0;\n }\n\n if (command === \"--version\" || command === \"-v\") {\n io.stdout(`@puzzle-ui/i18n ${await readPackageVersion()}`);\n return 0;\n }\n\n if (command === \"validate\") {\n return await validateCommand(commandArgs, io);\n }\n\n if (command === \"generate-types\") {\n return await generateTypesCommand(commandArgs, io);\n }\n\n if (command === \"scan\") {\n return await scanCommand(commandArgs, io);\n }\n\n if (command === \"init\") {\n return await initCommand(commandArgs, io);\n }\n\n throw new CliUsageError(`Unknown command \"${command}\".`);\n } catch (error) {\n io.stderr(error instanceof Error ? error.message : String(error));\n return error instanceof CliUsageError ? error.exitCode : 1;\n }\n};\n"],"mappings":";;;;;AAiBA,IAAM,gBAAN,cAA4B,MAAM;CAChC,WAAoB;AACtB;AAEA,MAAM,gBAA2B;CAC/B,SAAS,YAAY,QAAQ,OAAO,MAAM,GAAG,QAAQ,GAAG;CACxD,SAAS,YAAY,QAAQ,OAAO,MAAM,GAAG,QAAQ,GAAG;CACxD,KAAK,QAAQ,IAAI;AACnB;AAEA,MAAM,QAAQ;;;;;;;;;;;;;AAcd,MAAM,eACJ,MACA,WACuB;CACvB,MAAM,QAAQ,KAAK,QAAQ,MAAM;CAEjC,IAAI,QAAQ,GACV;CAGF,MAAM,QAAQ,KAAK,QAAQ;CAE3B,IAAI,CAAC,SAAS,MAAM,WAAW,IAAI,GACjC,MAAM,IAAI,cAAc,0BAA0B,OAAO,EAAE;CAG7D,IAAI,KAAK,YAAY,MAAM,MAAM,OAC/B,MAAM,IAAI,cAAc,UAAU,OAAO,4BAA4B;CAGvE,OAAO;AACT;AAaA,MAAM,kBACJ,MACA,iBACa;CACb,MAAM,cAAwB,CAAC;CAE/B,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAAG;EACnD,MAAM,MAAM,KAAK;EAEjB,IAAI,CAAC,KACH;EAGF,IAAI,IAAI,WAAW,IAAI,GAAG;GACxB,IAAI,CAAC,aAAa,SAAS,GAAG,GAC5B,MAAM,IAAI,cAAc,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MAAM,YAAY,aAAa,EAAE;EAG1C,IAAI,YAAY,QACd,OAAO,MAAM,YAAY,aAAa,EAAE;EAG1C,MAAM,IAAI,cAAc,oBAAoB,QAAQ,GAAG;CACzD,SAAS,OAAO;EACd,GAAG,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;EAChE,OAAO,iBAAiB,gBAAgB,MAAM,WAAW;CAC3D;AACF"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
let intl_messageformat = require("intl-messageformat");
|
|
4
|
+
intl_messageformat = require_runtime.__toESM(intl_messageformat, 1);
|
|
5
|
+
// src/compiler/index.ts
|
|
6
|
+
const isRecord = (value) => {
|
|
7
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
8
|
+
const prototype = Object.getPrototypeOf(value);
|
|
9
|
+
return prototype === Object.prototype || prototype === null;
|
|
10
|
+
};
|
|
11
|
+
const flattenCatalog = (value, prefix = "", entries = Object.create(null), ancestors = /* @__PURE__ */ new WeakSet()) => {
|
|
12
|
+
if (!isRecord(value)) throw new Error(`Catalog value at "${prefix || "<root>"}" must be an object.`);
|
|
13
|
+
if (ancestors.has(value)) throw new Error(`Catalog value at "${prefix || "<root>"}" contains a circular reference.`);
|
|
14
|
+
ancestors.add(value);
|
|
15
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
16
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
17
|
+
if (!key || key.includes(".")) throw new Error(`Catalog key "${key}" at "${prefix || "<root>"}" is empty or contains ".", which is reserved for nested paths.`);
|
|
18
|
+
if (typeof entry === "string") entries[path] = entry;
|
|
19
|
+
else if (isRecord(entry)) flattenCatalog(entry, path, entries, ancestors);
|
|
20
|
+
else throw new Error(`Catalog value at "${path}" must be a string or object.`);
|
|
21
|
+
}
|
|
22
|
+
ancestors.delete(value);
|
|
23
|
+
return entries;
|
|
24
|
+
};
|
|
25
|
+
const canonicalLocale = (locale) => {
|
|
26
|
+
try {
|
|
27
|
+
return Intl.getCanonicalLocales(locale)[0];
|
|
28
|
+
} catch {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const getVariables = (message) => [...message.matchAll(/\{\s*([A-Za-z_][\w.-]*)/g)].map((match) => match[1]).filter((name) => name !== void 0).sort();
|
|
33
|
+
const placeholdersMatch = (left, right) => {
|
|
34
|
+
const leftVariables = getVariables(left);
|
|
35
|
+
const rightVariables = getVariables(right);
|
|
36
|
+
return leftVariables.length === rightVariables.length && leftVariables.every((variable, index) => variable === rightVariables[index]);
|
|
37
|
+
};
|
|
38
|
+
const validateCatalogs = (options) => {
|
|
39
|
+
const issues = [];
|
|
40
|
+
const catalogs = /* @__PURE__ */ new Map();
|
|
41
|
+
for (const [inputLocale, catalog] of Object.entries(options.catalogs)) {
|
|
42
|
+
const locale = canonicalLocale(inputLocale);
|
|
43
|
+
if (!locale) {
|
|
44
|
+
issues.push({
|
|
45
|
+
code: "invalid-locale",
|
|
46
|
+
locale: inputLocale,
|
|
47
|
+
message: `Invalid BCP 47 locale "${inputLocale}".`
|
|
48
|
+
});
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (catalogs.has(locale)) {
|
|
52
|
+
issues.push({
|
|
53
|
+
code: "invalid-locale",
|
|
54
|
+
locale,
|
|
55
|
+
message: `More than one catalog resolves to "${locale}".`
|
|
56
|
+
});
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
catalogs.set(locale, flattenCatalog(catalog));
|
|
61
|
+
} catch (error) {
|
|
62
|
+
issues.push({
|
|
63
|
+
code: "invalid-catalog",
|
|
64
|
+
locale,
|
|
65
|
+
message: error instanceof Error ? error.message : String(error)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const defaultLocale = canonicalLocale(options.defaultLocale);
|
|
70
|
+
if (!defaultLocale) {
|
|
71
|
+
issues.push({
|
|
72
|
+
code: "invalid-locale",
|
|
73
|
+
locale: options.defaultLocale,
|
|
74
|
+
message: `Invalid default BCP 47 locale "${options.defaultLocale}".`
|
|
75
|
+
});
|
|
76
|
+
return issues;
|
|
77
|
+
}
|
|
78
|
+
const referenceCatalog = catalogs.get(defaultLocale);
|
|
79
|
+
if (!referenceCatalog) {
|
|
80
|
+
issues.push({
|
|
81
|
+
code: "invalid-catalog",
|
|
82
|
+
locale: defaultLocale,
|
|
83
|
+
message: `The default locale "${defaultLocale}" has no valid catalog.`
|
|
84
|
+
});
|
|
85
|
+
return issues;
|
|
86
|
+
}
|
|
87
|
+
for (const [locale, catalog] of catalogs) {
|
|
88
|
+
for (const [key, message] of Object.entries(catalog)) {
|
|
89
|
+
try {
|
|
90
|
+
new intl_messageformat.default(message, locale);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
issues.push({
|
|
93
|
+
code: "invalid-message",
|
|
94
|
+
locale,
|
|
95
|
+
key,
|
|
96
|
+
message: error instanceof Error ? error.message : String(error)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const referenceMessage = referenceCatalog[key];
|
|
100
|
+
if (referenceMessage !== void 0 && !placeholdersMatch(referenceMessage, message)) issues.push({
|
|
101
|
+
code: "placeholder-mismatch",
|
|
102
|
+
locale,
|
|
103
|
+
key,
|
|
104
|
+
message: `Placeholder names in "${key}" do not match "${defaultLocale}".`
|
|
105
|
+
});
|
|
106
|
+
if (referenceMessage === void 0) issues.push({
|
|
107
|
+
code: "unused-key",
|
|
108
|
+
locale,
|
|
109
|
+
key,
|
|
110
|
+
message: `Key "${key}" is not present in the default locale "${defaultLocale}".`
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
for (const key of Object.keys(referenceCatalog)) if (catalog[key] === void 0) issues.push({
|
|
114
|
+
code: "missing-key",
|
|
115
|
+
locale,
|
|
116
|
+
key,
|
|
117
|
+
message: `Key "${key}" is missing from locale "${locale}".`
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return issues;
|
|
121
|
+
};
|
|
122
|
+
const findUnusedTranslationKeys = (catalog, usedKeys) => {
|
|
123
|
+
const used = new Set(usedKeys);
|
|
124
|
+
return Object.keys(flattenCatalog(catalog)).filter((key) => !used.has(key)).sort();
|
|
125
|
+
};
|
|
126
|
+
const findMissingTranslationKeys = (catalog, usedKeys) => {
|
|
127
|
+
const available = new Set(Object.keys(flattenCatalog(catalog)));
|
|
128
|
+
return [...new Set(usedKeys)].filter((key) => !available.has(key)).sort();
|
|
129
|
+
};
|
|
130
|
+
const optimizeCatalog = (catalog, usedKeys) => {
|
|
131
|
+
flattenCatalog(catalog);
|
|
132
|
+
const used = new Set(usedKeys);
|
|
133
|
+
const prune = (current, prefix = "") => {
|
|
134
|
+
const entries = [];
|
|
135
|
+
for (const [key, value] of Object.entries(current)) {
|
|
136
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
137
|
+
if (typeof value === "string") {
|
|
138
|
+
if (used.has(path)) entries.push([key, value]);
|
|
139
|
+
} else {
|
|
140
|
+
const nested = prune(value, path);
|
|
141
|
+
if (nested && Object.keys(nested).length > 0) entries.push([key, nested]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return entries.length > 0 ? Object.freeze(Object.fromEntries(entries)) : void 0;
|
|
145
|
+
};
|
|
146
|
+
return prune(catalog) ?? Object.freeze({});
|
|
147
|
+
};
|
|
148
|
+
const renderInterface = (catalog, indent) => {
|
|
149
|
+
const padding = " ".repeat(indent);
|
|
150
|
+
const lines = ["{"];
|
|
151
|
+
for (const [key, value] of Object.entries(catalog).sort(([left], [right]) => left.localeCompare(right))) if (typeof value === "string") lines.push(`${padding} readonly ${JSON.stringify(key)}: ${JSON.stringify(value)};`);
|
|
152
|
+
else if (isRecord(value)) lines.push(`${padding} readonly ${JSON.stringify(key)}: ${renderInterface(value, indent + 2).trimStart()};`);
|
|
153
|
+
lines.push(`${padding}}`);
|
|
154
|
+
return lines.join("\n");
|
|
155
|
+
};
|
|
156
|
+
const generateCatalogTypes = (catalog, typeName = "Messages") => {
|
|
157
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(typeName)) throw new Error(`Invalid TypeScript type name "${typeName}".`);
|
|
158
|
+
flattenCatalog(catalog);
|
|
159
|
+
return `export interface ${typeName} ${renderInterface(catalog, 0)}\n`;
|
|
160
|
+
};
|
|
161
|
+
const generateLocaleCatalogTypes = (catalogs, typeName = "Messages") => {
|
|
162
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(typeName)) throw new Error(`Invalid TypeScript type name "${typeName}".`);
|
|
163
|
+
const flattened = /* @__PURE__ */ new Map();
|
|
164
|
+
const localeCatalogs = /* @__PURE__ */ new Map();
|
|
165
|
+
for (const [inputLocale, catalog] of Object.entries(catalogs)) {
|
|
166
|
+
const locale = canonicalLocale(inputLocale);
|
|
167
|
+
if (!locale) throw new Error(`Invalid BCP 47 locale "${inputLocale}".`);
|
|
168
|
+
if (flattened.has(locale)) throw new Error(`More than one catalog resolves to "${locale}".`);
|
|
169
|
+
flattened.set(locale, flattenCatalog(catalog));
|
|
170
|
+
localeCatalogs.set(locale, catalog);
|
|
171
|
+
}
|
|
172
|
+
if (flattened.size === 0) throw new Error("At least one locale catalog is required.");
|
|
173
|
+
const locales = [...flattened.keys()].sort((left, right) => left.localeCompare(right));
|
|
174
|
+
const firstCatalog = flattened.get(locales[0] ?? "");
|
|
175
|
+
const commonKeys = Object.keys(firstCatalog ?? {}).filter((key) => locales.every((locale) => flattened.get(locale)?.[key] !== void 0));
|
|
176
|
+
const commonTree = Object.create(null);
|
|
177
|
+
for (const key of commonKeys) {
|
|
178
|
+
const messages = [...new Set(locales.map((locale) => flattened.get(locale)?.[key]).filter((message) => message !== void 0))].sort();
|
|
179
|
+
const path = key.split(".");
|
|
180
|
+
let current = commonTree;
|
|
181
|
+
for (const segment of path.slice(0, -1)) {
|
|
182
|
+
const child = current[segment];
|
|
183
|
+
if (!isRecord(child)) current[segment] = Object.create(null);
|
|
184
|
+
current = current[segment];
|
|
185
|
+
}
|
|
186
|
+
const leaf = path[path.length - 1];
|
|
187
|
+
if (leaf !== void 0) current[leaf] = messages;
|
|
188
|
+
}
|
|
189
|
+
const renderTypeObject = (value, indent) => {
|
|
190
|
+
const padding = " ".repeat(indent);
|
|
191
|
+
const lines = ["{"];
|
|
192
|
+
for (const [key, entry] of Object.entries(value).sort(([left], [right]) => left.localeCompare(right))) if (Array.isArray(entry) && entry.every((item) => typeof item === "string")) lines.push(`${padding} readonly ${JSON.stringify(key)}: ${entry.map((item) => JSON.stringify(item)).join(" | ")};`);
|
|
193
|
+
else if (isRecord(entry)) lines.push(`${padding} readonly ${JSON.stringify(key)}: ${renderTypeObject(entry, indent + 2).trimStart()};`);
|
|
194
|
+
lines.push(`${padding}}`);
|
|
195
|
+
return lines.join("\n");
|
|
196
|
+
};
|
|
197
|
+
const localizedTypes = locales.map((locale) => {
|
|
198
|
+
const catalog = localeCatalogs.get(locale);
|
|
199
|
+
if (!catalog) throw new Error(`Missing catalog for locale "${locale}".`);
|
|
200
|
+
return ` readonly ${JSON.stringify(locale)}: ${renderInterface(catalog, 2).trimStart()};`;
|
|
201
|
+
});
|
|
202
|
+
const localizedTypeName = `${typeName}ByLocale`;
|
|
203
|
+
return [
|
|
204
|
+
`export type ${typeName} = ${renderTypeObject(commonTree, 0)};`,
|
|
205
|
+
`export type ${localizedTypeName} = {`,
|
|
206
|
+
...localizedTypes,
|
|
207
|
+
"};",
|
|
208
|
+
""
|
|
209
|
+
].join("\n");
|
|
210
|
+
};
|
|
211
|
+
exports.findMissingTranslationKeys = findMissingTranslationKeys;
|
|
212
|
+
exports.findUnusedTranslationKeys = findUnusedTranslationKeys;
|
|
213
|
+
exports.generateCatalogTypes = generateCatalogTypes;
|
|
214
|
+
exports.generateLocaleCatalogTypes = generateLocaleCatalogTypes;
|
|
215
|
+
exports.optimizeCatalog = optimizeCatalog;
|
|
216
|
+
exports.validateCatalogs = validateCatalogs;
|
|
217
|
+
|
|
218
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["IntlMessageFormat"],"sources":["../../src/compiler/index.ts"],"sourcesContent":["import IntlMessageFormat from \"intl-messageformat\";\n\nimport type { MessageCatalog, MessageEntry } from \"../runtime\";\n\nexport interface CatalogValidationIssue {\n code:\n | \"invalid-locale\"\n | \"invalid-catalog\"\n | \"missing-key\"\n | \"unused-key\"\n | \"invalid-message\"\n | \"placeholder-mismatch\";\n locale: string;\n key?: string;\n message: string;\n}\n\nexport interface ValidateCatalogsOptions {\n catalogs: Readonly<Record<string, unknown>>;\n defaultLocale: string;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n};\n\nconst flattenCatalog = (\n value: unknown,\n prefix = \"\",\n entries: Record<string, string> = Object.create(null) as Record<\n string,\n string\n >,\n ancestors = new WeakSet<object>(),\n): Record<string, string> => {\n if (!isRecord(value)) {\n throw new Error(`Catalog value at \"${prefix || \"<root>\"}\" must be an object.`);\n }\n\n if (ancestors.has(value)) {\n throw new Error(\n `Catalog value at \"${prefix || \"<root>\"}\" contains a circular reference.`,\n );\n }\n\n ancestors.add(value);\n\n for (const [key, entry] of Object.entries(value)) {\n const path = prefix ? `${prefix}.${key}` : key;\n\n if (!key || key.includes(\".\")) {\n throw new Error(\n `Catalog key \"${key}\" at \"${prefix || \"<root>\"}\" is empty or contains \".\", which is reserved for nested paths.`,\n );\n }\n\n if (typeof entry === \"string\") {\n entries[path] = entry;\n } else if (isRecord(entry)) {\n flattenCatalog(entry, path, entries, ancestors);\n } else {\n throw new Error(`Catalog value at \"${path}\" must be a string or object.`);\n }\n }\n\n ancestors.delete(value);\n return entries;\n};\n\nconst canonicalLocale = (locale: string): string | undefined => {\n try {\n return Intl.getCanonicalLocales(locale)[0];\n } catch {\n return undefined;\n }\n};\n\nconst getVariables = (message: string): string[] =>\n [...message.matchAll(/\\{\\s*([A-Za-z_][\\w.-]*)/g)]\n .map((match) => match[1])\n .filter((name): name is string => name !== undefined)\n .sort();\n\nconst placeholdersMatch = (left: string, right: string): boolean => {\n const leftVariables = getVariables(left);\n const rightVariables = getVariables(right);\n\n return (\n leftVariables.length === rightVariables.length &&\n leftVariables.every((variable, index) => variable === rightVariables[index])\n );\n};\n\nexport const validateCatalogs = (\n options: ValidateCatalogsOptions,\n): CatalogValidationIssue[] => {\n const issues: CatalogValidationIssue[] = [];\n const catalogs = new Map<string, Record<string, string>>();\n\n for (const [inputLocale, catalog] of Object.entries(options.catalogs)) {\n const locale = canonicalLocale(inputLocale);\n\n if (!locale) {\n issues.push({\n code: \"invalid-locale\",\n locale: inputLocale,\n message: `Invalid BCP 47 locale \"${inputLocale}\".`,\n });\n continue;\n }\n\n if (catalogs.has(locale)) {\n issues.push({\n code: \"invalid-locale\",\n locale,\n message: `More than one catalog resolves to \"${locale}\".`,\n });\n continue;\n }\n\n try {\n catalogs.set(locale, flattenCatalog(catalog));\n } catch (error) {\n issues.push({\n code: \"invalid-catalog\",\n locale,\n message: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n const defaultLocale = canonicalLocale(options.defaultLocale);\n\n if (!defaultLocale) {\n issues.push({\n code: \"invalid-locale\",\n locale: options.defaultLocale,\n message: `Invalid default BCP 47 locale \"${options.defaultLocale}\".`,\n });\n return issues;\n }\n\n const referenceCatalog = catalogs.get(defaultLocale);\n\n if (!referenceCatalog) {\n issues.push({\n code: \"invalid-catalog\",\n locale: defaultLocale,\n message: `The default locale \"${defaultLocale}\" has no valid catalog.`,\n });\n return issues;\n }\n\n for (const [locale, catalog] of catalogs) {\n for (const [key, message] of Object.entries(catalog)) {\n try {\n new IntlMessageFormat(message, locale);\n } catch (error) {\n issues.push({\n code: \"invalid-message\",\n locale,\n key,\n message: error instanceof Error ? error.message : String(error),\n });\n }\n\n const referenceMessage = referenceCatalog[key];\n\n if (\n referenceMessage !== undefined &&\n !placeholdersMatch(referenceMessage, message)\n ) {\n issues.push({\n code: \"placeholder-mismatch\",\n locale,\n key,\n message: `Placeholder names in \"${key}\" do not match \"${defaultLocale}\".`,\n });\n }\n\n if (referenceMessage === undefined) {\n issues.push({\n code: \"unused-key\",\n locale,\n key,\n message: `Key \"${key}\" is not present in the default locale \"${defaultLocale}\".`,\n });\n }\n }\n\n for (const key of Object.keys(referenceCatalog)) {\n if (catalog[key] === undefined) {\n issues.push({\n code: \"missing-key\",\n locale,\n key,\n message: `Key \"${key}\" is missing from locale \"${locale}\".`,\n });\n }\n }\n }\n\n return issues;\n};\n\nexport const findUnusedTranslationKeys = (\n catalog: MessageCatalog,\n usedKeys: Iterable<string>,\n): string[] => {\n const used = new Set(usedKeys);\n return Object.keys(flattenCatalog(catalog))\n .filter((key) => !used.has(key))\n .sort();\n};\n\nexport const findMissingTranslationKeys = (\n catalog: MessageCatalog,\n usedKeys: Iterable<string>,\n): string[] => {\n const available = new Set(Object.keys(flattenCatalog(catalog)));\n\n return [...new Set(usedKeys)]\n .filter((key) => !available.has(key))\n .sort();\n};\n\nexport const optimizeCatalog = (\n catalog: MessageCatalog,\n usedKeys: Iterable<string>,\n): MessageCatalog => {\n flattenCatalog(catalog);\n const used = new Set(usedKeys);\n const prune = (\n current: MessageCatalog,\n prefix = \"\",\n ): MessageCatalog | undefined => {\n const entries: [string, MessageEntry][] = [];\n\n for (const [key, value] of Object.entries(current)) {\n const path = prefix ? `${prefix}.${key}` : key;\n\n if (typeof value === \"string\") {\n if (used.has(path)) {\n entries.push([key, value]);\n }\n } else {\n const nested = prune(value, path);\n\n if (nested && Object.keys(nested).length > 0) {\n entries.push([key, nested]);\n }\n }\n }\n\n return entries.length > 0\n ? Object.freeze(Object.fromEntries(entries))\n : undefined;\n };\n\n return prune(catalog) ?? Object.freeze({});\n};\n\nconst renderInterface = (\n catalog: Readonly<Record<string, unknown>>,\n indent: number,\n): string => {\n const padding = \" \".repeat(indent);\n const lines: string[] = [\"{\"];\n\n for (const [key, value] of Object.entries(catalog).sort(([left], [right]) =>\n left.localeCompare(right),\n )) {\n if (typeof value === \"string\") {\n lines.push(`${padding} readonly ${JSON.stringify(key)}: ${JSON.stringify(value)};`);\n } else if (isRecord(value)) {\n lines.push(\n `${padding} readonly ${JSON.stringify(key)}: ${renderInterface(value, indent + 2).trimStart()};`,\n );\n }\n }\n\n lines.push(`${padding}}`);\n return lines.join(\"\\n\");\n};\n\nexport const generateCatalogTypes = (\n catalog: MessageCatalog,\n typeName = \"Messages\",\n): string => {\n if (!/^[A-Za-z_$][\\w$]*$/.test(typeName)) {\n throw new Error(`Invalid TypeScript type name \"${typeName}\".`);\n }\n\n flattenCatalog(catalog);\n\n return `export interface ${typeName} ${renderInterface(catalog, 0)}\\n`;\n};\n\nexport const generateLocaleCatalogTypes = (\n catalogs: Readonly<Record<string, MessageCatalog>>,\n typeName = \"Messages\",\n): string => {\n if (!/^[A-Za-z_$][\\w$]*$/.test(typeName)) {\n throw new Error(`Invalid TypeScript type name \"${typeName}\".`);\n }\n\n const flattened = new Map<string, Record<string, string>>();\n const localeCatalogs = new Map<string, MessageCatalog>();\n\n for (const [inputLocale, catalog] of Object.entries(catalogs)) {\n const locale = canonicalLocale(inputLocale);\n\n if (!locale) {\n throw new Error(`Invalid BCP 47 locale \"${inputLocale}\".`);\n }\n\n if (flattened.has(locale)) {\n throw new Error(`More than one catalog resolves to \"${locale}\".`);\n }\n\n flattened.set(locale, flattenCatalog(catalog));\n localeCatalogs.set(locale, catalog);\n }\n\n if (flattened.size === 0) {\n throw new Error(\"At least one locale catalog is required.\");\n }\n\n const locales = [...flattened.keys()].sort((left, right) =>\n left.localeCompare(right),\n );\n const firstCatalog = flattened.get(locales[0] ?? \"\");\n const commonKeys = Object.keys(firstCatalog ?? {}).filter((key) =>\n locales.every((locale) => flattened.get(locale)?.[key] !== undefined),\n );\n const commonTree: Record<string, unknown> = Object.create(null) as Record<\n string,\n unknown\n >;\n\n for (const key of commonKeys) {\n const messages = [\n ...new Set(\n locales\n .map((locale) => flattened.get(locale)?.[key])\n .filter((message): message is string => message !== undefined),\n ),\n ].sort();\n const path = key.split(\".\");\n let current = commonTree;\n\n for (const segment of path.slice(0, -1)) {\n const child = current[segment];\n\n if (!isRecord(child)) {\n current[segment] = Object.create(null) as Record<string, unknown>;\n }\n\n current = current[segment] as Record<string, unknown>;\n }\n\n const leaf = path[path.length - 1];\n\n if (leaf !== undefined) {\n current[leaf] = messages;\n }\n }\n\n const renderTypeObject = (\n value: Readonly<Record<string, unknown>>,\n indent: number,\n ): string => {\n const padding = \" \".repeat(indent);\n const lines = [\"{\"];\n\n for (const [key, entry] of Object.entries(value).sort(([left], [right]) =>\n left.localeCompare(right),\n )) {\n if (Array.isArray(entry) && entry.every((item) => typeof item === \"string\")) {\n lines.push(\n `${padding} readonly ${JSON.stringify(key)}: ${entry.map((item) => JSON.stringify(item)).join(\" | \")};`,\n );\n } else if (isRecord(entry)) {\n lines.push(\n `${padding} readonly ${JSON.stringify(key)}: ${renderTypeObject(entry, indent + 2).trimStart()};`,\n );\n }\n }\n\n lines.push(`${padding}}`);\n return lines.join(\"\\n\");\n };\n\n const localizedTypes = locales.map((locale) => {\n const catalog = localeCatalogs.get(locale);\n\n if (!catalog) {\n throw new Error(`Missing catalog for locale \"${locale}\".`);\n }\n\n return ` readonly ${JSON.stringify(locale)}: ${renderInterface(catalog, 2).trimStart()};`;\n });\n const localizedTypeName = `${typeName}ByLocale`;\n const messagesType = renderTypeObject(commonTree, 0);\n\n return [\n `export type ${typeName} = ${messagesType};`,\n `export type ${localizedTypeName} = {`,\n ...localizedTypes,\n \"};\",\n \"\",\n ].join(\"\\n\");\n};\n\nexport type { MessageCatalog, MessageEntry };\n"],"mappings":";;;;;AAsBA,MAAM,YAAY,UAAqD;CACrE,IAAI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