@homedev/framework 1.0.15 → 1.0.17
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/index.d.ts +6 -0
- package/dist/index.js +5 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -694,6 +694,9 @@ declare global {
|
|
|
694
694
|
tokenize(from: Record<string, unknown>, tokenizer?: RegExp): string;
|
|
695
695
|
mapLinesAsync(cb: (value: string, index: number, array: string[]) => Promise<string>, delimiter?: string): Promise<string>;
|
|
696
696
|
mapLines(cb: (value: string, index: number, array: string[]) => string, delimiter?: string): string;
|
|
697
|
+
prefix(value: string): string;
|
|
698
|
+
suffix(value: string): string;
|
|
699
|
+
chain(...fns: ((value: string) => string | undefined)[]): string;
|
|
697
700
|
toRgb(): string;
|
|
698
701
|
toArgb(): string;
|
|
699
702
|
toColor(defaultColor?: ColorValue): ColorValue;
|
|
@@ -705,6 +708,9 @@ declare global {
|
|
|
705
708
|
toStringBuilder(): StringBuilder;
|
|
706
709
|
toHtmlLink(path?: string): string;
|
|
707
710
|
toHtml(): string;
|
|
711
|
+
oneOf(...values: string[]): string | false;
|
|
712
|
+
icompare(value?: string): boolean;
|
|
713
|
+
itcompare(value?: string): boolean;
|
|
708
714
|
}
|
|
709
715
|
}
|
|
710
716
|
|
package/dist/index.js
CHANGED
|
@@ -2,17 +2,17 @@ Array.prototype.findOrFail=function(T,U,O){let K=this.find(T,O);if(K===void 0)th
|
|
|
2
2
|
`))};String.prototype.findBlocks=function(T){let U=[],O=this.length,K=T?.open??"",A=T?.close??"",X=K.length,j=A.length,$=T?.rangeStart??0,F=T?.rangeEnd??O;if(X===0||j===0||$>=F)return U;let Q=(G)=>{let Y=this.lastIndexOf(`
|
|
3
3
|
`,G-1);return Y===-1?0:Y+1},D=(G,Y)=>{let Z=this.indexOf(`
|
|
4
4
|
`,G);return Z===-1||Z>Y?Y-G:Z-G},_=(G,Y)=>{if(Y<=G)return 0;let Z=this.lastIndexOf(`
|
|
5
|
-
`,Y-1);return Z<G?Y-G:Y-(Z+1)},y=(G)=>{let Y=G.length-1;while(Y>=0&&(G.charCodeAt(Y)===32||G.charCodeAt(Y)===9))Y--;if(Y>=0&&G.charCodeAt(Y)===10)return G.substring(0,Y);return G},J=this.indexOf(K,$);while(J!==-1&&J<F){let G=J+X,Y=this.indexOf(A,G);if(Y===-1||Y>=F)break;let Z=this.substring(G,Y),M=J-Q(J),
|
|
6
|
-
`);if(
|
|
5
|
+
`,Y-1);return Z<G?Y-G:Y-(Z+1)},y=(G)=>{let Y=G.length-1;while(Y>=0&&(G.charCodeAt(Y)===32||G.charCodeAt(Y)===9))Y--;if(Y>=0&&G.charCodeAt(Y)===10)return G.substring(0,Y);return G},J=this.indexOf(K,$);while(J!==-1&&J<F){let G=J+X,Y=this.indexOf(A,G);if(Y===-1||Y>=F)break;let Z=this.substring(G,Y),M=J-Q(J),C=D(G,Y),N=_(J,Y),b=Y+j,k=b<O?1:0;if(C===0){let w=Z.indexOf(`
|
|
6
|
+
`);if(w!==-1)Z=Z.substring(w+1)}Z=y(Z);let B=Math.max(Z.getIndentation()-M,0);if(T?.reindent&&B>0)Z=Z.reindent(B);if(T?.trim)Z=Z.trim();U.push({content:Z,indentation:B,start:J,end:b,openTagIndentation:M,openTagPostIndentation:C,endTagIndentation:N,endTagPostIndentation:k}),J=this.indexOf(K,b)}return U};String.prototype.toWords=function(T){let O=new Map((T??[]).map(($)=>[$.open,$.close])),K=[],A=[],X="",j=()=>{if(X.length>0)K.push(X),X=""};for(let $ of this){let F=A[A.length-1];if(A.length===0&&/\s/.test($)){j();continue}if(X+=$,F&&$===F){A.pop();continue}let Q=O.get($);if(Q)A.push(Q)}return j(),K};String.prototype.padBlock=function(T,U=`
|
|
7
7
|
`,O=" "){let K=O.repeat(T);return this.split(U).map((A)=>K+A).join(U)};String.prototype.stripIndent=function(){let T=this.split(/\r?\n/),U=T.filter((K)=>K.trim().length>0).map((K)=>/^[ \t]*/.exec(K)?.[0].length??0),O=U.length>0?Math.min(...U):0;if(O===0)return this;return T.map((K)=>K.slice(O)).join(`
|
|
8
8
|
`)};String.prototype.getIndentation=function(){let U=this.split(/\r?\n/).filter((O)=>O.trim().length>0).map((O)=>/^[ \t]*/.exec(O)?.[0].length??0);return U.length>0?Math.min(...U):0};String.prototype.reindent=function(T,U=`
|
|
9
|
-
`,O=" "){return this.stripIndent().padBlock(T,U,O)};String.prototype.toHtmlLink=function(T){return`<a href="${T??this.toString()}">${this.toString()}</a>`};String.prototype.toHtml=function(){return this.toString().trim().replace(/[<>&"_]/g,(T)=>`&#${T.charCodeAt(0).toString()};`).replace(/\n/g,"<br/>")};String.prototype.toRgb=function(){let T=this.toString().replace("#","");if(T.length!==6)throw Error("Invalid hex color");let U=parseInt(T.substring(0,2),16),O=parseInt(T.substring(2,4),16),K=parseInt(T.substring(4,6),16);return`rgb(${U.toString()}, ${O.toString()}, ${K.toString()})`};String.prototype.toArgb=function(){let T=this.toString().replace("#","");if(T.length!==8)throw Error("Invalid hex color");let U=parseInt(T.substring(0,2),16),O=parseInt(T.substring(2,4),16),K=parseInt(T.substring(4,6),16),A=parseInt(T.substring(6,8),16);return`argb(${U.toString()}, ${O.toString()}, ${K.toString()}, ${A.toString()})`};var
|
|
9
|
+
`,O=" "){return this.stripIndent().padBlock(T,U,O)};String.prototype.toHtmlLink=function(T){return`<a href="${T??this.toString()}">${this.toString()}</a>`};String.prototype.toHtml=function(){return this.toString().trim().replace(/[<>&"_]/g,(T)=>`&#${T.charCodeAt(0).toString()};`).replace(/\n/g,"<br/>")};String.prototype.toRgb=function(){let T=this.toString().replace("#","");if(T.length!==6)throw Error("Invalid hex color");let U=parseInt(T.substring(0,2),16),O=parseInt(T.substring(2,4),16),K=parseInt(T.substring(4,6),16);return`rgb(${U.toString()}, ${O.toString()}, ${K.toString()})`};String.prototype.toArgb=function(){let T=this.toString().replace("#","");if(T.length!==8)throw Error("Invalid hex color");let U=parseInt(T.substring(0,2),16),O=parseInt(T.substring(2,4),16),K=parseInt(T.substring(4,6),16),A=parseInt(T.substring(6,8),16);return`argb(${U.toString()}, ${O.toString()}, ${K.toString()}, ${A.toString()})`};var P={red:"#FF0000",green:"#00FF00",blue:"#0000FF",yellow:"#FFFF00",cyan:"#00FFFF",magenta:"#FF00FF",white:"#FFFFFF",black:"#000000",orange:"#FFA500",purple:"#800080",pink:"#FFC0CB",gray:"#808080",grey:"#808080"};String.prototype.toColor=function(T){let U=this.toString().trim(),O,K,A;if(P[U])U=P[U];if(U.startsWith("#")){let X=U.slice(1);if(X.length===3)O=parseInt(X[0]+X[0],16),K=parseInt(X[1]+X[1],16),A=parseInt(X[2]+X[2],16);else if(X.length===6)O=parseInt(X.slice(0,2),16),K=parseInt(X.slice(2,4),16),A=parseInt(X.slice(4,6),16);else{if(T)return T;throw Error(`Invalid hex color: ${U}`)}return{r:O,g:K,b:A}}if(U.includes(";")){let X=U.split(";").map(Number);if(X.length!==3||X.some(isNaN)){if(T)return T;throw Error(`Invalid RGB color string: ${U}`)}return{r:X[0],g:X[1],b:X[2]}}if(T)return T;throw Error(`Unsupported color string format: ${U}`)};String.prototype.colorize=function(T){let U=typeof T==="string"?T.toColor({r:255,g:255,b:255}):T;return`\x1B[38;2;${U.r.toString()};${U.g.toString()};${U.b.toString()}m${this.toString()}\x1B[0m`};String.prototype.single=function(T){return this.replaceAll(new RegExp(`(${T})+`,"g"),"$1")};String.prototype.remove=function(T){return this.replaceAll(new RegExp(T,"g"),"")};String.prototype.toAlphanum=function(T=""){return this.replace(/[^a-z0-9]/gi,T)};String.prototype.toAlpha=function(T=""){return this.replace(/[^a-z]/gi,T)};String.prototype.mapLinesAsync=async function(T,U=`
|
|
10
10
|
`){return(await Promise.all(this.split(U).map(T))).filter((O)=>O!==null&&O!==void 0).join(U)};String.prototype.mapLines=function(T,U=`
|
|
11
|
-
`){return this.split(U).map(T).filter((O)=>O!==null&&O!==void 0).join(U)};class g{options;#T=/(["'])(?:(?=(\\?))\2.)*?\1/g;#U=/<color=([^>]+)>(.*?)<\/color>/g;#O=/\b\d+(?:\.\d+)?\b/g;constructor(T){this.options={level:"INFO",showClass:!1,levels:["DEBUG","VERBOSE","INFO","WARN","ERROR"],timeStamp:!1,timeOptions:{second:"2-digit",minute:"2-digit",hour:"2-digit",day:"2-digit",month:"2-digit",year:"2-digit"},colors:{},...T}}write(T,...U){if(this.options.level){let A=this.options.levels.indexOf(this.options.level),X=this.options.levels.indexOf(T);if(A===-1)throw Error(`Unknown configured log level: ${this.options.level}`);if(X===-1)throw Error(`Unknown log level: ${T}`);if(X<A)return}let O=[],K=[];if(this.options.timeStamp)K.push(this.onTime(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions),T));if(this.options.showClass)K.push(this.onClass(T));if(K.length>0)O.push(`[${K.join(" ")}]`);O.push(...U.map((A)=>this.onElement(A,T))),this.onLog(T,...O)}onTime(T,U){if(this.options.colors?.time)T=T.colorize(this.options.colors.time);return T}onClass(T){if(this.options.colors?.levels?.[T])T=T.colorize(this.options.colors.levels[T]);return T}onElement(T,U){if(typeof T==="number")return this.#K(T.toString(),this.options.colors?.number);if(typeof T==="string")return this.#$(T,this.options.colors?.default);return T}#K(T,U){if(!U)return T;return T.colorize(U)}#$(T,U){let O=[],K=0;while(K<T.length){let A=this.#X(T,K,this.#T,"quoted"),X=this.#X(T,K,this.#U,"color"),j=this.#X(T,K,this.#O,"number"),$=this.#A(A,X,j);if(!$){O.push(this.#K(T.slice(K),U));break}if($.index>K)O.push(this.#K(T.slice(K,$.index),U));if($.kind==="quoted")O.push(this.#K($.match[0],this.options.colors?.quoted));else if($.kind==="number")O.push(this.#K($.match[0],this.options.colors?.number));else{let F=$.match[2]??"";O.push(this.#$(F,$.match[1]))}K=$.index+$.match[0].length}return O.join("")}#X(T,U,O,K){let A=new RegExp(O.source,O.flags);A.lastIndex=U;let X=A.exec(T);if(!X)return null;return{index:X.index,match:X,kind:K}}#A(T,U,O){let K=[T,U,O].filter((A)=>A!==null);if(K.length===0)return null;return K.reduce((A,X)=>X.index<A.index?X:A)}onLog(T,...U){switch(T){case"ERROR":console.error(...U);break;case"WARN":console.warn(...U);break;case"DEBUG":console.debug(...U);break;case"VERBOSE":console.log(...U);break;default:console.log(...U)}}info(...T){this.write("INFO",...T)}error(...T){this.write("ERROR",...T)}warn(...T){this.write("WARN",...T)}debug(...T){this.write("DEBUG",...T)}verbose(...T){this.write("VERBOSE",...T)}}class q{#T=[];#U=0;options;constructor(T,U){if(T instanceof q)this.options={...T.options,...U},this.#T.push(...T.#T);else if(this.options=U??{},T)if(Array.isArray(T))this.#T.push(...T);else this.#T.push(T)}setOptions(T){return this.options=T,this}clear(){return this.#T.length=0,this}isEmpty(){return this.#T.length===0}toString(){return this.#T.join("")}indent(){return this.#U+=1,this}dedent(){if(this.#U>0)this.#U-=1;return this}getCurrentIndent(){return this.#U}getLines(){return this.toString().split(`
|
|
11
|
+
`){return this.split(U).map(T).filter((O)=>O!==null&&O!==void 0).join(U)};String.prototype.prefix=function(T){return this.startsWith(T)?this:T+this};String.prototype.suffix=function(T){return this.endsWith(T)?this:this+T};String.prototype.chain=function(...T){return T.reduce((U,O)=>O(U)??U,this)};String.prototype.oneOf=function(...T){return T.includes(this)?this:!1};String.prototype.icompare=function(T){return this.toLowerCase()===T?.toLowerCase()};String.prototype.itcompare=function(T){return this.trim().toLowerCase()===T?.trim().toLowerCase()};class g{options;#T=/(["'])(?:(?=(\\?))\2.)*?\1/g;#U=/<color=([^>]+)>(.*?)<\/color>/g;#O=/\b\d+(?:\.\d+)?\b/g;constructor(T){this.options={level:"INFO",showClass:!1,levels:["DEBUG","VERBOSE","INFO","WARN","ERROR"],timeStamp:!1,timeOptions:{second:"2-digit",minute:"2-digit",hour:"2-digit",day:"2-digit",month:"2-digit",year:"2-digit"},colors:{},...T}}write(T,...U){if(this.options.level){let A=this.options.levels.indexOf(this.options.level),X=this.options.levels.indexOf(T);if(A===-1)throw Error(`Unknown configured log level: ${this.options.level}`);if(X===-1)throw Error(`Unknown log level: ${T}`);if(X<A)return}let O=[],K=[];if(this.options.timeStamp)K.push(this.onTime(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions),T));if(this.options.showClass)K.push(this.onClass(T));if(K.length>0)O.push(`[${K.join(" ")}]`);O.push(...U.map((A)=>this.onElement(A,T))),this.onLog(T,...O)}onTime(T,U){if(this.options.colors?.time)T=T.colorize(this.options.colors.time);return T}onClass(T){if(this.options.colors?.levels?.[T])T=T.colorize(this.options.colors.levels[T]);return T}onElement(T,U){if(typeof T==="number")return this.#K(T.toString(),this.options.colors?.number);if(typeof T==="string")return this.#$(T,this.options.colors?.default);return T}#K(T,U){if(!U)return T;return T.colorize(U)}#$(T,U){let O=[],K=0;while(K<T.length){let A=this.#X(T,K,this.#T,"quoted"),X=this.#X(T,K,this.#U,"color"),j=this.#X(T,K,this.#O,"number"),$=this.#A(A,X,j);if(!$){O.push(this.#K(T.slice(K),U));break}if($.index>K)O.push(this.#K(T.slice(K,$.index),U));if($.kind==="quoted")O.push(this.#K($.match[0],this.options.colors?.quoted));else if($.kind==="number")O.push(this.#K($.match[0],this.options.colors?.number));else{let F=$.match[2]??"";O.push(this.#$(F,$.match[1]))}K=$.index+$.match[0].length}return O.join("")}#X(T,U,O,K){let A=new RegExp(O.source,O.flags);A.lastIndex=U;let X=A.exec(T);if(!X)return null;return{index:X.index,match:X,kind:K}}#A(T,U,O){let K=[T,U,O].filter((A)=>A!==null);if(K.length===0)return null;return K.reduce((A,X)=>X.index<A.index?X:A)}onLog(T,...U){switch(T){case"ERROR":console.error(...U);break;case"WARN":console.warn(...U);break;case"DEBUG":console.debug(...U);break;case"VERBOSE":console.log(...U);break;default:console.log(...U)}}info(...T){this.write("INFO",...T)}error(...T){this.write("ERROR",...T)}warn(...T){this.write("WARN",...T)}debug(...T){this.write("DEBUG",...T)}verbose(...T){this.write("VERBOSE",...T)}}class q{#T=[];#U=0;options;constructor(T,U){if(T instanceof q)this.options={...T.options,...U},this.#T.push(...T.#T);else if(this.options=U??{},T)if(Array.isArray(T))this.#T.push(...T);else this.#T.push(T)}setOptions(T){return this.options=T,this}clear(){return this.#T.length=0,this}isEmpty(){return this.#T.length===0}toString(){return this.#T.join("")}indent(){return this.#U+=1,this}dedent(){if(this.#U>0)this.#U-=1;return this}getCurrentIndent(){return this.#U}getLines(){return this.toString().split(`
|
|
12
12
|
`)}formatLine(T){T??=`
|
|
13
13
|
`;let U=(this.options.indentChar??" ").repeat(this.#U*(this.options.indentSize??2));if(this.options.trim)T=T.trim();return U+(this.options.linePrefix??"")+T+(this.options.lineSuffix??"")+(this.options.lineSeparator??`
|
|
14
14
|
`)}write(...T){return this.#T.push(...T.flatMap((U)=>{if(U!==void 0){if(typeof U==="string")return U;if(Array.isArray(U))return U.flat();if(U instanceof q)return U.toString();if(typeof U==="function")return U(this);return String(U)}}).filter((U)=>U!==void 0)),this}writeLine(...T){return this.write(T.length>0?T.map((U)=>this.formatLine(U)):`
|
|
15
15
|
`)}writeMap(T,U){return T.forEach((O,K)=>U(O,K,this)),this}}class d extends q{#T=0;#U="```";#O(T){return Math.min(6,Math.max(1,Math.floor(T)))}#K(T){if(T===void 0)return"```";let U=0;for(let O of T.matchAll(/`+/g))U=Math.max(U,O[0].length);return"`".repeat(Math.max(3,U+1))}header(T,U=1){let O=this.#O(U);return this.writeLine(`${"#".repeat(O)} ${T}`,"")}codeBlock(T,U){let O=this.#K(T);if(this.#U=O,U??="",this.writeLine(O+U),T!==void 0)this.writeLine(T).endCodeBlock();return this}endCodeBlock(){let T=this.#U;return this.#U="```",this.writeLine(T)}link(T,U,O){if(O)return this.write(`[${T}](${U} "${O}")`);return this.write(`[${T}](${U})`)}table(T,U){if(T.length===0)throw Error("Table requires at least one header");let O=T.map((X,j)=>{let $=X.length;return U.forEach((F)=>{if(F[j])$=Math.max($,F[j].length)}),$}),K=T.map((X,j)=>X.padEnd(O[j]));this.writeLine("| "+K.join(" | ")+" |");let A=O.map((X)=>"-".repeat(X));return this.writeLine("| "+A.join(" | ")+" |"),U.forEach((X)=>{let j=T.map(($,F)=>(X[F]??"").padEnd(O[F]));this.writeLine("| "+j.join(" | ")+" |")}),this}blockquote(T){return T.split(`
|
|
16
16
|
`).forEach((O)=>this.writeLine("> "+O)),this}bold(T){return this.write(`**${T}**`)}italic(T){return this.write(`*${T}*`)}item(T){return this.writeLine(`- ${T}`)}items(T){if(Array.isArray(T))T.forEach((U)=>this.item(U));else Object.entries(T).forEach(([U,O])=>O!==void 0&&this.item(`${U}: ${O!==void 0?String(O):""}`));return this}orderedList(T,U=1){return T.forEach((O,K)=>this.writeLine(`${(K+U).toString()}. ${O}`)),this}code(T){return this.write(`\`${T}\``)}horizontalRule(){return this.writeLine("---")}image(T,U){return this.writeLine(``)}strikethrough(T){return this.write(`~~${T}~~`)}highlight(T){return this.write(`==${T}==`)}subscript(T){return this.write(`~${T}~`)}superscript(T){return this.write(`^${T}^`)}taskList(T){return T.forEach((U)=>this.writeLine(`- [${U.checked?"x":" "}] ${U.text}`)),this}section(T,U){if(U!==void 0)this.#T=this.#O(U);else this.#T=Math.min(6,this.#T+1);return this.header(T,this.#T)}endSection(){if(this.#T>0)this.#T--;return this}setSectionLevel(T){return this.#T=Math.min(6,Math.max(0,Math.floor(T))),this}}class c{#T;#U;#O=new Map;#K=[];constructor(T,U=[]){this.#T=[...T],this.#U=[...U],this.#$()}get args(){return[...this.#T]}get positionals(){return[...this.#K]}has(T){return this.#O.has(this.#A(T))}getArgs(T){return[...this.#O.get(this.#A(T))?.values??[]]}get(T){let U=this.#O.get(this.#A(T))?.values;if(!U)return;if(U.length===0)return!0;return U[0]}toObject(){let T={};for(let[U,O]of this.#O.entries())T[U]=O.values.length>0?[...O.values]:!0;return T}usage(T="command"){let U=[`Usage: ${T} [options]`];if(this.#K.length>0)U[0]+=" [values]";if(this.#U.length===0)return U.join(`
|
|
17
17
|
`);U.push("","Options:");for(let O of this.#U){let K=`--${O.name}`,A=O.alias?`-${O.alias}`:void 0,X=O.valueName??"value",j=O.takesValue?O.multiple?` <${X}...>`:` <${X}>`:"",$=A?`${A}, ${K}`:K,F=O.description?` ${O.description}`:"";U.push(` ${$}${j}${F}`)}return U.join(`
|
|
18
|
-
`)}#$(){for(let T=0;T<this.#T.length;T++){let U=this.#T[T];if(!U.startsWith("-")||U==="-"){this.#K.push(U);continue}if(U.startsWith("--")&&U.includes("=")){let A=U.indexOf("="),X=this.#A(U.slice(0,A)),j=U.slice(A+1);this.#X(X,j.length>0?[j]:[""],!0);continue}let O=this.#A(U),K=[];while(T+1<this.#T.length){let A=this.#T[T+1];if(A.startsWith("-")&&A!=="-")break;K.push(A),T++}this.#X(O,K,!1)}}#X(T,U,O){let K=this.#O.get(T);if(!K){this.#O.set(T,{values:[...U],sawEqualsStyle:O});return}K.values.push(...U),K.sawEqualsStyle=K.sawEqualsStyle||O}#A(T){return T.replace(/^-+/,"").trim()}}import
|
|
18
|
+
`)}#$(){for(let T=0;T<this.#T.length;T++){let U=this.#T[T];if(!U.startsWith("-")||U==="-"){this.#K.push(U);continue}if(U.startsWith("--")&&U.includes("=")){let A=U.indexOf("="),X=this.#A(U.slice(0,A)),j=U.slice(A+1);this.#X(X,j.length>0?[j]:[""],!0);continue}let O=this.#A(U),K=[];while(T+1<this.#T.length){let A=this.#T[T+1];if(A.startsWith("-")&&A!=="-")break;K.push(A),T++}this.#X(O,K,!1)}}#X(T,U,O){let K=this.#O.get(T);if(!K){this.#O.set(T,{values:[...U],sawEqualsStyle:O});return}K.values.push(...U),K.sawEqualsStyle=K.sawEqualsStyle||O}#A(T){return T.replace(/^-+/,"").trim()}}import f from"fs/promises";var L=async(T)=>{try{return await f.access(T,f.constants.R_OK),!0}catch{return!1}};import W from"path";var R=async(T,U)=>{let O=!W.isAbsolute(T)&&U?["",...U]:[""];for(let K of O){let A=W.join(K,T);if(await L(A))return W.resolve(A)}throw Error(`File not found: "${T}"`)};import r from"fs/promises";import o from"path";var s=(T,U)=>U?.some((O)=>new RegExp(O).test(T))===!0,UU=async(T,U)=>{let O=await R(T,U?.dirs),K=await r.readFile(O,"utf-8"),A=o.dirname(O),X={text:{fn:(F)=>F,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...U?.parsers},j=U?.format?X[U.format]:Object.values(X).find((F)=>s(T,F.matching));if(!j)throw Error(`Unsupported format for file "${T}" and no matching parser found`);return{content:await j.fn(K),fullPath:O,folderPath:A}};import n from"fs/promises";var l=(T,U)=>U?.some((O)=>new RegExp(O).test(T))===!0,S=async(T,U,O)=>{let K={text:{fn:(X)=>X,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...O?.encoders},A=O?.format?K[O.format]:Object.values(K).find((X)=>l(T,X.matching));if(!A)throw Error(`Unsupported format for file "${T}" and no matching encoder found`);await n.writeFile(T,await A.fn(U))};import i from"fs/promises";var $U=async(T,U)=>{if(typeof T==="string"&&!T.includes("*"))return await U.map(T,0,[]);let O=await Array.fromAsync(i.glob(T,{cwd:U.cwd})),K=U.filter?O.filter(U.filter):O;return await Promise.all(K.map(U.map))};import x from"fs/promises";import I from"path";var GU=async(T,U)=>{if(U?.targetDirectory&&U?.removeFirst)try{await x.rm(U?.targetDirectory,{recursive:!0,force:!0})}catch(O){throw Error(`Failed to clean the output directory: ${O.message}`,{cause:O})}for(let O of T)await a(O,U)},a=async(T,U)=>{let O=I.join(U?.targetDirectory??".",T.name),K=I.dirname(O);if(U?.classes){if(T.class!==void 0&&!U.classes.includes(T.class))return;if(U.classRequired&&T.class===void 0)throw Error(`Output "${T.name}" is missing class field`)}if(U?.writing?.(T)===!1)return;try{await x.mkdir(K,{recursive:!0})}catch(A){throw Error(`Failed to create target directory "${K}" for output "${O}": ${A.message}`,{cause:A})}try{await S(O,T.value,{format:T.type??"text"})}catch(A){throw Error(`Failed to write output "${O}": ${A.message}`,{cause:A})}};import t from"fs/promises";import V from"path";import m from"path";var z=(T)=>T?m.isAbsolute(T)?T:m.join(process.cwd(),T):process.cwd();var e=async(T,U)=>{let O=[];for(let K of T)try{let A=!V.isAbsolute(K)?V.join(z(U?.cwd),K):K;if(U?.filter?.(A)===!1)continue;let X=await import(A);if(U?.resolveDefault==="only"&&!X.default)throw Error(`Module ${K} does not have a default export`);let j=U?.resolveDefault?X.default??X:X,$=U?.map?await U.map(j,K):j;if($!==void 0)O.push($)}catch(A){if(U?.fail?.(K,A)===!1)continue;throw Error(`Failed to import module ${K}: ${A.message??A}`,{cause:A})}return O},qU=async(T,U)=>{let O=[],K=z(U?.cwd);for(let A of T){let X=(await Array.fromAsync(t.glob(A,{cwd:K}))).map((j)=>V.join(K,j));O.push(...await e(X,U))}return O};class TT{#T={};#U(T,U,O){return{handler:T,calls:0,cleared:!1,mode:U,errorMode:"throw",...O}}#O(T){return this.#T[T]??=[]}on(T,U,O){return this.#O(T).push(this.#U(U,"on",O)),this}once(T,U,O){return this.#O(T).push(this.#U(U,"once",O)),this}clear(T){return this.#T[T]=[],this}getListeners(T){return this.#O(T)}async emit(T,U){let O=this.#O(T);if(!O)return!0;let K=null,A=null,X=!0;for(let j of O){let $;try{$=await j.handler(U,j)}catch(F){K=F,A=j}if(j.calls++,j.mode==="once")j.cleared=!0;if(typeof $==="boolean"){X=$;break}if(K&&j.errorMode!=="continue")break}if(this.#T[T]=O.filter((j)=>!j.cleared),K&&A?.errorMode==="throw")throw K;return X}}export{GU as writeOutputs,a as writeOutput,S as writeFormat,R as locate,UU as loadFormat,e as importList,qU as importGlob,$U as globMap,z as getCwd,L as exists,q as StringBuilder,H as NavigateResult,h as NavigateAction,d as Markdown,g as Logger,c as CommandLineArgs,TT as AsyncEmitter};
|