@terai/dev 0.0.2 → 0.0.4

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