@uisimple/create-simple-cli
Version:
Simple CLI
60 lines (56 loc) • 46.7 kB
JavaScript
import E from"node:path";import x from"node:fs";import{fileURLToPath as re}from"node:url";import ne from"readline";import oe from"events";function $t(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function le(s,t){var e=s;t.slice(0,-1).forEach(function(n){e=e[n]||{}});var i=t[t.length-1];return i in e}function yt(s){return typeof s=="number"||/^0x[0-9a-f]+$/i.test(s)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(s)}function xt(s,t){return t==="constructor"&&typeof s[t]=="function"||t==="__proto__"}var he=function(s,t){t||(t={});var e={bools:{},strings:{},unknownFn:null};typeof t.unknown=="function"&&(e.unknownFn=t.unknown),typeof t.boolean=="boolean"&&t.boolean?e.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach(function(u){e.bools[u]=!0});var i={};function n(u){return i[u].some(function(w){return e.bools[w]})}Object.keys(t.alias||{}).forEach(function(u){i[u]=[].concat(t.alias[u]),i[u].forEach(function(w){i[w]=[u].concat(i[u].filter(function(_){return w!==_}))})}),[].concat(t.string).filter(Boolean).forEach(function(u){e.strings[u]=!0,i[u]&&[].concat(i[u]).forEach(function(w){e.strings[w]=!0})});var o=t.default||{},r={_:[]};function l(u,w){return e.allBools&&/^--[^=]+$/.test(w)||e.strings[u]||e.bools[u]||i[u]}function g(u,w,_){for(var p=u,k=0;k<w.length-1;k++){var C=w[k];if(xt(p,C))return;p[C]===void 0&&(p[C]={}),(p[C]===Object.prototype||p[C]===Number.prototype||p[C]===String.prototype)&&(p[C]={}),p[C]===Array.prototype&&(p[C]=[]),p=p[C]}var A=w[w.length-1];xt(p,A)||((p===Object.prototype||p===Number.prototype||p===String.prototype)&&(p={}),p===Array.prototype&&(p=[]),p[A]===void 0||e.bools[A]||typeof p[A]=="boolean"?p[A]=_:Array.isArray(p[A])?p[A].push(_):p[A]=[p[A],_])}function a(u,w,_){if(!(_&&e.unknownFn&&!l(u,_)&&e.unknownFn(_)===!1)){var p=!e.strings[u]&&yt(w)?Number(w):w;g(r,u.split("."),p),(i[u]||[]).forEach(function(k){g(r,k.split("."),p)})}}Object.keys(e.bools).forEach(function(u){a(u,o[u]===void 0?!1:o[u])});var O=[];s.indexOf("--")!==-1&&(O=s.slice(s.indexOf("--")+1),s=s.slice(0,s.indexOf("--")));for(var f=0;f<s.length;f++){var h=s[f],c,v;if(/^--.+=/.test(h)){var M=h.match(/^--([^=]+)=([\s\S]*)$/);c=M[1];var y=M[2];e.bools[c]&&(y=y!=="false"),a(c,y,h)}else if(/^--no-.+/.test(h))c=h.match(/^--no-(.+)/)[1],a(c,!1,h);else if(/^--.+/.test(h))c=h.match(/^--(.+)/)[1],v=s[f+1],v!==void 0&&!/^(-|--)[^-]/.test(v)&&!e.bools[c]&&!e.allBools&&(!i[c]||!n(c))?(a(c,v,h),f+=1):/^(true|false)$/.test(v)?(a(c,v==="true",h),f+=1):a(c,e.strings[c]?"":!0,h);else if(/^-[^-]+/.test(h)){for(var $=h.slice(1,-1).split(""),Y=!1,S=0;S<$.length;S++){if(v=h.slice(S+2),v==="-"){a($[S],v,h);continue}if(/[A-Za-z]/.test($[S])&&v[0]==="="){a($[S],v.slice(1),h),Y=!0;break}if(/[A-Za-z]/.test($[S])&&/-?\d+(\.\d*)?(e-?\d+)?$/.test(v)){a($[S],v,h),Y=!0;break}if($[S+1]&&$[S+1].match(/\W/)){a($[S],h.slice(S+2),h),Y=!0;break}else a($[S],e.strings[$[S]]?"":!0,h)}c=h.slice(-1)[0],!Y&&c!=="-"&&(s[f+1]&&!/^(-|--)[^-]/.test(s[f+1])&&!e.bools[c]&&(!i[c]||!n(c))?(a(c,s[f+1],h),f+=1):s[f+1]&&/^(true|false)$/.test(s[f+1])?(a(c,s[f+1]==="true",h),f+=1):a(c,e.strings[c]?"":!0,h))}else if((!e.unknownFn||e.unknownFn(h)!==!1)&&r._.push(e.strings._||!yt(h)?h:Number(h)),t.stopEarly){r._.push.apply(r._,s.slice(f+1));break}}return Object.keys(o).forEach(function(u){le(r,u.split("."))||(g(r,u.split("."),o[u]),(i[u]||[]).forEach(function(w){g(r,w.split("."),o[u])}))}),t["--"]?r["--"]=O.slice():O.forEach(function(u){r._.push(u)}),r};const ae=$t(he),ue=`Usage: create-simple-cli [OPTION]... [DIRECTORY]
Create a new project
Options:
-t, --template NAME use a likely template
Available template: TODO
`;var St={};const{FORCE_COLOR:ce,NODE_DISABLE_COLORS:de,TERM:fe}=process.env,d={enabled:!de&&fe!=="dumb"&&ce!=="0",reset:m(0,0),bold:m(1,22),dim:m(2,22),italic:m(3,23),underline:m(4,24),inverse:m(7,27),hidden:m(8,28),strikethrough:m(9,29),black:m(30,39),red:m(31,39),green:m(32,39),yellow:m(33,39),blue:m(34,39),magenta:m(35,39),cyan:m(36,39),white:m(37,39),gray:m(90,39),grey:m(90,39),bgBlack:m(40,49),bgRed:m(41,49),bgGreen:m(42,49),bgYellow:m(43,49),bgBlue:m(44,49),bgMagenta:m(45,49),bgCyan:m(46,49),bgWhite:m(47,49)};function Ot(s,t){let e=0,i,n="",o="";for(;e<s.length;e++)i=s[e],n+=i.open,o+=i.close,t.includes(i.close)&&(t=t.replace(i.rgx,i.close+i.open));return n+t+o}function pe(s,t){let e={has:s,keys:t};return e.reset=d.reset.bind(e),e.bold=d.bold.bind(e),e.dim=d.dim.bind(e),e.italic=d.italic.bind(e),e.underline=d.underline.bind(e),e.inverse=d.inverse.bind(e),e.hidden=d.hidden.bind(e),e.strikethrough=d.strikethrough.bind(e),e.black=d.black.bind(e),e.red=d.red.bind(e),e.green=d.green.bind(e),e.yellow=d.yellow.bind(e),e.blue=d.blue.bind(e),e.magenta=d.magenta.bind(e),e.cyan=d.cyan.bind(e),e.white=d.white.bind(e),e.gray=d.gray.bind(e),e.grey=d.grey.bind(e),e.bgBlack=d.bgBlack.bind(e),e.bgRed=d.bgRed.bind(e),e.bgGreen=d.bgGreen.bind(e),e.bgYellow=d.bgYellow.bind(e),e.bgBlue=d.bgBlue.bind(e),e.bgMagenta=d.bgMagenta.bind(e),e.bgCyan=d.bgCyan.bind(e),e.bgWhite=d.bgWhite.bind(e),e}function m(s,t){let e={open:`\x1B[${s}m`,close:`\x1B[${t}m`,rgx:new RegExp(`\\x1b\\[${t}m`,"g")};return function(i){return this!==void 0&&this.has!==void 0?(this.has.includes(s)||(this.has.push(s),this.keys.push(e)),i===void 0?this:d.enabled?Ot(this.keys,i+""):i+""):i===void 0?pe([s],[e]):d.enabled?Ot([e],i+""):i+""}}var D=d,me=(s,t)=>{if(!(s.meta&&s.name!=="escape")){if(s.ctrl){if(s.name==="a")return"first";if(s.name==="c"||s.name==="d")return"abort";if(s.name==="e")return"last";if(s.name==="g")return"reset"}if(t){if(s.name==="j")return"down";if(s.name==="k")return"up"}return s.name==="return"||s.name==="enter"?"submit":s.name==="backspace"?"delete":s.name==="delete"?"deleteForward":s.name==="abort"?"abort":s.name==="escape"?"exit":s.name==="tab"?"next":s.name==="pagedown"?"nextPage":s.name==="pageup"?"prevPage":s.name==="home"?"home":s.name==="end"?"end":s.name==="up"?"up":s.name==="down"?"down":s.name==="right"?"right":s.name==="left"?"left":!1}},rt=s=>{const t=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"].join("|"),e=new RegExp(t,"g");return typeof s=="string"?s.replace(e,""):s};const nt="\x1B",b=`${nt}[`,ge="\x07",ot={to(s,t){return t?`${b}${t+1};${s+1}H`:`${b}${s+1}G`},move(s,t){let e="";return s<0?e+=`${b}${-s}D`:s>0&&(e+=`${b}${s}C`),t<0?e+=`${b}${-t}A`:t>0&&(e+=`${b}${t}B`),e},up:(s=1)=>`${b}${s}A`,down:(s=1)=>`${b}${s}B`,forward:(s=1)=>`${b}${s}C`,backward:(s=1)=>`${b}${s}D`,nextLine:(s=1)=>`${b}E`.repeat(s),prevLine:(s=1)=>`${b}F`.repeat(s),left:`${b}G`,hide:`${b}?25l`,show:`${b}?25h`,save:`${nt}7`,restore:`${nt}8`},be={up:(s=1)=>`${b}S`.repeat(s),down:(s=1)=>`${b}T`.repeat(s)},ve={screen:`${b}2J`,up:(s=1)=>`${b}1J`.repeat(s),down:(s=1)=>`${b}J`.repeat(s),line:`${b}2K`,lineEnd:`${b}K`,lineStart:`${b}1K`,lines(s){let t="";for(let e=0;e<s;e++)t+=this.line+(e<s-1?ot.up():"");return s&&(t+=ot.left),t}};var P={cursor:ot,scroll:be,erase:ve,beep:ge};const we=rt,{erase:Mt,cursor:$e}=P,ye=s=>[...we(s)].length;var xe=function(s,t){if(!t)return Mt.line+$e.to(0);let e=0;const i=s.split(/\r?\n/);for(let n of i)e+=1+Math.floor(Math.max(ye(n)-1,0)/t);return Mt.lines(e)};const G={arrowUp:"\u2191",arrowDown:"\u2193",arrowLeft:"\u2190",arrowRight:"\u2192",radioOn:"\u25C9",radioOff:"\u25EF",tick:"\u2714",cross:"\u2716",ellipsis:"\u2026",pointerSmall:"\u203A",line:"\u2500",pointer:"\u276F"},Se={arrowUp:G.arrowUp,arrowDown:G.arrowDown,arrowLeft:G.arrowLeft,arrowRight:G.arrowRight,radioOn:"(*)",radioOff:"( )",tick:"\u221A",cross:"\xD7",ellipsis:"...",pointerSmall:"\xBB",line:"\u2500",pointer:">"},Oe=process.platform==="win32"?Se:G;var Et=Oe;const U=D,H=Et,lt=Object.freeze({password:{scale:1,render:s=>"*".repeat(s.length)},emoji:{scale:2,render:s=>"\u{1F603}".repeat(s.length)},invisible:{scale:0,render:s=>""},default:{scale:1,render:s=>`${s}`}}),Me=s=>lt[s]||lt.default,K=Object.freeze({aborted:U.red(H.cross),done:U.green(H.tick),exited:U.yellow(H.cross),default:U.cyan("?")}),Ee=(s,t,e)=>t?K.aborted:e?K.exited:s?K.done:K.default,De=s=>U.gray(s?H.ellipsis:H.pointerSmall),Pe=(s,t)=>U.gray(s?t?H.pointerSmall:"+":H.line);var Ce={styles:lt,render:Me,symbols:K,symbol:Ee,delimiter:De,item:Pe};const Te=rt;var Ie=function(s,t){let e=String(Te(s)||"").split(/\r?\n/);return t?e.map(i=>Math.ceil(i.length/t)).reduce((i,n)=>i+n):e.length},_e=(s,t={})=>{const e=Number.isSafeInteger(parseInt(t.margin))?new Array(parseInt(t.margin)).fill(" ").join(""):t.margin||"",i=t.width;return(s||"").split(/\r?\n/g).map(n=>n.split(/\s+/g).reduce((o,r)=>(r.length+e.length>=i||o[o.length-1].length+r.length+1<i?o[o.length-1]+=` ${r}`:o.push(`${e}${r}`),o),[e]).join(`
`)).join(`
`)},Ae=(s,t,e)=>{e=e||t;let i=Math.min(t-e,s-Math.floor(e/2));i<0&&(i=0);let n=Math.min(i+e,t);return{startIndex:i,endIndex:n}},T={action:me,clear:xe,style:Ce,strip:rt,figures:Et,lines:Ie,wrap:_e,entriesToDisplay:Ae};const Dt=ne,{action:Fe}=T,Re=oe,{beep:je,cursor:Le}=P,Be=D;let Ne=class extends Re{constructor(t={}){super(),this.firstRender=!0,this.in=t.stdin||process.stdin,this.out=t.stdout||process.stdout,this.onRender=(t.onRender||(()=>{})).bind(this);const e=Dt.createInterface({input:this.in,escapeCodeTimeout:50});Dt.emitKeypressEvents(this.in,e),this.in.isTTY&&this.in.setRawMode(!0);const i=["SelectPrompt","MultiselectPrompt"].indexOf(this.constructor.name)>-1,n=(o,r)=>{let l=Fe(r,i);l===!1?this._&&this._(o,r):typeof this[l]=="function"?this[l](r):this.bell()};this.close=()=>{this.out.write(Le.show),this.in.removeListener("keypress",n),this.in.isTTY&&this.in.setRawMode(!1),e.close(),this.emit(this.aborted?"abort":this.exited?"exit":"submit",this.value),this.closed=!0},this.in.on("keypress",n)}fire(){this.emit("state",{value:this.value,aborted:!!this.aborted,exited:!!this.exited})}bell(){this.out.write(je)}render(){this.onRender(Be),this.firstRender&&(this.firstRender=!1)}};var L=Ne;const Q=D,Ye=L,{erase:He,cursor:W}=P,{style:ht,clear:at,lines:Ve,figures:Ue}=T;class ze extends Ye{constructor(t={}){super(t),this.transform=ht.render(t.style),this.scale=this.transform.scale,this.msg=t.message,this.initial=t.initial||"",this.validator=t.validate||(()=>!0),this.value="",this.errorMsg=t.error||"Please Enter A Valid Value",this.cursor=+!!this.initial,this.cursorOffset=0,this.clear=at("",this.out.columns),this.render()}set value(t){!t&&this.initial?(this.placeholder=!0,this.rendered=Q.gray(this.transform.render(this.initial))):(this.placeholder=!1,this.rendered=this.transform.render(t)),this._value=t,this.fire()}get value(){return this._value}reset(){this.value="",this.cursor=+!!this.initial,this.cursorOffset=0,this.fire(),this.render()}exit(){this.abort()}abort(){this.value=this.value||this.initial,this.done=this.aborted=!0,this.error=!1,this.red=!1,this.fire(),this.render(),this.out.write(`
`),this.close()}async validate(){let t=await this.validator(this.value);typeof t=="string"&&(this.errorMsg=t,t=!1),this.error=!t}async submit(){if(this.value=this.value||this.initial,this.cursorOffset=0,this.cursor=this.rendered.length,await this.validate(),this.error){this.red=!0,this.fire(),this.render();return}this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
`),this.close()}next(){if(!this.placeholder)return this.bell();this.value=this.initial,this.cursor=this.rendered.length,this.fire(),this.render()}moveCursor(t){this.placeholder||(this.cursor=this.cursor+t,this.cursorOffset+=t)}_(t,e){let i=this.value.slice(0,this.cursor),n=this.value.slice(this.cursor);this.value=`${i}${t}${n}`,this.red=!1,this.cursor=this.placeholder?0:i.length+1,this.render()}delete(){if(this.isCursorAtStart())return this.bell();let t=this.value.slice(0,this.cursor-1),e=this.value.slice(this.cursor);this.value=`${t}${e}`,this.red=!1,this.isCursorAtStart()?this.cursorOffset=0:(this.cursorOffset++,this.moveCursor(-1)),this.render()}deleteForward(){if(this.cursor*this.scale>=this.rendered.length||this.placeholder)return this.bell();let t=this.value.slice(0,this.cursor),e=this.value.slice(this.cursor+1);this.value=`${t}${e}`,this.red=!1,this.isCursorAtEnd()?this.cursorOffset=0:this.cursorOffset++,this.render()}first(){this.cursor=0,this.render()}last(){this.cursor=this.value.length,this.render()}left(){if(this.cursor<=0||this.placeholder)return this.bell();this.moveCursor(-1),this.render()}right(){if(this.cursor*this.scale>=this.rendered.length||this.placeholder)return this.bell();this.moveCursor(1),this.render()}isCursorAtStart(){return this.cursor===0||this.placeholder&&this.cursor===1}isCursorAtEnd(){return this.cursor===this.rendered.length||this.placeholder&&this.cursor===this.rendered.length+1}render(){this.closed||(this.firstRender||(this.outputError&&this.out.write(W.down(Ve(this.outputError,this.out.columns)-1)+at(this.outputError,this.out.columns)),this.out.write(at(this.outputText,this.out.columns))),super.render(),this.outputError="",this.outputText=[ht.symbol(this.done,this.aborted),Q.bold(this.msg),ht.delimiter(this.done),this.red?Q.red(this.rendered):this.rendered].join(" "),this.error&&(this.outputError+=this.errorMsg.split(`
`).reduce((t,e,i)=>t+`
${i?" ":Ue.pointerSmall} ${Q.red().italic(e)}`,"")),this.out.write(He.line+W.to(0)+this.outputText+W.save+this.outputError+W.restore+W.move(this.cursorOffset,0)))}}var Je=ze;const F=D,ke=L,{style:Pt,clear:Ct,figures:tt,wrap:Ge,entriesToDisplay:Ke}=T,{cursor:We}=P;class Ze extends ke{constructor(t={}){super(t),this.msg=t.message,this.hint=t.hint||"- Use arrow-keys. Return to submit.",this.warn=t.warn||"- This option is disabled",this.cursor=t.initial||0,this.choices=t.choices.map((e,i)=>(typeof e=="string"&&(e={title:e,value:i}),{title:e&&(e.title||e.value||e),value:e&&(e.value===void 0?i:e.value),description:e&&e.description,selected:e&&e.selected,disabled:e&&e.disabled})),this.optionsPerPage=t.optionsPerPage||10,this.value=(this.choices[this.cursor]||{}).value,this.clear=Ct("",this.out.columns),this.render()}moveCursor(t){this.cursor=t,this.value=this.choices[t].value,this.fire()}reset(){this.moveCursor(0),this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
`),this.close()}submit(){this.selection.disabled?this.bell():(this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
`),this.close())}first(){this.moveCursor(0),this.render()}last(){this.moveCursor(this.choices.length-1),this.render()}up(){this.cursor===0?this.moveCursor(this.choices.length-1):this.moveCursor(this.cursor-1),this.render()}down(){this.cursor===this.choices.length-1?this.moveCursor(0):this.moveCursor(this.cursor+1),this.render()}next(){this.moveCursor((this.cursor+1)%this.choices.length),this.render()}_(t,e){if(t===" ")return this.submit()}get selection(){return this.choices[this.cursor]}render(){if(this.closed)return;this.firstRender?this.out.write(We.hide):this.out.write(Ct(this.outputText,this.out.columns)),super.render();let{startIndex:t,endIndex:e}=Ke(this.cursor,this.choices.length,this.optionsPerPage);if(this.outputText=[Pt.symbol(this.done,this.aborted),F.bold(this.msg),Pt.delimiter(!1),this.done?this.selection.title:this.selection.disabled?F.yellow(this.warn):F.gray(this.hint)].join(" "),!this.done){this.outputText+=`
`;for(let i=t;i<e;i++){let n,o,r="",l=this.choices[i];i===t&&t>0?o=tt.arrowUp:i===e-1&&e<this.choices.length?o=tt.arrowDown:o=" ",l.disabled?(n=this.cursor===i?F.gray().underline(l.title):F.strikethrough().gray(l.title),o=(this.cursor===i?F.bold().gray(tt.pointer)+" ":" ")+o):(n=this.cursor===i?F.cyan().underline(l.title):l.title,o=(this.cursor===i?F.cyan(tt.pointer)+" ":" ")+o,l.description&&this.cursor===i&&(r=` - ${l.description}`,(o.length+n.length+r.length>=this.out.columns||l.description.split(/\r?\n/).length>1)&&(r=`
`+Ge(l.description,{margin:3,width:this.out.columns})))),this.outputText+=`${o} ${n}${F.gray(r)}
`}}this.out.write(this.outputText)}}var qe=Ze;const et=D,Xe=L,{style:Tt,clear:Qe}=T,{cursor:It,erase:ts}=P;class es extends Xe{constructor(t={}){super(t),this.msg=t.message,this.value=!!t.initial,this.active=t.active||"on",this.inactive=t.inactive||"off",this.initialValue=this.value,this.render()}reset(){this.value=this.initialValue,this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
`),this.close()}submit(){this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
`),this.close()}deactivate(){if(this.value===!1)return this.bell();this.value=!1,this.render()}activate(){if(this.value===!0)return this.bell();this.value=!0,this.render()}delete(){this.deactivate()}left(){this.deactivate()}right(){this.activate()}down(){this.deactivate()}up(){this.activate()}next(){this.value=!this.value,this.fire(),this.render()}_(t,e){if(t===" ")this.value=!this.value;else if(t==="1")this.value=!0;else if(t==="0")this.value=!1;else return this.bell();this.render()}render(){this.closed||(this.firstRender?this.out.write(It.hide):this.out.write(Qe(this.outputText,this.out.columns)),super.render(),this.outputText=[Tt.symbol(this.done,this.aborted),et.bold(this.msg),Tt.delimiter(this.done),this.value?this.inactive:et.cyan().underline(this.inactive),et.gray("/"),this.value?et.cyan().underline(this.active):this.active].join(" "),this.out.write(ts.line+It.to(0)+this.outputText))}}var ss=es;let is=class wt{constructor({token:t,date:e,parts:i,locales:n}){this.token=t,this.date=e||new Date,this.parts=i||[this],this.locales=n||{}}up(){}down(){}next(){const t=this.parts.indexOf(this);return this.parts.find((e,i)=>i>t&&e instanceof wt)}setTo(t){}prev(){let t=[].concat(this.parts).reverse();const e=t.indexOf(this);return t.find((i,n)=>n>e&&i instanceof wt)}toString(){return String(this.date)}};var R=is;const rs=R;let ns=class extends rs{constructor(t={}){super(t)}up(){this.date.setHours((this.date.getHours()+12)%24)}down(){this.up()}toString(){let t=this.date.getHours()>12?"pm":"am";return/\A/.test(this.token)?t.toUpperCase():t}};var os=ns;const ls=R,hs=s=>(s=s%10,s===1?"st":s===2?"nd":s===3?"rd":"th");let as=class extends ls{constructor(t={}){super(t)}up(){this.date.setDate(this.date.getDate()+1)}down(){this.date.setDate(this.date.getDate()-1)}setTo(t){this.date.setDate(parseInt(t.substr(-2)))}toString(){let t=this.date.getDate(),e=this.date.getDay();return this.token==="DD"?String(t).padStart(2,"0"):this.token==="Do"?t+hs(t):this.token==="d"?e+1:this.token==="ddd"?this.locales.weekdaysShort[e]:this.token==="dddd"?this.locales.weekdays[e]:t}};var us=as;const cs=R;let ds=class extends cs{constructor(t={}){super(t)}up(){this.date.setHours(this.date.getHours()+1)}down(){this.date.setHours(this.date.getHours()-1)}setTo(t){this.date.setHours(parseInt(t.substr(-2)))}toString(){let t=this.date.getHours();return/h/.test(this.token)&&(t=t%12||12),this.token.length>1?String(t).padStart(2,"0"):t}};var fs=ds;const ps=R;let ms=class extends ps{constructor(t={}){super(t)}up(){this.date.setMilliseconds(this.date.getMilliseconds()+1)}down(){this.date.setMilliseconds(this.date.getMilliseconds()-1)}setTo(t){this.date.setMilliseconds(parseInt(t.substr(-this.token.length)))}toString(){return String(this.date.getMilliseconds()).padStart(4,"0").substr(0,this.token.length)}};var gs=ms;const bs=R;let vs=class extends bs{constructor(t={}){super(t)}up(){this.date.setMinutes(this.date.getMinutes()+1)}down(){this.date.setMinutes(this.date.getMinutes()-1)}setTo(t){this.date.setMinutes(parseInt(t.substr(-2)))}toString(){let t=this.date.getMinutes();return this.token.length>1?String(t).padStart(2,"0"):t}};var ws=vs;const $s=R;let ys=class extends $s{constructor(t={}){super(t)}up(){this.date.setMonth(this.date.getMonth()+1)}down(){this.date.setMonth(this.date.getMonth()-1)}setTo(t){t=parseInt(t.substr(-2))-1,this.date.setMonth(t<0?0:t)}toString(){let t=this.date.getMonth(),e=this.token.length;return e===2?String(t+1).padStart(2,"0"):e===3?this.locales.monthsShort[t]:e===4?this.locales.months[t]:String(t+1)}};var xs=ys;const Ss=R;let Os=class extends Ss{constructor(t={}){super(t)}up(){this.date.setSeconds(this.date.getSeconds()+1)}down(){this.date.setSeconds(this.date.getSeconds()-1)}setTo(t){this.date.setSeconds(parseInt(t.substr(-2)))}toString(){let t=this.date.getSeconds();return this.token.length>1?String(t).padStart(2,"0"):t}};var Ms=Os;const Es=R;let Ds=class extends Es{constructor(t={}){super(t)}up(){this.date.setFullYear(this.date.getFullYear()+1)}down(){this.date.setFullYear(this.date.getFullYear()-1)}setTo(t){this.date.setFullYear(t.substr(-4))}toString(){let t=String(this.date.getFullYear()).padStart(4,"0");return this.token.length===2?t.substr(-2):t}};var Ps=Ds,Cs={DatePart:R,Meridiem:os,Day:us,Hours:fs,Milliseconds:gs,Minutes:ws,Month:xs,Seconds:Ms,Year:Ps};const ut=D,Ts=L,{style:_t,clear:At,figures:Is}=T,{erase:_s,cursor:Ft}=P,{DatePart:Rt,Meridiem:As,Day:Fs,Hours:Rs,Milliseconds:js,Minutes:Ls,Month:Bs,Seconds:Ns,Year:Ys}=Cs,Hs=/\\(.)|"((?:\\["\\]|[^"])+)"|(D[Do]?|d{3,4}|d)|(M{1,4})|(YY(?:YY)?)|([aA])|([Hh]{1,2})|(m{1,2})|(s{1,2})|(S{1,4})|./g,jt={1:({token:s})=>s.replace(/\\(.)/g,"$1"),2:s=>new Fs(s),3:s=>new Bs(s),4:s=>new Ys(s),5:s=>new As(s),6:s=>new Rs(s),7:s=>new Ls(s),8:s=>new Ns(s),9:s=>new js(s)},Vs={months:"January,February,March,April,May,June,July,August,September,October,November,December".split(","),monthsShort:"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(","),weekdays:"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(","),weekdaysShort:"Sun,Mon,Tue,Wed,Thu,Fri,Sat".split(",")};class Us extends Ts{constructor(t={}){super(t),this.msg=t.message,this.cursor=0,this.typed="",this.locales=Object.assign(Vs,t.locales),this._date=t.initial||new Date,this.errorMsg=t.error||"Please Enter A Valid Value",this.validator=t.validate||(()=>!0),this.mask=t.mask||"YYYY-MM-DD HH:mm:ss",this.clear=At("",this.out.columns),this.render()}get value(){return this.date}get date(){return this._date}set date(t){t&&this._date.setTime(t.getTime())}set mask(t){let e;for(this.parts=[];e=Hs.exec(t);){let n=e.shift(),o=e.findIndex(r=>r!=null);this.parts.push(o in jt?jt[o]({token:e[o]||n,date:this.date,parts:this.parts,locales:this.locales}):e[o]||n)}let i=this.parts.reduce((n,o)=>(typeof o=="string"&&typeof n[n.length-1]=="string"?n[n.length-1]+=o:n.push(o),n),[]);this.parts.splice(0),this.parts.push(...i),this.reset()}moveCursor(t){this.typed="",this.cursor=t,this.fire()}reset(){this.moveCursor(this.parts.findIndex(t=>t instanceof Rt)),this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.error=!1,this.fire(),this.render(),this.out.write(`
`),this.close()}async validate(){let t=await this.validator(this.value);typeof t=="string"&&(this.errorMsg=t,t=!1),this.error=!t}async submit(){if(await this.validate(),this.error){this.color="red",this.fire(),this.render();return}this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
`),this.close()}up(){this.typed="",this.parts[this.cursor].up(),this.render()}down(){this.typed="",this.parts[this.cursor].down(),this.render()}left(){let t=this.parts[this.cursor].prev();if(t==null)return this.bell();this.moveCursor(this.parts.indexOf(t)),this.render()}right(){let t=this.parts[this.cursor].next();if(t==null)return this.bell();this.moveCursor(this.parts.indexOf(t)),this.render()}next(){let t=this.parts[this.cursor].next();this.moveCursor(t?this.parts.indexOf(t):this.parts.findIndex(e=>e instanceof Rt)),this.render()}_(t){/\d/.test(t)&&(this.typed+=t,this.parts[this.cursor].setTo(this.typed),this.render())}render(){this.closed||(this.firstRender?this.out.write(Ft.hide):this.out.write(At(this.outputText,this.out.columns)),super.render(),this.outputText=[_t.symbol(this.done,this.aborted),ut.bold(this.msg),_t.delimiter(!1),this.parts.reduce((t,e,i)=>t.concat(i===this.cursor&&!this.done?ut.cyan().underline(e.toString()):e),[]).join("")].join(" "),this.error&&(this.outputText+=this.errorMsg.split(`
`).reduce((t,e,i)=>t+`
${i?" ":Is.pointerSmall} ${ut.red().italic(e)}`,"")),this.out.write(_s.line+Ft.to(0)+this.outputText))}}var zs=Us;const st=D,Js=L,{cursor:it,erase:ks}=P,{style:ct,figures:Gs,clear:Lt,lines:Ks}=T,Ws=/[0-9]/,dt=s=>s!==void 0,Bt=(s,t)=>{let e=Math.pow(10,t);return Math.round(s*e)/e};class Zs extends Js{constructor(t={}){super(t),this.transform=ct.render(t.style),this.msg=t.message,this.initial=dt(t.initial)?t.initial:"",this.float=!!t.float,this.round=t.round||2,this.inc=t.increment||1,this.min=dt(t.min)?t.min:-1/0,this.max=dt(t.max)?t.max:1/0,this.errorMsg=t.error||"Please Enter A Valid Value",this.validator=t.validate||(()=>!0),this.color="cyan",this.value="",this.typed="",this.lastHit=0,this.render()}set value(t){!t&&t!==0?(this.placeholder=!0,this.rendered=st.gray(this.transform.render(`${this.initial}`)),this._value=""):(this.placeholder=!1,this.rendered=this.transform.render(`${Bt(t,this.round)}`),this._value=Bt(t,this.round)),this.fire()}get value(){return this._value}parse(t){return this.float?parseFloat(t):parseInt(t)}valid(t){return t==="-"||t==="."&&this.float||Ws.test(t)}reset(){this.typed="",this.value="",this.fire(),this.render()}exit(){this.abort()}abort(){let t=this.value;this.value=t!==""?t:this.initial,this.done=this.aborted=!0,this.error=!1,this.fire(),this.render(),this.out.write(`
`),this.close()}async validate(){let t=await this.validator(this.value);typeof t=="string"&&(this.errorMsg=t,t=!1),this.error=!t}async submit(){if(await this.validate(),this.error){this.color="red",this.fire(),this.render();return}let t=this.value;this.value=t!==""?t:this.initial,this.done=!0,this.aborted=!1,this.error=!1,this.fire(),this.render(),this.out.write(`
`),this.close()}up(){if(this.typed="",this.value===""&&(this.value=this.min-this.inc),this.value>=this.max)return this.bell();this.value+=this.inc,this.color="cyan",this.fire(),this.render()}down(){if(this.typed="",this.value===""&&(this.value=this.min+this.inc),this.value<=this.min)return this.bell();this.value-=this.inc,this.color="cyan",this.fire(),this.render()}delete(){let t=this.value.toString();if(t.length===0)return this.bell();this.value=this.parse(t=t.slice(0,-1))||"",this.value!==""&&this.value<this.min&&(this.value=this.min),this.color="cyan",this.fire(),this.render()}next(){this.value=this.initial,this.fire(),this.render()}_(t,e){if(!this.valid(t))return this.bell();const i=Date.now();if(i-this.lastHit>1e3&&(this.typed=""),this.typed+=t,this.lastHit=i,this.color="cyan",t===".")return this.fire();this.value=Math.min(this.parse(this.typed),this.max),this.value>this.max&&(this.value=this.max),this.value<this.min&&(this.value=this.min),this.fire(),this.render()}render(){this.closed||(this.firstRender||(this.outputError&&this.out.write(it.down(Ks(this.outputError,this.out.columns)-1)+Lt(this.outputError,this.out.columns)),this.out.write(Lt(this.outputText,this.out.columns))),super.render(),this.outputError="",this.outputText=[ct.symbol(this.done,this.aborted),st.bold(this.msg),ct.delimiter(this.done),!this.done||!this.done&&!this.placeholder?st[this.color]().underline(this.rendered):this.rendered].join(" "),this.error&&(this.outputError+=this.errorMsg.split(`
`).reduce((t,e,i)=>t+`
${i?" ":Gs.pointerSmall} ${st.red().italic(e)}`,"")),this.out.write(ks.line+it.to(0)+this.outputText+it.save+this.outputError+it.restore))}}var qs=Zs;const I=D,{cursor:Xs}=P,Qs=L,{clear:Nt,figures:B,style:Yt,wrap:ti,entriesToDisplay:ei}=T;let si=class extends Qs{constructor(t={}){super(t),this.msg=t.message,this.cursor=t.cursor||0,this.scrollIndex=t.cursor||0,this.hint=t.hint||"",this.warn=t.warn||"- This option is disabled -",this.minSelected=t.min,this.showMinError=!1,this.maxChoices=t.max,this.instructions=t.instructions,this.optionsPerPage=t.optionsPerPage||10,this.value=t.choices.map((e,i)=>(typeof e=="string"&&(e={title:e,value:i}),{title:e&&(e.title||e.value||e),description:e&&e.description,value:e&&(e.value===void 0?i:e.value),selected:e&&e.selected,disabled:e&&e.disabled})),this.clear=Nt("",this.out.columns),t.overrideRender||this.render()}reset(){this.value.map(t=>!t.selected),this.cursor=0,this.fire(),this.render()}selected(){return this.value.filter(t=>t.selected)}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
`),this.close()}submit(){const t=this.value.filter(e=>e.selected);this.minSelected&&t.length<this.minSelected?(this.showMinError=!0,this.render()):(this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
`),this.close())}first(){this.cursor=0,this.render()}last(){this.cursor=this.value.length-1,this.render()}next(){this.cursor=(this.cursor+1)%this.value.length,this.render()}up(){this.cursor===0?this.cursor=this.value.length-1:this.cursor--,this.render()}down(){this.cursor===this.value.length-1?this.cursor=0:this.cursor++,this.render()}left(){this.value[this.cursor].selected=!1,this.render()}right(){if(this.value.filter(t=>t.selected).length>=this.maxChoices)return this.bell();this.value[this.cursor].selected=!0,this.render()}handleSpaceToggle(){const t=this.value[this.cursor];if(t.selected)t.selected=!1,this.render();else{if(t.disabled||this.value.filter(e=>e.selected).length>=this.maxChoices)return this.bell();t.selected=!0,this.render()}}toggleAll(){if(this.maxChoices!==void 0||this.value[this.cursor].disabled)return this.bell();const t=!this.value[this.cursor].selected;this.value.filter(e=>!e.disabled).forEach(e=>e.selected=t),this.render()}_(t,e){if(t===" ")this.handleSpaceToggle();else if(t==="a")this.toggleAll();else return this.bell()}renderInstructions(){return this.instructions===void 0||this.instructions?typeof this.instructions=="string"?this.instructions:`
Instructions:
${B.arrowUp}/${B.arrowDown}: Highlight option
${B.arrowLeft}/${B.arrowRight}/[space]: Toggle selection
`+(this.maxChoices===void 0?` a: Toggle all
`:"")+" enter/return: Complete answer":""}renderOption(t,e,i,n){const o=(e.selected?I.green(B.radioOn):B.radioOff)+" "+n+" ";let r,l;return e.disabled?r=t===i?I.gray().underline(e.title):I.strikethrough().gray(e.title):(r=t===i?I.cyan().underline(e.title):e.title,t===i&&e.description&&(l=` - ${e.description}`,(o.length+r.length+l.length>=this.out.columns||e.description.split(/\r?\n/).length>1)&&(l=`
`+ti(e.description,{margin:o.length,width:this.out.columns})))),o+r+I.gray(l||"")}paginateOptions(t){if(t.length===0)return I.red("No matches for this query.");let{startIndex:e,endIndex:i}=ei(this.cursor,t.length,this.optionsPerPage),n,o=[];for(let r=e;r<i;r++)r===e&&e>0?n=B.arrowUp:r===i-1&&i<t.length?n=B.arrowDown:n=" ",o.push(this.renderOption(this.cursor,t[r],r,n));return`
`+o.join(`
`)}renderOptions(t){return this.done?"":this.paginateOptions(t)}renderDoneOrInstructions(){if(this.done)return this.value.filter(e=>e.selected).map(e=>e.title).join(", ");const t=[I.gray(this.hint),this.renderInstructions()];return this.value[this.cursor].disabled&&t.push(I.yellow(this.warn)),t.join(" ")}render(){if(this.closed)return;this.firstRender&&this.out.write(Xs.hide),super.render();let t=[Yt.symbol(this.done,this.aborted),I.bold(this.msg),Yt.delimiter(!1),this.renderDoneOrInstructions()].join(" ");this.showMinError&&(t+=I.red(`You must select a minimum of ${this.minSelected} choices.`),this.showMinError=!1),t+=this.renderOptions(this.value),this.out.write(this.clear+t),this.clear=Nt(t,this.out.columns)}};var Ht=si;const Z=D,ii=L,{erase:ri,cursor:Vt}=P,{style:ft,clear:Ut,figures:pt,wrap:ni,entriesToDisplay:oi}=T,zt=(s,t)=>s[t]&&(s[t].value||s[t].title||s[t]),li=(s,t)=>s[t]&&(s[t].title||s[t].value||s[t]),hi=(s,t)=>{const e=s.findIndex(i=>i.value===t||i.title===t);return e>-1?e:void 0};class ai extends ii{constructor(t={}){super(t),this.msg=t.message,this.suggest=t.suggest,this.choices=t.choices,this.initial=typeof t.initial=="number"?t.initial:hi(t.choices,t.initial),this.select=this.initial||t.cursor||0,this.i18n={noMatches:t.noMatches||"no matches found"},this.fallback=t.fallback||this.initial,this.clearFirst=t.clearFirst||!1,this.suggestions=[],this.input="",this.limit=t.limit||10,this.cursor=0,this.transform=ft.render(t.style),this.scale=this.transform.scale,this.render=this.render.bind(this),this.complete=this.complete.bind(this),this.clear=Ut("",this.out.columns),this.complete(this.render),this.render()}set fallback(t){this._fb=Number.isSafeInteger(parseInt(t))?parseInt(t):t}get fallback(){let t;return typeof this._fb=="number"?t=this.choices[this._fb]:typeof this._fb=="string"&&(t={title:this._fb}),t||this._fb||{title:this.i18n.noMatches}}moveSelect(t){this.select=t,this.suggestions.length>0?this.value=zt(this.suggestions,t):this.value=this.fallback.value,this.fire()}async complete(t){const e=this.completing=this.suggest(this.input,this.choices),i=await e;if(this.completing!==e)return;this.suggestions=i.map((o,r,l)=>({title:li(l,r),value:zt(l,r),description:o.description})),this.completing=!1;const n=Math.max(i.length-1,0);this.moveSelect(Math.min(n,this.select)),t&&t()}reset(){this.input="",this.complete(()=>{this.moveSelect(this.initial!==void 0?this.initial:0),this.render()}),this.render()}exit(){this.clearFirst&&this.input.length>0?this.reset():(this.done=this.exited=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
`),this.close())}abort(){this.done=this.aborted=!0,this.exited=!1,this.fire(),this.render(),this.out.write(`
`),this.close()}submit(){this.done=!0,this.aborted=this.exited=!1,this.fire(),this.render(),this.out.write(`
`),this.close()}_(t,e){let i=this.input.slice(0,this.cursor),n=this.input.slice(this.cursor);this.input=`${i}${t}${n}`,this.cursor=i.length+1,this.complete(this.render),this.render()}delete(){if(this.cursor===0)return this.bell();let t=this.input.slice(0,this.cursor-1),e=this.input.slice(this.cursor);this.input=`${t}${e}`,this.complete(this.render),this.cursor=this.cursor-1,this.render()}deleteForward(){if(this.cursor*this.scale>=this.rendered.length)return this.bell();let t=this.input.slice(0,this.cursor),e=this.input.slice(this.cursor+1);this.input=`${t}${e}`,this.complete(this.render),this.render()}first(){this.moveSelect(0),this.render()}last(){this.moveSelect(this.suggestions.length-1),this.render()}up(){this.select===0?this.moveSelect(this.suggestions.length-1):this.moveSelect(this.select-1),this.render()}down(){this.select===this.suggestions.length-1?this.moveSelect(0):this.moveSelect(this.select+1),this.render()}next(){this.select===this.suggestions.length-1?this.moveSelect(0):this.moveSelect(this.select+1),this.render()}nextPage(){this.moveSelect(Math.min(this.select+this.limit,this.suggestions.length-1)),this.render()}prevPage(){this.moveSelect(Math.max(this.select-this.limit,0)),this.render()}left(){if(this.cursor<=0)return this.bell();this.cursor=this.cursor-1,this.render()}right(){if(this.cursor*this.scale>=this.rendered.length)return this.bell();this.cursor=this.cursor+1,this.render()}renderOption(t,e,i,n){let o,r=i?pt.arrowUp:n?pt.arrowDown:" ",l=e?Z.cyan().underline(t.title):t.title;return r=(e?Z.cyan(pt.pointer)+" ":" ")+r,t.description&&(o=` - ${t.description}`,(r.length+l.length+o.length>=this.out.columns||t.description.split(/\r?\n/).length>1)&&(o=`
`+ni(t.description,{margin:3,width:this.out.columns}))),r+" "+l+Z.gray(o||"")}render(){if(this.closed)return;this.firstRender?this.out.write(Vt.hide):this.out.write(Ut(this.outputText,this.out.columns)),super.render();let{startIndex:t,endIndex:e}=oi(this.select,this.choices.length,this.limit);if(this.outputText=[ft.symbol(this.done,this.aborted,this.exited),Z.bold(this.msg),ft.delimiter(this.completing),this.done&&this.suggestions[this.select]?this.suggestions[this.select].title:this.rendered=this.transform.render(this.input)].join(" "),!this.done){const i=this.suggestions.slice(t,e).map((n,o)=>this.renderOption(n,this.select===o+t,o===0&&t>0,o+t===e-1&&e<this.choices.length)).join(`
`);this.outputText+=`
`+(i||Z.gray(this.fallback.title))}this.out.write(ri.line+Vt.to(0)+this.outputText)}}var ui=ai;const j=D,{cursor:ci}=P,di=Ht,{clear:Jt,style:kt,figures:z}=T;class fi extends di{constructor(t={}){t.overrideRender=!0,super(t),this.inputValue="",this.clear=Jt("",this.out.columns),this.filteredOptions=this.value,this.render()}last(){this.cursor=this.filteredOptions.length-1,this.render()}next(){this.cursor=(this.cursor+1)%this.filteredOptions.length,this.render()}up(){this.cursor===0?this.cursor=this.filteredOptions.length-1:this.cursor--,this.render()}down(){this.cursor===this.filteredOptions.length-1?this.cursor=0:this.cursor++,this.render()}left(){this.filteredOptions[this.cursor].selected=!1,this.render()}right(){if(this.value.filter(t=>t.selected).length>=this.maxChoices)return this.bell();this.filteredOptions[this.cursor].selected=!0,this.render()}delete(){this.inputValue.length&&(this.inputValue=this.inputValue.substr(0,this.inputValue.length-1),this.updateFilteredOptions())}updateFilteredOptions(){const t=this.filteredOptions[this.cursor];this.filteredOptions=this.value.filter(i=>this.inputValue?!!(typeof i.title=="string"&&i.title.toLowerCase().includes(this.inputValue.toLowerCase())||typeof i.value=="string"&&i.value.toLowerCase().includes(this.inputValue.toLowerCase())):!0);const e=this.filteredOptions.findIndex(i=>i===t);this.cursor=e<0?0:e,this.render()}handleSpaceToggle(){const t=this.filteredOptions[this.cursor];if(t.selected)t.selected=!1,this.render();else{if(t.disabled||this.value.filter(e=>e.selected).length>=this.maxChoices)return this.bell();t.selected=!0,this.render()}}handleInputChange(t){this.inputValue=this.inputValue+t,this.updateFilteredOptions()}_(t,e){t===" "?this.handleSpaceToggle():this.handleInputChange(t)}renderInstructions(){return this.instructions===void 0||this.instructions?typeof this.instructions=="string"?this.instructions:`
Instructions:
${z.arrowUp}/${z.arrowDown}: Highlight option
${z.arrowLeft}/${z.arrowRight}/[space]: Toggle selection
[a,b,c]/delete: Filter choices
enter/return: Complete answer
`:""}renderCurrentInput(){return`
Filtered results for: ${this.inputValue?this.inputValue:j.gray("Enter something to filter")}
`}renderOption(t,e,i){let n;return e.disabled?n=t===i?j.gray().underline(e.title):j.strikethrough().gray(e.title):n=t===i?j.cyan().underline(e.title):e.title,(e.selected?j.green(z.radioOn):z.radioOff)+" "+n}renderDoneOrInstructions(){if(this.done)return this.value.filter(e=>e.selected).map(e=>e.title).join(", ");const t=[j.gray(this.hint),this.renderInstructions(),this.renderCurrentInput()];return this.filteredOptions.length&&this.filteredOptions[this.cursor].disabled&&t.push(j.yellow(this.warn)),t.join(" ")}render(){if(this.closed)return;this.firstRender&&this.out.write(ci.hide),super.render();let t=[kt.symbol(this.done,this.aborted),j.bold(this.msg),kt.delimiter(!1),this.renderDoneOrInstructions()].join(" ");this.showMinError&&(t+=j.red(`You must select a minimum of ${this.minSelected} choices.`),this.showMinError=!1),t+=this.renderOptions(this.filteredOptions),this.out.write(this.clear+t),this.clear=Jt(t,this.out.columns)}}var pi=fi;const Gt=D,mi=L,{style:Kt,clear:gi}=T,{erase:bi,cursor:Wt}=P;class vi extends mi{constructor(t={}){super(t),this.msg=t.message,this.value=t.initial,this.initialValue=!!t.initial,this.yesMsg=t.yes||"yes",this.yesOption=t.yesOption||"(Y/n)",this.noMsg=t.no||"no",this.noOption=t.noOption||"(y/N)",this.render()}reset(){this.value=this.initialValue,this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
`),this.close()}submit(){this.value=this.value||!1,this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
`),this.close()}_(t,e){return t.toLowerCase()==="y"?(this.value=!0,this.submit()):t.toLowerCase()==="n"?(this.value=!1,this.submit()):this.bell()}render(){this.closed||(this.firstRender?this.out.write(Wt.hide):this.out.write(gi(this.outputText,this.out.columns)),super.render(),this.outputText=[Kt.symbol(this.done,this.aborted),Gt.bold(this.msg),Kt.delimiter(this.done),this.done?this.value?this.yesMsg:this.noMsg:Gt.gray(this.initialValue?this.yesOption:this.noOption)].join(" "),this.out.write(bi.line+Wt.to(0)+this.outputText))}}var wi=vi,$i={TextPrompt:Je,SelectPrompt:qe,TogglePrompt:ss,DatePrompt:zs,NumberPrompt:qs,MultiselectPrompt:Ht,AutocompletePrompt:ui,AutocompleteMultiselectPrompt:pi,ConfirmPrompt:wi};(function(s){const t=s,e=$i,i=r=>r;function n(r,l,g={}){return new Promise((a,O)=>{const f=new e[r](l),h=g.onAbort||i,c=g.onSubmit||i,v=g.onExit||i;f.on("state",l.onState||i),f.on("submit",M=>a(c(M))),f.on("exit",M=>a(v(M))),f.on("abort",M=>O(h(M)))})}t.text=r=>n("TextPrompt",r),t.password=r=>(r.style="password",t.text(r)),t.invisible=r=>(r.style="invisible",t.text(r)),t.number=r=>n("NumberPrompt",r),t.date=r=>n("DatePrompt",r),t.confirm=r=>n("ConfirmPrompt",r),t.list=r=>{const l=r.separator||",";return n("TextPrompt",r,{onSubmit:g=>g.split(l).map(a=>a.trim())})},t.toggle=r=>n("TogglePrompt",r),t.select=r=>n("SelectPrompt",r),t.multiselect=r=>{r.choices=[].concat(r.choices||[]);const l=g=>g.filter(a=>a.selected).map(a=>a.value);return n("MultiselectPrompt",r,{onAbort:l,onSubmit:l})},t.autocompleteMultiselect=r=>{r.choices=[].concat(r.choices||[]);const l=g=>g.filter(a=>a.selected).map(a=>a.value);return n("AutocompleteMultiselectPrompt",r,{onAbort:l,onSubmit:l})};const o=(r,l)=>Promise.resolve(l.filter(g=>g.title.slice(0,r.length).toLowerCase()===r.toLowerCase()));t.autocomplete=r=>(r.suggest=r.suggest||o,r.choices=[].concat(r.choices||[]),n("AutocompletePrompt",r))})(St);const mt=St,yi=["suggest","format","onState","validate","onRender","type"],Zt=()=>{};async function N(s=[],{onSubmit:t=Zt,onCancel:e=Zt}={}){const i={},n=N._override||{};s=[].concat(s);let o,r,l,g,a,O;const f=async(h,c,v=!1)=>{if(!(!v&&h.validate&&h.validate(c)!==!0))return h.format?await h.format(c,i):c};for(r of s)if({name:g,type:a}=r,typeof a=="function"&&(a=await a(o,{...i},r),r.type=a),!!a){for(let h in r){if(yi.includes(h))continue;let c=r[h];r[h]=typeof c=="function"?await c(o,{...i},O):c}if(O=r,typeof r.message!="string")throw new Error("prompt message is required");if({name:g,type:a}=r,mt[a]===void 0)throw new Error(`prompt type (${a}) is not defined`);if(n[r.name]!==void 0&&(o=await f(r,n[r.name]),o!==void 0)){i[g]=o;continue}try{o=N._injected?xi(N._injected,r.initial):await mt[a](r),i[g]=o=await f(r,o,!0),l=await t(r,o,i)}catch{l=!await e(r,i)}if(l)return i}return i}function xi(s,t){const e=s.shift();if(e instanceof Error)throw e;return e===void 0?t:e}function Si(s){N._injected=(N._injected||[]).concat(s)}function Oi(s){N._override=Object.assign({},s)}var Mi=Object.assign(N,{prompt:N,prompts:mt,inject:Si,override:Oi});const qt=$t(Mi);let V=!0;const J=typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{};let q=0;if(J.process&&J.process.env&&J.process.stdout){const{FORCE_COLOR:s,NODE_DISABLE_COLORS:t,NO_COLOR:e,TERM:i,COLORTERM:n}=J.process.env;t||e||s==="0"?V=!1:s==="1"||s==="2"||s==="3"?V=!0:i==="dumb"?V=!1:"CI"in J.process.env&&["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE","DRONE"].some(o=>o in J.process.env)?V=!0:V=process.stdout.isTTY,V&&(process.platform==="win32"||n&&(n==="truecolor"||n==="24bit")?q=3:i&&(i.endsWith("-256color")||i.endsWith("256"))?q=2:q=1)}let Xt={enabled:V,supportLevel:q};function Qt(s,t,e=1){const i=`\x1B[${s}m`,n=`\x1B[${t}m`,o=new RegExp(`\\x1b\\[${t}m`,"g");return r=>Xt.enabled&&Xt.supportLevel>=e?i+(""+r).replace(o,i)+n:""+r}const te=Qt(0,0),gt=Qt(31,39),X=ae(process.argv.splice(2),{default:{help:!1},alias:{h:"help",t:"template"}}),bt=process.cwd(),Ei={_gitignore:".gitignore"},vt="simple-demo";async function Di(){const s=ee(X._[0]),t=X.template||X.t;if(X.help){console.log(ue);return}let e=s||vt;const i=()=>e==="."?E.basename(E.resolve()):e;let n;qt.override({overwrite:X.overwrite});try{n=await qt([{type:s?null:"text",name:"projectName",message:te("Project name:"),initial:vt,onState:y=>{e=ee(y.value)||vt}},{type:()=>!x.existsSync(e)||Pi(e)?null:"select",name:"overwrite",message:()=>(e==="."?"\u5F53\u524D\u6587\u4EF6\u5939":`\u76EE\u6807\u6587\u4EF6\u5939 "${e}"`)+"is not empty, Please choose how to proceed:",initial:0,choices:[{title:"\u79FB\u9664\u73B0\u5B58\u7684\u6587\u4EF6\u5939\u5E76\u4E14\u7EE7\u7EED ",value:"yes"},{title:"\u53D6\u6D88\u64CD\u4F5C",value:"no"},{title:"\u5FFD\u7565\u5E76\u4E14\u7EE7\u7EED",value:"ignore"}]},{type:(y,{overwrite:$})=>{if($==="no")throw new Error(gt("\u2716")+" \u64CD\u4F5C\u53D6\u6D88");return null},name:"overwriteChecker"},{type:()=>se(i())?null:"text",name:"packageName",message:te("Package name:"),initial:()=>Ci(i()),validate:y=>se(y)||"package.json name \u65E0\u6548"}],{onCancel:()=>{throw new Error(gt("\u2716")+"\u64CD\u4F5C\u53D6\u6D88")}})}catch(y){console.log(y.message);return}const{packageName:o,overwrite:r}=n,l=E.join(bt,e);let g=t||"default";const a=Ii(process.env.npm_conconfig_user_agent),O=a?a.name:"npm";console.log(`\u5F53\u524D\u5DE5\u7A0B\u5728 ${l}`);const f=E.resolve(re(import.meta.url),"../..",`template-${g}`),h=(y,$)=>{const Y=E.join(l,Ei[y]??y);$?x.writeFileSync(Y,$):ie(E.join(f,y),Y)};if(!x.existsSync(f)){console.error(gt("\u{1F232}")+"\u6A21\u7248\u4E0D\u5B58\u5728 sorry");return}r==="yes"?Ti(l):x.existsSync(l)||x.mkdirSync(l,{recursive:!0});const c=x.readdirSync(f);for(const y of c.filter($=>$!=="package.json"))h(y);const v=JSON.parse(x.readFileSync(E.join(f,"package.json"),"utf-8"));v.name=o||i(),h("package.json",JSON.stringify(v,null,2)+`
`);const M=E.relative(bt,l);switch(console.log(`
\u6784\u5EFA\u5B8C\u6210\u2705 \u8BF7\u8FD0\u884C:
`),l!==bt&&console.log(` cd ${M.includes(" ")?`"${M}"`:M}`),O){case"yarn":console.log(" yarn"),console.log(" yarn dev");default:console.log(` ${O} install`),console.log(` ${O} run dev`)}console.log()}function ee(s){return s?.trim().replace(/\/+$/g,"")}function Pi(s){const t=x.readdirSync(s);return t.length===0||t.length===1&&t[0]===".git"}function se(s){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(s)}function Ci(s){return s.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function Ti(s){if(x.existsSync(s))for(const t of x.readdirSync(s))t!==".git"&&x.rmSync(E.resolve(s,t),{recursive:!0,force:!0})}function Ii(s){if(!s)return;const t=s.split(" ")[0].split("/");return{name:t[0],version:t[1]}}function ie(s,t){x.statSync(s).isDirectory()?_i(s,t):x.copyFileSync(s,t)}function _i(s,t){x.mkdirSync(t,{recursive:!0});for(const e of x.readdirSync(s)){const i=E.resolve(s,e),n=E.resolve(t,e);ie(i,n)}}Di().catch(s=>{console.error(s)});