@menapo/vi18n 0.1.0 → 0.1.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.
- package/README.md +14 -14
- package/dist/{apply-Bre-lY9J.js → apply-FAHl1R6T.js} +69 -89
- package/dist/{captured-Bj8bO6vd.js → captured-CTjjDF5o.js} +196 -217
- package/dist/{check-DyrAbv73.js → check-DwFwOB1d.js} +66 -84
- package/dist/cli.js +2 -3
- package/dist/{collect-Cx4_SKOe.js → collect-CYATDjdo.js} +1 -2
- package/dist/collisions-uMTuq36M.js +215 -0
- package/dist/compile-CEvH-6sY.js +240 -0
- package/dist/{compile-Cc97JaW2.js → compile-DqkofbiO.js} +376 -331
- package/dist/concurrency-BCY_4zcr.js +1 -0
- package/dist/concurrency-Dy2ny50V.js +107 -0
- package/dist/config.d.ts +1 -5
- package/dist/config.js +4 -5
- package/dist/{types-D3QGM8XO.js → diagnostics-1onDF6Ua.js} +26 -26
- package/dist/{dir-zw6bGMKQ.js → dir-TGLYuOZb.js} +34 -37
- package/dist/{duplicates-yuRljQ6h.js → duplicates-CsUXRX2J.js} +10 -27
- package/dist/engine-Bf7nVigL.js +556 -0
- package/dist/engine.d.ts +1 -5
- package/dist/engine.js +297 -168
- package/dist/exchange-DYG9RZoT.js +41 -0
- package/dist/{exclude-Du-Zd_qI.js → exclude-vMnm3lqU.js} +2 -3
- package/dist/{export-DGsMbcTZ.js → export-BYq0gfLd.js} +17 -38
- package/dist/{extract-Dujlsgnk.js → extract-CYtuEo8u.js} +114 -82
- package/dist/{formats-KPIg-08V.js → formats-ChV1LVH_.js} +352 -276
- package/dist/fs-ezCMZeDV.js +52 -0
- package/dist/i18next-1waHziMy.js +1 -0
- package/dist/i18next-D66Icz3L.js +1907 -0
- package/dist/{import-Cwdhcywt.js → import-BApbQlmm.js} +81 -75
- package/dist/index.d.ts +1 -13
- package/dist/index.js +14 -16
- package/dist/{init-BecCTvKi.js → init-J7AwwA5e.js} +466 -501
- package/dist/{library-D5CWvTQs.js → library-BfSOBeBd.js} +975 -451
- package/dist/lingui-Ee2farVo.js +902 -0
- package/dist/lint.d.ts +0 -4
- package/dist/lint.js +69 -82
- package/dist/{load-gW-oJt1Q.js → load-BFLLqY8x.js} +272 -147
- package/dist/{load-CQRz4PpM.js → load-CMwhukZ4.js} +1211 -1115
- package/dist/{locales-DX4MOBFE.js → locales-DxLDrx-h.js} +271 -237
- package/dist/{lsp-Cq1Nuu-Q.js → lsp-BC7xDGON.js} +4 -5
- package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
- package/dist/{mcp-Cf0T7qPW.js → mcp-Cka8ywDF.js} +4 -5
- package/dist/{merge-driver-CpiiSVIc.js → merge-driver-B04Apm29.js} +138 -122
- package/dist/migrate-D7TNl6SD.js +2169 -0
- package/dist/migrate-khCY8TE0.js +1 -0
- package/dist/{openai-CTaMDcl-.js → openai-RWw0YlAx.js} +128 -87
- package/dist/{output-DsaHKHEt.js → output-CF9uvk_-.js} +15 -9
- package/dist/parse.d.ts +1 -3
- package/dist/parse.js +7 -8
- package/dist/{pipeline-wxS0SApG.js → pipeline-B30irGMD.js} +1 -1
- package/dist/{pipeline-C7g11THL.js → pipeline-sgl_q_op.js} +387 -359
- package/dist/project-DSzWKU3C.js +544 -0
- package/dist/{pseudo-DRv30iN5.js → pseudo-DNbNNVGP.js} +125 -3
- package/dist/{raw-C4Y6vyGY.js → raw-YsYZMS9n.js} +52 -29
- package/dist/react-intl-tzGIk6G3.js +634 -0
- package/dist/restore-BG_zMpSj.js +199 -0
- package/dist/rewrite-hAcRJwiZ.js +415 -0
- package/dist/{rich-DCUKl5HM.js → rich-ApY1Dm4S.js} +35 -28
- package/dist/rolldown-runtime-C1I3wEg2.js +43 -0
- package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
- package/dist/run-CFzR3V93.js +647 -0
- package/dist/scan-worker.d.ts +2 -4
- package/dist/scan-worker.js +1 -1
- package/dist/{scoped-BMYpSthj.js → scoped-h3KE8XWW.js} +3 -4
- package/dist/{server-BDkykMjb.js → server-WlxZH0oX.js} +275 -330
- package/dist/{server-qv3mz70d.js → server-ceuzzkal.js} +292 -386
- package/dist/server.d.ts +1 -17
- package/dist/server.js +415 -381
- package/dist/{sitemap-DV3o8QD7.js → sitemap-796jJKUT.js} +21 -33
- package/dist/{sources-D19czDSA.js → sources-DuOdM02f.js} +712 -373
- package/dist/{status-DZArW5aE.js → status-CTH3qI-0.js} +30 -30
- package/dist/{stdio-FPOKQAgu.js → stdio-D9kTzyqB.js} +2 -4
- package/dist/{stdio-CVaJfxA7.js → stdio-FWIVU3P4.js} +1 -2
- package/dist/sync-CpL0Qsgw.js +1352 -0
- package/dist/{t-DC-c9zE5.js → t-gvEXx25s.js} +76 -53
- package/dist/test.d.ts +5 -16
- package/dist/test.js +77 -48
- package/dist/translate-BrfVRkjl.js +336 -0
- package/dist/{ts-BaU5yOf0.js → ts-BX6kwig5.js} +25 -14
- package/dist/{types-DtvQ7UdD.js → types-3kwyaCAm.js} +1 -2
- package/dist/{types-DsdWBG0b.d.ts → types-BaG1LboH.d.ts} +2 -6
- package/dist/{types-CgUCkFU1.d.ts → types-Cy2bPdSg.d.ts} +14 -20
- package/dist/types-Ds_vebja.js +41 -0
- package/dist/{units-CQ5Q99RC.js → units-VVLgQ7x7.js} +7 -16
- package/dist/{url-CRfCOhUI.js → url-Bpc6wLea.js} +24 -11
- package/dist/{url-CsBkRaJy.js → url-D2_VlEeH.js} +25 -12
- package/dist/{validate-D6DJepZv.js → validate-PGgMsasz.js} +3 -5
- package/dist/{validate-BxpupdAf.js → validate-zv4-IZyZ.js} +690 -377
- package/dist/{version-BlyLGlOa.js → version-BFs370Ce.js} +3 -5
- package/dist/{vite-scan-B_YW4X_a.js → vite-scan-DFKSGVE9.js} +87 -92
- package/dist/vite.d.ts +2 -6
- package/dist/vite.js +6482 -6018
- package/dist/vue-i18n-CBmZqHbG.js +806 -0
- package/dist/{which-C6PFI1Dm.js → which-BpyJyBkX.js} +44 -37
- package/dist/{worker-84U6uYB3.js → worker-BjzVqJVO.js} +454 -608
- package/package.json +8 -8
- package/dist/check-D34P-S--.js +0 -1
- package/dist/codec-DuvU2VQy.js +0 -207
- package/dist/collisions-CfpZU8e4.js +0 -217
- package/dist/compile-B5Mz6WJm.js +0 -245
- package/dist/concurrency-C9UUWuDC.js +0 -96
- package/dist/concurrency-DONL7t4V.js +0 -1
- package/dist/engine-B7p40M__.js +0 -531
- package/dist/i18next-CrUnKFfh.js +0 -1596
- package/dist/i18next-Rgo-v9l0.js +0 -1
- package/dist/lingui--PcOOYry.js +0 -833
- package/dist/messages-Cxa-5tR0.js +0 -166
- package/dist/migrate-CntqvrW4.js +0 -1
- package/dist/migrate-dPgq9uzy.js +0 -1484
- package/dist/project-Dwx7iPm6.js +0 -381
- package/dist/project-pXipT8iG.js +0 -1046
- package/dist/react-intl-CaBVwJ9u.js +0 -519
- package/dist/restore-Btq66Tid.js +0 -175
- package/dist/rewrite-CiTRAICl.js +0 -803
- package/dist/run-DYD_VXKy.js +0 -694
- package/dist/runtime-DTMmliT1.js +0 -64
- package/dist/sync-CcVzger_.js +0 -658
- package/dist/translate-DZR3MkSA.js +0 -299
- package/dist/types-wSh9fCBY.js +0 -11
- package/dist/vue-i18n-CEMnpv7k.js +0 -651
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { h as updateCatalogFile } from "./library-BfSOBeBd.js";
|
|
2
|
+
import { s as sourceIndexOf } from "./units-VVLgQ7x7.js";
|
|
3
|
+
import { t as VERSION } from "./version-BFs370Ce.js";
|
|
4
|
+
// src/cli/exchange.ts
|
|
5
|
+
/**
|
|
6
|
+
* What `export`, `import` and `restore` share: the source texts exchange
|
|
7
|
+
* rows are matched against, and one way to apply a change to a target
|
|
8
|
+
* locale's catalog, dry or written.
|
|
9
|
+
*/
|
|
10
|
+
/** What exchange readers and writers match rows against: the source locale's texts. */
|
|
11
|
+
function sourceContext(project, set) {
|
|
12
|
+
const { codec, layout, config } = project;
|
|
13
|
+
return {
|
|
14
|
+
layout,
|
|
15
|
+
codec,
|
|
16
|
+
sourceIndex: sourceIndexOf(set.get(config.sourceLocale)?.catalog ?? null, layout, codec)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Applies `apply` to a target locale's catalog: to the catalog as loaded on
|
|
21
|
+
* a dry run, else through the compare-and-swap writer, which re-reads the
|
|
22
|
+
* file and writes only a changed result. Null when the catalog vanished
|
|
23
|
+
* meanwhile.
|
|
24
|
+
*/
|
|
25
|
+
async function applyToCatalog(project, target, options, apply) {
|
|
26
|
+
if (options.dryRun) return apply(target.catalog);
|
|
27
|
+
let outcome = null;
|
|
28
|
+
await updateCatalogFile(target.path, target.hash, (current) => {
|
|
29
|
+
if (current === null) return null;
|
|
30
|
+
const applied = apply(current);
|
|
31
|
+
outcome = applied;
|
|
32
|
+
return applied.catalog === current ? null : applied.catalog;
|
|
33
|
+
}, {
|
|
34
|
+
locale: options.locale,
|
|
35
|
+
layout: project.layout,
|
|
36
|
+
isSourceLocale: false,
|
|
37
|
+
version: VERSION
|
|
38
|
+
});
|
|
39
|
+
return outcome;
|
|
40
|
+
}
|
|
41
|
+
export { sourceContext as n, applyToCatalog as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { g as isValidManualId } from "./validate-zv4-IZyZ.js";
|
|
2
|
+
// src/core/config/exclude.ts
|
|
3
3
|
/**
|
|
4
4
|
* `ai.exclude` entries (PLAN §4.6, §5.20; INTERNALS §2.15): a configured
|
|
5
5
|
* locale, a message id, or a glob over the config-relative files that use a
|
|
@@ -22,5 +22,4 @@ function excludeKind(entry, locales, idLength) {
|
|
|
22
22
|
if (isValidManualId(entry)) return "id";
|
|
23
23
|
return entry.length === idLength && BASE64URL.test(entry) ? "id" : null;
|
|
24
24
|
}
|
|
25
|
-
//#endregion
|
|
26
25
|
export { excludeKind as t };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { n as serializeExport } from "./formats-ChV1LVH_.js";
|
|
2
|
+
import { a as exchangeUnits, n as EXTENSIONS } from "./units-VVLgQ7x7.js";
|
|
3
|
+
import { n as sourceContext } from "./exchange-DYG9RZoT.js";
|
|
4
|
+
import { r as plural } from "./output-CF9uvk_-.js";
|
|
5
|
+
import { f as readErrors, g as usageError, h as targetLocales, o as loadCatalogs, s as loadProject, t as CliExit } from "./project-DSzWKU3C.js";
|
|
6
|
+
import { r as EXIT } from "./types-Ds_vebja.js";
|
|
6
7
|
import { join, resolve } from "node:path";
|
|
7
8
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
8
|
-
|
|
9
|
+
// src/cli/commands/export.ts
|
|
9
10
|
/**
|
|
10
11
|
* `vi18n export --format po|json|flat|xliff2|arb|csv [--locale l]… [--out dir]
|
|
11
12
|
* [--missing] [--ai]` (PLAN §4.4, §5.19, INTERNALS §2.6.9): each locale's
|
|
@@ -15,22 +16,14 @@ import { mkdir, writeFile } from "node:fs/promises";
|
|
|
15
16
|
*/
|
|
16
17
|
async function exportCatalogs(ctx, flags) {
|
|
17
18
|
const project = await loadProject(ctx);
|
|
18
|
-
const { config
|
|
19
|
+
const { config } = project;
|
|
19
20
|
const filtered = flags.missing || flags.ai;
|
|
20
|
-
const locales =
|
|
21
|
-
if (flags.out === null && locales.length !== 1) throw
|
|
22
|
-
code: "config-invalid",
|
|
23
|
-
severity: "error",
|
|
24
|
-
message: `${plural(locales.length, "locale")} to export: pass --out <dir> for one file per locale, or one --locale for stdout`
|
|
25
|
-
}]);
|
|
21
|
+
const locales = flags.locales.length === 0 && !filtered ? [...config.locales] : targetLocales(config, flags.locales, { includeSource: true });
|
|
22
|
+
if (flags.out === null && locales.length !== 1) throw usageError(`${plural(locales.length, "locale")} to export: pass --out <dir> for one file per locale, or one --locale for stdout`);
|
|
26
23
|
const loaded = await loadCatalogs(project);
|
|
27
24
|
const unreadable = readErrors(loaded.diagnostics);
|
|
28
25
|
if (unreadable.length > 0) throw new CliExit(EXIT.failure, unreadable);
|
|
29
|
-
const context =
|
|
30
|
-
layout,
|
|
31
|
-
codec,
|
|
32
|
-
sourceIndex: sourceIndexOf(loaded.set.get(config.sourceLocale)?.catalog ?? null, layout, codec)
|
|
33
|
-
};
|
|
26
|
+
const context = sourceContext(project, loaded.set);
|
|
34
27
|
const data = {
|
|
35
28
|
format: flags.format,
|
|
36
29
|
files: []
|
|
@@ -46,16 +39,16 @@ async function exportCatalogs(ctx, flags) {
|
|
|
46
39
|
locale,
|
|
47
40
|
isSourceLocale
|
|
48
41
|
});
|
|
49
|
-
const selected = filtered && !isSourceLocale ? units.filter((
|
|
42
|
+
const selected = filtered && !isSourceLocale ? units.filter((u) => isSelected(u, flags)) : units;
|
|
50
43
|
if (unsourced > 0) ctx.out.note(`vi18n export: ${locale}: left out ${plural(unsourced, "entry", "entries")} whose source text the catalogs do not hold; run vi18n extract`);
|
|
51
44
|
const text = serializeExport(flags.format, selected, {
|
|
52
45
|
locale,
|
|
53
46
|
sourceLocale: config.sourceLocale,
|
|
54
47
|
isSourceLocale,
|
|
55
|
-
idScheme: codec.idScheme,
|
|
48
|
+
idScheme: project.codec.idScheme,
|
|
56
49
|
msgid: config.catalogs.msgid,
|
|
57
50
|
header: catalog?.header ?? null,
|
|
58
|
-
layout
|
|
51
|
+
layout: project.layout
|
|
59
52
|
});
|
|
60
53
|
if (out === null) {
|
|
61
54
|
data.files.push({
|
|
@@ -82,22 +75,8 @@ async function exportCatalogs(ctx, flags) {
|
|
|
82
75
|
data
|
|
83
76
|
};
|
|
84
77
|
}
|
|
85
|
-
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
*/
|
|
89
|
-
function exportLocales(configured, sourceLocale, requested, filtered) {
|
|
90
|
-
if (requested.length === 0) return filtered ? configured.filter((locale) => locale !== sourceLocale) : [...configured];
|
|
91
|
-
const out = [];
|
|
92
|
-
for (const locale of requested) {
|
|
93
|
-
if (!configured.includes(locale)) throw new CliExit(EXIT.usage, [{
|
|
94
|
-
code: "config-invalid",
|
|
95
|
-
severity: "error",
|
|
96
|
-
message: `--locale ${locale} is not in locales (${configured.join(", ")})`
|
|
97
|
-
}]);
|
|
98
|
-
if (!out.includes(locale)) out.push(locale);
|
|
99
|
-
}
|
|
100
|
-
return out;
|
|
78
|
+
/** `--missing`: no translation that would ship; `--ai`: an AI translation (both: either). */
|
|
79
|
+
function isSelected(unit, flags) {
|
|
80
|
+
return flags.missing && !unit.usable || flags.ai && unit.state === "ai" && unit.translation !== "";
|
|
101
81
|
}
|
|
102
|
-
//#endregion
|
|
103
82
|
export { exportCatalogs };
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { a as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { dirname, join, resolve } from "node:path";
|
|
1
|
+
import { t as findCollisions } from "./collisions-uMTuq36M.js";
|
|
2
|
+
import { F as isIncluded, h as updateCatalogFile, n as libraryCoverage, s as catalogPath } from "./library-BfSOBeBd.js";
|
|
3
|
+
import { a as writeGenFile, n as syncCatalogs, s as scanProject, t as syncCatalog } from "./sync-CpL0Qsgw.js";
|
|
4
|
+
import { t as VERSION } from "./version-BFs370Ce.js";
|
|
5
|
+
import { a as table, i as rootRelative, o as errorMessage, r as plural } from "./output-CF9uvk_-.js";
|
|
6
|
+
import { a as hasErrors, c as occurrencesOf, f as readErrors, g as usageError, i as computeDrift, m as scan, o as loadCatalogs, s as loadProject } from "./project-DSzWKU3C.js";
|
|
7
|
+
import { r as EXIT } from "./types-Ds_vebja.js";
|
|
8
|
+
import { dirname, resolve } from "node:path";
|
|
10
9
|
import { watch } from "node:fs";
|
|
11
10
|
import { stat } from "node:fs/promises";
|
|
11
|
+
// src/cli/commands/extract.ts
|
|
12
|
+
/**
|
|
13
|
+
* `vi18n extract [--check] [--watch] [--yes]` (INTERNALS §2.14, PLAN §5.5):
|
|
14
|
+
* scan the whole include set, refuse on collisions or past the safety limit,
|
|
15
|
+
* then write every changed catalog through the compare-and-swap writer and
|
|
16
|
+
* refresh `vi18n.gen.ts`. `--check` writes nothing and fails on drift;
|
|
17
|
+
* `--watch` only ever adds, after each debounced change.
|
|
18
|
+
*/
|
|
19
|
+
/** Quiet period after the last file event before `--watch` re-scans (INTERNALS §2.14). */
|
|
20
|
+
const WATCH_DEBOUNCE_MS = 200;
|
|
12
21
|
async function extract(ctx, flags) {
|
|
13
22
|
const project = await loadProject(ctx);
|
|
14
23
|
if (flags.watch) return watchMode(ctx, project);
|
|
@@ -83,7 +92,7 @@ async function extract(ctx, flags) {
|
|
|
83
92
|
};
|
|
84
93
|
}
|
|
85
94
|
data.wrote = await writeCatalogs(project, loaded.set, sync, scanned, options);
|
|
86
|
-
if (await writeGenFile(config)) data.wrote.push(rootRelative(config.root,
|
|
95
|
+
if (await writeGenFile(config)) data.wrote.push(rootRelative(config.root, project.genPath));
|
|
87
96
|
printStats(ctx, data);
|
|
88
97
|
return {
|
|
89
98
|
exitCode: hasErrors(ctx.out.diagnostics) ? EXIT.failure : EXIT.ok,
|
|
@@ -168,16 +177,103 @@ function printStats(ctx, data) {
|
|
|
168
177
|
* files alone could not do.
|
|
169
178
|
*/
|
|
170
179
|
async function watchMode(ctx, project) {
|
|
171
|
-
const
|
|
172
|
-
|
|
180
|
+
const signal = ctx.io.signal;
|
|
181
|
+
if (signal === void 0) throw usageError("vi18n extract --watch needs a stop signal to end");
|
|
182
|
+
await writeGenFile(project.config);
|
|
183
|
+
const watcher = new CatalogWatcher(ctx, project);
|
|
184
|
+
await watcher.start(await watchRoots(project.config.project.include));
|
|
185
|
+
await watcher.stopOn(signal);
|
|
186
|
+
watcher.data.wrote = [...watcher.wrote].sort();
|
|
187
|
+
return {
|
|
188
|
+
exitCode: EXIT.ok,
|
|
189
|
+
data: watcher.data
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/** The watchers of `--watch`, a debounced pass after changes, and one way to stop both. */
|
|
193
|
+
var CatalogWatcher = class {
|
|
194
|
+
data = {
|
|
173
195
|
check: false,
|
|
174
196
|
wrote: [],
|
|
175
197
|
stats: {},
|
|
176
198
|
blocked: []
|
|
177
199
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
200
|
+
wrote = /* @__PURE__ */ new Set();
|
|
201
|
+
ctx;
|
|
202
|
+
project;
|
|
203
|
+
watchers = [];
|
|
204
|
+
timer = null;
|
|
205
|
+
running = Promise.resolve();
|
|
206
|
+
pending = false;
|
|
207
|
+
stopped = false;
|
|
208
|
+
/** Changes wait for the first pass: it may have read the file before the edit. */
|
|
209
|
+
first = true;
|
|
210
|
+
constructor(ctx, project) {
|
|
211
|
+
this.ctx = ctx;
|
|
212
|
+
this.project = project;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Watching starts before the first pass, so an edit made while it runs is
|
|
216
|
+
* seen; so is one made just after, which on macOS could otherwise land
|
|
217
|
+
* before FSEvents, started a moment after `watch()` returns, was listening.
|
|
218
|
+
*/
|
|
219
|
+
async start(roots) {
|
|
220
|
+
for (const root of roots) this.watchRoot(root);
|
|
221
|
+
try {
|
|
222
|
+
await this.pass();
|
|
223
|
+
} catch (error) {
|
|
224
|
+
this.stop();
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
this.first = false;
|
|
228
|
+
if (this.pending) this.schedule();
|
|
229
|
+
}
|
|
230
|
+
/** Resolves once the signal aborted and the running pass settled. */
|
|
231
|
+
stopOn(signal) {
|
|
232
|
+
return new Promise((done) => {
|
|
233
|
+
const stop = () => {
|
|
234
|
+
if (this.stopped) return;
|
|
235
|
+
this.stop();
|
|
236
|
+
this.running.then(done, done);
|
|
237
|
+
};
|
|
238
|
+
if (signal.aborted) stop();
|
|
239
|
+
else signal.addEventListener("abort", stop, { once: true });
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
stop() {
|
|
243
|
+
this.stopped = true;
|
|
244
|
+
if (this.timer !== null) clearTimeout(this.timer);
|
|
245
|
+
for (const watcher of this.watchers) watcher.close();
|
|
246
|
+
}
|
|
247
|
+
watchRoot(root) {
|
|
248
|
+
const { config } = this.project;
|
|
249
|
+
const onEvent = (_event, name) => {
|
|
250
|
+
if (this.stopped) return;
|
|
251
|
+
const file = name === null ? null : resolve(root.dir, name.toString());
|
|
252
|
+
if (file !== null && root.file !== null && file !== root.file) return;
|
|
253
|
+
if (file !== null && !isIncluded(file, config)) return;
|
|
254
|
+
this.pending = true;
|
|
255
|
+
if (!this.first) this.schedule();
|
|
256
|
+
};
|
|
257
|
+
try {
|
|
258
|
+
this.watchers.push(root.file === null ? watch(root.dir, { recursive: true }, onEvent) : watch(root.dir, {}, onEvent));
|
|
259
|
+
} catch (error) {
|
|
260
|
+
this.ctx.out.note(`vi18n: cannot watch ${root.dir}: ${errorMessage(error)}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
schedule() {
|
|
264
|
+
if (this.timer !== null) clearTimeout(this.timer);
|
|
265
|
+
this.timer = setTimeout(() => {
|
|
266
|
+
this.timer = null;
|
|
267
|
+
if (!this.pending) return;
|
|
268
|
+
this.pending = false;
|
|
269
|
+
this.running = this.running.then(() => this.pass()).catch((error) => {
|
|
270
|
+
this.ctx.out.note(`vi18n: ${errorMessage(error)}`);
|
|
271
|
+
});
|
|
272
|
+
}, WATCH_DEBOUNCE_MS);
|
|
273
|
+
}
|
|
274
|
+
async pass() {
|
|
275
|
+
const { ctx, project } = this;
|
|
276
|
+
const { config } = project;
|
|
181
277
|
const scanned = await scanProject(config, project.codec, { cache: true });
|
|
182
278
|
ctx.out.report(scanned.diagnostics);
|
|
183
279
|
if (scanned.aborted) return;
|
|
@@ -201,7 +297,7 @@ async function watchMode(ctx, project) {
|
|
|
201
297
|
if (hasErrors(collided)) return;
|
|
202
298
|
const files = await writeCatalogs(project, loaded.set, sync, scanned, options);
|
|
203
299
|
for (const [locale, stats] of Object.entries(sync.stats)) {
|
|
204
|
-
const total = data.stats[locale] ??= {
|
|
300
|
+
const total = this.data.stats[locale] ??= {
|
|
205
301
|
added: 0,
|
|
206
302
|
deleted: 0,
|
|
207
303
|
cleared: 0,
|
|
@@ -212,73 +308,10 @@ async function watchMode(ctx, project) {
|
|
|
212
308
|
total.added += stats.added;
|
|
213
309
|
total.updated += stats.updated;
|
|
214
310
|
}
|
|
215
|
-
for (const file of files) wrote.add(file);
|
|
311
|
+
for (const file of files) this.wrote.add(file);
|
|
216
312
|
if (files.length > 0) ctx.out.note(`vi18n: updated ${files.join(", ")}`);
|
|
217
|
-
};
|
|
218
|
-
await writeGenFile(config);
|
|
219
|
-
const roots = await watchRoots(config.project.include);
|
|
220
|
-
const watchers = [];
|
|
221
|
-
let timer = null;
|
|
222
|
-
let running = Promise.resolve();
|
|
223
|
-
let pending = false;
|
|
224
|
-
let stopped = false;
|
|
225
|
-
let first = true;
|
|
226
|
-
const schedule = () => {
|
|
227
|
-
if (timer !== null) clearTimeout(timer);
|
|
228
|
-
timer = setTimeout(() => {
|
|
229
|
-
timer = null;
|
|
230
|
-
if (!pending) return;
|
|
231
|
-
pending = false;
|
|
232
|
-
running = running.then(pass).catch((error) => {
|
|
233
|
-
ctx.out.note(`vi18n: ${error instanceof Error ? error.message : String(error)}`);
|
|
234
|
-
});
|
|
235
|
-
}, 200);
|
|
236
|
-
};
|
|
237
|
-
for (const root of roots) {
|
|
238
|
-
const onEvent = (_event, name) => {
|
|
239
|
-
if (stopped) return;
|
|
240
|
-
const file = name === null ? null : resolve(root.dir, name.toString());
|
|
241
|
-
if (file !== null && root.file !== null && file !== root.file) return;
|
|
242
|
-
if (file !== null && !isIncluded(file, config)) return;
|
|
243
|
-
pending = true;
|
|
244
|
-
if (!first) schedule();
|
|
245
|
-
};
|
|
246
|
-
try {
|
|
247
|
-
watchers.push(root.file === null ? watch(root.dir, { recursive: true }, onEvent) : watch(root.dir, {}, onEvent));
|
|
248
|
-
} catch (error) {
|
|
249
|
-
ctx.out.note(`vi18n: cannot watch ${root.dir}: ${error instanceof Error ? error.message : String(error)}`);
|
|
250
|
-
}
|
|
251
313
|
}
|
|
252
|
-
|
|
253
|
-
await pass();
|
|
254
|
-
} catch (error) {
|
|
255
|
-
stopped = true;
|
|
256
|
-
for (const watcher of watchers) watcher.close();
|
|
257
|
-
throw error;
|
|
258
|
-
}
|
|
259
|
-
first = false;
|
|
260
|
-
if (pending) schedule();
|
|
261
|
-
await new Promise((done) => {
|
|
262
|
-
const stop = () => {
|
|
263
|
-
if (stopped) return;
|
|
264
|
-
stopped = true;
|
|
265
|
-
if (timer !== null) clearTimeout(timer);
|
|
266
|
-
for (const watcher of watchers) watcher.close();
|
|
267
|
-
running.then(done, done);
|
|
268
|
-
};
|
|
269
|
-
if (signal === void 0) return;
|
|
270
|
-
if (signal.aborted) stop();
|
|
271
|
-
else signal.addEventListener("abort", stop, { once: true });
|
|
272
|
-
});
|
|
273
|
-
return finishWatch(data, wrote);
|
|
274
|
-
}
|
|
275
|
-
function finishWatch(data, wrote) {
|
|
276
|
-
data.wrote = [...wrote].sort();
|
|
277
|
-
return {
|
|
278
|
-
exitCode: EXIT.ok,
|
|
279
|
-
data
|
|
280
|
-
};
|
|
281
|
-
}
|
|
314
|
+
};
|
|
282
315
|
/** Directories to watch: each include directory recursively, a file's parent for a file entry. */
|
|
283
316
|
async function watchRoots(include) {
|
|
284
317
|
const roots = [];
|
|
@@ -294,5 +327,4 @@ async function watchRoots(include) {
|
|
|
294
327
|
} catch {}
|
|
295
328
|
return roots;
|
|
296
329
|
}
|
|
297
|
-
//#endregion
|
|
298
330
|
export { extract };
|