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