@terai/dev 0.0.7 → 0.0.8

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