@terai/dev 0.0.0-dev-20251119185121 → 0.0.0-dev-20251119203052

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