@menapo/vi18n 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.
- package/LICENSE +49 -0
- package/README.md +110 -2
- package/dist/apply-Bre-lY9J.js +228 -0
- package/dist/captured-Bj8bO6vd.js +1034 -0
- package/dist/check-D34P-S--.js +1 -0
- package/dist/check-DyrAbv73.js +201 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +41 -0
- package/dist/codec-DuvU2VQy.js +207 -0
- package/dist/collect-Cx4_SKOe.js +13 -0
- package/dist/collisions-CfpZU8e4.js +217 -0
- package/dist/compile-B5Mz6WJm.js +245 -0
- package/dist/compile-Cc97JaW2.js +2502 -0
- package/dist/concurrency-C9UUWuDC.js +96 -0
- package/dist/concurrency-DONL7t4V.js +1 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +39 -0
- package/dist/dir-zw6bGMKQ.js +290 -0
- package/dist/duplicates-yuRljQ6h.js +185 -0
- package/dist/engine-B7p40M__.js +531 -0
- package/dist/engine.d.ts +43 -0
- package/dist/engine.js +1241 -0
- package/dist/exclude-Du-Zd_qI.js +26 -0
- package/dist/export-DGsMbcTZ.js +103 -0
- package/dist/extract-Dujlsgnk.js +298 -0
- package/dist/formats-KPIg-08V.js +781 -0
- package/dist/i18next-CrUnKFfh.js +1596 -0
- package/dist/i18next-Rgo-v9l0.js +1 -0
- package/dist/import-Cwdhcywt.js +225 -0
- package/dist/index.d.ts +156 -0
- package/dist/index.js +239 -0
- package/dist/init-BecCTvKi.js +792 -0
- package/dist/library-D5CWvTQs.js +1882 -0
- package/dist/lingui--PcOOYry.js +833 -0
- package/dist/lint.d.ts +105 -0
- package/dist/lint.js +971 -0
- package/dist/load-CQRz4PpM.js +2950 -0
- package/dist/load-gW-oJt1Q.js +747 -0
- package/dist/locales-DX4MOBFE.js +827 -0
- package/dist/lsp-Cq1Nuu-Q.js +31 -0
- package/dist/match-BGr8EXB3.js +89 -0
- package/dist/mcp-Cf0T7qPW.js +28 -0
- package/dist/merge-driver-CpiiSVIc.js +422 -0
- package/dist/messages-Cxa-5tR0.js +166 -0
- package/dist/migrate-CntqvrW4.js +1 -0
- package/dist/migrate-dPgq9uzy.js +1484 -0
- package/dist/openai-CTaMDcl-.js +346 -0
- package/dist/output-DsaHKHEt.js +164 -0
- package/dist/parse.d.ts +62 -0
- package/dist/parse.js +156 -0
- package/dist/pipeline-C7g11THL.js +2031 -0
- package/dist/pipeline-wxS0SApG.js +1 -0
- package/dist/project-Dwx7iPm6.js +381 -0
- package/dist/project-pXipT8iG.js +1046 -0
- package/dist/pseudo-DRv30iN5.js +145 -0
- package/dist/raw-C4Y6vyGY.js +4708 -0
- package/dist/react-intl-CaBVwJ9u.js +519 -0
- package/dist/restore-Btq66Tid.js +175 -0
- package/dist/rewrite-CiTRAICl.js +803 -0
- package/dist/rich-DCUKl5HM.js +97 -0
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/run-DYD_VXKy.js +694 -0
- package/dist/runtime-DTMmliT1.js +64 -0
- package/dist/scan-worker.d.ts +62 -0
- package/dist/scan-worker.js +1 -0
- package/dist/scoped-BMYpSthj.js +44 -0
- package/dist/server-BDkykMjb.js +11823 -0
- package/dist/server-qv3mz70d.js +10485 -0
- package/dist/server.d.ts +169 -0
- package/dist/server.js +1234 -0
- package/dist/sitemap-DV3o8QD7.js +159 -0
- package/dist/sources-D19czDSA.js +2242 -0
- package/dist/status-DZArW5aE.js +149 -0
- package/dist/stdio-CVaJfxA7.js +29 -0
- package/dist/stdio-FPOKQAgu.js +95 -0
- package/dist/sync-CcVzger_.js +658 -0
- package/dist/t-DC-c9zE5.js +454 -0
- package/dist/test.d.ts +116 -0
- package/dist/test.js +319 -0
- package/dist/translate-DZR3MkSA.js +299 -0
- package/dist/ts-BaU5yOf0.js +4863 -0
- package/dist/types-CgUCkFU1.d.ts +707 -0
- package/dist/types-D3QGM8XO.js +146 -0
- package/dist/types-DsdWBG0b.d.ts +558 -0
- package/dist/types-DtvQ7UdD.js +1948 -0
- package/dist/types-wSh9fCBY.js +11 -0
- package/dist/units-CQ5Q99RC.js +150 -0
- package/dist/url-CRfCOhUI.js +172 -0
- package/dist/url-CsBkRaJy.js +225 -0
- package/dist/validate-BxpupdAf.js +2615 -0
- package/dist/validate-D6DJepZv.js +365 -0
- package/dist/version-BlyLGlOa.js +28 -0
- package/dist/vite-scan-B_YW4X_a.js +242 -0
- package/dist/vite.d.ts +34 -0
- package/dist/vite.js +7558 -0
- package/dist/vue-i18n-CEMnpv7k.js +651 -0
- package/dist/which-C6PFI1Dm.js +116 -0
- package/dist/worker-84U6uYB3.js +1656 -0
- package/package.json +97 -3
- package/schemas/catalog.json +57 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { i as toRuntimeConfig, n as normalizeBase } from "./runtime-DTMmliT1.js";
|
|
2
|
+
import { n as localeOrigin, r as localizePath, t as atHome } from "./url-CRfCOhUI.js";
|
|
3
|
+
import { r as plural } from "./output-DsaHKHEt.js";
|
|
4
|
+
import { t as EXIT } from "./types-wSh9fCBY.js";
|
|
5
|
+
import { o as loadProject, t as CliExit } from "./project-Dwx7iPm6.js";
|
|
6
|
+
import { dirname, resolve } from "node:path";
|
|
7
|
+
import { randomBytes } from "node:crypto";
|
|
8
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
9
|
+
//#region src/cli/commands/sitemap.ts
|
|
10
|
+
/**
|
|
11
|
+
* `vi18n sitemap [<route>…] [--routes <file>] [--base-url <url>] [--out <file>] [--check]`
|
|
12
|
+
* (PLAN §4.11, INTERNALS §2.14, §6 D137): a sitemap.xml listing every route
|
|
13
|
+
* in every advertised locale, each `<url>` with its hreflang alternates and
|
|
14
|
+
* `x-default`, built by the runtime's own URL codec (localized paths,
|
|
15
|
+
* domains), so it names exactly the URLs the app serves and `alternates()`
|
|
16
|
+
* prints. Routes are the app's route paths, as `localizedPaths()` takes them.
|
|
17
|
+
*/
|
|
18
|
+
/** XML text and attribute values: the five predefined entities. */
|
|
19
|
+
const xml = (text) => text.replace(/[&<>"']/g, (c) => ({
|
|
20
|
+
"&": "&",
|
|
21
|
+
"<": "<",
|
|
22
|
+
">": ">",
|
|
23
|
+
"\"": """,
|
|
24
|
+
"'": "'"
|
|
25
|
+
})[c]);
|
|
26
|
+
/** A usage error found after the flags parsed (a routes file, a missing base URL). */
|
|
27
|
+
function refuse(ctx, message) {
|
|
28
|
+
ctx.out.note(`vi18n sitemap: ${message}`);
|
|
29
|
+
throw new CliExit(EXIT.usage, [], { usage: message });
|
|
30
|
+
}
|
|
31
|
+
/** Route paths of `--routes <file>`: a JSON array, or one per line (`#` starts a comment). */
|
|
32
|
+
async function readRoutes(ctx, file) {
|
|
33
|
+
let text;
|
|
34
|
+
try {
|
|
35
|
+
text = await readFile(resolve(ctx.global.cwd, file), "utf8");
|
|
36
|
+
} catch (error) {
|
|
37
|
+
refuse(ctx, `--routes ${file}: ${error.message}`);
|
|
38
|
+
}
|
|
39
|
+
if (/^\s*\[/.test(text)) {
|
|
40
|
+
let list;
|
|
41
|
+
try {
|
|
42
|
+
list = JSON.parse(text);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
refuse(ctx, `--routes ${file}: ${error.message}`);
|
|
45
|
+
}
|
|
46
|
+
if (!Array.isArray(list) || !list.every((x) => typeof x === "string")) refuse(ctx, `--routes ${file}: expected an array of route paths`);
|
|
47
|
+
return list;
|
|
48
|
+
}
|
|
49
|
+
return text.split(/\r?\n/).map((line) => line.replace(/#.*/, "").trim()).filter((line) => line !== "");
|
|
50
|
+
}
|
|
51
|
+
/** The sitemap of `routes`: per route, per advertised locale, its URL and the alternates. */
|
|
52
|
+
function sitemapEntries(routes, config, baseUrl) {
|
|
53
|
+
const base = baseUrl ? normalizeBase(baseUrl.pathname) : normalizeBase(config.routing.base ?? "/");
|
|
54
|
+
const rc = toRuntimeConfig(config, {
|
|
55
|
+
base,
|
|
56
|
+
pseudo: false
|
|
57
|
+
});
|
|
58
|
+
const single = rc.routing.url === "no_prefix";
|
|
59
|
+
const href = (route, l) => {
|
|
60
|
+
const path = base + new URL(route, "http://h").pathname.slice(1);
|
|
61
|
+
const origin = localeOrigin(l, rc);
|
|
62
|
+
if (origin !== void 0) return origin + localizePath(path, l, atHome(rc, l));
|
|
63
|
+
return baseUrl.origin + localizePath(path, l, rc);
|
|
64
|
+
};
|
|
65
|
+
const out = [];
|
|
66
|
+
const seen = /* @__PURE__ */ new Set();
|
|
67
|
+
for (const route of routes) {
|
|
68
|
+
if (seen.has(route)) continue;
|
|
69
|
+
seen.add(route);
|
|
70
|
+
const urls = {};
|
|
71
|
+
for (const l of single ? [rc.sourceLocale] : rc.locales) urls[l] = href(route, l);
|
|
72
|
+
if (!single) urls["x-default"] = href(route, rc.sourceLocale);
|
|
73
|
+
out.push({
|
|
74
|
+
path: route,
|
|
75
|
+
urls
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
/** The sitemap document: one `<url>` per route and locale, each with the route's alternates. */
|
|
81
|
+
function sitemapXml(routes) {
|
|
82
|
+
let body = "";
|
|
83
|
+
const seen = /* @__PURE__ */ new Set();
|
|
84
|
+
for (const { urls } of routes) {
|
|
85
|
+
const links = Object.entries(urls);
|
|
86
|
+
for (const [hreflang, loc] of links) {
|
|
87
|
+
if (hreflang === "x-default" || seen.has(loc)) continue;
|
|
88
|
+
seen.add(loc);
|
|
89
|
+
body += ` <url>\n <loc>${xml(loc)}</loc>\n`;
|
|
90
|
+
if (links.length > 1) for (const [h, url] of links) body += ` <xhtml:link rel="alternate" hreflang="${xml(h)}" href="${xml(url)}"/>\n`;
|
|
91
|
+
body += " </url>\n";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n" + body + "</urlset>\n";
|
|
95
|
+
}
|
|
96
|
+
async function sitemap(ctx, flags) {
|
|
97
|
+
const { config } = await loadProject(ctx);
|
|
98
|
+
const routes = [...flags.routes];
|
|
99
|
+
if (flags.routesFile !== null) routes.push(...await readRoutes(ctx, flags.routesFile));
|
|
100
|
+
const bad = routes.find((r) => !r.startsWith("/") || /[?#]/.test(r));
|
|
101
|
+
if (bad !== void 0) refuse(ctx, `${JSON.stringify(bad)} is not a route path (/about)`);
|
|
102
|
+
if (routes.length === 0) refuse(ctx, "no routes: list route paths, or --routes <file>");
|
|
103
|
+
let baseUrl = null;
|
|
104
|
+
if (flags.baseUrl !== null) {
|
|
105
|
+
try {
|
|
106
|
+
baseUrl = new URL(flags.baseUrl);
|
|
107
|
+
} catch {
|
|
108
|
+
baseUrl = null;
|
|
109
|
+
}
|
|
110
|
+
if (baseUrl === null || baseUrl.protocol !== "https:" && baseUrl.protocol !== "http:") refuse(ctx, `--base-url ${flags.baseUrl}: expected an absolute http(s) URL`);
|
|
111
|
+
} else if (config.locales.some((l) => !Object.values(config.routing.domains).includes(l))) refuse(ctx, "--base-url <url> is required: sitemaps list absolute URLs");
|
|
112
|
+
const entries = sitemapEntries(routes, config, baseUrl);
|
|
113
|
+
const text = sitemapXml(entries);
|
|
114
|
+
const urls = new Set(entries.flatMap((e) => Object.values(e.urls))).size;
|
|
115
|
+
const data = {
|
|
116
|
+
out: flags.out,
|
|
117
|
+
written: false,
|
|
118
|
+
routes: entries
|
|
119
|
+
};
|
|
120
|
+
if (flags.out === null) {
|
|
121
|
+
ctx.out.result(text);
|
|
122
|
+
return {
|
|
123
|
+
exitCode: EXIT.ok,
|
|
124
|
+
data
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const file = resolve(ctx.global.cwd, flags.out);
|
|
128
|
+
const current = await readFile(file, "utf8").catch(() => null);
|
|
129
|
+
if (flags.check) {
|
|
130
|
+
if (current === text) return {
|
|
131
|
+
exitCode: EXIT.ok,
|
|
132
|
+
data
|
|
133
|
+
};
|
|
134
|
+
ctx.out.note(`vi18n sitemap --check: ${ctx.out.display(file)} is out of date`);
|
|
135
|
+
return {
|
|
136
|
+
exitCode: EXIT.failure,
|
|
137
|
+
data
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (current !== text) {
|
|
141
|
+
const temp = `${file}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`;
|
|
142
|
+
await mkdir(dirname(file), { recursive: true });
|
|
143
|
+
try {
|
|
144
|
+
await writeFile(temp, text);
|
|
145
|
+
await rename(temp, file);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
await rm(temp, { force: true });
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
data.written = true;
|
|
151
|
+
}
|
|
152
|
+
ctx.out.result(`${data.written ? "wrote" : "unchanged:"} ${ctx.out.display(file)} (${plural(urls, "URL")} for ${plural(entries.length, "route")})`);
|
|
153
|
+
return {
|
|
154
|
+
exitCode: EXIT.ok,
|
|
155
|
+
data
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
export { sitemap };
|