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