@terai/dev 0.0.0-dev-20251120061434 → 0.0.0-dev-20251122135504

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.
Files changed (52) hide show
  1. package/bin.js +1 -1
  2. package/dist/cli.default.cjs +71 -0
  3. package/dist/cli.default.cjs.map +1 -0
  4. package/dist/cli.default.d.cts +1 -0
  5. package/dist/cli.default.d.mts +1 -1
  6. package/dist/cli.default.mjs +67 -20936
  7. package/dist/cli.default.mjs.map +1 -1
  8. package/dist/index.cjs +2 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +9 -0
  11. package/dist/index.d.cts.map +1 -0
  12. package/dist/index.d.mts +6 -4
  13. package/dist/index.d.mts.map +1 -0
  14. package/dist/index.mjs +1 -14
  15. package/dist/index.mjs.map +1 -1
  16. package/package.json +21 -16
  17. package/dist/cli.d.mts +0 -3
  18. package/dist/cli.d.ts +0 -3
  19. package/dist/cli.default.d.ts +0 -1
  20. package/dist/cli.default.js +0 -20920
  21. package/dist/cli.default.js.map +0 -1
  22. package/dist/cli.js +0 -20906
  23. package/dist/cli.js.map +0 -1
  24. package/dist/cli.mjs +0 -20914
  25. package/dist/cli.mjs.map +0 -1
  26. package/dist/commands/extract.d.mts +0 -12
  27. package/dist/commands/extract.d.ts +0 -12
  28. package/dist/commands/extract.js +0 -694
  29. package/dist/commands/extract.js.map +0 -1
  30. package/dist/commands/extract.mjs +0 -662
  31. package/dist/commands/extract.mjs.map +0 -1
  32. package/dist/commands/index.d.mts +0 -5
  33. package/dist/commands/index.d.ts +0 -5
  34. package/dist/commands/index.js +0 -1004
  35. package/dist/commands/index.js.map +0 -1
  36. package/dist/commands/index.mjs +0 -966
  37. package/dist/commands/index.mjs.map +0 -1
  38. package/dist/commands/init.d.mts +0 -12
  39. package/dist/commands/init.d.ts +0 -12
  40. package/dist/commands/init.js +0 -784
  41. package/dist/commands/init.js.map +0 -1
  42. package/dist/commands/init.mjs +0 -748
  43. package/dist/commands/init.mjs.map +0 -1
  44. package/dist/commands/translate.d.mts +0 -10
  45. package/dist/commands/translate.d.ts +0 -10
  46. package/dist/commands/translate.js +0 -731
  47. package/dist/commands/translate.js.map +0 -1
  48. package/dist/commands/translate.mjs +0 -693
  49. package/dist/commands/translate.mjs.map +0 -1
  50. package/dist/index.d.ts +0 -7
  51. package/dist/index.js +0 -41
  52. package/dist/index.js.map +0 -1
