hofii 0.1.0 → 0.1.1
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/main.js +29 -29
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
3
|
+
var vn=Object.create;var{getPrototypeOf:$n,defineProperty:st,getOwnPropertyNames:bn}=Object;var kn=Object.prototype.hasOwnProperty;function wn(e){return this[e]}var xn,_n,rt=(e,t,n)=>{var s=e!=null&&typeof e==="object";if(s){var r=t?xn??=new WeakMap:_n??=new WeakMap,u=r.get(e);if(u)return u}n=e!=null?vn($n(e)):{};let o=t||!e||!e.__esModule?st(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let a of bn(e))if(!kn.call(o,a))st(o,a,{get:wn.bind(e,a),enumerable:!0})}if(s)r.set(e,o);return o};var En=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var qe=En(function($r,Mt){var Ge={to(e,t){if(!t)return`\x1B[${e+1}G`;return`\x1B[${t+1};${e+1}H`},move(e,t){let n="";if(e<0)n+=`\x1B[${-e}D`;else if(e>0)n+=`\x1B[${e}C`;if(t<0)n+=`\x1B[${-t}A`;else if(t>0)n+=`\x1B[${t}B`;return n},up:(e=1)=>`\x1B[${e}A`,down:(e=1)=>`\x1B[${e}B`,forward:(e=1)=>`\x1B[${e}C`,backward:(e=1)=>`\x1B[${e}D`,nextLine:(e=1)=>"\x1B[E".repeat(e),prevLine:(e=1)=>"\x1B[F".repeat(e),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},ss={up:(e=1)=>"\x1B[S".repeat(e),down:(e=1)=>"\x1B[T".repeat(e)},rs={screen:"\x1B[2J",up:(e=1)=>"\x1B[1J".repeat(e),down:(e=1)=>"\x1B[J".repeat(e),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(e){let t="";for(let n=0;n<e;n++)t+=this.line+(n<e-1?Ge.up():"");if(e)t+=Ge.left;return t}};Mt.exports={cursor:Ge,scroll:ss,erase:rs,beep:"\x07"}});function De(e){return e==null?[]:Array.isArray(e)?e:[e]}function In(e,t,n,s){var r,u=e[t],o=~s.string.indexOf(t)?n==null||n===!0?"":String(n):typeof n==="boolean"?n:~s.boolean.indexOf(t)?n==="false"?!1:n==="true"||(e._.push((r=+n,r*0===0)?r:n),!!n):(r=+n,r*0===0)?r:n;e[t]=u==null?o:Array.isArray(u)?u.concat(o):[u,o]}function Sn(e,t){e=e||[],t=t||{};var n,s,r,u,o,a={_:[]},i=0,l=0,c=0,f=e.length;let h=t.alias!==void 0,g=t.unknown!==void 0,m=t.default!==void 0;if(t.alias=t.alias||{},t.string=De(t.string),t.boolean=De(t.boolean),h)for(n in t.alias){s=t.alias[n]=De(t.alias[n]);for(i=0;i<s.length;i++)(t.alias[s[i]]=s.concat(n)).splice(i,1)}for(i=t.boolean.length;i-- >0;){s=t.alias[t.boolean[i]]||[];for(l=s.length;l-- >0;)t.boolean.push(s[l])}for(i=t.string.length;i-- >0;){s=t.alias[t.string[i]]||[];for(l=s.length;l-- >0;)t.string.push(s[l])}if(m){for(n in t.default)if(u=typeof t.default[n],s=t.alias[n]=t.alias[n]||[],t[u]!==void 0){t[u].push(n);for(i=0;i<s.length;i++)t[u].push(s[i])}}let y=g?Object.keys(t.alias):[];for(i=0;i<f;i++){if(r=e[i],r==="--"){a._=a._.concat(e.slice(++i));break}for(l=0;l<r.length;l++)if(r.charCodeAt(l)!==45)break;if(l===0)a._.push(r);else if(r.substring(l,l+3)==="no-"){if(u=r.substring(l+3),g&&!~y.indexOf(u))return t.unknown(r);a[u]=!1}else{for(c=l+1;c<r.length;c++)if(r.charCodeAt(c)===61)break;u=r.substring(l,c),o=r.substring(++c)||i+1===f||(""+e[i+1]).charCodeAt(0)===45||e[++i],s=l===2?[u]:u;for(c=0;c<s.length;c++){if(u=s[c],g&&!~y.indexOf(u))return t.unknown("-".repeat(l)+u);In(a,u,c+1<s.length||o,t)}}}if(m){for(n in t.default)if(a[n]===void 0)a[n]=t.default[n]}if(h)for(n in a){s=t.alias[n]||[];while(s.length>0)a[s.shift()]=a[n]}return a}function ot(e){return e.replace(/[<[].+/,"").trim()}function Cn(e){let t=/<([^>]+)>/g,n=/\[([^\]]+)\]/g,s=[],r=(a)=>{let i=!1,l=a[1];if(l.startsWith("..."))l=l.slice(3),i=!0;return{required:a[0].startsWith("<"),value:l,variadic:i}},u;while(u=t.exec(e))s.push(r(u));let o;while(o=n.exec(e))s.push(r(o));return s}function An(e){let t={alias:{},boolean:[]};for(let[n,s]of e.entries()){if(s.names.length>1)t.alias[s.names[0]]=s.names.slice(1);if(s.isBoolean)if(s.negated){if(!e.some((r,u)=>u!==n&&r.names.some((o)=>s.names.includes(o))&&typeof r.required==="boolean"))t.boolean.push(s.names[0])}else t.boolean.push(s.names[0])}return t}function it(e){return e.sort((t,n)=>t.length>n.length?-1:1)[0]}function ut(e,t){return e.length>=t?e:`${e}${" ".repeat(t-e.length)}`}function On(e){return e.replaceAll(/([a-z])-([a-z])/g,(t,n,s)=>n+s.toUpperCase())}function Mn(e,t,n){let s=e;for(let r=0;r<t.length;r++){let u=t[r];if(r===t.length-1){s[u]=n;return}if(s[u]==null){let o=+t[r+1]>-1;s[u]=o?[]:{}}s=s[u]}}function Dn(e,t){for(let n of Object.keys(t)){let s=t[n];if(s.shouldTransform){if(e[n]=[e[n]].flat(),typeof s.transformFunction==="function")e[n]=e[n].map(s.transformFunction)}}}function Fn(e){let t=/([^\\/]+)$/.exec(e);return t?t[1]:""}function at(e){return e.split(".").map((t,n)=>n===0?On(t):t).join(".")}var ae=class extends Error{constructor(e){super(e);if(this.name="CACError",typeof Error.captureStackTrace!=="function")this.stack=Error(e).stack}},jn=class{rawName;description;name;names;isBoolean;required;config;negated;constructor(e,t,n){if(this.rawName=e,this.description=t,this.config=Object.assign({},n),e=e.replaceAll(".*",""),this.negated=!1,this.names=ot(e).split(",").map((s)=>{let r=s.trim().replace(/^-{1,2}/,"");if(r.startsWith("no-"))this.negated=!0,r=r.replace(/^no-/,"");return at(r)}).sort((s,r)=>s.length>r.length?1:-1),this.name=this.names.at(-1),this.negated&&this.config.default==null)this.config.default=!0;if(e.includes("<"))this.required=!0;else if(e.includes("["))this.required=!1;else this.isBoolean=!0}},Fe,le;if(typeof process<"u"){let e;if(typeof Deno<"u"&&typeof Deno.version?.deno==="string")e="deno";else if(typeof Bun<"u"&&typeof Bun.version==="string")e="bun";else e="node";le=`${process.platform}-${process.arch} ${e}-${process.version}`,Fe=process.argv}else if(typeof navigator>"u")le="unknown";else le=`${navigator.platform} ${navigator.userAgent}`;var lt=class{rawName;description;config;cli;options;aliasNames;name;args;commandAction;usageText;versionNumber;examples;helpCallback;globalCommand;constructor(e,t,n={},s){this.rawName=e,this.description=t,this.config=n,this.cli=s,this.options=[],this.aliasNames=[],this.name=ot(e),this.args=Cn(e),this.examples=[]}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t="-v, --version"){return this.versionNumber=e,this.option(t,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,t,n){let s=new jn(e,t,n);return this.options.push(s),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}isMatched(e){return this.name===e||this.aliasNames.includes(e)}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof ct}hasOption(e){return e=e.split(".")[0],this.options.find((t)=>t.names.includes(e))}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:n,options:s,helpCallback:r}=this.cli.globalCommand,u=[{body:`${e}${n?`/${n}`:""}`}];if(u.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let a=it(t.map((i)=>i.rawName));u.push({title:"Commands",body:t.map((i)=>` ${ut(i.rawName,a.length)} ${i.description}`).join(`
|
|
4
4
|
`)},{title:"For more info, run any command with the `--help` flag",body:t.map((i)=>` $ ${e}${i.name===""?"":` ${i.name}`} --help`).join(`
|
|
5
|
-
`)})}let o=this.isGlobalCommand?s:[...this.options,...s||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)o=o.filter((a)=>a.name!=="version");if(o.length>0){let a=
|
|
5
|
+
`)})}let o=this.isGlobalCommand?s:[...this.options,...s||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)o=o.filter((a)=>a.name!=="version");if(o.length>0){let a=it(o.map((i)=>i.rawName));u.push({title:"Options",body:o.map((i)=>` ${ut(i.rawName,a.length)} ${i.description} ${i.config.default===void 0?"":`(default: ${i.config.default})`}`).join(`
|
|
6
6
|
`)})}if(this.examples.length>0)u.push({title:"Examples",body:this.examples.map((a)=>{if(typeof a==="function")return a(e);return a}).join(`
|
|
7
7
|
`)});if(r)u=r(u)||u;console.info(u.map((a)=>a.title?`${a.title}:
|
|
8
8
|
${a.body}`:a.body).join(`
|
|
9
9
|
|
|
10
|
-
`))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;if(t)console.info(`${e}/${t} ${le}`)}checkRequiredArgs(){let e=this.args.filter((t)=>t.required).length;if(this.cli.args.length<e)throw new ae(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!=="--"&&!this.hasOption(n)&&!t.hasOption(n))throw new ae(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,n=[...t.options,...this.options];for(let s of n){let r=e[s.name.split(".")[0]];if(s.required){let u=n.some((o)=>o.negated&&o.names.includes(s.name));if(r===!0||r===!1&&!u)throw new ae(`option \`${s.rawName}\` value is missing`)}}}checkUnusedArgs(){let e=this.args.some((t)=>t.variadic)?1/0:this.args.length;if(e<this.cli.args.length)throw new ae(`Unused args: ${this.cli.args.slice(e).map((t)=>`\`${t}\``).join(", ")}`)}},lt=class extends at{constructor(e){super("@@global@@","",{},e)}},Fn=class extends EventTarget{name;commands;globalCommand;matchedCommand;matchedCommandName;rawArgs;args;options;showHelpOnExit;showVersionOnExit;constructor(e=""){super();this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new lt(this),this.globalCommand.usage("<command> [options]")}usage(e){return this.globalCommand.usage(e),this}command(e,t,n){let s=new at(e,t||"",n,this);return s.globalCommand=this.globalCommand,this.commands.push(s),s}option(e,t,n){return this.globalCommand.option(e,t,n),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t="-v, --version"){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},n,s){if(this.args=e,this.options=t,n)this.matchedCommand=n;if(s)this.matchedCommandName=s;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e,{run:t=!0}={}){if(!e){if(!De)throw Error("No argv provided and runtime process argv is not available.");e=De}if(this.rawArgs=e,!this.name)this.name=e[1]?Mn(e[1]):"cli";let n=!0;for(let r of this.commands){let u=this.mri(e.slice(2),r),o=u.args[0];if(r.isMatched(o)){n=!1;let a={...u,args:u.args.slice(1)};this.setParsedInfo(a,r,o),this.dispatchEvent(new CustomEvent(`command:${o}`,{detail:r}))}}if(n){for(let r of this.commands)if(r.isDefaultCommand){n=!1;let u=this.mri(e.slice(2),r);this.setParsedInfo(u,r),this.dispatchEvent(new CustomEvent("command:!",{detail:r}))}}if(n){let r=this.mri(e.slice(2));this.setParsedInfo(r)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),t=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),t=!1,this.unsetMatchedCommand();let s={args:this.args,options:this.options};if(t)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.dispatchEvent(new CustomEvent("command:*",{detail:this.args[0]}));return s}mri(e,t){let n=[...this.globalCommand.options,...t?t.options:[]],s=Sn(n),r=[],u=e.indexOf("--");if(u!==-1)r=e.slice(u+1),e=e.slice(0,u);let o=En(e,s);o=Object.keys(o).reduce((f,h)=>({...f,[ot(h)]:o[h]}),{_:[]});let a=o._,i={"--":r},l=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,c=Object.create(null);for(let f of n){if(!l&&f.config.default!==void 0)for(let h of f.names)i[h]=f.config.default;if(Array.isArray(f.config.type)&&c[f.name]===void 0)c[f.name]=Object.create(null),c[f.name].shouldTransform=!0,c[f.name].transformFunction=f.config.type[0]}for(let f of Object.keys(o))if(f!=="_")An(i,f.split("."),o[f]),On(i,c);return{args:a,options:i}}runMatchedCommand(){let{args:e,options:t,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs(),n.checkUnusedArgs();let s=[];return n.args.forEach((r,u)=>{if(r.variadic)s.push(e.slice(u));else s.push(e[u])}),s.push(t),n.commandAction.apply(this,s)}},ct=(e="")=>new Fn(e);import nr from"path";var ce,jn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function ht(e){if(!e&&!ce)return jn;return{lang:e?.lang??ce?.lang,message:e?.message,abortEarly:e?.abortEarly??ce?.abortEarly,abortPipeEarly:e?.abortPipeEarly??ce?.abortPipeEarly}}var Tn;function Rn(e){return Tn?.get(e)}var Pn;function Nn(e){return Pn?.get(e)}var Vn;function Ln(e,t){return Vn?.get(e)?.get(t)}function Fe(e){let t=typeof e;if(t==="string")return`"${e}"`;if(t==="number"||t==="bigint"||t==="boolean")return`${e}`;if(t==="object"||t==="function")return(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null";return t}function P(e,t,n,s,r){let u=r&&"input"in r?r.input:n.value,o=r?.expected??e.expects??null,a=r?.received??Fe(u),i={kind:e.kind,type:e.type,input:u,expected:o,received:a,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${a}`,requirement:e.requirement,path:r?.path,issues:r?.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly},l=e.kind==="schema",c=r?.message??e.message??Ln(e.reference,i.lang)??(l?Nn(i.lang):null)??s.message??Rn(i.lang);if(c!==void 0)i.message=typeof c==="function"?c(i):c;if(l)n.typed=!1;if(n.issues)n.issues.push(i);else n.issues=[i]}var ft=new WeakMap;function N(e){let t=ft.get(e);if(!t)t={version:1,vendor:"valibot",validate(n){return e["~run"]({value:n},ht())}},ft.set(e,t);return t}function mt(e,t){let n=[...new Set(e)];if(n.length>1)return`(${n.join(` ${t} `)})`;return n[0]??"never"}var je=class extends Error{constructor(e){super(e[0].message);this.name="ValiError",this.issues=e}};function Gn(e,t,n){return typeof e.fallback==="function"?e.fallback(t,n):e.fallback}function yt(e,t,n){return typeof e.default==="function"?e.default(t,n):e.default}function V(e,t){return{kind:"schema",type:"array",reference:V,expects:"Array",async:!1,item:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){let r=n.value;if(Array.isArray(r)){n.typed=!0,n.value=[];for(let u=0;u<r.length;u++){let o=r[u],a=this.item["~run"]({value:o},s);if(a.issues){let i={type:"array",origin:"value",input:r,key:u,value:o};for(let l of a.issues){if(l.path)l.path.unshift(i);else l.path=[i];n.issues?.push(l)}if(!n.issues)n.issues=a.issues;if(s.abortEarly){n.typed=!1;break}}if(!a.typed)n.typed=!1;n.value.push(a.value)}}else P(this,"type",n,s);return n}}}function Q(e){return{kind:"schema",type:"boolean",reference:Q,expects:"boolean",async:!1,message:e,get "~standard"(){return N(this)},"~run"(t,n){if(typeof t.value==="boolean")t.typed=!0;else P(this,"type",t,n);return t}}}function Te(e,t){return{kind:"schema",type:"literal",reference:Te,expects:Fe(e),async:!1,literal:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){if(n.value===this.literal)n.typed=!0;else P(this,"type",n,s);return n}}}function z(e,t){return{kind:"schema",type:"object",reference:z,expects:"Object",async:!1,entries:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){let r=n.value;if(r&&typeof r==="object"){n.typed=!0,n.value={};for(let u in this.entries){let o=this.entries[u];if(u in r||(o.type==="exact_optional"||o.type==="optional"||o.type==="nullish")&&o.default!==void 0){let a=u in r?r[u]:yt(o),i=o["~run"]({value:a},s);if(i.issues){let l={type:"object",origin:"value",input:r,key:u,value:a};for(let c of i.issues){if(c.path)c.path.unshift(l);else c.path=[l];n.issues?.push(c)}if(!n.issues)n.issues=i.issues;if(s.abortEarly){n.typed=!1;break}}if(!i.typed)n.typed=!1;n.value[u]=i.value}else if(o.fallback!==void 0)n.value[u]=Gn(o);else if(o.type!=="exact_optional"&&o.type!=="optional"&&o.type!=="nullish"){if(P(this,"key",n,s,{input:void 0,expected:`"${u}"`,path:[{type:"object",origin:"key",input:r,key:u,value:r[u]}]}),s.abortEarly)break}}}else P(this,"type",n,s);return n}}}function ee(e,t){return{kind:"schema",type:"optional",reference:ee,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get "~standard"(){return N(this)},"~run"(n,s){if(n.value===void 0){if(this.default!==void 0)n.value=yt(this,n,s);if(n.value===void 0)return n.typed=!0,n}return this.wrapped["~run"](n,s)}}}function te(e,t){return{kind:"schema",type:"picklist",reference:te,expects:mt(e.map(Fe),"|"),async:!1,options:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){if(this.options.includes(n.value))n.typed=!0;else P(this,"type",n,s);return n}}}function D(e){return{kind:"schema",type:"string",reference:D,expects:"string",async:!1,message:e,get "~standard"(){return N(this)},"~run"(t,n){if(typeof t.value==="string")t.typed=!0;else P(this,"type",t,n);return t}}}function pt(e){let t;if(e)for(let n of e)if(t)for(let s of n.issues)t.push(s);else t=n.issues;return t}function ne(e,t){return{kind:"schema",type:"union",reference:ne,expects:mt(e.map((n)=>n.expects),"|"),async:!1,options:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){let r,u,o;for(let a of this.options){let i=a["~run"]({value:n.value},s);if(i.typed)if(i.issues)if(u)u.push(i);else u=[i];else{r=i;break}else if(o)o.push(i);else o=[i]}if(r)return r;if(u){if(u.length===1)return u[0];P(this,"type",n,s,{issues:pt(u)}),n.typed=!0}else if(o?.length===1)return o[0];else P(this,"type",n,s,{issues:pt(o)});return n}}}function fe(e,t,n){let s=e["~run"]({value:t},ht(n));if(s.issues)throw new je(s.issues);return s.value}function Re(e,t){let n={};for(let s in e.entries)n[s]=!t||t.includes(s)?ee(e.entries[s]):e.entries[s];return{...e,entries:n,get "~standard"(){return N(this)}}}import{stdout as Ue,stdin as Dt}from"process";import*as H from"readline";import ss from"readline";var dt=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(t)=>{let n=0;e.lastIndex=0;while(e.test(t))n+=1;return t.length-n}})(),gt=(e)=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,vt=(e)=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141;var qn=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Un=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,$t=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,Bn=/\t{1,1000}/y,bt=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,Wn=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,zn=/\p{M}+/gu,Hn={limit:1/0,ellipsis:""},kt=(e,t={},n={})=>{let s=t.limit??1/0,r=t.ellipsis??"",u=t?.ellipsisWidth??(r?kt(r,Hn,n).width:0),o=0,a=n.controlWidth??0,i=n.tabWidth??8,l=n.emojiWidth??2,c=2,f=n.regularWidth??1,h=n.wideWidth??2,g=[[Wn,f],[qn,0],[Un,a],[Bn,i],[bt,l],[$t,h]],m=0,y=0,F=e.length,U=0,B=!1,O=F,j=Math.max(0,s-u),I=0,Z=0,M=0,E=0;e:while(!0){if(Z>I||y>=F&&y>m){let W=e.slice(I,Z)||e.slice(m,y);U=0;for(let X of W.replaceAll(zn,"")){let S=X.codePointAt(0)||0;if(gt(S))E=2;else if(vt(S))E=h;else E=f;if(M+E>j)O=Math.min(O,Math.max(I,m)+U);if(M+E>s){B=!0;break e}U+=X.length,M+=E}I=Z=0}if(y>=F)break e;for(let W=0,X=g.length;W<X;W++){let[S,ue]=g[W];if(S.lastIndex=y,S.test(e)){if(U=S===$t?dt(e.slice(y,S.lastIndex)):S===bt?1:S.lastIndex-y,E=U*ue,M+E>j)O=Math.min(O,y+Math.floor((j-M)/ue));if(M+E>s){B=!0;break e}M+=E,I=m,Z=y,y=m=S.lastIndex;continue e}}y+=1}return{width:B?j:M,index:B?O:F,truncated:B,ellipsed:B&&s>=u}},wt=kt;var Kn={limit:1/0,ellipsis:"",ellipsisWidth:0},Xn=(e,t={})=>wt(e,Kn,t).width,w=Xn;var he="\x1B",St="\x9B",Jn=39,Ne="\x07",Ct="[",Zn="]",At="m",Ve=`${Zn}8;;`,xt=new RegExp(`(?:\\${Ct}(?<code>\\d+)m|\\${Ve}(?<uri>.*)${Ne})`,"y"),_t=(e)=>{if(e>=30&&e<=37)return 39;if(e>=90&&e<=97)return 39;if(e>=40&&e<=47)return 49;if(e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0;return},Et=(e)=>`${he}${Ct}${e}${At}`,It=(e)=>`${he}${Ve}${e}${Ne}`,Pe=(e,t,n)=>{let s=t[Symbol.iterator](),r=!1,u=!1,o=e.at(-1),a=o===void 0?0:w(o),i=s.next(),l=s.next(),c=0;while(!i.done){let f=i.value,h=w(f);if(a+h<=n)e[e.length-1]+=f;else e.push(f),a=0;if(f===he||f===St)r=!0,u=t.startsWith(Ve,c+1);if(r){if(u){if(f===Ne)r=!1,u=!1}else if(f===At)r=!1}else if(a+=h,a===n&&!l.done)e.push(""),a=0;i=l,l=s.next(),c+=f.length}if(o=e.at(-1),!a&&o!==void 0&&o.length&&e.length>1)e[e.length-2]+=e.pop()},Yn=(e)=>{let t=e.split(" "),n=t.length;while(n){if(w(t[n-1]))break;n--}if(n===t.length)return e;return t.slice(0,n).join(" ")+t.slice(n).join("")},Qn=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let s="",r,u,o=e.split(" "),a=[""],i=0;for(let f=0;f<o.length;f++){let h=o[f];if(n.trim!==!1){let m=a.at(-1)??"",y=m.trimStart();if(m.length!==y.length)a[a.length-1]=y,i=w(y)}if(f!==0){if(i>=t&&(n.wordWrap===!1||n.trim===!1))a.push(""),i=0;if(i||n.trim===!1)a[a.length-1]+=" ",i++}let g=w(h);if(n.hard&&g>t){let m=t-i,y=1+Math.floor((g-m-1)/t);if(Math.floor((g-1)/t)<y)a.push("");Pe(a,h,t),i=w(a.at(-1)??"");continue}if(i+g>t&&i&&g){if(n.wordWrap===!1&&i<t){Pe(a,h,t),i=w(a.at(-1)??"");continue}a.push(""),i=0}if(i+g>t&&n.wordWrap===!1){Pe(a,h,t),i=w(a.at(-1)??"");continue}a[a.length-1]+=h,i+=g}if(n.trim!==!1)a=a.map((f)=>Yn(f));let l=a.join(`
|
|
11
|
-
`),c=!1;for(let f=0;f<l.length;f++){let h=l[f];if(s+=h,!c){if(c=h>="\uD800"&&h<="\uDBFF",c)continue}else c=!1;if(h===he||h===
|
|
12
|
-
`){if(u)s+=
|
|
13
|
-
`){if(r&&
|
|
14
|
-
`)}var k=
|
|
10
|
+
`))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;if(t)console.info(`${e}/${t} ${le}`)}checkRequiredArgs(){let e=this.args.filter((t)=>t.required).length;if(this.cli.args.length<e)throw new ae(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!=="--"&&!this.hasOption(n)&&!t.hasOption(n))throw new ae(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,n=[...t.options,...this.options];for(let s of n){let r=e[s.name.split(".")[0]];if(s.required){let u=n.some((o)=>o.negated&&o.names.includes(s.name));if(r===!0||r===!1&&!u)throw new ae(`option \`${s.rawName}\` value is missing`)}}}checkUnusedArgs(){let e=this.args.some((t)=>t.variadic)?1/0:this.args.length;if(e<this.cli.args.length)throw new ae(`Unused args: ${this.cli.args.slice(e).map((t)=>`\`${t}\``).join(", ")}`)}},ct=class extends lt{constructor(e){super("@@global@@","",{},e)}},Tn=class extends EventTarget{name;commands;globalCommand;matchedCommand;matchedCommandName;rawArgs;args;options;showHelpOnExit;showVersionOnExit;constructor(e=""){super();this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new ct(this),this.globalCommand.usage("<command> [options]")}usage(e){return this.globalCommand.usage(e),this}command(e,t,n){let s=new lt(e,t||"",n,this);return s.globalCommand=this.globalCommand,this.commands.push(s),s}option(e,t,n){return this.globalCommand.option(e,t,n),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t="-v, --version"){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},n,s){if(this.args=e,this.options=t,n)this.matchedCommand=n;if(s)this.matchedCommandName=s;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e,{run:t=!0}={}){if(!e){if(!Fe)throw Error("No argv provided and runtime process argv is not available.");e=Fe}if(this.rawArgs=e,!this.name)this.name=e[1]?Fn(e[1]):"cli";let n=!0;for(let r of this.commands){let u=this.mri(e.slice(2),r),o=u.args[0];if(r.isMatched(o)){n=!1;let a={...u,args:u.args.slice(1)};this.setParsedInfo(a,r,o),this.dispatchEvent(new CustomEvent(`command:${o}`,{detail:r}))}}if(n){for(let r of this.commands)if(r.isDefaultCommand){n=!1;let u=this.mri(e.slice(2),r);this.setParsedInfo(u,r),this.dispatchEvent(new CustomEvent("command:!",{detail:r}))}}if(n){let r=this.mri(e.slice(2));this.setParsedInfo(r)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),t=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),t=!1,this.unsetMatchedCommand();let s={args:this.args,options:this.options};if(t)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.dispatchEvent(new CustomEvent("command:*",{detail:this.args[0]}));return s}mri(e,t){let n=[...this.globalCommand.options,...t?t.options:[]],s=An(n),r=[],u=e.indexOf("--");if(u!==-1)r=e.slice(u+1),e=e.slice(0,u);let o=Sn(e,s);o=Object.keys(o).reduce((f,h)=>({...f,[at(h)]:o[h]}),{_:[]});let a=o._,i={"--":r},l=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,c=Object.create(null);for(let f of n){if(!l&&f.config.default!==void 0)for(let h of f.names)i[h]=f.config.default;if(Array.isArray(f.config.type)&&c[f.name]===void 0)c[f.name]=Object.create(null),c[f.name].shouldTransform=!0,c[f.name].transformFunction=f.config.type[0]}for(let f of Object.keys(o))if(f!=="_")Mn(i,f.split("."),o[f]),Dn(i,c);return{args:a,options:i}}runMatchedCommand(){let{args:e,options:t,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs(),n.checkUnusedArgs();let s=[];return n.args.forEach((r,u)=>{if(r.variadic)s.push(e.slice(u));else s.push(e[u])}),s.push(t),n.commandAction.apply(this,s)}},ft=(e="")=>new Tn(e);import sr from"path";var ce,Rn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function mt(e){if(!e&&!ce)return Rn;return{lang:e?.lang??ce?.lang,message:e?.message,abortEarly:e?.abortEarly??ce?.abortEarly,abortPipeEarly:e?.abortPipeEarly??ce?.abortPipeEarly}}var Pn;function Nn(e){return Pn?.get(e)}var Vn;function Ln(e){return Vn?.get(e)}var Gn;function qn(e,t){return Gn?.get(e)?.get(t)}function je(e){let t=typeof e;if(t==="string")return`"${e}"`;if(t==="number"||t==="bigint"||t==="boolean")return`${e}`;if(t==="object"||t==="function")return(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null";return t}function P(e,t,n,s,r){let u=r&&"input"in r?r.input:n.value,o=r?.expected??e.expects??null,a=r?.received??je(u),i={kind:e.kind,type:e.type,input:u,expected:o,received:a,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${a}`,requirement:e.requirement,path:r?.path,issues:r?.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly},l=e.kind==="schema",c=r?.message??e.message??qn(e.reference,i.lang)??(l?Ln(i.lang):null)??s.message??Nn(i.lang);if(c!==void 0)i.message=typeof c==="function"?c(i):c;if(l)n.typed=!1;if(n.issues)n.issues.push(i);else n.issues=[i]}var pt=new WeakMap;function N(e){let t=pt.get(e);if(!t)t={version:1,vendor:"valibot",validate(n){return e["~run"]({value:n},mt())}},pt.set(e,t);return t}function yt(e,t){let n=[...new Set(e)];if(n.length>1)return`(${n.join(` ${t} `)})`;return n[0]??"never"}var Te=class extends Error{constructor(e){super(e[0].message);this.name="ValiError",this.issues=e}};function Un(e,t,n){return typeof e.fallback==="function"?e.fallback(t,n):e.fallback}function dt(e,t,n){return typeof e.default==="function"?e.default(t,n):e.default}function V(e,t){return{kind:"schema",type:"array",reference:V,expects:"Array",async:!1,item:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){let r=n.value;if(Array.isArray(r)){n.typed=!0,n.value=[];for(let u=0;u<r.length;u++){let o=r[u],a=this.item["~run"]({value:o},s);if(a.issues){let i={type:"array",origin:"value",input:r,key:u,value:o};for(let l of a.issues){if(l.path)l.path.unshift(i);else l.path=[i];n.issues?.push(l)}if(!n.issues)n.issues=a.issues;if(s.abortEarly){n.typed=!1;break}}if(!a.typed)n.typed=!1;n.value.push(a.value)}}else P(this,"type",n,s);return n}}}function Q(e){return{kind:"schema",type:"boolean",reference:Q,expects:"boolean",async:!1,message:e,get "~standard"(){return N(this)},"~run"(t,n){if(typeof t.value==="boolean")t.typed=!0;else P(this,"type",t,n);return t}}}function Re(e,t){return{kind:"schema",type:"literal",reference:Re,expects:je(e),async:!1,literal:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){if(n.value===this.literal)n.typed=!0;else P(this,"type",n,s);return n}}}function W(e,t){return{kind:"schema",type:"object",reference:W,expects:"Object",async:!1,entries:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){let r=n.value;if(r&&typeof r==="object"){n.typed=!0,n.value={};for(let u in this.entries){let o=this.entries[u];if(u in r||(o.type==="exact_optional"||o.type==="optional"||o.type==="nullish")&&o.default!==void 0){let a=u in r?r[u]:dt(o),i=o["~run"]({value:a},s);if(i.issues){let l={type:"object",origin:"value",input:r,key:u,value:a};for(let c of i.issues){if(c.path)c.path.unshift(l);else c.path=[l];n.issues?.push(c)}if(!n.issues)n.issues=i.issues;if(s.abortEarly){n.typed=!1;break}}if(!i.typed)n.typed=!1;n.value[u]=i.value}else if(o.fallback!==void 0)n.value[u]=Un(o);else if(o.type!=="exact_optional"&&o.type!=="optional"&&o.type!=="nullish"){if(P(this,"key",n,s,{input:void 0,expected:`"${u}"`,path:[{type:"object",origin:"key",input:r,key:u,value:r[u]}]}),s.abortEarly)break}}}else P(this,"type",n,s);return n}}}function ee(e,t){return{kind:"schema",type:"optional",reference:ee,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get "~standard"(){return N(this)},"~run"(n,s){if(n.value===void 0){if(this.default!==void 0)n.value=dt(this,n,s);if(n.value===void 0)return n.typed=!0,n}return this.wrapped["~run"](n,s)}}}function te(e,t){return{kind:"schema",type:"picklist",reference:te,expects:yt(e.map(je),"|"),async:!1,options:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){if(this.options.includes(n.value))n.typed=!0;else P(this,"type",n,s);return n}}}function D(e){return{kind:"schema",type:"string",reference:D,expects:"string",async:!1,message:e,get "~standard"(){return N(this)},"~run"(t,n){if(typeof t.value==="string")t.typed=!0;else P(this,"type",t,n);return t}}}function ht(e){let t;if(e)for(let n of e)if(t)for(let s of n.issues)t.push(s);else t=n.issues;return t}function ne(e,t){return{kind:"schema",type:"union",reference:ne,expects:yt(e.map((n)=>n.expects),"|"),async:!1,options:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){let r,u,o;for(let a of this.options){let i=a["~run"]({value:n.value},s);if(i.typed)if(i.issues)if(u)u.push(i);else u=[i];else{r=i;break}else if(o)o.push(i);else o=[i]}if(r)return r;if(u){if(u.length===1)return u[0];P(this,"type",n,s,{issues:ht(u)}),n.typed=!0}else if(o?.length===1)return o[0];else P(this,"type",n,s,{issues:ht(o)});return n}}}function fe(e,t,n){let s=e["~run"]({value:t},mt(n));if(s.issues)throw new Te(s.issues);return s.value}function Pe(e,t){let n={};for(let s in e.entries)n[s]=!t||t.includes(s)?ee(e.entries[s]):e.entries[s];return{...e,entries:n,get "~standard"(){return N(this)}}}import{stdout as Be,stdin as Ft}from"process";import*as H from"readline";import is from"readline";var gt=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(t)=>{let n=0;e.lastIndex=0;while(e.test(t))n+=1;return t.length-n}})(),vt=(e)=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,$t=(e)=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141;var Bn=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Wn=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,bt=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,Hn=/\t{1,1000}/y,kt=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,zn=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Kn=/\p{M}+/gu,Xn={limit:1/0,ellipsis:""},wt=(e,t={},n={})=>{let s=t.limit??1/0,r=t.ellipsis??"",u=t?.ellipsisWidth??(r?wt(r,Xn,n).width:0),o=0,a=n.controlWidth??0,i=n.tabWidth??8,l=n.emojiWidth??2,c=2,f=n.regularWidth??1,h=n.wideWidth??2,g=[[zn,f],[Bn,0],[Wn,a],[Hn,i],[kt,l],[bt,h]],m=0,y=0,F=e.length,q=0,U=!1,O=F,j=Math.max(0,s-u),I=0,J=0,M=0,E=0;e:while(!0){if(J>I||y>=F&&y>m){let B=e.slice(I,J)||e.slice(m,y);q=0;for(let K of B.replaceAll(Kn,"")){let S=K.codePointAt(0)||0;if(vt(S))E=2;else if($t(S))E=h;else E=f;if(M+E>j)O=Math.min(O,Math.max(I,m)+q);if(M+E>s){U=!0;break e}q+=K.length,M+=E}I=J=0}if(y>=F)break e;for(let B=0,K=g.length;B<K;B++){let[S,ue]=g[B];if(S.lastIndex=y,S.test(e)){if(q=S===bt?gt(e.slice(y,S.lastIndex)):S===kt?1:S.lastIndex-y,E=q*ue,M+E>j)O=Math.min(O,y+Math.floor((j-M)/ue));if(M+E>s){U=!0;break e}M+=E,I=m,J=y,y=m=S.lastIndex;continue e}}y+=1}return{width:U?j:M,index:U?O:F,truncated:U,ellipsed:U&&s>=u}},xt=wt;var Jn={limit:1/0,ellipsis:"",ellipsisWidth:0},Zn=(e,t={})=>xt(e,Jn,t).width,w=Zn;var he="\x1B",Ct="\x9B",Yn=39,Ve="\x07",At="[",Qn="]",Ot="m",Le=`${Qn}8;;`,_t=new RegExp(`(?:\\${At}(?<code>\\d+)m|\\${Le}(?<uri>.*)${Ve})`,"y"),Et=(e)=>{if(e>=30&&e<=37)return 39;if(e>=90&&e<=97)return 39;if(e>=40&&e<=47)return 49;if(e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0;return},It=(e)=>`${he}${At}${e}${Ot}`,St=(e)=>`${he}${Le}${e}${Ve}`,Ne=(e,t,n)=>{let s=t[Symbol.iterator](),r=!1,u=!1,o=e.at(-1),a=o===void 0?0:w(o),i=s.next(),l=s.next(),c=0;while(!i.done){let f=i.value,h=w(f);if(a+h<=n)e[e.length-1]+=f;else e.push(f),a=0;if(f===he||f===Ct)r=!0,u=t.startsWith(Le,c+1);if(r){if(u){if(f===Ve)r=!1,u=!1}else if(f===Ot)r=!1}else if(a+=h,a===n&&!l.done)e.push(""),a=0;i=l,l=s.next(),c+=f.length}if(o=e.at(-1),!a&&o!==void 0&&o.length&&e.length>1)e[e.length-2]+=e.pop()},es=(e)=>{let t=e.split(" "),n=t.length;while(n){if(w(t[n-1]))break;n--}if(n===t.length)return e;return t.slice(0,n).join(" ")+t.slice(n).join("")},ts=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let s="",r,u,o=e.split(" "),a=[""],i=0;for(let f=0;f<o.length;f++){let h=o[f];if(n.trim!==!1){let m=a.at(-1)??"",y=m.trimStart();if(m.length!==y.length)a[a.length-1]=y,i=w(y)}if(f!==0){if(i>=t&&(n.wordWrap===!1||n.trim===!1))a.push(""),i=0;if(i||n.trim===!1)a[a.length-1]+=" ",i++}let g=w(h);if(n.hard&&g>t){let m=t-i,y=1+Math.floor((g-m-1)/t);if(Math.floor((g-1)/t)<y)a.push("");Ne(a,h,t),i=w(a.at(-1)??"");continue}if(i+g>t&&i&&g){if(n.wordWrap===!1&&i<t){Ne(a,h,t),i=w(a.at(-1)??"");continue}a.push(""),i=0}if(i+g>t&&n.wordWrap===!1){Ne(a,h,t),i=w(a.at(-1)??"");continue}a[a.length-1]+=h,i+=g}if(n.trim!==!1)a=a.map((f)=>es(f));let l=a.join(`
|
|
11
|
+
`),c=!1;for(let f=0;f<l.length;f++){let h=l[f];if(s+=h,!c){if(c=h>="\uD800"&&h<="\uDBFF",c)continue}else c=!1;if(h===he||h===Ct){_t.lastIndex=f+1;let m=_t.exec(l)?.groups;if(m?.code!==void 0){let y=Number.parseFloat(m.code);r=y===Yn?void 0:y}else if(m?.uri!==void 0)u=m.uri.length===0?void 0:m.uri}if(l[f+1]===`
|
|
12
|
+
`){if(u)s+=St("");let g=r?Et(r):void 0;if(r&&g)s+=It(g)}else if(h===`
|
|
13
|
+
`){if(r&&Et(r))s+=It(r);if(u)s+=St(u)}}return s},ns=/\r?\n/;function L(e,t,n){return String(e).normalize().split(ns).map((s)=>ts(s,t,n)).join(`
|
|
14
|
+
`)}var k=rt(qe(),1);import{ReadStream as Dt}from"tty";var us=["up","down","left","right","space","enter","cancel"],os=["January","February","March","April","May","June","July","August","September","October","November","December"],_={actions:new Set(us),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,date:{monthNames:[...os],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(e,t)=>`There are only ${e} days in ${t}`,afterMin:(e)=>`Date must be on or after ${e.toISOString().slice(0,10)}`,beforeMax:(e)=>`Date must be on or before ${e.toISOString().slice(0,10)}`}}};function We(e,t){if(typeof e=="string")return _.aliases.get(e)===t;for(let n of e)if(n!==void 0&&We(n,t))return!0;return!1}function as(e,t){if(e===t)return;let n=e.split(`
|
|
15
15
|
`),s=t.split(`
|
|
16
|
-
`),r=Math.max(n.length,s.length),u=[];for(let o=0;o<r;o++)n[o]!==s[o]&&u.push(o);return{lines:u,numLinesBefore:n.length,numLinesAfter:s.length,numLines:r}}var
|
|
16
|
+
`),r=Math.max(n.length,s.length),u=[];for(let o=0;o<r;o++)n[o]!==s[o]&&u.push(o);return{lines:u,numLinesBefore:n.length,numLinesAfter:s.length,numLines:r}}var ls=globalThis.process.platform.startsWith("win"),Ue=Symbol("clack:cancel");function ye(e){return e===Ue}function me(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function jt({input:e=Ft,output:t=Be,overwrite:n=!0,hideCursor:s=!0}={}){let r=H.createInterface({input:e,output:t,prompt:"",tabSize:1});H.emitKeypressEvents(e,r),e instanceof Dt&&e.isTTY&&e.setRawMode(!0);let u=(o,{name:a,sequence:i})=>{let l=String(o);if(We([l,a,i],"cancel")){s&&t.write(k.cursor.show),process.exit(0);return}if(!n)return;H.moveCursor(t,a==="return"?0:-1,a==="return"?-1:0,()=>{H.clearLine(t,1,()=>{e.once("keypress",u)})})};return s&&t.write(k.cursor.hide),e.once("keypress",u),()=>{e.off("keypress",u),s&&t.write(k.cursor.show),e instanceof Dt&&e.isTTY&&!ls&&e.setRawMode(!1),r.terminal=!1,r.close()}}var de=(e)=>("columns"in e)&&typeof e.columns=="number"?e.columns:80,Tt=(e)=>("rows"in e)&&typeof e.rows=="number"?e.rows:20;function Rt(e,t,n,s=n,r=n,u){let o=de(e??Be);return L(t,o-n.length,{hard:!0,trim:!1}).split(`
|
|
17
17
|
`).map((a,i,l)=>{let c=u?u(a,i):a;return i===0?`${s}${c}`:i===l.length-1?`${r}${c}`:`${n}${c}`}).join(`
|
|
18
|
-
`)}function
|
|
18
|
+
`)}function Pt(e,t){if("~standard"in e){let n=e["~standard"].validate(t);if(n instanceof Promise)throw TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");return n.issues?.at(0)?.message}return e(t)}class Nt{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(e,t=!0){let{input:n=Ft,output:s=Be,render:r,signal:u,...o}=e;this.opts=o,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=r.bind(this),this._track=t,this._abortSignal=u,this.input=n,this.output=s}unsubscribe(){this._subscribers.clear()}setSubscriber(e,t){let n=this._subscribers.get(e)??[];n.push(t),this._subscribers.set(e,n)}on(e,t){this.setSubscriber(e,{cb:t})}once(e,t){this.setSubscriber(e,{cb:t,once:!0})}emit(e,...t){let n=this._subscribers.get(e)??[],s=[];for(let r of n)r.cb(...t),r.once&&s.push(()=>n.splice(n.indexOf(r),1));for(let r of s)r()}prompt(){return new Promise((e)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),e(Ue);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=is.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),me(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(k.cursor.show),this.output.off("resize",this.render),me(this.input,!1),e(this.value)}),this.once("cancel",()=>{this.output.write(k.cursor.show),this.output.off("resize",this.render),me(this.input,!1),e(Ue)})})}_isActionKey(e,t){return e==="\t"}_shouldSubmit(e,t){return!0}_setValue(e){this.value=e,this.emit("value",this.value)}_setUserInput(e,t){this.userInput=e??"",this.emit("userInput",this.userInput),t&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}onKeypress(e,t){if(this._track&&t.name!=="return"&&(t.name&&this._isActionKey(e,t)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),t?.name&&(!this._track&&_.aliases.has(t.name)&&this.emit("cursor",_.aliases.get(t.name)),_.actions.has(t.name)&&this.emit("cursor",t.name)),e&&(e.toLowerCase()==="y"||e.toLowerCase()==="n")&&this.emit("confirm",e.toLowerCase()==="y"),this.emit("key",e,t),t?.name==="return"&&this._shouldSubmit(e,t)){if(this.opts.validate){let n=Pt(this.opts.validate,this.value);n&&(this.error=n instanceof Error?n.message:n,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}We([e,t?.name,t?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
|
|
19
19
|
`),me(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=L(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
|
|
20
|
-
`).length-1;this.output.write(k.cursor.move(-999,e*-1))}render(){let e=L(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(e!==this._prevFrame){if(this.state==="initial")this.output.write(k.cursor.hide);else{let t=
|
|
20
|
+
`).length-1;this.output.write(k.cursor.move(-999,e*-1))}render(){let e=L(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(e!==this._prevFrame){if(this.state==="initial")this.output.write(k.cursor.hide);else{let t=as(this._prevFrame,e),n=Tt(this.output);if(this.restoreCursor(),t){let s=Math.max(0,t.numLinesAfter-n),r=Math.max(0,t.numLinesBefore-n),u=t.lines.find((o)=>o>=s);if(u===void 0){this._prevFrame=e;return}if(t.lines.length===1){this.output.write(k.cursor.move(0,u-r)),this.output.write(k.erase.lines(1));let o=e.split(`
|
|
21
21
|
`);this.output.write(o[u]),this._prevFrame=e,this.output.write(k.cursor.move(0,o.length-u-1));return}else if(t.lines.length>1){if(s<r)u=s;else{let a=u-r;a>0&&this.output.write(k.cursor.move(0,a))}this.output.write(k.erase.down());let o=e.split(`
|
|
22
22
|
`).slice(u);this.output.write(o.join(`
|
|
23
|
-
`)),this._prevFrame=e;return}}this.output.write(k.erase.down())}this.output.write(e),this.state==="initial"&&(this.state="active"),this._prevFrame=e}}}class
|
|
23
|
+
`)),this._prevFrame=e;return}}this.output.write(k.erase.down())}this.output.write(e),this.state==="initial"&&(this.state="active"),this._prevFrame=e}}}class He extends Nt{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(e){super(e,!1),this.value=!!e.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",(t)=>{this.output.write(k.cursor.move(0,-1)),this.value=t,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}import{styleText as p,stripVTControlCharacters as Pr}from"util";import A from"process";var se=rt(qe(),1);function cs(){if(A.platform!=="win32")return A.env.TERM!=="linux";return Boolean(A.env.CI)||Boolean(A.env.WT_SESSION)||Boolean(A.env.TERMINUS_SUBLIME)||A.env.ConEmuTask==="{cmd::Cmder}"||A.env.TERM_PROGRAM==="Terminus-Sublime"||A.env.TERM_PROGRAM==="vscode"||A.env.TERM==="xterm-256color"||A.env.TERM==="alacritty"||A.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var ze=cs(),fs=()=>process.env.CI==="true";var d=(e,t)=>ze?e:t,ps=d("\u25C6","*"),qt=d("\u25A0","x"),Ut=d("\u25B2","x"),ge=d("\u25C7","o"),hs=d("\u250C","T"),x=d("\u2502","|"),Bt=d("\u2514","\u2014"),Gr=d("\u2510","T"),qr=d("\u2518","\u2014"),Vt=d("\u25CF",">"),Lt=d("\u25CB"," "),Ur=d("\u25FB","[\u2022]"),Br=d("\u25FC","[+]"),Wr=d("\u25FB","[ ]"),Hr=d("\u25AA","\u2022"),Gt=d("\u2500","-"),ms=d("\u256E","+"),ys=d("\u251C","+"),ds=d("\u256F","+"),gs=d("\u2570","+"),zr=d("\u256D","+"),vs=d("\u25CF","\u2022"),$s=d("\u25C6","*"),bs=d("\u25B2","!"),ks=d("\u25A0","x"),ws=(e)=>{switch(e){case"initial":case"active":return p("cyan",ps);case"cancel":return p("red",qt);case"error":return p("yellow",Ut);case"submit":return p("green",ge)}};var Wt=(e)=>{let t=e.active??"Yes",n=e.inactive??"No";return new He({active:t,inactive:n,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue??!0,render(){let s=e.withGuide??_.withGuide,r=`${ws(this.state)} `,u=s?`${p("gray",x)} `:"",o=Rt(e.output,e.message,u,r),a=`${s?`${p("gray",x)}
|
|
24
24
|
`:""}${o}
|
|
25
25
|
`,i=this.value?t:n;switch(this.state){case"submit":{let l=s?`${p("gray",x)} `:"";return`${a}${l}${p("dim",i)}`}case"cancel":{let l=s?`${p("gray",x)} `:"";return`${a}${l}${p(["strikethrough","dim"],i)}${s?`
|
|
26
|
-
${p("gray",x)}`:""}`}default:{let l=s?`${p("cyan",x)} `:"",c=s?p("cyan",
|
|
26
|
+
${p("gray",x)}`:""}`}default:{let l=s?`${p("cyan",x)} `:"",c=s?p("cyan",Bt):"";return`${a}${l}${this.value?`${p("green",Vt)} ${t}`:`${p("dim",Lt)} ${p("dim",t)}`}${e.vertical?s?`
|
|
27
27
|
${p("cyan",x)} `:`
|
|
28
|
-
`:` ${p("dim","/")} `}${this.value?`${p("dim",
|
|
28
|
+
`:` ${p("dim","/")} `}${this.value?`${p("dim",Lt)} ${p("dim",n)}`:`${p("green",Vt)} ${n}`}
|
|
29
29
|
${c}
|
|
30
|
-
`}}}}).prompt()};var
|
|
30
|
+
`}}}}).prompt()};var Kr=[`${p("dim","\u2191/\u2193")} to navigate`,`${p("dim","Space:")} select`,`${p("dim","Enter:")} confirm`];var v={message:(e=[],{symbol:t=p("gray",x),secondarySymbol:n=p("gray",x),output:s=process.stdout,spacing:r=1,withGuide:u}={})=>{let o=[],a=u??_.withGuide,i=a?n:"",l=a?`${t} `:"",c=a?`${n} `:"";for(let h=0;h<r;h++)o.push(i);let f=Array.isArray(e)?e:e.split(`
|
|
31
31
|
`);if(f.length>0){let[h,...g]=f;h.length>0?o.push(`${l}${h}`):o.push(a?t:"");for(let m of g)m.length>0?o.push(`${c}${m}`):o.push(a?n:"")}s.write(`${o.join(`
|
|
32
32
|
`)}
|
|
33
|
-
`)},info:(e,t)=>{v.message(e,{...t,symbol:p("blue",
|
|
34
|
-
`)},
|
|
35
|
-
${p("gray",
|
|
33
|
+
`)},info:(e,t)=>{v.message(e,{...t,symbol:p("blue",vs)})},success:(e,t)=>{v.message(e,{...t,symbol:p("green",$s)})},step:(e,t)=>{v.message(e,{...t,symbol:p("green",ge)})},warn:(e,t)=>{v.message(e,{...t,symbol:p("yellow",bs)})},warning:(e,t)=>{v.warn(e,t)},error:(e,t)=>{v.message(e,{...t,symbol:p("red",ks)})}};var ve=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??_.withGuide?`${p("gray",hs)} `:"";n.write(`${s}${e}
|
|
34
|
+
`)},Ht=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??_.withGuide?`${p("gray",x)}
|
|
35
|
+
${p("gray",Bt)} `:"";n.write(`${s}${e}
|
|
36
36
|
|
|
37
|
-
`)};var
|
|
38
|
-
`),u=r.reduce((i,l)=>Math.max(w(l),i),0),o=r.map(n).reduce((i,l)=>Math.max(w(l),i),0),a=t-(o-u);return L(e,a,s)},$e=(e="",t="",n)=>{let s=n?.output??A.stdout,r=n?.withGuide??_.withGuide,u=n?.format??
|
|
37
|
+
`)};var xs=(e)=>e,_s=(e,t,n)=>{let s={hard:!0,trim:!1},r=L(e,t,s).split(`
|
|
38
|
+
`),u=r.reduce((i,l)=>Math.max(w(l),i),0),o=r.map(n).reduce((i,l)=>Math.max(w(l),i),0),a=t-(o-u);return L(e,a,s)},$e=(e="",t="",n)=>{let s=n?.output??A.stdout,r=n?.withGuide??_.withGuide,u=n?.format??xs,o=["",..._s(e,de(s)-6,u).split(`
|
|
39
39
|
`).map(u),""],a=w(t),i=Math.max(o.reduce((h,g)=>{let m=w(g);return m>h?m:h},0),a)+2,l=o.map((h)=>`${p("gray",x)} ${h}${" ".repeat(i-w(h))}${p("gray",x)}`).join(`
|
|
40
40
|
`),c=r?`${p("gray",x)}
|
|
41
|
-
`:"",f=r?
|
|
41
|
+
`:"",f=r?ys:gs;s.write(`${c}${p("green",ge)} ${p("reset",t)} ${p("gray",Gt.repeat(Math.max(i-a-1,1))+ms)}
|
|
42
42
|
${l}
|
|
43
|
-
${p("gray",f+
|
|
44
|
-
`)};var
|
|
45
|
-
`);let b=L(y,
|
|
46
|
-
`);b.length>1&&n.write(se.cursor.up(b.length-1)),n.write(se.cursor.to(0)),n.write(se.erase.down())},
|
|
47
|
-
`);let C=0,T=0;
|
|
43
|
+
${p("gray",f+Gt.repeat(i+2)+ds)}
|
|
44
|
+
`)};var Es=(e)=>p("magenta",e),be=({indicator:e="dots",onCancel:t,output:n=process.stdout,cancelMessage:s,errorMessage:r,frames:u=ze?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:o=ze?80:120,signal:a,...i}={})=>{let l=fs(),c,f,h=!1,g=!1,m="",y,F=performance.now(),q=de(n),U=i?.styleFrame??Es,O=(b)=>{let C=b>1?r??_.messages.error:s??_.messages.cancel;g=b===1,h&&(Y(C,b),g&&typeof t=="function"&&t())},j=()=>O(2),I=()=>O(1),J=()=>{process.on("uncaughtExceptionMonitor",j),process.on("unhandledRejection",j),process.on("SIGINT",I),process.on("SIGTERM",I),process.on("exit",O),a&&a.addEventListener("abort",I)},M=()=>{process.removeListener("uncaughtExceptionMonitor",j),process.removeListener("unhandledRejection",j),process.removeListener("SIGINT",I),process.removeListener("SIGTERM",I),process.removeListener("exit",O),a&&a.removeEventListener("abort",I)},E=()=>{if(y===void 0)return;l&&n.write(`
|
|
45
|
+
`);let b=L(y,q,{hard:!0,trim:!1}).split(`
|
|
46
|
+
`);b.length>1&&n.write(se.cursor.up(b.length-1)),n.write(se.cursor.to(0)),n.write(se.erase.down())},B=(b)=>b.replace(/\.+$/,""),K=(b)=>{let C=(performance.now()-b)/1000,T=Math.floor(C/60),R=Math.floor(C%60);return T>0?`[${T}m ${R}s]`:`[${R}s]`},S=i.withGuide??_.withGuide,ue=(b="")=>{h=!0,c=jt({output:n}),m=B(b),F=performance.now(),S&&n.write(`${p("gray",x)}
|
|
47
|
+
`);let C=0,T=0;J(),f=setInterval(()=>{if(l&&m===y)return;E(),y=m;let R=U(u[C]),oe;if(l)oe=`${R} ${m}...`;else if(e==="timer")oe=`${R} ${m} ${K(F)}`;else{let gn=".".repeat(Math.floor(T)).slice(0,3);oe=`${R} ${m}${gn}`}let dn=L(oe,q,{hard:!0,trim:!1});n.write(dn),C=C+1<u.length?C+1:0,T=T<4?T+0.125:0},o)},Y=(b="",C=0,T=!1)=>{if(!h)return;h=!1,clearInterval(f),E();let R=C===0?p("green",ge):C===1?p("red",qt):p("red",Ut);m=b??m,T||(e==="timer"?n.write(`${R} ${m} ${K(F)}
|
|
48
48
|
`):n.write(`${R} ${m}
|
|
49
|
-
`)),M(),c()};return{start:ue,stop:(b="")=>Y(b,0),message:(b="")=>{m=
|
|
50
|
-
`),"System Environment",{withGuide:!0}),
|
|
49
|
+
`)),M(),c()};return{start:ue,stop:(b="")=>Y(b,0),message:(b="")=>{m=B(b??m)},cancel:(b="")=>Y(b,1),error:(b="")=>Y(b,2),clear:()=>Y("",0,!0),get isCancelled(){return g}}},Xr={light:d("\u2500","-"),heavy:d("\u2501","="),block:d("\u2588","#")};var Jr=[`${p("dim","\u2191/\u2193")} to navigate`,`${p("dim","Enter:")} confirm`];var Zr=`${p("gray",x)} `;var{$:Ke}=globalThis.Bun;var Is={pacman:["arch","endeavouros","manjaro","garuda","cachyos","arcolinux","rebornos","blendos","steamos","chimeraos"],dnf:["fedora","nobara","bazzite","ultramarine"]},zt=(e)=>{for(let[t,n]of Object.entries(Is))if(n.includes(e))return t;return null};var Kt={osName:void 0,osId:void 0,platform:"linux",packageManager:void 0,helperAur:null,isFlatpak:!1,flatpak:!1};function Z(e){return Kt[e]}function G(e,t){Kt[e]=t}async function Xe(e){try{return await Ke`which ${e}`.quiet(),!0}catch{return!1}}async function Ss(){let e=[];if(await Xe("yay"))e.push("yay");if(await Xe("paru"))e.push("paru");return e}async function Cs(){if(process.platform==="linux"){let e=await Ke`cat /etc/os-release | grep ^NAME`.quiet().text()||"",t=await Ke`cat /etc/os-release | grep ^ID`.quiet().text()||"",n=e.trim().slice(5).replace(/"/g,"");return{id:t.trim().slice(3).replace(/"/g,""),name:n}}return{id:"unknown",name:"unknown"}}async function ke(){let{name:e="",id:t=""}=await Cs(),n=zt(t),s=n==="pacman"?await Ss():null,r=await Xe("flatpak");if(G("osName",e),G("osId",t),G("flatpak",r),s)G("helperAur",s[0]);if(n)G("packageManager",n);return{osName:e,osId:t,packageManager:n,aurHelper:s,flatpak:r}}async function Xt(){ve("\uD83D\uDD0D Scanning system");let e=be();e.start("Detecting environment...");let t=await ke();return e.stop("Environment detected"),$e([`OS ${t.osName} (${t.osId})`,`Package Manager ${t.packageManager}`,t.aurHelper?`AUR Helper ${t.aurHelper}`:null,`Flatpak ${t.flatpak?"Enabled":"Disabled"}`].filter(Boolean).join(`
|
|
50
|
+
`),"System Environment",{withGuide:!0}),Ht("Scan completed"),t}import Jt from"path";import{homedir as Zt}from"os";function we(e){if(e.startsWith("~"))return Jt.join(Zt(),e.slice(1));return Jt.resolve(e)}function Je(){return Zt()}var As=Pe(W({flatpak:Q(),backup:Q(),aur_helper:te(["yay","paru"])})),Os=W({source:D(),target:D(),sudo:ee(Q())}),Ms=te(["aur","pacman"]),Ds=ne([D(),V(D()),V(V(D()))]),Fs=W({name:D(),post_hooks:ee(Ds)}),Yt=V(ne([D(),Fs])),js=W({manager:Ms,items:Yt}),Ts=W({manager:Re("flatpak"),scope:te(["system","user"]),items:Yt}),xe=Pe(W({imports:V(D()),settings:As,packages:V(ne([Ts,js])),symlinks:V(Os)}));import Ee from"path";var z={defaultMerge:Symbol("deepmerge-ts: default merge"),skip:Symbol("deepmerge-ts: skip")},pi={defaultMerge:z.defaultMerge};function Rs(e,t){return t}function Ps(e,t){return e.filter((n)=>n!==void 0)}var Qt;(function(e){e[e.NOT=0]="NOT",e[e.RECORD=1]="RECORD",e[e.ARRAY=2]="ARRAY",e[e.SET=3]="SET",e[e.MAP=4]="MAP",e[e.OTHER=5]="OTHER"})(Qt||(Qt={}));function en(e){if(typeof e!=="object"||e===null)return 0;if(Array.isArray(e))return 2;if(Ls(e))return 1;if(e instanceof Set)return 3;if(e instanceof Map)return 4;return 5}function Ns(e){let t=new Set;for(let n of e)for(let s of[...Object.keys(n),...Object.getOwnPropertySymbols(n)])t.add(s);return t}function Vs(e,t){return typeof e==="object"&&Object.prototype.propertyIsEnumerable.call(e,t)}function nn(e){let t=0,n=e[0]?.[Symbol.iterator]();return{[Symbol.iterator](){return{next(){do{if(n===void 0)return{done:!0,value:void 0};let s=n.next();if(s.done===!0){t+=1,n=e[t]?.[Symbol.iterator]();continue}return{done:!1,value:s.value}}while(!0)}}}}}var tn=["[object Object]","[object Module]"];function Ls(e){if(!tn.includes(Object.prototype.toString.call(e)))return!1;let{constructor:t}=e;if(t===void 0)return!0;let n=t.prototype;if(n===null||typeof n!=="object"||!tn.includes(Object.prototype.toString.call(n)))return!1;if(!n.hasOwnProperty("isPrototypeOf"))return!1;return!0}function Gs(e,t,n){let s={};for(let r of Ns(e)){let u=[];for(let i of e)if(Vs(i,r))u.push(i[r]);if(u.length===0)continue;let o=t.metaDataUpdater(n,{key:r,parents:e}),a=sn(u,t,o);if(a===z.skip)continue;if(r==="__proto__")Object.defineProperty(s,r,{value:a,configurable:!0,enumerable:!0,writable:!0});else s[r]=a}return s}function qs(e){return e.flat()}function Us(e){return new Set(nn(e))}function Bs(e){return new Map(nn(e))}function Ws(e){return e.at(-1)}var _e={mergeRecords:Gs,mergeArrays:qs,mergeSets:Us,mergeMaps:Bs,mergeOthers:Ws};function ie(...e){return Hs({})(...e)}function Hs(e,t){let n=zs(e,s);function s(...r){return sn(r,n,t)}return s}function zs(e,t){return{defaultMergeFunctions:_e,mergeFunctions:{..._e,...Object.fromEntries(Object.entries(e).filter(([n,s])=>Object.hasOwn(_e,n)).map(([n,s])=>s===!1?[n,_e.mergeOthers]:[n,s]))},metaDataUpdater:e.metaDataUpdater??Rs,deepmerge:t,useImplicitDefaultMerging:e.enableImplicitDefaultMerging??!1,filterValues:e.filterValues===!1?void 0:e.filterValues??Ps,actions:z}}function sn(e,t,n){let s=t.filterValues?.(e,n)??e;if(s.length===0)return;if(s.length===1)return Ze(s,t,n);let r=en(s[0]);if(r!==0&&r!==5)for(let u=1;u<s.length;u++){if(en(s[u])===r)continue;return Ze(s,t,n)}switch(r){case 1:return Ks(s,t,n);case 2:return Xs(s,t,n);case 3:return Js(s,t,n);case 4:return Zs(s,t,n);default:return Ze(s,t,n)}}function Ks(e,t,n){let s=t.mergeFunctions.mergeRecords(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeRecords!==t.defaultMergeFunctions.mergeRecords)return t.defaultMergeFunctions.mergeRecords(e,t,n);return s}function Xs(e,t,n){let s=t.mergeFunctions.mergeArrays(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeArrays!==t.defaultMergeFunctions.mergeArrays)return t.defaultMergeFunctions.mergeArrays(e);return s}function Js(e,t,n){let s=t.mergeFunctions.mergeSets(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeSets!==t.defaultMergeFunctions.mergeSets)return t.defaultMergeFunctions.mergeSets(e);return s}function Zs(e,t,n){let s=t.mergeFunctions.mergeMaps(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeMaps!==t.defaultMergeFunctions.mergeMaps)return t.defaultMergeFunctions.mergeMaps(e);return s}function Ze(e,t,n){let s=t.mergeFunctions.mergeOthers(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeOthers!==t.defaultMergeFunctions.mergeOthers)return t.defaultMergeFunctions.mergeOthers(e);return s}async function Ye(e,t=new Set){let n=Ee.resolve(e);if(t.has(n))throw Error(`Circular dependency detected: ${n}`);t.add(n);let s=await Bun.file(n).text(),r=Bun.TOML.parse(s),u=fe(xe,r),{imports:o=[],symlinks:a=[]}=u;delete u.imports;let i=Ee.dirname(n);u.symlinks=Ys(i,a);let l={};for(let c of o){let f=Ee.resolve(i,c),h=await Ye(f,t);l=ie(l,h)}return ie(u,l)}function Ys(e,t){if(!t||t.length===0)return[];let n=[];for(let s of t){if(!s)continue;let{source:r,target:u}=s,o=Ee.resolve(e,r),a=we(u);n.push({source:o,target:a})}return n}async function Ie(e){let t=we(e);v.step("Validating Configuration");let n=be();n.start("Validating...");let s=await Ye(t),r=fe(xe,s);return n.stop("Successfully validated with no errors!"),r}import nr from"path";var{deepEquals:Qs}=globalThis.Bun;import er from"fs/promises";import Se from"path";import Qe from"fs/promises";var Ce={};function Ae(){return Ce}function rn(e,t){Ce[e]=t}async function un(){let e=Se.resolve(Je(),".cache/hofii"),t=Se.resolve(e,"hofii-lock.json");if(await Qe.exists(t)){let n=await Bun.file(t).json();Object.assign(Ce,n.config)}}async function on(){let e=Se.resolve(Je(),".cache/hofii");if(!await Qe.exists(e))await Qe.mkdir(e,{recursive:!0});let t={config:Ce};await Bun.write(Se.resolve(e,"hofii-lock.json"),JSON.stringify(t,null,2))}import Me from"fs/promises";async function Oe({cmd:e,errMsg:t,opt:n={stdin:"inherit",stdout:"inherit",stderr:"inherit"}}){let s=Bun.spawn(e,{stdin:n.stdin,stdout:n.stdout,stderr:n.stderr}),r=n.stdout==="pipe"?new Response(s.stdout).text():void 0,u=n.stderr==="pipe"?new Response(s.stderr).text():void 0,o=s.exited,[a,i,l]=await Promise.all([r,u,o]);if(l!==0)throw Error(t??`Error caused with exit code ${l}`);return{stdout:a,stderr:i,exitCode:l}}async function et(e,t,n=!1){if(n){if(Z("platform")!=="linux"){v.warn("Sudo only support in Linux");return}await Oe({cmd:["sudo","ln","-s",e,t],errMsg:`Failed create symlink ${e+" -> "+t}`})}else await Me.symlink(e,t)}async function tt(e,t=!1){if(t){if(Z("platform")!=="linux"){v.warn("Sudo only support in Linux");return}await Oe({cmd:["sudo","rm",e],errMsg:`Failed remove symlink ${e}`})}else await Me.unlink(e)}async function nt(e){try{return await Me.lstat(e)}catch(t){return null}}async function an({oldPath:e,newPath:t,sudo:n=!1}){if(n){if(Z("platform")!=="linux"){v.warn("Sudo only support in Linux");return}await Oe({cmd:["sudo","mv",e,t],errMsg:`Failed rename file ${e+" -> "+t}`})}else await Me.rename(e,t)}async function fn(e){if(!e)return;let t=Z("settings")?.backup??!0,{added:n=[],removed:s=[]}=e,r=[],u=[];try{let o=cn(await Promise.allSettled(s.map(async(i)=>{let l=await nt(i.target);if(!l){v.warn(`Target doesn't exist: ${i.target}, did you remove it manually?`),u.push(i);return}if(!l.isSymbolicLink()){v.warn(`${i.target} not a symlink, did you remove it manually?`),u.push(i);return}await tt(i.target,i.sudo),u.push(i),v.success(`Succesfully remove symlink ${i.target}`)}))),a=cn(await Promise.allSettled(n.map(async(i)=>{let l=await nt(i.target);if(l){if(l.isSymbolicLink()){let c=await er.readlink(i.target);if(c===i.source){await tt(i.target,i.sudo),await et(i.source,i.target,i.sudo),r.push(i),v.warn(`Recreate ${c} -> ${i.target}`);return}}if(t)await an({oldPath:i.target,newPath:i.target+".bak",sudo:i.sudo});else{v.error(`Target already exists, skip create: ${i.target}`);return}}await et(i.source,i.target,i.sudo),r.push(i),v.success(`Succesfully create symlink ${i.source} -> ${i.target}`)})));for(let i of a)console.error(`Failed to add symlink: ${ln(i)}`);for(let i of o)console.error(`Failed to remove symlink: ${ln(i)}`);if(a.length>0||o.length>0)v.error(" [FATAL] Error caused while applying symlinks"),process.exitCode=1}catch(o){console.error(o),v.error(" [FATAL] Failed to apply symlinks"),process.exitCode=1}finally{let i=((Ae()??{}).symlinks??[]).filter((l)=>!u.some((c)=>Qs(c,l))).concat(r);v.info(`Updated symlinks state: ${i.length}`),rn("symlinks",i)}}function ln(e){if(e instanceof Error)return`[${"code"in e?String(e.code):"ERROR"}] ${e.message}`;return`[ERROR] ${String(e)}`}function cn(e){return e.filter((t)=>t.status==="rejected")}var{deepEquals:pn}=globalThis.Bun;function tr(e,t){let n=t?.filter((r)=>!e?.some((u)=>pn(r,u,!0)))??[],s=e?.filter((r)=>!t?.some((u)=>pn(r,u,!0)))??[];return{added:n,removed:s}}function hn(e){let t=Ae();return{symlinks:tr(t.symlinks,e.symlinks)}}function mn(e){let{symlinks:t}=e;return[(()=>{let s=["SYMLINKS"],{added:r=[],removed:u=[]}=t;if(r?.length===0&&u?.length===0)return s.push(" - No changes to apply with symlinks"),s.join(`
|
|
51
51
|
`);for(let o of r)s.push(` - [ADDED] ${o.sudo?"(sudo) ":""}${o.source} -> ${o.target}`);for(let o of u)s.push(` - [REMOVED] ${o.sudo?"(sudo) ":""}${o.source} -> ${o.target}`);return s.join(`
|
|
52
|
-
`)})()].join("/n")}
|
|
52
|
+
`)})()].join("/n")}async function yn(e){let t=nr.join(e,"config.toml");G("configDir",e),await un(),ve("Switching configuration"),v.info("Scanning system environment..."),await ke();let n=await Ie(t);G("settings",ie(n.settings,{backup:!0}));let s=hn(n),r=mn(s);$e(r,"Config To Apply");let u=await Wt({message:"Apply config changes? (Please review the changes first!!)"});if(!u||ye(u))v.warn("Config changes not applied."),process.exit(0);await fn(s.symlinks)}var X=ft("hofii");X.version("0.0.3");X.command("scan","Detect system environment").alias("s").action(async()=>{await Xt(),process.exit(0)});X.command("validate [dir]","Validate configuration files").alias("v").action(async(e)=>{await Ie(e),process.exit(0)});X.command("switch [dir]","Switch to new configuration").alias("sw").action(async(e)=>{let t=sr.resolve(e);await yn(t)});try{if(process.argv.slice(2).length===0)X.outputHelp(),process.exit(0);X.help().parse(process.argv,{run:!1}),await X.runMatchedCommand()}catch(e){if(e instanceof Te){let t=e.issues.map((n)=>{let s=n.path.at(-1)?.input;return[`\u2717 ${n.message}`,` at: ${JSON.stringify(s)}`].join(`
|
|
53
53
|
`)}).join(`
|
|
54
54
|
|
|
55
|
-
`);console.error(t)}console.error(e)}finally{await
|
|
55
|
+
`);console.error(t)}console.error(e)}finally{await on()}
|
package/package.json
CHANGED