@terai/dev 0.0.7 → 0.0.8

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