@@ -1,662 +0,0 @@
1
- // src/commands/extract.ts
2
- import { debounce } from "perfect-debounce";
3
- import { extract } from "@terai/extractor";
4
-
5
- // ../generator/dist/chunk-N4N3TZO6.mjs
6
- import { runtime } from "@terai/runtime";
7
- import { stringify } from "@terai/utils";
8
- async function generate({
9
- dictionaries,
10
- locale,
11
- cwd,
12
- outDir
13
- }) {
14
- const folderPath = runtime.path.resolve(cwd, outDir, locale);
15
- const output = [];
16
- for (const id in dictionaries) {
17
- const fileDir = runtime.path.resolve(folderPath, `${id}.json`);
18
- const fileContent = dictionaries[id];
19
- const idOutput = stringify(fileContent);
20
- runtime.fs.write(fileDir, idOutput);
21
- output.push(idOutput);
22
- }
23
- return output;
24
- }
25
-
26
- // src/commands/extract.ts
27
- import { loadConfig, runtime as runtime2 } from "@terai/runtime";
28
-
29
- // ../logger/dist/chunk-HH7ZIRTH.mjs
30
- import process from "process";
31
- import os from "os";
32
- import tty from "tty";
33
- var ANSI_BACKGROUND_OFFSET = 10;
34
- var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
35
- var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
36
- var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
37
- var styles = {
38
- modifier: {
39
- reset: [0, 0],
40
- // 21 isn't widely supported and 22 does the same thing
41
- bold: [1, 22],
42
- dim: [2, 22],
43
- italic: [3, 23],
44
- underline: [4, 24],
45
- overline: [53, 55],
46
- inverse: [7, 27],
47
- hidden: [8, 28],
48
- strikethrough: [9, 29]
49
- },
50
- color: {
51
- black: [30, 39],
52
- red: [31, 39],
53
- green: [32, 39],
54
- yellow: [33, 39],
55
- blue: [34, 39],
56
- magenta: [35, 39],
57
- cyan: [36, 39],
58
- white: [37, 39],
59
- // Bright color
60
- blackBright: [90, 39],
61
- gray: [90, 39],
62
- // Alias of `blackBright`
63
- grey: [90, 39],
64
- // Alias of `blackBright`
65
- redBright: [91, 39],
66
- greenBright: [92, 39],
67
- yellowBright: [93, 39],
68
- blueBright: [94, 39],
69
- magentaBright: [95, 39],
70
- cyanBright: [96, 39],
71
- whiteBright: [97, 39]
72
- },
73
- bgColor: {
74
- bgBlack: [40, 49],
75
- bgRed: [41, 49],
76
- bgGreen: [42, 49],
77
- bgYellow: [43, 49],
78
- bgBlue: [44, 49],
79
- bgMagenta: [45, 49],
80
- bgCyan: [46, 49],
81
- bgWhite: [47, 49],
82
- // Bright color
83
- bgBlackBright: [100, 49],
84
- bgGray: [100, 49],
85
- // Alias of `bgBlackBright`
86
- bgGrey: [100, 49],
87
- // Alias of `bgBlackBright`
88
- bgRedBright: [101, 49],
89
- bgGreenBright: [102, 49],
90
- bgYellowBright: [103, 49],
91
- bgBlueBright: [104, 49],
92
- bgMagentaBright: [105, 49],
93
- bgCyanBright: [106, 49],
94
- bgWhiteBright: [107, 49]
95
- }
96
- };
97
- Object.keys(styles.modifier);
98
- var foregroundColorNames = Object.keys(styles.color);
99
- var backgroundColorNames = Object.keys(styles.bgColor);
100
- [...foregroundColorNames, ...backgroundColorNames];
101
- function assembleStyles() {
102
- const codes = /* @__PURE__ */ new Map();
103
- for (const [groupName, group] of Object.entries(styles)) {
104
- for (const [styleName, style] of Object.entries(group)) {
105
- styles[styleName] = {
106
- open: `\x1B[${style[0]}m`,
107
- close: `\x1B[${style[1]}m`
108
- };
109
- group[styleName] = styles[styleName];
110
- codes.set(style[0], style[1]);
111
- }
112
- Object.defineProperty(styles, groupName, {
113
- value: group,
114
- enumerable: false
115
- });
116
- }
117
- Object.defineProperty(styles, "codes", {
118
- value: codes,
119
- enumerable: false
120
- });
121
- styles.color.close = "\x1B[39m";
122
- styles.bgColor.close = "\x1B[49m";
123
- styles.color.ansi = wrapAnsi16();
124
- styles.color.ansi256 = wrapAnsi256();
125
- styles.color.ansi16m = wrapAnsi16m();
126
- styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
127
- styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
128
- styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
129
- Object.defineProperties(styles, {
130
- rgbToAnsi256: {
131
- value(red, green, blue) {
132
- if (red === green && green === blue) {
133
- if (red < 8) {
134
- return 16;
135
- }
136
- if (red > 248) {
137
- return 231;
138
- }
139
- return Math.round((red - 8) / 247 * 24) + 232;
140
- }
141
- return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
142
- },
143
- enumerable: false
144
- },
145
- hexToRgb: {
146
- value(hex) {
147
- const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
148
- if (!matches) {
149
- return [0, 0, 0];
150
- }
151
- let [colorString] = matches;
152
- if (colorString.length === 3) {
153
- colorString = [...colorString].map((character) => character + character).join("");
154
- }
155
- const integer = Number.parseInt(colorString, 16);
156
- return [
157
- /* eslint-disable no-bitwise */
158
- integer >> 16 & 255,
159
- integer >> 8 & 255,
160
- integer & 255
161
- /* eslint-enable no-bitwise */
162
- ];
163
- },
164
- enumerable: false
165
- },
166
- hexToAnsi256: {
167
- value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
168
- enumerable: false
169
- },
170
- ansi256ToAnsi: {
171
- value(code) {
172
- if (code < 8) {
173
- return 30 + code;
174
- }
175
- if (code < 16) {
176
- return 90 + (code - 8);
177
- }
178
- let red;
179
- let green;
180
- let blue;
181
- if (code >= 232) {
182
- red = ((code - 232) * 10 + 8) / 255;
183
- green = red;
184
- blue = red;
185
- } else {
186
- code -= 16;
187
- const remainder = code % 36;
188
- red = Math.floor(code / 36) / 5;
189
- green = Math.floor(remainder / 6) / 5;
190
- blue = remainder % 6 / 5;
191
- }
192
- const value = Math.max(red, green, blue) * 2;
193
- if (value === 0) {
194
- return 30;
195
- }
196
- let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
197
- if (value === 2) {
198
- result += 60;
199
- }
200
- return result;
201
- },
202
- enumerable: false
203
- },
204
- rgbToAnsi: {
205
- value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
206
- enumerable: false
207
- },
208
- hexToAnsi: {
209
- value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
210
- enumerable: false
211
- }
212
- });
213
- return styles;
214
- }
215
- var ansiStyles = assembleStyles();
216
- var ansi_styles_default = ansiStyles;
217
- function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {
218
- const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
219
- const position = argv.indexOf(prefix + flag);
220
- const terminatorPosition = argv.indexOf("--");
221
- return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
222
- }
223
- var { env } = process;
224
- var flagForceColor;
225
- if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
226
- flagForceColor = 0;
227
- } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
228
- flagForceColor = 1;
229
- }
230
- function envForceColor() {
231
- if ("FORCE_COLOR" in env) {
232
- if (env.FORCE_COLOR === "true") {
233
- return 1;
234
- }
235
- if (env.FORCE_COLOR === "false") {
236
- return 0;
237
- }
238
- return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
239
- }
240
- }
241
- function translateLevel(level) {
242
- if (level === 0) {
243
- return false;
244
- }
245
- return {
246
- level,
247
- hasBasic: true,
248
- has256: level >= 2,
249
- has16m: level >= 3
250
- };
251
- }
252
- function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
253
- const noFlagForceColor = envForceColor();
254
- if (noFlagForceColor !== void 0) {
255
- flagForceColor = noFlagForceColor;
256
- }
257
- const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
258
- if (forceColor === 0) {
259
- return 0;
260
- }
261
- if (sniffFlags) {
262
- if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
263
- return 3;
264
- }
265
- if (hasFlag("color=256")) {
266
- return 2;
267
- }
268
- }
269
- if ("TF_BUILD" in env && "AGENT_NAME" in env) {
270
- return 1;
271
- }
272
- if (haveStream && !streamIsTTY && forceColor === void 0) {
273
- return 0;
274
- }
275
- const min = forceColor || 0;
276
- if (env.TERM === "dumb") {
277
- return min;
278
- }
279
- if (process.platform === "win32") {
280
- const osRelease = os.release().split(".");
281
- if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
282
- return Number(osRelease[2]) >= 14931 ? 3 : 2;
283
- }
284
- return 1;
285
- }
286
- if ("CI" in env) {
287
- if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
288
- return 3;
289
- }
290
- if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
291
- return 1;
292
- }
293
- return min;
294
- }
295
- if ("TEAMCITY_VERSION" in env) {
296
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
297
- }
298
- if (env.COLORTERM === "truecolor") {
299
- return 3;
300
- }
301
- if (env.TERM === "xterm-kitty") {
302
- return 3;
303
- }
304
- if (env.TERM === "xterm-ghostty") {
305
- return 3;
306
- }
307
- if (env.TERM === "wezterm") {
308
- return 3;
309
- }
310
- if ("TERM_PROGRAM" in env) {
311
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
312
- switch (env.TERM_PROGRAM) {
313
- case "iTerm.app": {
314
- return version >= 3 ? 3 : 2;
315
- }
316
- case "Apple_Terminal": {
317
- return 2;
318
- }
319
- }
320
- }
321
- if (/-256(color)?$/i.test(env.TERM)) {
322
- return 2;
323
- }
324
- if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
325
- return 1;
326
- }
327
- if ("COLORTERM" in env) {
328
- return 1;
329
- }
330
- return min;
331
- }
332
- function createSupportsColor(stream, options = {}) {
333
- const level = _supportsColor(stream, {
334
- streamIsTTY: stream && stream.isTTY,
335
- ...options
336
- });
337
- return translateLevel(level);
338
- }
339
- var supportsColor = {
340
- stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
341
- stderr: createSupportsColor({ isTTY: tty.isatty(2) })
342
- };
343
- var supports_color_default = supportsColor;
344
- function stringReplaceAll(string, substring, replacer) {
345
- let index = string.indexOf(substring);
346
- if (index === -1) {
347
- return string;
348
- }
349
- const substringLength = substring.length;
350
- let endIndex = 0;
351
- let returnValue = "";
352
- do {
353
- returnValue += string.slice(endIndex, index) + substring + replacer;
354
- endIndex = index + substringLength;
355
- index = string.indexOf(substring, endIndex);
356
- } while (index !== -1);
357
- returnValue += string.slice(endIndex);
358
- return returnValue;
359
- }
360
- function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
361
- let endIndex = 0;
362
- let returnValue = "";
363
- do {
364
- const gotCR = string[index - 1] === "\r";
365
- returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
366
- endIndex = index + 1;
367
- index = string.indexOf("\n", endIndex);
368
- } while (index !== -1);
369
- returnValue += string.slice(endIndex);
370
- return returnValue;
371
- }
372
- var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
373
- var GENERATOR = Symbol("GENERATOR");
374
- var STYLER = Symbol("STYLER");
375
- var IS_EMPTY = Symbol("IS_EMPTY");
376
- var levelMapping = [
377
- "ansi",
378
- "ansi",
379
- "ansi256",
380
- "ansi16m"
381
- ];
382
- var styles2 = /* @__PURE__ */ Object.create(null);
383
- var applyOptions = (object, options = {}) => {
384
- if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
385
- throw new Error("The `level` option should be an integer from 0 to 3");
386
- }
387
- const colorLevel = stdoutColor ? stdoutColor.level : 0;
388
- object.level = options.level === void 0 ? colorLevel : options.level;
389
- };
390
- var chalkFactory = (options) => {
391
- const chalk2 = (...strings) => strings.join(" ");
392
- applyOptions(chalk2, options);
393
- Object.setPrototypeOf(chalk2, createChalk.prototype);
394
- return chalk2;
395
- };
396
- function createChalk(options) {
397
- return chalkFactory(options);
398
- }
399
- Object.setPrototypeOf(createChalk.prototype, Function.prototype);
400
- for (const [styleName, style] of Object.entries(ansi_styles_default)) {
401
- styles2[styleName] = {
402
- get() {
403
- const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
404
- Object.defineProperty(this, styleName, { value: builder });
405
- return builder;
406
- }
407
- };
408
- }
409
- styles2.visible = {
410
- get() {
411
- const builder = createBuilder(this, this[STYLER], true);
412
- Object.defineProperty(this, "visible", { value: builder });
413
- return builder;
414
- }
415
- };
416
- var getModelAnsi = (model, level, type, ...arguments_) => {
417
- if (model === "rgb") {
418
- if (level === "ansi16m") {
419
- return ansi_styles_default[type].ansi16m(...arguments_);
420
- }
421
- if (level === "ansi256") {
422
- return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
423
- }
424
- return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
425
- }
426
- if (model === "hex") {
427
- return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
428
- }
429
- return ansi_styles_default[type][model](...arguments_);
430
- };
431
- var usedModels = ["rgb", "hex", "ansi256"];
432
- for (const model of usedModels) {
433
- styles2[model] = {
434
- get() {
435
- const { level } = this;
436
- return function(...arguments_) {
437
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
438
- return createBuilder(this, styler, this[IS_EMPTY]);
439
- };
440
- }
441
- };
442
- const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
443
- styles2[bgModel] = {
444
- get() {
445
- const { level } = this;
446
- return function(...arguments_) {
447
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
448
- return createBuilder(this, styler, this[IS_EMPTY]);
449
- };
450
- }
451
- };
452
- }
453
- var proto = Object.defineProperties(() => {
454
- }, {
455
- ...styles2,
456
- level: {
457
- enumerable: true,
458
- get() {
459
- return this[GENERATOR].level;
460
- },
461
- set(level) {
462
- this[GENERATOR].level = level;
463
- }
464
- }
465
- });
466
- var createStyler = (open, close, parent) => {
467
- let openAll;
468
- let closeAll;
469
- if (parent === void 0) {
470
- openAll = open;
471
- closeAll = close;
472
- } else {
473
- openAll = parent.openAll + open;
474
- closeAll = close + parent.closeAll;
475
- }
476
- return {
477
- open,
478
- close,
479
- openAll,
480
- closeAll,
481
- parent
482
- };
483
- };
484
- var createBuilder = (self, _styler, _isEmpty) => {
485
- const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
486
- Object.setPrototypeOf(builder, proto);
487
- builder[GENERATOR] = self;
488
- builder[STYLER] = _styler;
489
- builder[IS_EMPTY] = _isEmpty;
490
- return builder;
491
- };
492
- var applyStyle = (self, string) => {
493
- if (self.level <= 0 || !string) {
494
- return self[IS_EMPTY] ? "" : string;
495
- }
496
- let styler = self[STYLER];
497
- if (styler === void 0) {
498
- return string;
499
- }
500
- const { openAll, closeAll } = styler;
501
- if (string.includes("\x1B")) {
502
- while (styler !== void 0) {
503
- string = stringReplaceAll(string, styler.close, styler.open);
504
- styler = styler.parent;
505
- }
506
- }
507
- const lfIndex = string.indexOf("\n");
508
- if (lfIndex !== -1) {
509
- string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
510
- }
511
- return openAll + string + closeAll;
512
- };
513
- Object.defineProperties(createChalk.prototype, styles2);
514
- var chalk = createChalk();
515
- createChalk({ level: stderrColor ? stderrColor.level : 0 });
516
- var source_default = chalk;
517
- function log(message) {
518
- return process.stdout.write(`${message}
519
- `);
520
- }
521
- function logError(message) {
522
- return process.stderr.write(`${message}
523
- `);
524
- }
525
- function logBullet(logger2, colorizePrefix, colorizeText, symbol, prefix, text) {
526
- const textParts = Array.isArray(text) ? text : [text || ""].filter(Boolean);
527
- const formattedText = textParts.map((textPart) => colorizeText(textPart)).join("");
528
- logger2(
529
- `${" ".repeat(3)} ${colorizePrefix(symbol)} ${colorizePrefix(
530
- prefix
531
- )} ${formattedText}`
532
- );
533
- }
534
- function warn(prefix, text) {
535
- logBullet(log, source_default.yellow, source_default.yellow, "\u25CF", prefix, text);
536
- }
537
- function debug(prefix, text) {
538
- logBullet(log, source_default.yellow, source_default.dim, "\u25CF", prefix, text);
539
- }
540
- function info(prefix, text) {
541
- logBullet(log, source_default.cyan, source_default.dim, "\u25FC", prefix, text);
542
- }
543
- function success(text) {
544
- logBullet(log, source_default.green, source_default.dim, "\u2714", text);
545
- }
546
- function error(prefix, text) {
547
- log("");
548
- logBullet(logError, source_default.red, source_default.red, "\u25B2", prefix, text);
549
- }
550
- function heading(heading2, description) {
551
- return log(
552
- `
553
- ${source_default.bgWhite(` ${source_default.whiteBright(heading2)} `)} ${source_default.bold(
554
- description
555
- )}
556
- `
557
- );
558
- }
559
- var timing = (fn) => () => {
560
- const start = performance.now();
561
- return (msg) => {
562
- const end = performance.now();
563
- const ms = end - start;
564
- fn(`${msg} ${source_default.gray(`(${ms.toFixed(2)}ms)`)}`);
565
- };
566
- };
567
- var logger = {
568
- colors: source_default,
569
- log,
570
- heading,
571
- debug,
572
- info,
573
- warn,
574
- success,
575
- error,
576
- time: {
577
- success: timing(success),
578
- info: timing(info),
579
- debug: timing(debug)
580
- }
581
- };
582
-
583
- // src/commands/extract.ts
584
- import {
585
- convertExtractedMessagesToDictionary,
586
- stringify as stringify2,
587
- groupDictionaryByChunks
588
- } from "@terai/utils";
589
- function createExtractCommand(cli, cwd) {
590
- return cli.command("extract", "Statically extract messages from your project").option("-w, --watch", "Watch files and rebuild").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(extractCmd);
591
- }
592
- async function extractCmd(options) {
593
- logger.heading("extract", "Statically extract messages from your project");
594
- const done = logger.time.success();
595
- const config = await loadConfig(options);
596
- const filesPaths = runtime2.fs.glob({
597
- ...config,
598
- cwd: options.cwd
599
- });
600
- const outDirPath = runtime2.path.resolve(options.cwd, config.outDir);
601
- const projectLocalePath = runtime2.path.resolve(
602
- outDirPath,
603
- config.projectLocale
604
- );
605
- const manifestPath = runtime2.path.resolve(
606
- outDirPath,
607
- ".terai",
608
- "locale-manifest.json"
609
- );
610
- logger.info("Scan:", "Processing files...");
611
- async function extractor(files = filesPaths) {
612
- const extractedMessages = await extract({
613
- ...config,
614
- filesPaths: files,
615
- cwd: options.cwd
616
- });
617
- const dictionary = convertExtractedMessagesToDictionary(extractedMessages);
618
- const manifest = {
619
- messages: extractedMessages
620
- };
621
- const dictionaries = groupDictionaryByChunks(
622
- dictionary,
623
- manifest,
624
- config.projectLocale
625
- );
626
- runtime2.fs.remove(runtime2.path.resolve(projectLocalePath));
627
- await generate({
628
- ...config,
629
- dictionaries,
630
- locale: config.projectLocale,
631
- cwd: options.cwd
632
- });
633
- runtime2.fs.write(manifestPath, stringify2(manifest));
634
- return Object.keys(dictionary).length;
635
- }
636
- logger.info("Extraction:", "Extracting messages...");
637
- const msgCount = await extractor();
638
- done(`Extracted ${msgCount} messages`);
639
- if (options.watch) {
640
- logger.log("");
641
- logger.info("Watch:", "Watching files for changes...\n");
642
- const configWatcher = runtime2.fs.watch({
643
- ...config,
644
- ...options
645
- });
646
- configWatcher.on(
647
- "change",
648
- debounce(async () => {
649
- const done2 = logger.time.success();
650
- logger.info("Extraction:", "Files changed, processing messages...");
651
- const msgCount2 = await extractor();
652
- done2(`Extracted ${msgCount2} messages`);
653
- logger.log("");
654
- })
655
- );
656
- }
657
- }
658
- export {
659
- createExtractCommand,
660
- extractCmd
661
- };
662
- //# sourceMappingURL=extract.mjs.map