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

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 +7 -5
  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,1004 +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/index.ts
31
- var commands_exports = {};
32
- __export(commands_exports, {
33
- createExtractCommand: () => createExtractCommand,
34
- createInitCommand: () => createInitCommand,
35
- createTranslateCommand: () => createTranslateCommand,
36
- extractCmd: () => extractCmd,
37
- initCmd: () => initCmd,
38
- translateCmd: () => translateCmd
39
- });
40
- module.exports = __toCommonJS(commands_exports);
41
-
42
- // src/commands/init.ts
43
- var import_runtime = require("@terai/runtime");
44
- var import_prompts = require("@inquirer/prompts");
45
-
46
- // ../logger/dist/chunk-HH7ZIRTH.mjs
47
- var import_process = __toESM(require("process"), 1);
48
- var import_os = __toESM(require("os"), 1);
49
- var import_tty = __toESM(require("tty"), 1);
50
- var ANSI_BACKGROUND_OFFSET = 10;
51
- var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
52
- var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
53
- var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
54
- var styles = {
55
- modifier: {
56
- reset: [0, 0],
57
- // 21 isn't widely supported and 22 does the same thing
58
- bold: [1, 22],
59
- dim: [2, 22],
60
- italic: [3, 23],
61
- underline: [4, 24],
62
- overline: [53, 55],
63
- inverse: [7, 27],
64
- hidden: [8, 28],
65
- strikethrough: [9, 29]
66
- },
67
- color: {
68
- black: [30, 39],
69
- red: [31, 39],
70
- green: [32, 39],
71
- yellow: [33, 39],
72
- blue: [34, 39],
73
- magenta: [35, 39],
74
- cyan: [36, 39],
75
- white: [37, 39],
76
- // Bright color
77
- blackBright: [90, 39],
78
- gray: [90, 39],
79
- // Alias of `blackBright`
80
- grey: [90, 39],
81
- // Alias of `blackBright`
82
- redBright: [91, 39],
83
- greenBright: [92, 39],
84
- yellowBright: [93, 39],
85
- blueBright: [94, 39],
86
- magentaBright: [95, 39],
87
- cyanBright: [96, 39],
88
- whiteBright: [97, 39]
89
- },
90
- bgColor: {
91
- bgBlack: [40, 49],
92
- bgRed: [41, 49],
93
- bgGreen: [42, 49],
94
- bgYellow: [43, 49],
95
- bgBlue: [44, 49],
96
- bgMagenta: [45, 49],
97
- bgCyan: [46, 49],
98
- bgWhite: [47, 49],
99
- // Bright color
100
- bgBlackBright: [100, 49],
101
- bgGray: [100, 49],
102
- // Alias of `bgBlackBright`
103
- bgGrey: [100, 49],
104
- // Alias of `bgBlackBright`
105
- bgRedBright: [101, 49],
106
- bgGreenBright: [102, 49],
107
- bgYellowBright: [103, 49],
108
- bgBlueBright: [104, 49],
109
- bgMagentaBright: [105, 49],
110
- bgCyanBright: [106, 49],
111
- bgWhiteBright: [107, 49]
112
- }
113
- };
114
- Object.keys(styles.modifier);
115
- var foregroundColorNames = Object.keys(styles.color);
116
- var backgroundColorNames = Object.keys(styles.bgColor);
117
- [...foregroundColorNames, ...backgroundColorNames];
118
- function assembleStyles() {
119
- const codes = /* @__PURE__ */ new Map();
120
- for (const [groupName, group] of Object.entries(styles)) {
121
- for (const [styleName, style] of Object.entries(group)) {
122
- styles[styleName] = {
123
- open: `\x1B[${style[0]}m`,
124
- close: `\x1B[${style[1]}m`
125
- };
126
- group[styleName] = styles[styleName];
127
- codes.set(style[0], style[1]);
128
- }
129
- Object.defineProperty(styles, groupName, {
130
- value: group,
131
- enumerable: false
132
- });
133
- }
134
- Object.defineProperty(styles, "codes", {
135
- value: codes,
136
- enumerable: false
137
- });
138
- styles.color.close = "\x1B[39m";
139
- styles.bgColor.close = "\x1B[49m";
140
- styles.color.ansi = wrapAnsi16();
141
- styles.color.ansi256 = wrapAnsi256();
142
- styles.color.ansi16m = wrapAnsi16m();
143
- styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
144
- styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
145
- styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
146
- Object.defineProperties(styles, {
147
- rgbToAnsi256: {
148
- value(red, green, blue) {
149
- if (red === green && green === blue) {
150
- if (red < 8) {
151
- return 16;
152
- }
153
- if (red > 248) {
154
- return 231;
155
- }
156
- return Math.round((red - 8) / 247 * 24) + 232;
157
- }
158
- return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
159
- },
160
- enumerable: false
161
- },
162
- hexToRgb: {
163
- value(hex) {
164
- const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
165
- if (!matches) {
166
- return [0, 0, 0];
167
- }
168
- let [colorString] = matches;
169
- if (colorString.length === 3) {
170
- colorString = [...colorString].map((character) => character + character).join("");
171
- }
172
- const integer = Number.parseInt(colorString, 16);
173
- return [
174
- /* eslint-disable no-bitwise */
175
- integer >> 16 & 255,
176
- integer >> 8 & 255,
177
- integer & 255
178
- /* eslint-enable no-bitwise */
179
- ];
180
- },
181
- enumerable: false
182
- },
183
- hexToAnsi256: {
184
- value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
185
- enumerable: false
186
- },
187
- ansi256ToAnsi: {
188
- value(code) {
189
- if (code < 8) {
190
- return 30 + code;
191
- }
192
- if (code < 16) {
193
- return 90 + (code - 8);
194
- }
195
- let red;
196
- let green;
197
- let blue;
198
- if (code >= 232) {
199
- red = ((code - 232) * 10 + 8) / 255;
200
- green = red;
201
- blue = red;
202
- } else {
203
- code -= 16;
204
- const remainder = code % 36;
205
- red = Math.floor(code / 36) / 5;
206
- green = Math.floor(remainder / 6) / 5;
207
- blue = remainder % 6 / 5;
208
- }
209
- const value = Math.max(red, green, blue) * 2;
210
- if (value === 0) {
211
- return 30;
212
- }
213
- let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
214
- if (value === 2) {
215
- result += 60;
216
- }
217
- return result;
218
- },
219
- enumerable: false
220
- },
221
- rgbToAnsi: {
222
- value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
223
- enumerable: false
224
- },
225
- hexToAnsi: {
226
- value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
227
- enumerable: false
228
- }
229
- });
230
- return styles;
231
- }
232
- var ansiStyles = assembleStyles();
233
- var ansi_styles_default = ansiStyles;
234
- function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_process.default.argv) {
235
- const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
236
- const position = argv.indexOf(prefix + flag);
237
- const terminatorPosition = argv.indexOf("--");
238
- return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
239
- }
240
- var { env } = import_process.default;
241
- var flagForceColor;
242
- if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
243
- flagForceColor = 0;
244
- } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
245
- flagForceColor = 1;
246
- }
247
- function envForceColor() {
248
- if ("FORCE_COLOR" in env) {
249
- if (env.FORCE_COLOR === "true") {
250
- return 1;
251
- }
252
- if (env.FORCE_COLOR === "false") {
253
- return 0;
254
- }
255
- return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
256
- }
257
- }
258
- function translateLevel(level) {
259
- if (level === 0) {
260
- return false;
261
- }
262
- return {
263
- level,
264
- hasBasic: true,
265
- has256: level >= 2,
266
- has16m: level >= 3
267
- };
268
- }
269
- function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
270
- const noFlagForceColor = envForceColor();
271
- if (noFlagForceColor !== void 0) {
272
- flagForceColor = noFlagForceColor;
273
- }
274
- const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
275
- if (forceColor === 0) {
276
- return 0;
277
- }
278
- if (sniffFlags) {
279
- if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
280
- return 3;
281
- }
282
- if (hasFlag("color=256")) {
283
- return 2;
284
- }
285
- }
286
- if ("TF_BUILD" in env && "AGENT_NAME" in env) {
287
- return 1;
288
- }
289
- if (haveStream && !streamIsTTY && forceColor === void 0) {
290
- return 0;
291
- }
292
- const min = forceColor || 0;
293
- if (env.TERM === "dumb") {
294
- return min;
295
- }
296
- if (import_process.default.platform === "win32") {
297
- const osRelease = import_os.default.release().split(".");
298
- if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
299
- return Number(osRelease[2]) >= 14931 ? 3 : 2;
300
- }
301
- return 1;
302
- }
303
- if ("CI" in env) {
304
- if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
305
- return 3;
306
- }
307
- if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
308
- return 1;
309
- }
310
- return min;
311
- }
312
- if ("TEAMCITY_VERSION" in env) {
313
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
314
- }
315
- if (env.COLORTERM === "truecolor") {
316
- return 3;
317
- }
318
- if (env.TERM === "xterm-kitty") {
319
- return 3;
320
- }
321
- if (env.TERM === "xterm-ghostty") {
322
- return 3;
323
- }
324
- if (env.TERM === "wezterm") {
325
- return 3;
326
- }
327
- if ("TERM_PROGRAM" in env) {
328
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
329
- switch (env.TERM_PROGRAM) {
330
- case "iTerm.app": {
331
- return version >= 3 ? 3 : 2;
332
- }
333
- case "Apple_Terminal": {
334
- return 2;
335
- }
336
- }
337
- }
338
- if (/-256(color)?$/i.test(env.TERM)) {
339
- return 2;
340
- }
341
- if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
342
- return 1;
343
- }
344
- if ("COLORTERM" in env) {
345
- return 1;
346
- }
347
- return min;
348
- }
349
- function createSupportsColor(stream, options = {}) {
350
- const level = _supportsColor(stream, {
351
- streamIsTTY: stream && stream.isTTY,
352
- ...options
353
- });
354
- return translateLevel(level);
355
- }
356
- var supportsColor = {
357
- stdout: createSupportsColor({ isTTY: import_tty.default.isatty(1) }),
358
- stderr: createSupportsColor({ isTTY: import_tty.default.isatty(2) })
359
- };
360
- var supports_color_default = supportsColor;
361
- function stringReplaceAll(string, substring, replacer) {
362
- let index = string.indexOf(substring);
363
- if (index === -1) {
364
- return string;
365
- }
366
- const substringLength = substring.length;
367
- let endIndex = 0;
368
- let returnValue = "";
369
- do {
370
- returnValue += string.slice(endIndex, index) + substring + replacer;
371
- endIndex = index + substringLength;
372
- index = string.indexOf(substring, endIndex);
373
- } while (index !== -1);
374
- returnValue += string.slice(endIndex);
375
- return returnValue;
376
- }
377
- function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
378
- let endIndex = 0;
379
- let returnValue = "";
380
- do {
381
- const gotCR = string[index - 1] === "\r";
382
- returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
383
- endIndex = index + 1;
384
- index = string.indexOf("\n", endIndex);
385
- } while (index !== -1);
386
- returnValue += string.slice(endIndex);
387
- return returnValue;
388
- }
389
- var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
390
- var GENERATOR = Symbol("GENERATOR");
391
- var STYLER = Symbol("STYLER");
392
- var IS_EMPTY = Symbol("IS_EMPTY");
393
- var levelMapping = [
394
- "ansi",
395
- "ansi",
396
- "ansi256",
397
- "ansi16m"
398
- ];
399
- var styles2 = /* @__PURE__ */ Object.create(null);
400
- var applyOptions = (object, options = {}) => {
401
- if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
402
- throw new Error("The `level` option should be an integer from 0 to 3");
403
- }
404
- const colorLevel = stdoutColor ? stdoutColor.level : 0;
405
- object.level = options.level === void 0 ? colorLevel : options.level;
406
- };
407
- var chalkFactory = (options) => {
408
- const chalk2 = (...strings) => strings.join(" ");
409
- applyOptions(chalk2, options);
410
- Object.setPrototypeOf(chalk2, createChalk.prototype);
411
- return chalk2;
412
- };
413
- function createChalk(options) {
414
- return chalkFactory(options);
415
- }
416
- Object.setPrototypeOf(createChalk.prototype, Function.prototype);
417
- for (const [styleName, style] of Object.entries(ansi_styles_default)) {
418
- styles2[styleName] = {
419
- get() {
420
- const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
421
- Object.defineProperty(this, styleName, { value: builder });
422
- return builder;
423
- }
424
- };
425
- }
426
- styles2.visible = {
427
- get() {
428
- const builder = createBuilder(this, this[STYLER], true);
429
- Object.defineProperty(this, "visible", { value: builder });
430
- return builder;
431
- }
432
- };
433
- var getModelAnsi = (model, level, type, ...arguments_) => {
434
- if (model === "rgb") {
435
- if (level === "ansi16m") {
436
- return ansi_styles_default[type].ansi16m(...arguments_);
437
- }
438
- if (level === "ansi256") {
439
- return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
440
- }
441
- return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
442
- }
443
- if (model === "hex") {
444
- return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
445
- }
446
- return ansi_styles_default[type][model](...arguments_);
447
- };
448
- var usedModels = ["rgb", "hex", "ansi256"];
449
- for (const model of usedModels) {
450
- styles2[model] = {
451
- get() {
452
- const { level } = this;
453
- return function(...arguments_) {
454
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
455
- return createBuilder(this, styler, this[IS_EMPTY]);
456
- };
457
- }
458
- };
459
- const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
460
- styles2[bgModel] = {
461
- get() {
462
- const { level } = this;
463
- return function(...arguments_) {
464
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
465
- return createBuilder(this, styler, this[IS_EMPTY]);
466
- };
467
- }
468
- };
469
- }
470
- var proto = Object.defineProperties(() => {
471
- }, {
472
- ...styles2,
473
- level: {
474
- enumerable: true,
475
- get() {
476
- return this[GENERATOR].level;
477
- },
478
- set(level) {
479
- this[GENERATOR].level = level;
480
- }
481
- }
482
- });
483
- var createStyler = (open, close, parent) => {
484
- let openAll;
485
- let closeAll;
486
- if (parent === void 0) {
487
- openAll = open;
488
- closeAll = close;
489
- } else {
490
- openAll = parent.openAll + open;
491
- closeAll = close + parent.closeAll;
492
- }
493
- return {
494
- open,
495
- close,
496
- openAll,
497
- closeAll,
498
- parent
499
- };
500
- };
501
- var createBuilder = (self, _styler, _isEmpty) => {
502
- const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
503
- Object.setPrototypeOf(builder, proto);
504
- builder[GENERATOR] = self;
505
- builder[STYLER] = _styler;
506
- builder[IS_EMPTY] = _isEmpty;
507
- return builder;
508
- };
509
- var applyStyle = (self, string) => {
510
- if (self.level <= 0 || !string) {
511
- return self[IS_EMPTY] ? "" : string;
512
- }
513
- let styler = self[STYLER];
514
- if (styler === void 0) {
515
- return string;
516
- }
517
- const { openAll, closeAll } = styler;
518
- if (string.includes("\x1B")) {
519
- while (styler !== void 0) {
520
- string = stringReplaceAll(string, styler.close, styler.open);
521
- styler = styler.parent;
522
- }
523
- }
524
- const lfIndex = string.indexOf("\n");
525
- if (lfIndex !== -1) {
526
- string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
527
- }
528
- return openAll + string + closeAll;
529
- };
530
- Object.defineProperties(createChalk.prototype, styles2);
531
- var chalk = createChalk();
532
- createChalk({ level: stderrColor ? stderrColor.level : 0 });
533
- var source_default = chalk;
534
- function log(message) {
535
- return import_process.default.stdout.write(`${message}
536
- `);
537
- }
538
- function logError(message) {
539
- return import_process.default.stderr.write(`${message}
540
- `);
541
- }
542
- function logBullet(logger2, colorizePrefix, colorizeText, symbol, prefix, text) {
543
- const textParts = Array.isArray(text) ? text : [text || ""].filter(Boolean);
544
- const formattedText = textParts.map((textPart) => colorizeText(textPart)).join("");
545
- logger2(
546
- `${" ".repeat(3)} ${colorizePrefix(symbol)} ${colorizePrefix(
547
- prefix
548
- )} ${formattedText}`
549
- );
550
- }
551
- function warn(prefix, text) {
552
- logBullet(log, source_default.yellow, source_default.yellow, "\u25CF", prefix, text);
553
- }
554
- function debug(prefix, text) {
555
- logBullet(log, source_default.yellow, source_default.dim, "\u25CF", prefix, text);
556
- }
557
- function info(prefix, text) {
558
- logBullet(log, source_default.cyan, source_default.dim, "\u25FC", prefix, text);
559
- }
560
- function success(text) {
561
- logBullet(log, source_default.green, source_default.dim, "\u2714", text);
562
- }
563
- function error(prefix, text) {
564
- log("");
565
- logBullet(logError, source_default.red, source_default.red, "\u25B2", prefix, text);
566
- }
567
- function heading(heading2, description) {
568
- return log(
569
- `
570
- ${source_default.bgWhite(` ${source_default.whiteBright(heading2)} `)} ${source_default.bold(
571
- description
572
- )}
573
- `
574
- );
575
- }
576
- var timing = (fn) => () => {
577
- const start = performance.now();
578
- return (msg) => {
579
- const end = performance.now();
580
- const ms = end - start;
581
- fn(`${msg} ${source_default.gray(`(${ms.toFixed(2)}ms)`)}`);
582
- };
583
- };
584
- var logger = {
585
- colors: source_default,
586
- log,
587
- heading,
588
- debug,
589
- info,
590
- warn,
591
- success,
592
- error,
593
- time: {
594
- success: timing(success),
595
- info: timing(info),
596
- debug: timing(debug)
597
- }
598
- };
599
-
600
- // ../../node_modules/.pnpm/outdent@0.8.0/node_modules/outdent/lib-module/index.js
601
- function noop() {
602
- var args = [];
603
- for (var _i = 0; _i < arguments.length; _i++) {
604
- args[_i] = arguments[_i];
605
- }
606
- }
607
- function createWeakMap() {
608
- if (typeof WeakMap !== "undefined") {
609
- return /* @__PURE__ */ new WeakMap();
610
- } else {
611
- return fakeSetOrMap();
612
- }
613
- }
614
- function fakeSetOrMap() {
615
- return {
616
- add: noop,
617
- delete: noop,
618
- get: noop,
619
- set: noop,
620
- has: function(k) {
621
- return false;
622
- }
623
- };
624
- }
625
- var hop = Object.prototype.hasOwnProperty;
626
- var has = function(obj, prop) {
627
- return hop.call(obj, prop);
628
- };
629
- function extend(target, source) {
630
- for (var prop in source) {
631
- if (has(source, prop)) {
632
- target[prop] = source[prop];
633
- }
634
- }
635
- return target;
636
- }
637
- var reLeadingNewline = /^[ \t]*(?:\r\n|\r|\n)/;
638
- var reTrailingNewline = /(?:\r\n|\r|\n)[ \t]*$/;
639
- var reStartsWithNewlineOrIsEmpty = /^(?:[\r\n]|$)/;
640
- var reDetectIndentation = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
641
- var reOnlyWhitespaceWithAtLeastOneNewline = /^[ \t]*[\r\n][ \t\r\n]*$/;
642
- function _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options) {
643
- var indentationLevel = 0;
644
- var match = strings[0].match(reDetectIndentation);
645
- if (match) {
646
- indentationLevel = match[1].length;
647
- }
648
- var reSource = "(\\r\\n|\\r|\\n).{0," + indentationLevel + "}";
649
- var reMatchIndent = new RegExp(reSource, "g");
650
- if (firstInterpolatedValueSetsIndentationLevel) {
651
- strings = strings.slice(1);
652
- }
653
- var newline = options.newline, trimLeadingNewline = options.trimLeadingNewline, trimTrailingNewline = options.trimTrailingNewline;
654
- var normalizeNewlines = typeof newline === "string";
655
- var l = strings.length;
656
- var outdentedStrings = strings.map(function(v, i) {
657
- v = v.replace(reMatchIndent, "$1");
658
- if (i === 0 && trimLeadingNewline) {
659
- v = v.replace(reLeadingNewline, "");
660
- }
661
- if (i === l - 1 && trimTrailingNewline) {
662
- v = v.replace(reTrailingNewline, "");
663
- }
664
- if (normalizeNewlines) {
665
- v = v.replace(/\r\n|\n|\r/g, function(_) {
666
- return newline;
667
- });
668
- }
669
- return v;
670
- });
671
- return outdentedStrings;
672
- }
673
- function concatStringsAndValues(strings, values) {
674
- var ret = "";
675
- for (var i = 0, l = strings.length; i < l; i++) {
676
- ret += strings[i];
677
- if (i < l - 1) {
678
- ret += values[i];
679
- }
680
- }
681
- return ret;
682
- }
683
- function isTemplateStringsArray(v) {
684
- return has(v, "raw") && has(v, "length");
685
- }
686
- function createInstance(options) {
687
- var arrayAutoIndentCache = createWeakMap();
688
- var arrayFirstInterpSetsIndentCache = createWeakMap();
689
- function outdent(stringsOrOptions) {
690
- var values = [];
691
- for (var _i = 1; _i < arguments.length; _i++) {
692
- values[_i - 1] = arguments[_i];
693
- }
694
- if (isTemplateStringsArray(stringsOrOptions)) {
695
- var strings = stringsOrOptions;
696
- var firstInterpolatedValueSetsIndentationLevel = (values[0] === outdent || values[0] === defaultOutdent) && reOnlyWhitespaceWithAtLeastOneNewline.test(strings[0]) && reStartsWithNewlineOrIsEmpty.test(strings[1]);
697
- var cache = firstInterpolatedValueSetsIndentationLevel ? arrayFirstInterpSetsIndentCache : arrayAutoIndentCache;
698
- var renderedArray = cache.get(strings);
699
- if (!renderedArray) {
700
- renderedArray = _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options);
701
- cache.set(strings, renderedArray);
702
- }
703
- if (values.length === 0) {
704
- return renderedArray[0];
705
- }
706
- var rendered = concatStringsAndValues(renderedArray, firstInterpolatedValueSetsIndentationLevel ? values.slice(1) : values);
707
- return rendered;
708
- } else {
709
- return createInstance(extend(extend({}, options), stringsOrOptions || {}));
710
- }
711
- }
712
- var fullOutdent = extend(outdent, {
713
- string: function(str) {
714
- return _outdentArray([str], false, options)[0];
715
- }
716
- });
717
- return fullOutdent;
718
- }
719
- var defaultOutdent = createInstance({
720
- trimLeadingNewline: true,
721
- trimTrailingNewline: true
722
- });
723
- if (typeof module !== "undefined") {
724
- try {
725
- module.exports = defaultOutdent;
726
- Object.defineProperty(defaultOutdent, "__esModule", { value: true });
727
- defaultOutdent.default = defaultOutdent;
728
- defaultOutdent.outdent = defaultOutdent;
729
- } catch (e) {
730
- }
731
- }
732
-
733
- // src/commands/init.ts
734
- var import_preferred_pm = __toESM(require("preferred-pm"));
735
- function createInitCommand(cli, cwd) {
736
- return cli.command("init", "Initialize config file").option("-f, --force", "Force overwrite existing config files").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(initCmd);
737
- }
738
- async function initCmd({ cwd, force }) {
739
- logger.heading("init", "Initialize config file");
740
- const configFile = (0, import_runtime.findConfig)({ cwd });
741
- const pmResult = await (0, import_preferred_pm.default)(cwd);
742
- const pm = pmResult?.name ?? "npm";
743
- const cmd = pm === "npm" ? "npm run" : pm;
744
- if (configFile && !force) {
745
- return logger.log(
746
- defaultOutdent`
747
- It looks like you already have terai created.
748
- You can now run ${logger.colors.cyan(`'${cmd} terai extract --watch'`)}
749
- `
750
- );
751
- }
752
- const projectLocale = await (0, import_prompts.input)({
753
- message: "What locale do you use for development?",
754
- default: "en"
755
- });
756
- const outDir = await (0, import_prompts.input)({
757
- message: "Where do you want to place your generated files?",
758
- default: "./locale-system"
759
- });
760
- const framework = await (0, import_prompts.select)({
761
- message: "Would you like to use any of these templates? (recommended)",
762
- choices: [
763
- {
764
- name: "No",
765
- value: null
766
- },
767
- {
768
- name: "Next",
769
- value: "next"
770
- },
771
- {
772
- name: "Vite",
773
- value: "vite"
774
- }
775
- ]
776
- });
777
- const done = logger.time.success();
778
- await (0, import_runtime.setupConfig)({ cwd, projectLocale, outDir });
779
- if (framework) {
780
- await (0, import_runtime.setupTemplate)({ cwd, outDir, framework });
781
- }
782
- done("Config file created");
783
- logger.log("\u{1F680} You are set up to start using Terai! Thanks for choosing it.");
784
- }
785
-
786
- // src/commands/extract.ts
787
- var import_perfect_debounce = require("perfect-debounce");
788
- var import_extractor = require("@terai/extractor");
789
-
790
- // ../generator/dist/chunk-N4N3TZO6.mjs
791
- var import_runtime2 = require("@terai/runtime");
792
- var import_utils = require("@terai/utils");
793
- async function generate({
794
- dictionaries,
795
- locale,
796
- cwd,
797
- outDir
798
- }) {
799
- const folderPath = import_runtime2.runtime.path.resolve(cwd, outDir, locale);
800
- const output = [];
801
- for (const id in dictionaries) {
802
- const fileDir = import_runtime2.runtime.path.resolve(folderPath, `${id}.json`);
803
- const fileContent = dictionaries[id];
804
- const idOutput = (0, import_utils.stringify)(fileContent);
805
- import_runtime2.runtime.fs.write(fileDir, idOutput);
806
- output.push(idOutput);
807
- }
808
- return output;
809
- }
810
-
811
- // src/commands/extract.ts
812
- var import_runtime3 = require("@terai/runtime");
813
- var import_utils2 = require("@terai/utils");
814
- function createExtractCommand(cli, cwd) {
815
- 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);
816
- }
817
- async function extractCmd(options) {
818
- logger.heading("extract", "Statically extract messages from your project");
819
- const done = logger.time.success();
820
- const config = await (0, import_runtime3.loadConfig)(options);
821
- const filesPaths = import_runtime3.runtime.fs.glob({
822
- ...config,
823
- cwd: options.cwd
824
- });
825
- const outDirPath = import_runtime3.runtime.path.resolve(options.cwd, config.outDir);
826
- const projectLocalePath = import_runtime3.runtime.path.resolve(
827
- outDirPath,
828
- config.projectLocale
829
- );
830
- const manifestPath = import_runtime3.runtime.path.resolve(
831
- outDirPath,
832
- ".terai",
833
- "locale-manifest.json"
834
- );
835
- logger.info("Scan:", "Processing files...");
836
- async function extractor(files = filesPaths) {
837
- const extractedMessages = await (0, import_extractor.extract)({
838
- ...config,
839
- filesPaths: files,
840
- cwd: options.cwd
841
- });
842
- const dictionary = (0, import_utils2.convertExtractedMessagesToDictionary)(extractedMessages);
843
- const manifest = {
844
- messages: extractedMessages
845
- };
846
- const dictionaries = (0, import_utils2.groupDictionaryByChunks)(
847
- dictionary,
848
- manifest,
849
- config.projectLocale
850
- );
851
- import_runtime3.runtime.fs.remove(import_runtime3.runtime.path.resolve(projectLocalePath));
852
- await generate({
853
- ...config,
854
- dictionaries,
855
- locale: config.projectLocale,
856
- cwd: options.cwd
857
- });
858
- import_runtime3.runtime.fs.write(manifestPath, (0, import_utils2.stringify)(manifest));
859
- return Object.keys(dictionary).length;
860
- }
861
- logger.info("Extraction:", "Extracting messages...");
862
- const msgCount = await extractor();
863
- done(`Extracted ${msgCount} messages`);
864
- if (options.watch) {
865
- logger.log("");
866
- logger.info("Watch:", "Watching files for changes...\n");
867
- const configWatcher = import_runtime3.runtime.fs.watch({
868
- ...config,
869
- ...options
870
- });
871
- configWatcher.on(
872
- "change",
873
- (0, import_perfect_debounce.debounce)(async () => {
874
- const done2 = logger.time.success();
875
- logger.info("Extraction:", "Files changed, processing messages...");
876
- const msgCount2 = await extractor();
877
- done2(`Extracted ${msgCount2} messages`);
878
- logger.log("");
879
- })
880
- );
881
- }
882
- }
883
-
884
- // src/commands/translate.ts
885
- var import_runtime4 = require("@terai/runtime");
886
- var import_translator = require("@terai/translator");
887
- var import_utils3 = require("@terai/utils");
888
- function createTranslateCommand(cli, cwd) {
889
- return cli.command("translate", "Translate messages from your project").option("--cwd <cwd>", "Current working directory", { default: cwd }).action(translateCmd);
890
- }
891
- async function translateCmd({ cwd }) {
892
- logger.heading("translate", "Translate messages from your project");
893
- const done = logger.time.success();
894
- const config = await (0, import_runtime4.loadConfig)({ cwd });
895
- const outDirPath = import_runtime4.runtime.path.resolve(cwd, config.outDir);
896
- const tmuDirPath = import_runtime4.runtime.path.resolve(cwd, config.outDir, ".terai");
897
- const manifestPath = import_runtime4.runtime.path.resolve(tmuDirPath, "locale-manifest.json");
898
- const existsManifest = import_runtime4.runtime.fs.exists(manifestPath);
899
- if (!existsManifest) {
900
- return logger.error(
901
- "translate",
902
- `No locale-manifest.json found in ${tmuDirPath}. Please run "extract" first.`
903
- );
904
- }
905
- const buildManifest = JSON.parse(
906
- import_runtime4.runtime.fs.readFile(manifestPath)
907
- );
908
- let totalTranslatedMsgs = 0;
909
- let totalCachedMsgs = 0;
910
- await Promise.all(
911
- config.outLocales.map(async (locale) => {
912
- try {
913
- let translatedDictionary = {};
914
- const untranslatedDictionary = {};
915
- const localeDirPath = import_runtime4.runtime.path.resolve(outDirPath, locale);
916
- const localeCachePath = import_runtime4.runtime.path.resolve(
917
- tmuDirPath,
918
- "cache",
919
- `${locale}.cache.json`
920
- );
921
- const cacheExists = import_runtime4.runtime.fs.exists(localeCachePath);
922
- let cache = cacheExists ? JSON.parse(import_runtime4.runtime.fs.readFile(localeCachePath)) : {};
923
- let localeCachedMsgs = 0;
924
- let localeTranslatedMsgs = 0;
925
- for (const id in buildManifest.messages) {
926
- const { value, chunksIds } = buildManifest.messages[id];
927
- const chnks = chunksIds.length ? chunksIds : [locale];
928
- for (const chunkId of chnks) {
929
- const chunkPath = import_runtime4.runtime.path.resolve(
930
- localeDirPath,
931
- `${chunkId}.json`
932
- );
933
- const existsChunk = import_runtime4.runtime.fs.exists(chunkPath);
934
- const chunk = existsChunk ? JSON.parse(import_runtime4.runtime.fs.readFile(chunkPath)) : {};
935
- const localeValue = chunk[id] ?? cache[id];
936
- if (!localeValue) {
937
- untranslatedDictionary[id] = value;
938
- localeTranslatedMsgs++;
939
- } else {
940
- translatedDictionary[id] = localeValue;
941
- cache[id] = localeValue;
942
- localeCachedMsgs++;
943
- }
944
- }
945
- }
946
- if (localeTranslatedMsgs > 0) {
947
- const translation = await (0, import_translator.translate)({
948
- ...config,
949
- dictionary: untranslatedDictionary,
950
- locale
951
- });
952
- translatedDictionary = (0, import_utils3.merge)(translation, translatedDictionary);
953
- }
954
- cache = {
955
- ...cache,
956
- ...translatedDictionary
957
- };
958
- import_runtime4.runtime.fs.remove(localeDirPath);
959
- const dictionaries = (0, import_utils3.groupDictionaryByChunks)(
960
- translatedDictionary,
961
- buildManifest,
962
- locale
963
- );
964
- await generate({
965
- ...config,
966
- dictionaries,
967
- locale,
968
- cwd
969
- });
970
- import_runtime4.runtime.fs.write(localeCachePath, (0, import_utils3.stringify)(cache));
971
- totalTranslatedMsgs += localeTranslatedMsgs;
972
- totalCachedMsgs += localeCachedMsgs;
973
- logger.info(
974
- `Locale ${locale.toUpperCase()}:`,
975
- `${localeTranslatedMsgs} new messages translated, ${localeCachedMsgs} recovered from cache`
976
- );
977
- } catch (err) {
978
- if (err instanceof Error) {
979
- logger.error(
980
- `${locale} translation:`,
981
- `Error translating to ${locale}: ${err.message}
982
- `
983
- );
984
- }
985
- }
986
- })
987
- );
988
- if (!totalTranslatedMsgs) {
989
- return done("Everything up-to-date");
990
- }
991
- done(
992
- `Translated ${totalTranslatedMsgs} messages, ${totalCachedMsgs} read from cache`
993
- );
994
- }
995
- // Annotate the CommonJS export names for ESM import in node:
996
- 0 && (module.exports = {
997
- createExtractCommand,
998
- createInitCommand,
999
- createTranslateCommand,
1000
- extractCmd,
1001
- initCmd,
1002
- translateCmd
1003
- });
1004
- //# sourceMappingURL=index.js.map