@terai/dev 0.0.0-dev-20240302092932 → 0.0.0-dev-20240302165901

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