@abw/badger 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("@abw/badger-utils"),t=require("@abw/badger-filesystem"),r=require("node:process"),o=require("prompts"),n=require("commander"),s=require("@abw/badger-timestamp"),i=require("dotenv"),a=require("chokidar"),l=require("node:child_process"),c=require("@abw/badger-codecs");const p={reset:0,bold:1,bright:1,dark:2,black:0,red:1,green:2,yellow:3,blue:4,magenta:5,cyan:6,grey:7,white:8,fg:30,bg:40},h={fg:e=>`38;2;${e.r};${e.g};${e.b}`,bg:e=>`48;2;${e.r};${e.g};${e.b}`},u=(t,r="fg")=>{const o=(e=>{const t=e.match(/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null})(t)||(t=>{const r=e.splitList(t);return 3===r.length?{r:r[0],g:r[1],b:r[2]}:null})(t);return o?((e,t="fg")=>"["+h[t](e)+"m")(o,r):((e,t="fg")=>{let r=[],o=e.split(/ /,2);const n=o.pop(),s=(t?p[t]:0)+p[n];if(r.push(s),o.length){const e=o.length?o.shift():"dark";r.push(p[e])}return"["+r.join(";")+"m"})(t,r)},g=(t={})=>{const r=e.isObject(t)?t:{fg:t};let o=[];return r.bg&&o.push(u(r.bg,"bg")),r.fg&&o.push(u(r.fg,"fg")),o.join("")},d=u("reset",!1),f=()=>d,b=e=>(...t)=>g(e)+t.join("")+d,m=e=>Object.entries(e).reduce((e,[t,r])=>(e[t]=b(r),e),{}),x=b("black"),w=b("red"),y=b("green"),$=b("yellow"),v=b("blue"),C=b("magenta"),k=b("cyan"),j=b("grey"),P=b("white"),V=b("bright black"),E=b("bright red"),q=b("bright green"),N=b("bright yellow"),D=b("bright blue"),S=b("bright magenta"),L=b("bright cyan"),T=b("bright grey"),A=b("bright white"),F=b("dark black"),O=b("dark red"),I=b("dark green"),z=b("dark yellow"),W=b("dark blue"),B=b("dark magenta"),G=b("dark cyan"),M=b("dark grey"),R=b("dark white");function U(t,r="",o){return t?r?(e,...t)=>console.log("%s"+r+"%s"+e,o?g(o):"",f(),...t):console.log.bind(console):e.doNothing}function Y(e,t,r="",o){e.debug=U(t,r,o)}const H={b:"\b",f:"\f",n:"\n",r:"\r",t:"\t",v:"\v",'"':'"',"'":"'","\\":"\\"},Q=t=>{let r,o,n=[];for(;t.length;){let s,i;(o=t.match(/^(\/+)/))?t=t.slice(o[1].length):(t.match(/^(\?)/)&&(t=t.slice(1),s=!0),(o=t.match(/^('((\\[\\'bfnrtv]|.)*?)')/))?(t=t.slice(o[1].length),r=o[2].replace(/\\([\\'bfnrtv])/g,(e,t)=>H[t]||`\\${t}`)):(o=t.match(/^("((\\[\\"bfnrtv]|.)*?)")/))?(t=t.slice(o[1].length),r=o[2].replace(/\\([\\"bfnrtv])/g,(e,t)=>H[t]||`\\${t}`)):(o=t.match(/^([^/?]+)/))?(r=o[1],t=t.slice(r.length)):e.fail(`Can't parse data path: ${t}`),t.match(/^(\?)/)&&(t=t.slice(1),i=!0),s?n.push([r,{maybe:!0}]):i?n.push([r,{optional:!0}]):n.push(r))}return n},_=(t,r)=>{let o=t,n=Q(r),s=[];for(let t of n){const[r,n]=e.isArray(t)?t:[t,{}],i=o[r];if(s.push(r),e.noValue(i)){if(n.maybe)return o;if(n.optional)return;e.fail("No value for data at path: ",s.join("/"))}o=i}return o},J={codec:["yaml","json"],jsExt:["js","mjs"]};class K extends t.DirPath{constructor(t,r={}){super(t);const o={...J,...r};this.state.codec=e.splitList(o.codec),this.state.jsExt=e.splitList(o.jsExt),Y(this,r.debug,r.debugPrefix,r.debugColor)}async firstFileWithExt(t,r,o=e.doNothing){const n=await this.dirs();for(let e of n)for(let n of r){const r=t+"."+n,s=e.file(r,o(t,n));if(this.debug("looking for config file: ",s.path()),await s.exists())return this.debug("config file exists: ",s.path()),s}}async jsFile(e){return await this.firstFileWithExt(e,this.state.jsExt)}async file(e){return await this.firstFileWithExt(e,this.state.codec,(e,t)=>({codec:t}))}async config(t,r){const[o,n]=t.split("#",2);let s,i,a;if(s=await this.jsFile(o))a=await import(s.path());else if(i=await this.file(o))a=await i.read();else{if(!r)return e.fail("No configuration file for "+o);a=r}return n?_(a,n):a}}const X={jsExt:"js mjs"};class Z extends t.DirPath{constructor(t,r={}){super(t);const o={...X,...r},n=e.splitList(o.jsExt).map(e=>e.replace(/^\./,""));this.state.exts=n,Y(this,r.debug,r.debugPrefix,r.debugColor),this.debug("state: ",this.state)}async library(t){const[r,o]=t.split("#",2),n=await this.dirs(),s=this.state.exts;for(let e of n)for(let t of s){const n=e.file(r+"."+t);this.debug("looking for module %s as",r,n.path());if(await n.exists()){const e=await import(n.path());return this.debug("loaded %s as",n.path()),o?_(e,o):e}}e.fail("Library not found: ",t)}}const ee=e=>async function(...t){try{const r=await e(...t);return r&&console.log(q(`✓ ${r}`)),!0}catch(e){return console.log(r.env.DEBUG?e:E(`✗ ${e.message||e}`)),!1}},te=async(t,r={})=>{const n=(r=e.isString(r)?{default:r}:r).name||"answer";return(await o([{name:n,type:r.type||"text",message:t,initial:r.default}]))[n]},re=()=>r.argv.slice(2);function oe(t,r){t?e.isArray(t)&&(r=t,t={}):t={},r||(r||=re());const o=!!t.options&&e.splitHash(t.options),n=t.others||"error",s=t.short||{},i=t.on||{};let a=!1,l=0,c={};for(;l<r.length;){const t=r[l].match(/^-(-)?(.*)/);if("--"===r[l]&&(a=!0,r.splice(l,1)),t&&!a){const a=!("-"===t[1])&&e.hasValue(s[t[2]])?s[t[2]]:t[2];if(i[a]){if(i[a](a,r.splice(l,1)[0],r,c))continue;r.splice(l,0,t[0])}if(o&&!o[a])switch(n){case"collect":break;case"remove":r.splice(l,1)[0];case"keep":l++;continue;case"error":return e.fail(`Invalid command line flag: ${t[0]}`);default:return e.fail(`Invalid "others" option: ${n}`)}r.splice(l,1),c[a]=!0}else l++}return{flags:c,args:r}}async function ne(e,t=re()){return t.length?t.shift():e?await te(e):void 0}function se(e,t){t&&console.log(t),r.exit(e)}function ie(e){se(0,e)}function ae(e){se(1,e)}const le={verboseColor:"magenta",titleColor:"bright yellow",underlineColor:"dark yellow",infoColor:"cyan",tickColor:"green",questionColor:"bright white",answerColor:"bright green",sectionNewlines:!0},ce=async t=>{const s=b(ce.verboseColor||le.verboseColor),i=new n.Command;t.name&&i.name(t.name),t.description&&i.description(t.description),t.version&&i.version(t.version),t.yes&&i.option("-y, --yes","Accept default answers"),t.verbose&&i.option("-v, --verbose","Verbose output"),t.quiet&&i.option("-q, --quiet","Quiet output"),t.options?.filter(t=>!(e.hasValue(t.arg)&&!t.arg)&&(t.title?void 0:e.hasValue(t.name))).forEach(t=>{const r=t.name,o=t.about,n=t.default,s=t.handler,a=t.short,l=t.type,c=t.pattern||(e.hasValue(l)?`<${l}>`:void 0);let p=`--${r}`,h=[];e.hasValue(a)&&(p=`-${a}, ${p}`),e.hasValue(c)&&(p=`${p} ${c}`),h.push(p),e.hasValue(o)&&h.push(o),e.hasValue(s)&&h.push(s),e.hasValue(n)&&h.push(n),i.option(...h)});let a={};t.commands?.forEach(t=>{const r=t.name,o=t.about,n=t.type,s=t.pattern||(e.hasValue(n)?`<${n}>`:void 0);let l=[],c=r,p=i.command(c);e.hasValue(s)&&p.argument(s),e.hasValue(o)&&p.description(o),e.hasValue(t.arguments)&&e.splitList(t.arguments).forEach(t=>{l.push(function(t){const r=t.match(/(\w+)/);r||e.fail("Can't parse argument name: ",t);return r[1]}(t)),p.argument(t)}),p.action((...e)=>{a[r]=l.length?l.reduce((t,r)=>(t[r]=e.shift(),t),{}):e[0]})}),i.parse();const l=i.opts(),c=t.yes&&l.yes,p=t.verbose&&l.verbose,h=t.quiet&&l.quiet;c&&(p&&!h&&r.stdout.write(s("Accepting default answers (-y option is set)\n")),o.override(l));let u=[];t.options?.forEach(t=>{const r=t.type||"text",o=t.name,n=t.prompt,s=e.hasValue(t.arg)&&!t.arg,i=t.validate||(t.required?t=>!(!e.hasValue(t)||!t.toString().length)||(ce.invalid||`You must enter a value for ${o}`):void 0);let a=s?t.default:l[o];"select"===r&&e.hasValue(a)&&(Number.isInteger(a)||(a=t.choices?.findIndex(e=>e.value===a),a<0&&(a=0))),e.hasValue(n)?u.push({...t,type:e.hasValue(a)?()=>(c&&(h||he({question:n,answer:a})),r):r,name:o,message:n,initial:a,validate:i}):(t.title||t.info)&&u.push({type:()=>(h||pe(t),!1)})});let g=!1;const d=await o(u,{onCancel:()=>(g=!0,!1)});return g?void 0:{...l,...d,...a}};const pe=t=>{const o=t.title,n=b(t.titleColor||le.titleColor),s=b(t.underlineColor||le.underlineColor),i=b(t.infoColor||le.infoColor),a=(e.hasValue(t.newlines)?t.newlines:le.sectionNewlines)?"\n":"";if(o){const e="-".repeat(o.length);r.stdout.write(a+n(o)+"\n"+s(e)+"\n"+a)}t.info&&r.stdout.write(i(t.info)+"\n"+a)},he=e=>{const t=b(e.tickColor||le.tickColor),o=b(e.questionColor||le.questionColor),n=b(e.answerColor||le.answerColor);r.stdout.write(t("✔ ")+o(e.question)+" "+n(e.answer)+"\n")};function ue(t={},r){const o=t[r];if(e.hasValue(o))return o;e.fail("Missing value for required parameter: ",r)}function ge(t={},r){return e.splitList(r).map(e=>ue(t,e))}const de=ge;const fe={border:"┌─┐│└─┘|-",background:"+∙",fill:"*"},be={border:"green",background:"dark grey",foreground:"blue",fill:"bright yellow"},me={charTypes:fe,source:"\n┌────────────────────────────────────────────────────────────────┐\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙ ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ∙∙ │\n│ ∙∙ ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ∙∙ │\n│ ∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙ │\n│ ∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙ │\n│ ∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙ │\n│ ∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙ │\n│ ∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙ │\n│ ∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙ ●● *◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦* ●● ∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙ ●● **◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦** ●● ∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙ ●● *****◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦***** ●● ∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● *******◦◦◦◦◦◦◦◦◦◦******* ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ****************** ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ************ ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ****** ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● **** ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● **** ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● **** ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ◦****◦ ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ◦◦◦◦****◦◦◦◦ ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦****◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦******◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦********◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦************◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦******************◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦************************◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙ │\n│ ∙∙∙∙∙ ●● ◦◦◦◦◦◦◦******************************◦◦◦◦◦◦◦ ●● ∙∙∙∙∙ │\n│ ∙∙∙∙ ●● ◦◦◦◦◦************************************◦◦◦◦◦ ●● ∙∙∙∙ │\n│ ∙∙∙ ●● ◦◦◦◦****************************************◦◦◦◦ ●● ∙∙∙ │\n│ ∙∙ ●● ◦◦◦********************************************◦◦◦ ●● ∙∙ │\n│ ∙∙ ●● ◦◦**********************************************◦◦ ●● ∙∙ │\n│ ∙∙ ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ∙∙ │\n│ ∙∙ ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n└────────────────────────────────────────────────────────────────┘\n"},xe={size:100,elapsed:!1,picture:me,colours:be};function we(e){const{source:t,charTypes:r={background:""}}=e,o=t.trim()+"\n",n=o.length,s=Object.entries(r).reduce((e,[t,r])=>(r.split("").forEach(r=>e[r]=t),e),{});return{picture:o,length:n,lineLength:t.split("\n").reduce((e,t)=>Math.max(e,t.length),0),charType:s}}function ye(e){return Object.entries(e).reduce((e,[t,r])=>(e[t]=b(r),e),{})}function $e(e){const{picture:t,charType:r={},colours:o={}}=e;return t.split("").map(e=>{const t=r[e]||"foreground",n=o[t];return n?n(e):e}).join("")}function ve(e){const t=e%60,r=Math.floor(e/60);return[Math.floor(e/3600),r,t].map(e=>e.toString().padStart(2,"0")).join(":")}class Ce{constructor(t={}){const r={...xe,...e.isInteger(t)?{size:t}:t},{size:o,colours:n,colors:i,debug:a,elapsed:l}=r,{picture:c,length:p,lineLength:h,charType:u}=we(e.isString(r.picture)?{source:r.picture,charTypes:fe}:r.picture);this.size=o,this.picture=c,this.pixels=this.picture.split(""),this.length=p,this.lineLength=h,this.charType=u,this.colours=ye(i||n),this.count=0,this.lastCount=0,this.lastPixel=0,this.startTime=s.now().epochSeconds(),this.elapsed=0,this.elapsedCol=b("dark grey"),this.showElapsed=l,this.debugging=a,Y(this,a,"Progress > ","blue")}progress(e=1){this.count+=e;const t=s.now().epochSeconds()-this.startTime;this.elapsed=t;const r=Math.floor(this.length*this.count/this.size);if(r>this.lastPixel){const e=this.lastPixel;return this.lastPixel=r,this.debug(`count: ${this.count}/${this.size} pixels from ${e} to ${r}`),this.pictureSegment(e,r)}return""}remains(){this.count=this.size;const e=this.lastPixel,t=this.length;return t>e?(this.lastPixel=this.length,this.pictureSegment(e,t)):""}pictureSegment(e,t){if(this.debugging)return"";let r=$e({picture:this.picture.substring(e,t),charType:this.charType,colours:this.colours});if(this.showElapsed&&r.match("\n")){const e=r.split("\n"),t=e.pop();r=e.map(e=>e+" "+this.elapsedCol(ve(this.elapsed))).join("\n").concat("\n",t)}return r}printProgress(e=1){r.stdout.write(this.progress(e))}printRemains(){r.stdout.write(this.remains())}}const ke={description:"Project setup script.",configFiles:["config/setup.yaml","config/setup.json","setup.yaml","setup.json",".setup.yaml",".setup.json"],dataFile:".env.yaml",envFile:".env",envComments:!0,envSections:!0,writeData:!0,writeEnv:!1,compact:!1,cancelled:"Setup cancelled",allDone:"All configuration options have been set",warning:e=>`\n#=============================================================================\n# WARNING: This file is generated automatically when the ${e.scriptName}\n# script is run. Any changes made here may be lost.\n#\n# Generated: ${s.now()}\n#=============================================================================\n\n`},je=ee(async e=>{await Pe(e)});async function Pe(o){const n={...ke,...o},s=n.rootDir?t.dir(n.rootDir):t.cwd(),a=s.file(n.envFile);i.config({path:a.path()});const l=r.env,c=s.file(n.dataFile,{codec:"auto"}),p=await c.exists()?await c.read():{},h=n.configFile?s.file(n.configFile,{codec:"auto"}):await Ve(s,n.configFiles),u=await h.read();u.name||=n.name||r.argv[1].replace(s.path()+"/",""),u.version||=n.version,u.description||=n.description,o.preprocess&&await o.preprocess(u);const g={root:s.path(),...n.values||{}},d={quiet:!0,verbose:!0,yes:!0};for(let t of u.options){const{name:r,save:o}=t;if(e.isBoolean(o)&&!o&&(d[r]=!0),!r)continue;t.pattern&&(t.type||="text");const n=t.envvar||=r.toUpperCase();e.hasValue(l[n])?t.default=l[n]:e.hasValue(p[r])?t.default=p[r]:e.hasValue(g[r])?t.default=g[r]:t.program&&(t.default=await Ee(t.program),t.pattern||="<path>")}const f=await ce(u);f||ie("\n👎 "+E(n.cancelled));const{debug:b,verbose:m,quiet:x}=f;return n.writeData&&(await c.write(e.extract(f,e=>!d[e])),m&&console.log(q(`✓ Wrote data file: ${c}`))),n.writeEnv&&(await a.write(await async function(t,r,o,n){const{compact:s,envComments:i,envSections:a,envPrefix:l=""}=r,c=s?"":"\n";let p=[qe(r.warning(r))];const h="#"+"-".repeat(77),u="#"+"=".repeat(77);for(let t of o.options){const{name:r,envvar:o,title:u,about:g,save:d}=t;if(!e.isBoolean(d)||d)if(u&&a)p.push(`${c}\n${h}\n${qe(u)}\n${h}`);else if(s||p.push(""),g&&i&&p.push(`${qe(g)}`),r){const t=n[r];if(e.hasValue(t)){const e=t.toString().match(/[#\r\n]/)?'"$value"':t;p.push(`${l}${o||r.toUpperCase()}=${e}`)}else p.push(qe(`No value for ${o||r.toUpperCase()}`))}}if(r.envExtra){const o=t.file(r.envExtra);await o.exists()||e.fail(`Cannot find envExtra file: ${r.envExtra}`),a&&p.push("\n",u,qe(` Additional configuration copied from ${r.envExtra}`),u,""),p.push(await o.read())}return p.join("\n")+"\n"}(s,n,u,f)),m&&console.log(q(`✓ Wrote .env file: ${a}`))),b&&console.log("\nGenerated configuration:",f),n.allDone&&!x&&console.log("\n👍 ",q(n.allDone),"\n"),f}async function Ve(t,r=[]){for(let e of r){const r=t.file(e,{codec:"auto"});if(await r.exists())return r}e.fail("Can't find a configFile: ",r.join(", "))}async function Ee(o){for(let n of e.splitList(o))for(let e of r.env.PATH.split(":")){const r=t.dir(e).file(n);if(await r.exists())return r.path()}}function qe(t){return e.splitLines(t.trim()).map(e=>e.match(/^#/)?e:`# ${e}`).join("\n")}const Ne={script:r.argv[1].split("/").at(-1),prefix:"watcher >",colors:{prefix:"dark grey",error:"bright red",watcher:"bright yellow",section:"bright white",program:"bright green",arg:"bright cyan",args:"bright blue",debug:"bright grey",command:"yellow",scanning:"cyan",watching:"cyan",change:"bright cyan",starting:"bright green",stopping:"bright red",stopped:"green",failed:"bright red"}};const De=e=>{const r={...Ne,...e},o=r.colors=m({...Ne.colors,...r.colors}),n=Le(r),s=()=>ie(n()),i=e=>ae(n(e));return{config:r,colors:o,helpText:n,help:s,barf:i,cmdLine:async()=>{const{flags:e,args:r}=oe({options:"watch restart verbose help",others:"keep",short:{w:"watch",r:"restart",v:"verbose",h:"help"},on:{help:s,watch:(e,t,r,o)=>(o.watch||=[],r.length||i("The -w option expects an argument!"),o.watch.push(r.shift()),!0)}}),[o,...n]=r,a=r.join(" ");return r.length<1&&i("No program specified to run!"),e.watch?.length||i("Nothing specified to watch!"),await t.file(o).exists()||i(`Program not found: ${o}`),{...e,progText:a,program:o,programArgs:n}}}},Se=({verbose:t,colors:r,prefix:o,progText:n})=>({scanning:()=>t?console.log(r.prefix(o),r.scanning("scanning...")):e.doNothing,watching:n=>t?n.forEach(e=>console.log(r.prefix(o),r.watching("watching "),r.command(e))):e.doNothing,change:(n,s)=>t?console.log(r.prefix(o),r.change(`${n}`.padEnd(9)),r.command(s)):e.doNothing,starting:()=>t?console.log(r.prefix(o),r.starting("starting "),r.command(n)):e.doNothing,stopping:()=>t?console.log(r.prefix(o),r.stopping("stopping "),r.command(n)):e.doNothing,failed:s=>t?console.log(r.prefix(o),r.failed(`failed ${s}`),r.command(n)):e.doNothing,stopped:()=>t?console.log(r.prefix(o),r.stopped("stopped "),r.command(n)):e.doNothing}),Le=({colors:e,script:t})=>{const{watcher:r,arg:o,section:n,program:s,args:i,error:a}=e,l=r(t);return e=>`${l}\n${e?`\n${a(e)}\n`:""}\n${n("Usage")}\n\n $ ${l} [${o("options")}] ${s("program")} [${i("arg1 arg2 ...")}]\n\n${n("Description")}\n\n This program will run another program and restart it if any files\n are added, deleted or modified in one or more watched locations.\n\n Paths to watch should be specified using the ${o("-w")} (or ${o("--watch")})\n option. You can specify this multiple times for different paths.\n\n The path to the ${s("program")} should follow, along with any additional\n ${i("arguments")} to be passed to it.\n\n If the ${o("-r")} (or ${o("--restart")}) option is specified then the\n program will be restarted when it exits.\n\n${n("Options")}\n\n ${o("-w <path>")} / ${o("--watch <path>")} Watch a path for changes\n ${o("-r")} / ${o("--restart")} Restart program on exit\n ${o("-v")} / ${o("--verbose")} Verbose mode\n ${o("-h")} / ${o("--help")} This help\n\n${n("Examples")}\n\n $ ${l} ${o("-w .")} ${s("bin/foo.js")}\n $ ${l} ${o("-w lib -w config")} ${s("bin/foo.js")}\n $ ${l} ${o("-w lib -w config")} ${s("bin/foo.js")} ${i("bar baz")}\n $ ${l} ${o("-w lib -w config -v")} ${s("bin/foo.js")} ${i("bar baz")}\n $ ${l} ${o("-w lib -w config -v -r")} ${s("bin/foo.js")} ${i("bar baz")}\n`},Te={dir:"config"},Ae={dir:"lib library src components"},Fe={};class Oe{constructor(r,o={}){const n=t.dir(r),s=e.splitList(o.config?.dir||Te.dir).map(e=>n.dir(e)),i={...Te,...o.config||{}},a=new K(s,i),l=e.splitList(o.library?.dir||Ae.dir).map(e=>n.dir(e)),c={...Ae,...o.library||{}},p=new Z(l,c);this.case={...Fe,...o.case||{}},this.state={rootDir:n,config:a,library:p},Y(this,o.debug,o.debugPrefix,o.debugColor),this.debug("root dir: ",n.path()),this.debug("config dir: ",s.map(e=>e.path())),this.debug("libDirs: ",l),this.debug("libOpts: ",c)}dir(t,r){return this.debug("dir(%s, %o)",t,r),e.hasValue(t)?this.state.rootDir.dir(t,r):this.state.rootDir}file(e,t){return this.debug("file(%s, %o)",e,t),this.state.rootDir.file(e,t)}read(e,t){return this.debug("read(%s, %o)",e,t),this.file(e,t).read()}write(e,t,r){return this.debug("write(%s, %o, %o)",e,t,r),this.file(e,r).write(t)}configDir(t,r){return this.debug("configDir(%s, %o)",t,r),e.hasValue(t)?this.state.configDir.dir(t,r):this.state.configDir}async config(t,r){return this.debug("config(%s, %o)",t,r),e.hasValue(t)?this.state.config.config(t,r):this.state.config}async library(t){return this.debug("library(%s, %o)",t),e.hasValue(t)?this.state.library.library(t):this.state.library}async component(t,r){const[o,n]=t.split("#",2),s=this.convertCase("config",o),i=await this.config(s,{}),a=i.component?.library||this.convertCase("library",o),l=await this.library(a),c=n||i.component?.export||"default";return new(l[c]||e.fail("No '",c,"' export from component library: ",t))(this,{...i,...r})}convertCase(e,t){const r=this.case[e];return r?r(t):t}}exports.ANSIescape=g,exports.ANSIescapeCode=u,exports.ANSIreset=f,exports.ANSIresetCode=d,exports.Component=class{constructor(e,t={}){this.workspace=e,this.props=t,Y(this,t.debug,t.debugPrefix,t.debugColor),this.initComponent(t)}initComponent(){}},exports.Config=K,exports.Debugger=U,exports.Library=Z,exports.Progress=Ce,exports.Workspace=Oe,exports.abort=ae,exports.addDebug=Y,exports.allParams=de,exports.answer=he,exports.anyParams=function(t,r){let o=!1;const n=e.splitList(r),s=n.map(r=>{const n=t[r];return e.hasValue(n)&&(o=!0),n});return o?s:e.fail("Missing value for one of: ",e.joinListOr(n))},exports.appStatus=ee,exports.args=function(e=r.argv){return e.slice(2)},exports.black=x,exports.blue=v,exports.brightBlack=V,exports.brightBlue=D,exports.brightCyan=L,exports.brightGreen=q,exports.brightGrey=T,exports.brightMagenta=S,exports.brightRed=E,exports.brightWhite=A,exports.brightYellow=N,exports.charTypes=fe,exports.cmdLine=re,exports.cmdLineArg=ne,exports.cmdLineArgs=async function(e,t=re()){let r=[];if(e){for(let o of e){const e=await ne(o,t);if(!e?.length)return;r.push(e)}return r}return t},exports.cmdLineFlags=oe,exports.color=b,exports.colours=be,exports.config=(e,t)=>new K(e,t),exports.confirm=async(t,r={})=>(r=e.isBoolean(r)?{default:r}:r,te(t,{...r,type:"confirm"})),exports.cyan=k,exports.darkBlack=F,exports.darkBlue=W,exports.darkCyan=G,exports.darkGreen=I,exports.darkGrey=M,exports.darkMagenta=B,exports.darkRed=O,exports.darkWhite=R,exports.darkYellow=z,exports.dataPath=_,exports.defaults=le,exports.exit=se,exports.findFirstFile=Ve,exports.findProgram=Ee,exports.formatElapsed=ve,exports.formatPicture=$e,exports.green=y,exports.grey=j,exports.library=(e,t)=>new Z(e,t),exports.magenta=C,exports.matchDoubleQuotedString=e=>{const t=e.match(/^"((?:\\[\\"bfnrtv]|.)*?)"$/);return t?t[1].replace(/\\([\\"bfnrtv])/g,(e,t)=>H[t]||`\\${t}`):null},exports.matchSingleQuotedString=e=>{const t=e.match(/^'((?:\\[\\'bfnrtv]|.)*?)'$/);return t?t[1].replace(/\\([\\'bfnrtv])/g,(e,t)=>H[t]||`\\${t}`):null},exports.options=ce,exports.palette=m,exports.picture=me,exports.prepareColours=ye,exports.preparePicture=we,exports.progress=e=>new Ce(e),exports.prompt=te,exports.quit=ie,exports.red=w,exports.requiredParam=ue,exports.requiredParams=ge,exports.runSetup=Pe,exports.section=pe,exports.select=async(t,r,n)=>(await o([{type:"select",name:"selected",message:t,initial:n,choices:e.isArray(r)?r:Object.entries(r).map(([e,t])=>({value:e,title:t}))}])).selected,exports.setup=je,exports.splitDataPath=Q,exports.watch=async function(t){const{config:r,cmdLine:o}=De(t),n=await o(),{watch:s,restart:i,program:c,programArgs:p}=n,{scanning:h,watching:u,starting:g,stopping:d,failed:f,stopped:b,change:m}=Se({...r,...n});let x,w=!1;h(),u(s);const y=()=>{x||(g(),x=l.spawn(c,p,{stdio:"inherit"}),x.on("exit",(t,r)=>{r||(t?f(t):b(),i?(x=null,e.sleep(500).then(y)):se(t))}))},$=e.debounce(()=>{x&&(d(),x.kill(),x=null),y()},300);a.watch(s).on("ready",()=>{y(),w=!0}).on("all",(e,t)=>{w&&(m(e,t),$())})},exports.watcherFunctions=De,exports.watcherHelpText=Le,exports.watcherStatus=Se,exports.white=P,exports.workspace=(e,t)=>new Oe(e,t),exports.yellow=$,Object.keys(t).forEach(function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}),Object.keys(c).forEach(function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return c[e]}})});
1
+ "use strict";var e=require("@abw/badger-utils"),t=require("@abw/badger-filesystem"),r=require("node:process"),n=require("prompts"),o=require("commander"),s=require("@abw/badger-timestamp"),i=require("chokidar"),a=require("node:child_process"),l=require("@abw/badger-codecs");const c={reset:0,bold:1,bright:1,dark:2,black:0,red:1,green:2,yellow:3,blue:4,magenta:5,cyan:6,grey:7,white:8,fg:30,bg:40},p={fg:e=>`38;2;${e.r};${e.g};${e.b}`,bg:e=>`48;2;${e.r};${e.g};${e.b}`},h=(t,r="fg")=>{const n=(e=>{const t=e.match(/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null})(t)||(t=>{const r=e.splitList(t);return 3===r.length?{r:r[0],g:r[1],b:r[2]}:null})(t);return n?((e,t="fg")=>"["+p[t](e)+"m")(n,r):((e,t="fg")=>{let r=[],n=e.split(/ /,2);const o=n.pop(),s=(t?c[t]:0)+c[o];if(r.push(s),n.length){const e=n.length?n.shift():"dark";r.push(c[e])}return"["+r.join(";")+"m"})(t,r)},u=(t={})=>{const r=e.isObject(t)?t:{fg:t};let n=[];return r.bg&&n.push(h(r.bg,"bg")),r.fg&&n.push(h(r.fg,"fg")),n.join("")},g=h("reset",!1),d=()=>g,f=e=>(...t)=>u(e)+t.join("")+g,b=e=>Object.entries(e).reduce((e,[t,r])=>(e[t]=f(r),e),{}),m=f("black"),x=f("red"),w=f("green"),y=f("yellow"),$=f("blue"),v=f("magenta"),C=f("cyan"),k=f("grey"),j=f("white"),P=f("bright black"),V=f("bright red"),E=f("bright green"),S=f("bright yellow"),q=f("bright blue"),D=f("bright magenta"),L=f("bright cyan"),N=f("bright grey"),T=f("bright white"),A=f("dark black"),F=f("dark red"),O=f("dark green"),I=f("dark yellow"),z=f("dark blue"),W=f("dark magenta"),B=f("dark cyan"),G=f("dark grey"),M=f("dark white");function R(t,r="",n){return t?r?(e,...t)=>console.log("%s"+r+"%s"+e,n?u(n):"",d(),...t):console.log.bind(console):e.doNothing}function U(e,t,r="",n){e.debug=R(t,r,n)}const Y={b:"\b",f:"\f",n:"\n",r:"\r",t:"\t",v:"\v",'"':'"',"'":"'","\\":"\\"},H=t=>{let r,n,o=[];for(;t.length;){let s,i;(n=t.match(/^(\/+)/))?t=t.slice(n[1].length):(t.match(/^(\?)/)&&(t=t.slice(1),s=!0),(n=t.match(/^('((\\[\\'bfnrtv]|.)*?)')/))?(t=t.slice(n[1].length),r=n[2].replace(/\\([\\'bfnrtv])/g,(e,t)=>Y[t]||`\\${t}`)):(n=t.match(/^("((\\[\\"bfnrtv]|.)*?)")/))?(t=t.slice(n[1].length),r=n[2].replace(/\\([\\"bfnrtv])/g,(e,t)=>Y[t]||`\\${t}`)):(n=t.match(/^([^/?]+)/))?(r=n[1],t=t.slice(r.length)):e.fail(`Can't parse data path: ${t}`),t.match(/^(\?)/)&&(t=t.slice(1),i=!0),s?o.push([r,{maybe:!0}]):i?o.push([r,{optional:!0}]):o.push(r))}return o},Q=(t,r)=>{let n=t,o=H(r),s=[];for(let t of o){const[r,o]=e.isArray(t)?t:[t,{}],i=n[r];if(s.push(r),e.noValue(i)){if(o.maybe)return n;if(o.optional)return;e.fail("No value for data at path: ",s.join("/"))}n=i}return n},_={codec:["yaml","json"],jsExt:["js","mjs"]};class J extends t.DirPath{constructor(t,r={}){super(t);const n={..._,...r};this.state.codec=e.splitList(n.codec),this.state.jsExt=e.splitList(n.jsExt),U(this,r.debug,r.debugPrefix,r.debugColor)}async firstFileWithExt(t,r,n=e.doNothing){const o=await this.dirs();for(let e of o)for(let o of r){const r=t+"."+o,s=e.file(r,n(t,o));if(this.debug("looking for config file: ",s.path()),await s.exists())return this.debug("config file exists: ",s.path()),s}}async jsFile(e){return await this.firstFileWithExt(e,this.state.jsExt)}async file(e){return await this.firstFileWithExt(e,this.state.codec,(e,t)=>({codec:t}))}async config(t,r){const[n,o]=t.split("#",2);let s,i,a;if(s=await this.jsFile(n))a=await import(s.path());else if(i=await this.file(n))a=await i.read();else{if(!r)return e.fail("No configuration file for "+n);a=r}return o?Q(a,o):a}}const K={jsExt:"js mjs"};class X extends t.DirPath{constructor(t,r={}){super(t);const n={...K,...r},o=e.splitList(n.jsExt).map(e=>e.replace(/^\./,""));this.state.exts=o,U(this,r.debug,r.debugPrefix,r.debugColor),this.debug("state: ",this.state)}async library(t){const[r,n]=t.split("#",2),o=await this.dirs(),s=this.state.exts;for(let e of o)for(let t of s){const o=e.file(r+"."+t);this.debug("looking for module %s as",r,o.path());if(await o.exists()){const e=await import(o.path());return this.debug("loaded %s as",o.path()),n?Q(e,n):e}}e.fail("Library not found: ",t)}}const Z=e=>async function(...t){try{const r=await e(...t);return r&&console.log(E(`✓ ${r}`)),!0}catch(e){return console.log(r.env.DEBUG?e:V(`✗ ${e.message||e}`)),!1}},ee=async(t,r={})=>{const o=(r=e.isString(r)?{default:r}:r).name||"answer";return(await n([{name:o,type:r.type||"text",message:t,initial:r.default}]))[o]},te=()=>r.argv.slice(2);function re(t,r){t?e.isArray(t)&&(r=t,t={}):t={},r||(r||=te());const n=!!t.options&&e.splitHash(t.options),o=t.others||"error",s=t.short||{},i=t.on||{};let a=!1,l=0,c={};for(;l<r.length;){const t=r[l].match(/^-(-)?(.*)/);if("--"===r[l]&&(a=!0,r.splice(l,1)),t&&!a){const a=!("-"===t[1])&&e.hasValue(s[t[2]])?s[t[2]]:t[2];if(i[a]){if(i[a](a,r.splice(l,1)[0],r,c))continue;r.splice(l,0,t[0])}if(n&&!n[a])switch(o){case"collect":break;case"remove":r.splice(l,1)[0];case"keep":l++;continue;case"error":return e.fail(`Invalid command line flag: ${t[0]}`);default:return e.fail(`Invalid "others" option: ${o}`)}r.splice(l,1),c[a]=!0}else l++}return{flags:c,args:r}}async function ne(e,t=te()){return t.length?t.shift():e?await ee(e):void 0}const oe=".env",se=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;async function ie({filename:r=oe,dirs:n=[t.bin(),t.cwd()],walkup:o=!0}){const s={},i=n.map(e=>t.dir(e));for(;i.length;){const e=i.shift();if(!s[e.path()]){s[e.path()]=!0;const t=e.file(r);if(await t.exists())return t.path();o&&i.push(e.up())}}e.fail(`Cannot locate ${oe} file in any parent directory of ${n.join(", ")}`)}function ae(e){const t={},r=e.toString().replace(/\r\n?/gm,"\n");let n;for(;null!=(n=se.exec(r));){const e=n[1];let r=n[2]??"";r=r.trim();const o=r[0];r=r.replace(/^(['"`])([\s\S]*)\1$/gm,"$2"),'"'===o&&(r=r.replace(/\\n/g,"\n"),r=r.replace(/\\r/g,"\r")),t[e]=r}return t}async function le({path:n,filename:o,dirs:s,addToProcessEnv:i=!0,debug:a=!1}){n||=await ie({filename:o,dirs:s}),a&&console.log(`Loading environment from ${n}`);const l=t.file(n);await l.exists()||e.fail(`Specified environment file does not exist: ${n}`);const c=ae(await l.read());return a&&console.log("Loaded environment:",c),i&&(Object.assign(r.env,c),a&&console.log("Added environment to process.env")),c}function ce(e,t){t&&console.log(t),r.exit(e)}function pe(e){ce(0,e)}function he(e){ce(1,e)}const ue={verboseColor:"magenta",titleColor:"bright yellow",underlineColor:"dark yellow",infoColor:"cyan",tickColor:"green",questionColor:"bright white",answerColor:"bright green",sectionNewlines:!0},ge=async t=>{const s=f(ge.verboseColor||ue.verboseColor),i=new o.Command;t.name&&i.name(t.name),t.description&&i.description(t.description),t.version&&i.version(t.version),t.yes&&i.option("-y, --yes","Accept default answers"),t.verbose&&i.option("-v, --verbose","Verbose output"),t.quiet&&i.option("-q, --quiet","Quiet output"),t.options?.filter(t=>!(e.hasValue(t.arg)&&!t.arg)&&(t.title?void 0:e.hasValue(t.name))).forEach(t=>{const r=t.name,n=t.about,o=t.default,s=t.handler,a=t.short,l=t.type,c=t.pattern||(e.hasValue(l)?`<${l}>`:void 0);let p=`--${r}`,h=[];e.hasValue(a)&&(p=`-${a}, ${p}`),e.hasValue(c)&&(p=`${p} ${c}`),h.push(p),e.hasValue(n)&&h.push(n),e.hasValue(s)&&h.push(s),e.hasValue(o)&&h.push(o),i.option(...h)});let a={};t.commands?.forEach(t=>{const r=t.name,n=t.about,o=t.type,s=t.pattern||(e.hasValue(o)?`<${o}>`:void 0);let l=[],c=r,p=i.command(c);e.hasValue(s)&&p.argument(s),e.hasValue(n)&&p.description(n),e.hasValue(t.arguments)&&e.splitList(t.arguments).forEach(t=>{l.push(function(t){const r=t.match(/(\w+)/);r||e.fail("Can't parse argument name: ",t);return r[1]}(t)),p.argument(t)}),p.action((...e)=>{a[r]=l.length?l.reduce((t,r)=>(t[r]=e.shift(),t),{}):e[0]})}),i.parse();const l=i.opts(),c=t.yes&&l.yes,p=t.verbose&&l.verbose,h=t.quiet&&l.quiet;c&&(p&&!h&&r.stdout.write(s("Accepting default answers (-y option is set)\n")),n.override(l));let u=[];t.options?.forEach(t=>{const r=t.type||"text",n=t.name,o=t.prompt,s=e.hasValue(t.arg)&&!t.arg,i=t.validate||(t.required?t=>!(!e.hasValue(t)||!t.toString().length)||(ge.invalid||`You must enter a value for ${n}`):void 0);let a=s?t.default:l[n];"select"===r&&e.hasValue(a)&&(Number.isInteger(a)||(a=t.choices?.findIndex(e=>e.value===a),a<0&&(a=0))),e.hasValue(o)?u.push({...t,type:e.hasValue(a)?()=>(c&&(h||fe({question:o,answer:a})),r):r,name:n,message:o,initial:a,validate:i}):(t.title||t.info)&&u.push({type:()=>(h||de(t),!1)})});let g=!1;const d=await n(u,{onCancel:()=>(g=!0,!1)});return g?void 0:{...l,...d,...a}};const de=t=>{const n=t.title,o=f(t.titleColor||ue.titleColor),s=f(t.underlineColor||ue.underlineColor),i=f(t.infoColor||ue.infoColor),a=(e.hasValue(t.newlines)?t.newlines:ue.sectionNewlines)?"\n":"";if(n){const e="-".repeat(n.length);r.stdout.write(a+o(n)+"\n"+s(e)+"\n"+a)}t.info&&r.stdout.write(i(t.info)+"\n"+a)},fe=e=>{const t=f(e.tickColor||ue.tickColor),n=f(e.questionColor||ue.questionColor),o=f(e.answerColor||ue.answerColor);r.stdout.write(t("✔ ")+n(e.question)+" "+o(e.answer)+"\n")};function be(t={},r){const n=t[r];if(e.hasValue(n))return n;e.fail("Missing value for required parameter: ",r)}function me(t={},r){return e.splitList(r).map(e=>be(t,e))}const xe=me;const we={border:"┌─┐│└─┘|-",background:"+∙",fill:"*"},ye={border:"green",background:"dark grey",foreground:"blue",fill:"bright yellow"},$e={charTypes:we,source:"\n┌────────────────────────────────────────────────────────────────┐\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙ ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ∙∙ │\n│ ∙∙ ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ∙∙ │\n│ ∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙ │\n│ ∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙ │\n│ ∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙ │\n│ ∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙ │\n│ ∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙ │\n│ ∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙ ●● *◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦* ●● ∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙ ●● **◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦** ●● ∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙ ●● *****◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦***** ●● ∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● *******◦◦◦◦◦◦◦◦◦◦******* ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ****************** ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ************ ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ****** ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● **** ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● **** ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● **** ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ◦****◦ ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ◦◦◦◦****◦◦◦◦ ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦****◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦******◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦********◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦◦************◦◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦◦******************◦◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙∙∙ │\n│ ∙∙∙∙∙∙ ●● ◦◦◦◦◦◦◦◦◦************************◦◦◦◦◦◦◦◦◦ ●● ∙∙∙∙∙∙ │\n│ ∙∙∙∙∙ ●● ◦◦◦◦◦◦◦******************************◦◦◦◦◦◦◦ ●● ∙∙∙∙∙ │\n│ ∙∙∙∙ ●● ◦◦◦◦◦************************************◦◦◦◦◦ ●● ∙∙∙∙ │\n│ ∙∙∙ ●● ◦◦◦◦****************************************◦◦◦◦ ●● ∙∙∙ │\n│ ∙∙ ●● ◦◦◦********************************************◦◦◦ ●● ∙∙ │\n│ ∙∙ ●● ◦◦**********************************************◦◦ ●● ∙∙ │\n│ ∙∙ ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ∙∙ │\n│ ∙∙ ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ∙∙ │\n│ ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ │\n└────────────────────────────────────────────────────────────────┘\n"},ve={size:100,elapsed:!1,picture:$e,colours:ye};function Ce(e){const{source:t,charTypes:r={background:""}}=e,n=t.trim()+"\n",o=n.length,s=Object.entries(r).reduce((e,[t,r])=>(r.split("").forEach(r=>e[r]=t),e),{});return{picture:n,length:o,lineLength:t.split("\n").reduce((e,t)=>Math.max(e,t.length),0),charType:s}}function ke(e){return Object.entries(e).reduce((e,[t,r])=>(e[t]=f(r),e),{})}function je(e){const{picture:t,charType:r={},colours:n={}}=e;return t.split("").map(e=>{const t=r[e]||"foreground",o=n[t];return o?o(e):e}).join("")}function Pe(e){const t=e%60,r=Math.floor(e/60);return[Math.floor(e/3600),r,t].map(e=>e.toString().padStart(2,"0")).join(":")}class Ve{constructor(t={}){const r={...ve,...e.isInteger(t)?{size:t}:t},{size:n,colours:o,colors:i,debug:a,elapsed:l}=r,{picture:c,length:p,lineLength:h,charType:u}=Ce(e.isString(r.picture)?{source:r.picture,charTypes:we}:r.picture);this.size=n,this.picture=c,this.pixels=this.picture.split(""),this.length=p,this.lineLength=h,this.charType=u,this.colours=ke(i||o),this.count=0,this.lastCount=0,this.lastPixel=0,this.startTime=s.now().epochSeconds(),this.elapsed=0,this.elapsedCol=f("dark grey"),this.showElapsed=l,this.debugging=a,U(this,a,"Progress > ","blue")}progress(e=1){this.count+=e;const t=s.now().epochSeconds()-this.startTime;this.elapsed=t;const r=Math.floor(this.length*this.count/this.size);if(r>this.lastPixel){const e=this.lastPixel;return this.lastPixel=r,this.debug(`count: ${this.count}/${this.size} pixels from ${e} to ${r}`),this.pictureSegment(e,r)}return""}remains(){this.count=this.size;const e=this.lastPixel,t=this.length;return t>e?(this.lastPixel=this.length,this.pictureSegment(e,t)):""}pictureSegment(e,t){if(this.debugging)return"";let r=je({picture:this.picture.substring(e,t),charType:this.charType,colours:this.colours});if(this.showElapsed&&r.match("\n")){const e=r.split("\n"),t=e.pop();r=e.map(e=>e+" "+this.elapsedCol(Pe(this.elapsed))).join("\n").concat("\n",t)}return r}printProgress(e=1){r.stdout.write(this.progress(e))}printRemains(){r.stdout.write(this.remains())}}const Ee={description:"Project setup script.",configFiles:["config/setup.yaml","config/setup.json","setup.yaml","setup.json",".setup.yaml",".setup.json"],dataFile:".env.yaml",envFile:".env",envComments:!0,envSections:!0,writeData:!0,writeEnv:!1,compact:!1,cancelled:"Setup cancelled",allDone:"All configuration options have been set",warning:e=>`\n#=============================================================================\n# WARNING: This file is generated automatically when the ${e.scriptName}\n# script is run. Any changes made here may be lost.\n#\n# Generated: ${s.now()}\n#=============================================================================\n\n`},Se=Z(async e=>{await qe(e)});async function qe(n){const o={...Ee,...n},s=o.rootDir?t.dir(o.rootDir):t.cwd(),i=s.file(o.envFile),a=le({path:i.path()}),l=s.file(o.dataFile,{codec:"auto"}),c=await l.exists()?await l.read():{},p=o.configFile?s.file(o.configFile,{codec:"auto"}):await De(s,o.configFiles),h=await p.read();h.name||=o.name||r.argv[1].replace(s.path()+"/",""),h.version||=o.version,h.description||=o.description,n.preprocess&&await n.preprocess(h);const u={root:s.path(),...o.values||{}},g={quiet:!0,verbose:!0,yes:!0};for(let t of h.options){const{name:r,save:n}=t;if(e.isBoolean(n)&&!n&&(g[r]=!0),!r)continue;t.pattern&&(t.type||="text");const o=t.envvar||=r.toUpperCase();e.hasValue(a[o])?t.default=a[o]:e.hasValue(c[r])?t.default=c[r]:e.hasValue(u[r])?t.default=u[r]:t.program&&(t.default=await Le(t.program),t.pattern||="<path>")}const d=await ge(h);d||pe("\n👎 "+V(o.cancelled));const{debug:f,verbose:b,quiet:m}=d;return o.writeData&&(await l.write(e.extract(d,e=>!g[e])),b&&console.log(E(`✓ Wrote data file: ${l}`))),o.writeEnv&&(await i.write(await async function(t,r,n,o){const{compact:s,envComments:i,envSections:a,envPrefix:l=""}=r,c=s?"":"\n";let p=[Ne(r.warning(r))];const h="#"+"-".repeat(77),u="#"+"=".repeat(77);for(let t of n.options){const{name:r,envvar:n,title:u,about:g,save:d}=t;if(!e.isBoolean(d)||d)if(u&&a)p.push(`${c}\n${h}\n${Ne(u)}\n${h}`);else if(s||p.push(""),g&&i&&p.push(`${Ne(g)}`),r){const t=o[r];if(e.hasValue(t)){const e=t.toString().match(/[#\r\n]/)?'"$value"':t;p.push(`${l}${n||r.toUpperCase()}=${e}`)}else p.push(Ne(`No value for ${n||r.toUpperCase()}`))}}if(r.envExtra){const n=t.file(r.envExtra);await n.exists()||e.fail(`Cannot find envExtra file: ${r.envExtra}`),a&&p.push("\n",u,Ne(` Additional configuration copied from ${r.envExtra}`),u,""),p.push(await n.read())}return p.join("\n")+"\n"}(s,o,h,d)),b&&console.log(E(`✓ Wrote .env file: ${i}`))),f&&console.log("\nGenerated configuration:",d),o.allDone&&!m&&console.log("\n👍 ",E(o.allDone),"\n"),d}async function De(t,r=[]){for(let e of r){const r=t.file(e,{codec:"auto"});if(await r.exists())return r}e.fail("Can't find a configFile: ",r.join(", "))}async function Le(n){for(let o of e.splitList(n))for(let e of r.env.PATH.split(":")){const r=t.dir(e).file(o);if(await r.exists())return r.path()}}function Ne(t){return e.splitLines(t.trim()).map(e=>e.match(/^#/)?e:`# ${e}`).join("\n")}const Te={script:r.argv[1].split("/").at(-1),prefix:"watcher >",colors:{prefix:"dark grey",error:"bright red",watcher:"bright yellow",section:"bright white",program:"bright green",arg:"bright cyan",args:"bright blue",debug:"bright grey",command:"yellow",scanning:"cyan",watching:"cyan",change:"bright cyan",starting:"bright green",stopping:"bright red",stopped:"green",failed:"bright red"}};const Ae=e=>{const r={...Te,...e},n=r.colors=b({...Te.colors,...r.colors}),o=Oe(r),s=()=>pe(o()),i=e=>he(o(e));return{config:r,colors:n,helpText:o,help:s,barf:i,cmdLine:async()=>{const{flags:e,args:r}=re({options:"watch restart verbose help",others:"keep",short:{w:"watch",r:"restart",v:"verbose",h:"help"},on:{help:s,watch:(e,t,r,n)=>(n.watch||=[],r.length||i("The -w option expects an argument!"),n.watch.push(r.shift()),!0)}}),[n,...o]=r,a=r.join(" ");return r.length<1&&i("No program specified to run!"),e.watch?.length||i("Nothing specified to watch!"),await t.file(n).exists()||i(`Program not found: ${n}`),{...e,progText:a,program:n,programArgs:o}}}},Fe=({verbose:t,colors:r,prefix:n,progText:o})=>({scanning:()=>t?console.log(r.prefix(n),r.scanning("scanning...")):e.doNothing,watching:o=>t?o.forEach(e=>console.log(r.prefix(n),r.watching("watching "),r.command(e))):e.doNothing,change:(o,s)=>t?console.log(r.prefix(n),r.change(`${o}`.padEnd(9)),r.command(s)):e.doNothing,starting:()=>t?console.log(r.prefix(n),r.starting("starting "),r.command(o)):e.doNothing,stopping:()=>t?console.log(r.prefix(n),r.stopping("stopping "),r.command(o)):e.doNothing,failed:s=>t?console.log(r.prefix(n),r.failed(`failed ${s}`),r.command(o)):e.doNothing,stopped:()=>t?console.log(r.prefix(n),r.stopped("stopped "),r.command(o)):e.doNothing}),Oe=({colors:e,script:t})=>{const{watcher:r,arg:n,section:o,program:s,args:i,error:a}=e,l=r(t);return e=>`${l}\n${e?`\n${a(e)}\n`:""}\n${o("Usage")}\n\n $ ${l} [${n("options")}] ${s("program")} [${i("arg1 arg2 ...")}]\n\n${o("Description")}\n\n This program will run another program and restart it if any files\n are added, deleted or modified in one or more watched locations.\n\n Paths to watch should be specified using the ${n("-w")} (or ${n("--watch")})\n option. You can specify this multiple times for different paths.\n\n The path to the ${s("program")} should follow, along with any additional\n ${i("arguments")} to be passed to it.\n\n If the ${n("-r")} (or ${n("--restart")}) option is specified then the\n program will be restarted when it exits.\n\n${o("Options")}\n\n ${n("-w <path>")} / ${n("--watch <path>")} Watch a path for changes\n ${n("-r")} / ${n("--restart")} Restart program on exit\n ${n("-v")} / ${n("--verbose")} Verbose mode\n ${n("-h")} / ${n("--help")} This help\n\n${o("Examples")}\n\n $ ${l} ${n("-w .")} ${s("bin/foo.js")}\n $ ${l} ${n("-w lib -w config")} ${s("bin/foo.js")}\n $ ${l} ${n("-w lib -w config")} ${s("bin/foo.js")} ${i("bar baz")}\n $ ${l} ${n("-w lib -w config -v")} ${s("bin/foo.js")} ${i("bar baz")}\n $ ${l} ${n("-w lib -w config -v -r")} ${s("bin/foo.js")} ${i("bar baz")}\n`},Ie={dir:"config"},ze={dir:"lib library src components"},We={};class Be{constructor(r,n={}){const o=t.dir(r),s=e.splitList(n.config?.dir||Ie.dir).map(e=>o.dir(e)),i={...Ie,...n.config||{}},a=new J(s,i),l=e.splitList(n.library?.dir||ze.dir).map(e=>o.dir(e)),c={...ze,...n.library||{}},p=new X(l,c);this.case={...We,...n.case||{}},this.state={rootDir:o,config:a,library:p},U(this,n.debug,n.debugPrefix,n.debugColor),this.debug("root dir: ",o.path()),this.debug("config dir: ",s.map(e=>e.path())),this.debug("libDirs: ",l),this.debug("libOpts: ",c)}dir(t,r){return this.debug("dir(%s, %o)",t,r),e.hasValue(t)?this.state.rootDir.dir(t,r):this.state.rootDir}file(e,t){return this.debug("file(%s, %o)",e,t),this.state.rootDir.file(e,t)}read(e,t){return this.debug("read(%s, %o)",e,t),this.file(e,t).read()}write(e,t,r){return this.debug("write(%s, %o, %o)",e,t,r),this.file(e,r).write(t)}configDir(t,r){return this.debug("configDir(%s, %o)",t,r),e.hasValue(t)?this.state.configDir.dir(t,r):this.state.configDir}async config(t,r){return this.debug("config(%s, %o)",t,r),e.hasValue(t)?this.state.config.config(t,r):this.state.config}async library(t){return this.debug("library(%s, %o)",t),e.hasValue(t)?this.state.library.library(t):this.state.library}async component(t,r){const[n,o]=t.split("#",2),s=this.convertCase("config",n),i=await this.config(s,{}),a=i.component?.library||this.convertCase("library",n),l=await this.library(a),c=o||i.component?.export||"default";return new(l[c]||e.fail("No '",c,"' export from component library: ",t))(this,{...i,...r})}convertCase(e,t){const r=this.case[e];return r?r(t):t}}exports.ANSIescape=u,exports.ANSIescapeCode=h,exports.ANSIreset=d,exports.ANSIresetCode=g,exports.Component=class{constructor(e,t={}){this.workspace=e,this.props=t,U(this,t.debug,t.debugPrefix,t.debugColor),this.initComponent(t)}initComponent(){}},exports.Config=J,exports.Debugger=R,exports.Library=X,exports.Progress=Ve,exports.Workspace=Be,exports.abort=he,exports.addDebug=U,exports.allParams=xe,exports.answer=fe,exports.anyParams=function(t,r){let n=!1;const o=e.splitList(r),s=o.map(r=>{const o=t[r];return e.hasValue(o)&&(n=!0),o});return n?s:e.fail("Missing value for one of: ",e.joinListOr(o))},exports.appStatus=Z,exports.args=function(e=r.argv){return e.slice(2)},exports.black=m,exports.blue=$,exports.brightBlack=P,exports.brightBlue=q,exports.brightCyan=L,exports.brightGreen=E,exports.brightGrey=N,exports.brightMagenta=D,exports.brightRed=V,exports.brightWhite=T,exports.brightYellow=S,exports.charTypes=we,exports.cmdLine=te,exports.cmdLineArg=ne,exports.cmdLineArgs=async function(e,t=te()){let r=[];if(e){for(let n of e){const e=await ne(n,t);if(!e?.length)return;r.push(e)}return r}return t},exports.cmdLineFlags=re,exports.color=f,exports.colours=ye,exports.config=(e,t)=>new J(e,t),exports.confirm=async(t,r={})=>(r=e.isBoolean(r)?{default:r}:r,ee(t,{...r,type:"confirm"})),exports.cyan=C,exports.darkBlack=A,exports.darkBlue=z,exports.darkCyan=B,exports.darkGreen=O,exports.darkGrey=G,exports.darkMagenta=W,exports.darkRed=F,exports.darkWhite=M,exports.darkYellow=I,exports.dataPath=Q,exports.defaults=ue,exports.dotenv=le,exports.exit=ce,exports.findDotenv=ie,exports.findFirstFile=De,exports.findProgram=Le,exports.formatElapsed=Pe,exports.formatPicture=je,exports.green=w,exports.grey=k,exports.library=(e,t)=>new X(e,t),exports.magenta=v,exports.matchDoubleQuotedString=e=>{const t=e.match(/^"((?:\\[\\"bfnrtv]|.)*?)"$/);return t?t[1].replace(/\\([\\"bfnrtv])/g,(e,t)=>Y[t]||`\\${t}`):null},exports.matchSingleQuotedString=e=>{const t=e.match(/^'((?:\\[\\'bfnrtv]|.)*?)'$/);return t?t[1].replace(/\\([\\'bfnrtv])/g,(e,t)=>Y[t]||`\\${t}`):null},exports.options=ge,exports.palette=b,exports.parseDotenv=ae,exports.picture=$e,exports.prepareColours=ke,exports.preparePicture=Ce,exports.progress=e=>new Ve(e),exports.prompt=ee,exports.quit=pe,exports.red=x,exports.requiredParam=be,exports.requiredParams=me,exports.runSetup=qe,exports.section=de,exports.select=async(t,r,o)=>(await n([{type:"select",name:"selected",message:t,initial:o,choices:e.isArray(r)?r:Object.entries(r).map(([e,t])=>({value:e,title:t}))}])).selected,exports.setup=Se,exports.splitDataPath=H,exports.watch=async function(t){const{config:r,cmdLine:n}=Ae(t),o=await n(),{watch:s,restart:l,program:c,programArgs:p}=o,{scanning:h,watching:u,starting:g,stopping:d,failed:f,stopped:b,change:m}=Fe({...r,...o});let x,w=!1;h(),u(s);const y=()=>{x||(g(),x=a.spawn(c,p,{stdio:"inherit"}),x.on("exit",(t,r)=>{r||(t?f(t):b(),l?(x=null,e.sleep(500).then(y)):ce(t))}))},$=e.debounce(()=>{x&&(d(),x.kill(),x=null),y()},300);i.watch(s).on("ready",()=>{y(),w=!0}).on("all",(e,t)=>{w&&(m(e,t),$())})},exports.watcherFunctions=Ae,exports.watcherHelpText=Oe,exports.watcherStatus=Fe,exports.white=j,exports.workspace=(e,t)=>new Be(e,t),exports.yellow=y,Object.keys(t).forEach(function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}),Object.keys(l).forEach(function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return l[e]}})});
2
2
  //# sourceMappingURL=badger.cjs.js.map