@abw/badger 1.1.18 → 1.1.20

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
- import{isObject as t,doNothing as e,fail as n,isArray as i,noValue as r,splitList as o,isString as s,isBoolean as a,splitHash as c,hasValue as l,joinListOr as u,isInteger as h,extract as p,splitLines as f}from"@abw/badger-utils";import{DirPath as g,dir as d,cwd as m}from"@abw/badger-filesystem";export*from"@abw/badger-filesystem";import b from"node:process";import w from"prompts";import{Command as y}from"commander";import{now as v}from"@abw/badger-timestamp";import x from"dotenv";export*from"@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},$=(t,e="fg")=>{let n=[],i=t.split(/ /,2);const r=i.pop(),o=(e?C[e]:0)+C[r];if(n.push(o),i.length){const t=i.length?i.shift():"dark";n.push(C[t])}return"["+n.join(";")+"m"},j=(e={})=>{const n=t(e)?e:{fg:e};let i=[];return n.bg&&i.push($(n.bg,"bg")),n.fg&&i.push($(n.fg,"fg")),i.join("")},k=()=>$("reset",!1),E=t=>(...e)=>j(t)+e.join("")+k(),D=E("black"),q=E("red"),F=E("green"),P=E("yellow"),T=E("blue"),S=E("magenta"),N=E("cyan"),z=E("grey"),A=E("white"),M=E("bright black"),W=E("bright red"),I=E("bright green"),G=E("bright yellow"),L=E("bright blue"),O=E("bright magenta"),U=E("bright cyan"),R=E("bright grey"),B=E("bright white"),H=E("dark black"),Q=E("dark red"),V=E("dark green"),Y=E("dark yellow"),J=E("dark blue"),K=E("dark magenta"),X=E("dark cyan"),Z=E("dark grey"),_=E("dark white");function tt(t,n="",i){return t?n?(t,...e)=>console.log("%s"+n+"%s"+t,i?j(i):"",k(),...e):console.log.bind(console):e}function et(t,e,n="",i){t.debug=tt(e,n,i)}class nt{constructor(t,e={}){this.workspace=t,this.props=e,et(this,e.debug,e.debugPrefix,e.debugColor),this.initComponent(e)}initComponent(){}}const it={b:"\b",f:"\f",n:"\n",r:"\r",t:"\t",v:"\v",'"':'"',"'":"'","\\":"\\"},rt=t=>{const e=t.match(/^"((?:\\[\\"bfnrtv]|.)*?)"$/);return e?e[1].replace(/\\([\\"bfnrtv])/g,((t,e)=>it[e]||`\\${e}`)):null},ot=t=>{const e=t.match(/^'((?:\\[\\'bfnrtv]|.)*?)'$/);return e?e[1].replace(/\\([\\'bfnrtv])/g,((t,e)=>it[e]||`\\${e}`)):null},st=t=>{let e,i,r=[];for(;t.length;){let o,s;(i=t.match(/^(\/+)/))?t=t.slice(i[1].length):(t.match(/^(\?)/)&&(t=t.slice(1),o=!0),(i=t.match(/^('((\\[\\'bfnrtv]|.)*?)')/))?(t=t.slice(i[1].length),e=i[2].replace(/\\([\\'bfnrtv])/g,((t,e)=>it[e]||`\\${e}`))):(i=t.match(/^("((\\[\\"bfnrtv]|.)*?)")/))?(t=t.slice(i[1].length),e=i[2].replace(/\\([\\"bfnrtv])/g,((t,e)=>it[e]||`\\${e}`))):(i=t.match(/^([^/?]+)/))?(e=i[1],t=t.slice(e.length)):n(`Can't parse data path: ${t}`),t.match(/^(\?)/)&&(t=t.slice(1),s=!0),o?r.push([e,{maybe:!0}]):s?r.push([e,{optional:!0}]):r.push(e))}return r},at=(t,e)=>{let o=t,s=st(e),a=[];for(let t of s){const[e,s]=i(t)?t:[t,{}],c=o[e];if(a.push(e),r(c)){if(s.maybe)return o;if(s.optional)return;n("No value for data at path: ",a.join("/"))}o=c}return o},ct={codec:["yaml","json"],jsExt:["js","mjs"]};class lt extends g{constructor(t,e={}){super(t);const n={...ct,...e};this.state.codec=o(n.codec),this.state.jsExt=o(n.jsExt),et(this,e.debug,e.debugPrefix,e.debugColor)}async firstFileWithExt(t,n,i=e){const r=await this.dirs();for(let e of r)for(let r of n){const n=t+"."+r,o=e.file(n,i(t,r));if(this.debug("looking for config file: ",o.path()),await o.exists())return this.debug("config file exists: ",o.path()),o}}async jsFile(t){return await this.firstFileWithExt(t,this.state.jsExt)}async file(t){return await this.firstFileWithExt(t,this.state.codec,((t,e)=>({codec:e})))}async config(t,e){const[i,r]=t.split("#",2);let o,s,a;if(o=await this.jsFile(i))a=await import(o.path());else if(s=await this.file(i))a=await s.read();else{if(!e)return n("No configuration file for "+i);a=e}return r?at(a,r):a}}const ut=(t,e)=>new lt(t,e),ht={jsExt:"js mjs"};class pt extends g{constructor(t,e={}){super(t);const n={...ht,...e},i=o(n.jsExt).map((t=>t.replace(/^\./,"")));this.state.exts=i,et(this,e.debug,e.debugPrefix,e.debugColor),this.debug("state: ",this.state)}async library(t){const[e,i]=t.split("#",2),r=await this.dirs(),o=this.state.exts;for(let t of r)for(let n of o){const r=t.file(e+"."+n);this.debug("looking for module %s as",e,r.path());if(await r.exists()){const t=await import(r.path());return this.debug("loaded %s as",r.path()),i?at(t,i):t}}n("Library not found: ",t)}}const ft=(t,e)=>new pt(t,e),gt=t=>async function(...e){try{const n=await t(...e);return n&&console.log(I(`✓ ${n}`)),!0}catch(t){return console.log(b.env.DEBUG?t:W(`✗ ${t.message||t}`)),!1}},dt=async(t,e={})=>{const n=(e=s(e)?{default:e}:e).name||"answer";return(await w([{name:n,type:e.type||"text",message:t,initial:e.default}]))[n]},mt=async(t,e={})=>(e=a(e)?{default:e}:e,dt(t,{...e,type:"confirm"})),bt=async(t,e,n)=>(await w([{type:"select",name:"selected",message:t,initial:n,choices:i(e)?e:Object.entries(e).map((([t,e])=>({value:t,title:e})))}])).selected,wt=()=>b.argv.slice(2);function yt(t,e){t?i(t)&&(e=t,t={}):t={},e||(e||=wt());const r=!!t.options&&c(t.options),o=t.others||"error",s=t.short||{},a=t.on||{};let u=0,h={};for(;u<e.length;){const t=e[u].match(/^-(-)?(.*)/);if(t){const i=!("-"===t[1])&&l(s[t[2]])?s[t[2]]:t[2];if(a[i]){if(a[i](i,e.splice(u,1)[0],e,h))continue;e.splice(u,0,t[0])}if(r&&!r[i])switch(o){case"collect":break;case"remove":e.splice(u,1)[0];case"keep":u++;continue;case"error":return n(`Invalid command line flag: ${t[0]}`);default:return n(`Invalid "others" option: ${o}`)}e.splice(u,1),h[i]=!0}else u++}return{flags:h,args:e}}async function vt(t,e=wt()){return e.length?e.shift():t?await dt(t):void 0}async function xt(t,e=wt()){let n=[];if(t){for(let i of t){const t=await vt(i,e);if(!t?.length)return;n.push(t)}return n}return e}function Ct(t,e){e&&console.log(e),b.exit(t)}function $t(t){Ct(0,t)}function jt(t){Ct(1,t)}function kt(t=b.argv){return t.slice(2)}const Et={verboseColor:"magenta",titleColor:"bright yellow",underlineColor:"dark yellow",infoColor:"cyan",tickColor:"green",questionColor:"bright white",answerColor:"bright green",sectionNewlines:!0},Dt=async t=>{const e=E(Dt.verboseColor||Et.verboseColor),i=new y;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=>!(l(t.arg)&&!t.arg)&&(t.title?void 0:l(t.name)))).forEach((t=>{const e=t.name,n=t.about,r=t.default,o=t.handler,s=t.short,a=t.type,c=t.pattern||(l(a)?`<${a}>`:void 0);let u=`--${e}`,h=[];l(s)&&(u=`-${s}, ${u}`),l(c)&&(u=`${u} ${c}`),h.push(u),l(n)&&h.push(n),l(o)&&h.push(o),l(r)&&h.push(r),i.option(...h)}));let r={};t.commands?.forEach((t=>{const e=t.name,s=t.about,a=t.type,c=t.pattern||(l(a)?`<${a}>`:void 0);let u=[],h=e,p=i.command(h);l(c)&&p.argument(c),l(s)&&p.description(s),l(t.arguments)&&o(t.arguments).forEach((t=>{u.push(function(t){const e=t.match(/(\w+)/);e||n("Can't parse argument name: ",t);return e[1]}(t)),p.argument(t)})),p.action(((...t)=>{r[e]=u.length?u.reduce(((e,n)=>(e[n]=t.shift(),e)),{}):t[0]}))})),i.parse();const s=i.opts(),a=t.yes&&s.yes,c=t.verbose&&s.verbose,u=t.quiet&&s.quiet;a&&(c&&!u&&b.stdout.write(e("Accepting default answers (-y option is set)\n")),w.override(s));let h=[];t.options?.forEach((t=>{const e=t.type||"text",n=t.name,i=t.prompt,r=l(t.arg)&&!t.arg,o=t.validate||(t.required?t=>!(!l(t)||!t.toString().length)||(Dt.invalid||`You must enter a value for ${n}`):void 0);let c=r?t.default:s[n];"select"===e&&l(c)&&(Number.isInteger(c)||(c=t.choices?.findIndex((t=>t.value===c)),c<0&&(c=0))),l(i)?h.push({...t,type:l(c)?()=>(a&&(u||Ft({question:i,answer:c})),e):e,name:n,message:i,initial:c,validate:o}):(t.title||t.info)&&h.push({type:()=>(u||qt(t),!1)})}));let p=!1;const f=await w(h,{onCancel:()=>(p=!0,!1)});return p?void 0:{...s,...f,...r}};const qt=t=>{const e=t.title,n=E(t.titleColor||Et.titleColor),i=E(t.underlineColor||Et.underlineColor),r=E(t.infoColor||Et.infoColor),o=(l(t.newlines)?t.newlines:Et.sectionNewlines)?"\n":"";if(e){const t="-".repeat(e.length);b.stdout.write(o+n(e)+"\n"+i(t)+"\n"+o)}t.info&&b.stdout.write(r(t.info)+"\n"+o)},Ft=t=>{const e=E(t.tickColor||Et.tickColor),n=E(t.questionColor||Et.questionColor),i=E(t.answerColor||Et.answerColor);b.stdout.write(e("✔ ")+n(t.question)+" "+i(t.answer)+"\n")};function Pt(t={},e){const i=t[e];if(l(i))return i;n("Missing value for required parameter: ",e)}function Tt(t={},e){return o(e).map((e=>Pt(t,e)))}const St=Tt;function Nt(t,e){let i=!1;const r=o(e),s=r.map((e=>{const n=t[e];return l(n)&&(i=!0),n}));return i?s:n("Missing value for one of: ",u(r))}const zt={border:"┌─┐│└─┘|-",background:"+∙",fill:"*"},At={border:"green",background:"dark grey",foreground:"blue",fill:"bright yellow"},Mt={charTypes:zt,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"},Wt={size:100,elapsed:!1,picture:Mt,colours:At};function It(t){const{source:e,charTypes:n={background:""}}=t,i=e.trim()+"\n",r=i.length,o=Object.entries(n).reduce(((t,[e,n])=>(n.split("").forEach((n=>t[n]=e)),t)),{});return{picture:i,length:r,lineLength:e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0),charType:o}}function Gt(t){return Object.entries(t).reduce(((t,[e,n])=>(t[e]=E(n),t)),{})}function Lt(t){const{picture:e,charType:n={},colours:i={}}=t;return e.split("").map((t=>{const e=n[t]||"foreground",r=i[e];return r?r(t):t})).join("")}function Ot(t){const e=t%60,n=Math.floor(t/60);return[Math.floor(t/3600),n,e].map((t=>t.toString().padStart(2,"0"))).join(":")}class Ut{constructor(t={}){const e={...Wt,...h(t)?{size:t}:t},{size:n,colours:i,colors:r,debug:o,elapsed:a}=e,{picture:c,length:l,lineLength:u,charType:p}=It(s(e.picture)?{source:e.picture,charTypes:zt}:e.picture);this.size=n,this.picture=c,this.pixels=this.picture.split(""),this.length=l,this.lineLength=u,this.charType=p,this.colours=Gt(r||i),this.count=0,this.lastCount=0,this.lastPixel=0,this.startTime=v().epochSeconds(),this.elapsed=0,this.elapsedCol=E("dark grey"),this.showElapsed=a,this.debugging=o,et(this,o,"Progress > ","blue")}progress(t=1){this.count+=t;const e=v().epochSeconds()-this.startTime;this.elapsed=e;const n=Math.floor(this.length*this.count/this.size);if(n>this.lastPixel){const t=this.lastPixel;return this.lastPixel=n,this.debug(`count: ${this.count}/${this.size} pixels from ${t} to ${n}`),this.pictureSegment(t,n)}return""}remains(){this.count=this.size;const t=this.lastPixel,e=this.length;return e>t?(this.lastPixel=this.length,this.pictureSegment(t,e)):""}pictureSegment(t,e){if(this.debugging)return"";let n=Lt({picture:this.picture.substring(t,e),charType:this.charType,colours:this.colours});if(this.showElapsed&&n.match("\n")){const t=n.split("\n"),e=t.pop();n=t.map((t=>t+" "+this.elapsedCol(Ot(this.elapsed)))).join("\n").concat("\n",e)}return n}printProgress(t=1){b.stdout.write(this.progress(t))}printRemains(){b.stdout.write(this.remains())}}const Rt=t=>new Ut(t),Bt={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:t=>`\n#=============================================================================\n# WARNING: This file is generated automatically when the ${t.scriptName}\n# script is run. Any changes made here may be lost.\n#\n# Generated: ${v()}\n#=============================================================================\n\n`},Ht=gt((async t=>{await Qt(t)}));async function Qt(t){const e={...Bt,...t},i=e.rootDir?d(e.rootDir):m(),r=i.file(e.envFile);x.config({path:r.path()});const o=b.env,s=i.file(e.dataFile,{codec:"auto"}),c=await s.exists()?await s.read():{},u=e.configFile?i.file(e.configFile,{codec:"auto"}):await Vt(i,e.configFiles),h=await u.read();h.name||=e.name||b.argv[1].replace(i.path()+"/",""),h.version||=e.version,h.description||=e.description,t.preprocess&&await t.preprocess(h);const f={root:i.path(),...e.values||{}},g={quiet:!0,verbose:!0,yes:!0};for(let t of h.options){const{name:e,save:n}=t;if(a(n)&&!n&&(g[e]=!0),!e)continue;t.pattern&&(t.type||="text");const i=t.envvar||=e.toUpperCase();l(o[i])?t.default=o[i]:l(c[e])?t.default=c[e]:l(f[e])?t.default=f[e]:t.program&&(t.default=await Yt(t.program),t.pattern||="<path>")}const w=await Dt(h);w||$t("\n👎 "+W(e.cancelled));const{debug:y,verbose:v,quiet:C}=w;return e.writeData&&(await s.write(p(w,(t=>!g[t]))),v&&console.log(I(`✓ Wrote data file: ${s}`))),e.writeEnv&&(await r.write(await async function(t,e,i,r){const{compact:o,envComments:s,envSections:c}=e,u=o?"":"\n";let h=[Jt(e.warning(e))];const p="#"+"-".repeat(77),f="#"+"=".repeat(77);for(let t of i.options){const{name:e,envvar:n,title:i,about:f,save:g}=t;if(!a(g)||g)if(i&&c)h.push(`${u}\n${p}\n${Jt(i)}\n${p}`);else if(o||h.push(""),f&&s&&h.push(`${Jt(f)}`),e){const t=r[e];if(l(t)){const i=t.toString().match(/[#\r\n]/)?'"$value"':t;h.push(`${n||e.toUpperCase()}=${i}`)}else h.push(Jt(`No value for ${n||e.toUpperCase()}`))}}if(e.envExtra){const i=t.file(e.envExtra);await i.exists()||n(`Cannot find envExtra file: ${e.envExtra}`),c&&h.push("\n",f,Jt(` Additional configuration copied from ${e.envExtra}`),f,""),h.push(await i.read())}return h.join("\n")+"\n"}(i,e,h,w)),v&&console.log(I(`✓ Wrote .env file: ${r}`))),y&&console.log("\nGenerated configuration:",w),e.allDone&&!C&&console.log("\n👍 ",I(e.allDone),"\n"),w}async function Vt(t,e=[]){for(let n of e){const e=t.file(n,{codec:"auto"});if(await e.exists())return e}n("Can't find a configFile: ",e.join(", "))}async function Yt(t){for(let e of o(t))for(let t of b.env.PATH.split(":")){const n=d(t).file(e);if(await n.exists())return n.path()}}function Jt(t){return f(t.trim()).map((t=>t.match(/^#/)?t:`# ${t}`)).join("\n")}const Kt={dir:"config"},Xt={dir:"lib library src components"},Zt={};class _t{constructor(t,e={}){const n=d(t),i=o(e.config?.dir||Kt.dir).map((t=>n.dir(t))),r={...Kt,...e.config||{}},s=new lt(i,r),a=o(e.library?.dir||Xt.dir).map((t=>n.dir(t))),c={...Xt,...e.library||{}},l=new pt(a,c);this.case={...Zt,...e.case||{}},this.state={rootDir:n,config:s,library:l},et(this,e.debug,e.debugPrefix,e.debugColor),this.debug("root dir: ",n.path()),this.debug("config dir: ",i.map((t=>t.path()))),this.debug("libDirs: ",a),this.debug("libOpts: ",c)}dir(t,e){return this.debug("dir(%s, %o)",t,e),l(t)?this.state.rootDir.dir(t,e):this.state.rootDir}file(t,e){return this.debug("file(%s, %o)",t,e),this.state.rootDir.file(t,e)}read(t,e){return this.debug("read(%s, %o)",t,e),this.file(t,e).read()}write(t,e,n){return this.debug("write(%s, %o, %o)",t,e,n),this.file(t,n).write(e)}configDir(t,e){return this.debug("configDir(%s, %o)",t,e),l(t)?this.state.configDir.dir(t,e):this.state.configDir}async config(t,e){return this.debug("config(%s, %o)",t,e),l(t)?this.state.config.config(t,e):this.state.config}async library(t){return this.debug("library(%s, %o)",t),l(t)?this.state.library.library(t):this.state.library}async component(t,e){const[i,r]=t.split("#",2),o=this.convertCase("config",i),s=await this.config(o,{}),a=s.component?.library||this.convertCase("library",i),c=await this.library(a),l=r||s.component?.export||"default";return new(c[l]||n("No '",l,"' export from component library: ",t))(this,{...s,...e})}convertCase(t,e){const n=this.case[t];return n?n(e):e}}const te=(t,e)=>new _t(t,e);export{j as ANSIescape,$ as ANSIescapeCode,k as ANSIreset,nt as Component,lt as Config,tt as Debugger,pt as Library,Ut as Progress,_t as Workspace,jt as abort,et as addDebug,St as allParams,Ft as answer,Nt as anyParams,gt as appStatus,kt as args,D as black,T as blue,M as brightBlack,L as brightBlue,U as brightCyan,I as brightGreen,R as brightGrey,O as brightMagenta,W as brightRed,B as brightWhite,G as brightYellow,zt as charTypes,wt as cmdLine,vt as cmdLineArg,xt as cmdLineArgs,yt as cmdLineFlags,E as color,At as colours,ut as config,mt as confirm,N as cyan,H as darkBlack,J as darkBlue,X as darkCyan,V as darkGreen,Z as darkGrey,K as darkMagenta,Q as darkRed,_ as darkWhite,Y as darkYellow,at as dataPath,Et as defaults,Ct as exit,Vt as findFirstFile,Yt as findProgram,Ot as formatElapsed,Lt as formatPicture,F as green,z as grey,ft as library,S as magenta,rt as matchDoubleQuotedString,ot as matchSingleQuotedString,Dt as options,Mt as picture,Gt as prepareColours,It as preparePicture,Rt as progress,dt as prompt,$t as quit,q as red,Pt as requiredParam,Tt as requiredParams,Qt as runSetup,qt as section,bt as select,Ht as setup,st as splitDataPath,A as white,te as workspace,P as yellow};
1
+ import{isObject as t,doNothing as e,fail as n,isArray as o,noValue as r,splitList as i,isString as s,isBoolean as a,splitHash as c,hasValue as l,joinListOr as h,isInteger as p,extract as u,splitLines as g,debounce as f,sleep as d}from"@abw/badger-utils";import{DirPath as m,dir as b,cwd as w,file as y}from"@abw/badger-filesystem";export*from"@abw/badger-filesystem";import $ from"node:process";import v from"prompts";import{Command as x}from"commander";import{now as C}from"@abw/badger-timestamp";import j from"dotenv";import k from"chokidar";import E from"node:child_process";export*from"@abw/badger-codecs";const T={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},D=(t,e="fg")=>{let n=[],o=t.split(/ /,2);const r=o.pop(),i=(e?T[e]:0)+T[r];if(n.push(i),o.length){const t=o.length?o.shift():"dark";n.push(T[t])}return"["+n.join(";")+"m"},P=(e={})=>{const n=t(e)?e:{fg:e};let o=[];return n.bg&&o.push(D(n.bg,"bg")),n.fg&&o.push(D(n.fg,"fg")),o.join("")},q=()=>D("reset",!1),F=t=>(...e)=>P(t)+e.join("")+q(),N=t=>Object.entries(t).reduce(((t,[e,n])=>(t[e]=F(n),t)),{}),S=F("black"),z=F("red"),A=F("green"),W=F("yellow"),I=F("blue"),L=F("magenta"),M=F("cyan"),O=F("grey"),U=F("white"),G=F("bright black"),R=F("bright red"),V=F("bright green"),Y=F("bright yellow"),B=F("bright blue"),H=F("bright magenta"),Q=F("bright cyan"),_=F("bright grey"),J=F("bright white"),K=F("dark black"),X=F("dark red"),Z=F("dark green"),tt=F("dark yellow"),et=F("dark blue"),nt=F("dark magenta"),ot=F("dark cyan"),rt=F("dark grey"),it=F("dark white");function st(t,n="",o){return t?n?(t,...e)=>console.log("%s"+n+"%s"+t,o?P(o):"",q(),...e):console.log.bind(console):e}function at(t,e,n="",o){t.debug=st(e,n,o)}class ct{constructor(t,e={}){this.workspace=t,this.props=e,at(this,e.debug,e.debugPrefix,e.debugColor),this.initComponent(e)}initComponent(){}}const lt={b:"\b",f:"\f",n:"\n",r:"\r",t:"\t",v:"\v",'"':'"',"'":"'","\\":"\\"},ht=t=>{const e=t.match(/^"((?:\\[\\"bfnrtv]|.)*?)"$/);return e?e[1].replace(/\\([\\"bfnrtv])/g,((t,e)=>lt[e]||`\\${e}`)):null},pt=t=>{const e=t.match(/^'((?:\\[\\'bfnrtv]|.)*?)'$/);return e?e[1].replace(/\\([\\'bfnrtv])/g,((t,e)=>lt[e]||`\\${e}`)):null},ut=t=>{let e,o,r=[];for(;t.length;){let i,s;(o=t.match(/^(\/+)/))?t=t.slice(o[1].length):(t.match(/^(\?)/)&&(t=t.slice(1),i=!0),(o=t.match(/^('((\\[\\'bfnrtv]|.)*?)')/))?(t=t.slice(o[1].length),e=o[2].replace(/\\([\\'bfnrtv])/g,((t,e)=>lt[e]||`\\${e}`))):(o=t.match(/^("((\\[\\"bfnrtv]|.)*?)")/))?(t=t.slice(o[1].length),e=o[2].replace(/\\([\\"bfnrtv])/g,((t,e)=>lt[e]||`\\${e}`))):(o=t.match(/^([^/?]+)/))?(e=o[1],t=t.slice(e.length)):n(`Can't parse data path: ${t}`),t.match(/^(\?)/)&&(t=t.slice(1),s=!0),i?r.push([e,{maybe:!0}]):s?r.push([e,{optional:!0}]):r.push(e))}return r},gt=(t,e)=>{let i=t,s=ut(e),a=[];for(let t of s){const[e,s]=o(t)?t:[t,{}],c=i[e];if(a.push(e),r(c)){if(s.maybe)return i;if(s.optional)return;n("No value for data at path: ",a.join("/"))}i=c}return i},ft={codec:["yaml","json"],jsExt:["js","mjs"]};class dt extends m{constructor(t,e={}){super(t);const n={...ft,...e};this.state.codec=i(n.codec),this.state.jsExt=i(n.jsExt),at(this,e.debug,e.debugPrefix,e.debugColor)}async firstFileWithExt(t,n,o=e){const r=await this.dirs();for(let e of r)for(let r of n){const n=t+"."+r,i=e.file(n,o(t,r));if(this.debug("looking for config file: ",i.path()),await i.exists())return this.debug("config file exists: ",i.path()),i}}async jsFile(t){return await this.firstFileWithExt(t,this.state.jsExt)}async file(t){return await this.firstFileWithExt(t,this.state.codec,((t,e)=>({codec:e})))}async config(t,e){const[o,r]=t.split("#",2);let i,s,a;if(i=await this.jsFile(o))a=await import(i.path());else if(s=await this.file(o))a=await s.read();else{if(!e)return n("No configuration file for "+o);a=e}return r?gt(a,r):a}}const mt=(t,e)=>new dt(t,e),bt={jsExt:"js mjs"};class wt extends m{constructor(t,e={}){super(t);const n={...bt,...e},o=i(n.jsExt).map((t=>t.replace(/^\./,"")));this.state.exts=o,at(this,e.debug,e.debugPrefix,e.debugColor),this.debug("state: ",this.state)}async library(t){const[e,o]=t.split("#",2),r=await this.dirs(),i=this.state.exts;for(let t of r)for(let n of i){const r=t.file(e+"."+n);this.debug("looking for module %s as",e,r.path());if(await r.exists()){const t=await import(r.path());return this.debug("loaded %s as",r.path()),o?gt(t,o):t}}n("Library not found: ",t)}}const yt=(t,e)=>new wt(t,e),$t=t=>async function(...e){try{const n=await t(...e);return n&&console.log(V(`✓ ${n}`)),!0}catch(t){return console.log($.env.DEBUG?t:R(`✗ ${t.message||t}`)),!1}},vt=async(t,e={})=>{const n=(e=s(e)?{default:e}:e).name||"answer";return(await v([{name:n,type:e.type||"text",message:t,initial:e.default}]))[n]},xt=async(t,e={})=>(e=a(e)?{default:e}:e,vt(t,{...e,type:"confirm"})),Ct=async(t,e,n)=>(await v([{type:"select",name:"selected",message:t,initial:n,choices:o(e)?e:Object.entries(e).map((([t,e])=>({value:t,title:e})))}])).selected,jt=()=>$.argv.slice(2);function kt(t,e){t?o(t)&&(e=t,t={}):t={},e||(e||=jt());const r=!!t.options&&c(t.options),i=t.others||"error",s=t.short||{},a=t.on||{};let h=!1,p=0,u={};for(;p<e.length;){const t=e[p].match(/^-(-)?(.*)/);if("--"===e[p]&&(h=!0,e.splice(p,1)),t&&!h){const o=!("-"===t[1])&&l(s[t[2]])?s[t[2]]:t[2];if(a[o]){if(a[o](o,e.splice(p,1)[0],e,u))continue;e.splice(p,0,t[0])}if(r&&!r[o])switch(i){case"collect":break;case"remove":e.splice(p,1)[0];case"keep":p++;continue;case"error":return n(`Invalid command line flag: ${t[0]}`);default:return n(`Invalid "others" option: ${i}`)}e.splice(p,1),u[o]=!0}else p++}return{flags:u,args:e}}async function Et(t,e=jt()){return e.length?e.shift():t?await vt(t):void 0}async function Tt(t,e=jt()){let n=[];if(t){for(let o of t){const t=await Et(o,e);if(!t?.length)return;n.push(t)}return n}return e}function Dt(t,e){e&&console.log(e),$.exit(t)}function Pt(t){Dt(0,t)}function qt(t){Dt(1,t)}function Ft(t=$.argv){return t.slice(2)}const Nt={verboseColor:"magenta",titleColor:"bright yellow",underlineColor:"dark yellow",infoColor:"cyan",tickColor:"green",questionColor:"bright white",answerColor:"bright green",sectionNewlines:!0},St=async t=>{const e=F(St.verboseColor||Nt.verboseColor),o=new x;t.name&&o.name(t.name),t.description&&o.description(t.description),t.version&&o.version(t.version),t.yes&&o.option("-y, --yes","Accept default answers"),t.verbose&&o.option("-v, --verbose","Verbose output"),t.quiet&&o.option("-q, --quiet","Quiet output"),t.options?.filter((t=>!(l(t.arg)&&!t.arg)&&(t.title?void 0:l(t.name)))).forEach((t=>{const e=t.name,n=t.about,r=t.default,i=t.handler,s=t.short,a=t.type,c=t.pattern||(l(a)?`<${a}>`:void 0);let h=`--${e}`,p=[];l(s)&&(h=`-${s}, ${h}`),l(c)&&(h=`${h} ${c}`),p.push(h),l(n)&&p.push(n),l(i)&&p.push(i),l(r)&&p.push(r),o.option(...p)}));let r={};t.commands?.forEach((t=>{const e=t.name,s=t.about,a=t.type,c=t.pattern||(l(a)?`<${a}>`:void 0);let h=[],p=e,u=o.command(p);l(c)&&u.argument(c),l(s)&&u.description(s),l(t.arguments)&&i(t.arguments).forEach((t=>{h.push(function(t){const e=t.match(/(\w+)/);e||n("Can't parse argument name: ",t);return e[1]}(t)),u.argument(t)})),u.action(((...t)=>{r[e]=h.length?h.reduce(((e,n)=>(e[n]=t.shift(),e)),{}):t[0]}))})),o.parse();const s=o.opts(),a=t.yes&&s.yes,c=t.verbose&&s.verbose,h=t.quiet&&s.quiet;a&&(c&&!h&&$.stdout.write(e("Accepting default answers (-y option is set)\n")),v.override(s));let p=[];t.options?.forEach((t=>{const e=t.type||"text",n=t.name,o=t.prompt,r=l(t.arg)&&!t.arg,i=t.validate||(t.required?t=>!(!l(t)||!t.toString().length)||(St.invalid||`You must enter a value for ${n}`):void 0);let c=r?t.default:s[n];"select"===e&&l(c)&&(Number.isInteger(c)||(c=t.choices?.findIndex((t=>t.value===c)),c<0&&(c=0))),l(o)?p.push({...t,type:l(c)?()=>(a&&(h||At({question:o,answer:c})),e):e,name:n,message:o,initial:c,validate:i}):(t.title||t.info)&&p.push({type:()=>(h||zt(t),!1)})}));let u=!1;const g=await v(p,{onCancel:()=>(u=!0,!1)});return u?void 0:{...s,...g,...r}};const zt=t=>{const e=t.title,n=F(t.titleColor||Nt.titleColor),o=F(t.underlineColor||Nt.underlineColor),r=F(t.infoColor||Nt.infoColor),i=(l(t.newlines)?t.newlines:Nt.sectionNewlines)?"\n":"";if(e){const t="-".repeat(e.length);$.stdout.write(i+n(e)+"\n"+o(t)+"\n"+i)}t.info&&$.stdout.write(r(t.info)+"\n"+i)},At=t=>{const e=F(t.tickColor||Nt.tickColor),n=F(t.questionColor||Nt.questionColor),o=F(t.answerColor||Nt.answerColor);$.stdout.write(e("✔ ")+n(t.question)+" "+o(t.answer)+"\n")};function Wt(t={},e){const o=t[e];if(l(o))return o;n("Missing value for required parameter: ",e)}function It(t={},e){return i(e).map((e=>Wt(t,e)))}const Lt=It;function Mt(t,e){let o=!1;const r=i(e),s=r.map((e=>{const n=t[e];return l(n)&&(o=!0),n}));return o?s:n("Missing value for one of: ",h(r))}const Ot={border:"┌─┐│└─┘|-",background:"+∙",fill:"*"},Ut={border:"green",background:"dark grey",foreground:"blue",fill:"bright yellow"},Gt={charTypes:Ot,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"},Rt={size:100,elapsed:!1,picture:Gt,colours:Ut};function Vt(t){const{source:e,charTypes:n={background:""}}=t,o=e.trim()+"\n",r=o.length,i=Object.entries(n).reduce(((t,[e,n])=>(n.split("").forEach((n=>t[n]=e)),t)),{});return{picture:o,length:r,lineLength:e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0),charType:i}}function Yt(t){return Object.entries(t).reduce(((t,[e,n])=>(t[e]=F(n),t)),{})}function Bt(t){const{picture:e,charType:n={},colours:o={}}=t;return e.split("").map((t=>{const e=n[t]||"foreground",r=o[e];return r?r(t):t})).join("")}function Ht(t){const e=t%60,n=Math.floor(t/60);return[Math.floor(t/3600),n,e].map((t=>t.toString().padStart(2,"0"))).join(":")}class Qt{constructor(t={}){const e={...Rt,...p(t)?{size:t}:t},{size:n,colours:o,colors:r,debug:i,elapsed:a}=e,{picture:c,length:l,lineLength:h,charType:u}=Vt(s(e.picture)?{source:e.picture,charTypes:Ot}:e.picture);this.size=n,this.picture=c,this.pixels=this.picture.split(""),this.length=l,this.lineLength=h,this.charType=u,this.colours=Yt(r||o),this.count=0,this.lastCount=0,this.lastPixel=0,this.startTime=C().epochSeconds(),this.elapsed=0,this.elapsedCol=F("dark grey"),this.showElapsed=a,this.debugging=i,at(this,i,"Progress > ","blue")}progress(t=1){this.count+=t;const e=C().epochSeconds()-this.startTime;this.elapsed=e;const n=Math.floor(this.length*this.count/this.size);if(n>this.lastPixel){const t=this.lastPixel;return this.lastPixel=n,this.debug(`count: ${this.count}/${this.size} pixels from ${t} to ${n}`),this.pictureSegment(t,n)}return""}remains(){this.count=this.size;const t=this.lastPixel,e=this.length;return e>t?(this.lastPixel=this.length,this.pictureSegment(t,e)):""}pictureSegment(t,e){if(this.debugging)return"";let n=Bt({picture:this.picture.substring(t,e),charType:this.charType,colours:this.colours});if(this.showElapsed&&n.match("\n")){const t=n.split("\n"),e=t.pop();n=t.map((t=>t+" "+this.elapsedCol(Ht(this.elapsed)))).join("\n").concat("\n",e)}return n}printProgress(t=1){$.stdout.write(this.progress(t))}printRemains(){$.stdout.write(this.remains())}}const _t=t=>new Qt(t),Jt={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:t=>`\n#=============================================================================\n# WARNING: This file is generated automatically when the ${t.scriptName}\n# script is run. Any changes made here may be lost.\n#\n# Generated: ${C()}\n#=============================================================================\n\n`},Kt=$t((async t=>{await Xt(t)}));async function Xt(t){const e={...Jt,...t},o=e.rootDir?b(e.rootDir):w(),r=o.file(e.envFile);j.config({path:r.path()});const i=$.env,s=o.file(e.dataFile,{codec:"auto"}),c=await s.exists()?await s.read():{},h=e.configFile?o.file(e.configFile,{codec:"auto"}):await Zt(o,e.configFiles),p=await h.read();p.name||=e.name||$.argv[1].replace(o.path()+"/",""),p.version||=e.version,p.description||=e.description,t.preprocess&&await t.preprocess(p);const g={root:o.path(),...e.values||{}},f={quiet:!0,verbose:!0,yes:!0};for(let t of p.options){const{name:e,save:n}=t;if(a(n)&&!n&&(f[e]=!0),!e)continue;t.pattern&&(t.type||="text");const o=t.envvar||=e.toUpperCase();l(i[o])?t.default=i[o]:l(c[e])?t.default=c[e]:l(g[e])?t.default=g[e]:t.program&&(t.default=await te(t.program),t.pattern||="<path>")}const d=await St(p);d||Pt("\n👎 "+R(e.cancelled));const{debug:m,verbose:y,quiet:v}=d;return e.writeData&&(await s.write(u(d,(t=>!f[t]))),y&&console.log(V(`✓ Wrote data file: ${s}`))),e.writeEnv&&(await r.write(await async function(t,e,o,r){const{compact:i,envComments:s,envSections:c}=e,h=i?"":"\n";let p=[ee(e.warning(e))];const u="#"+"-".repeat(77),g="#"+"=".repeat(77);for(let t of o.options){const{name:e,envvar:n,title:o,about:g,save:f}=t;if(!a(f)||f)if(o&&c)p.push(`${h}\n${u}\n${ee(o)}\n${u}`);else if(i||p.push(""),g&&s&&p.push(`${ee(g)}`),e){const t=r[e];if(l(t)){const o=t.toString().match(/[#\r\n]/)?'"$value"':t;p.push(`${n||e.toUpperCase()}=${o}`)}else p.push(ee(`No value for ${n||e.toUpperCase()}`))}}if(e.envExtra){const o=t.file(e.envExtra);await o.exists()||n(`Cannot find envExtra file: ${e.envExtra}`),c&&p.push("\n",g,ee(` Additional configuration copied from ${e.envExtra}`),g,""),p.push(await o.read())}return p.join("\n")+"\n"}(o,e,p,d)),y&&console.log(V(`✓ Wrote .env file: ${r}`))),m&&console.log("\nGenerated configuration:",d),e.allDone&&!v&&console.log("\n👍 ",V(e.allDone),"\n"),d}async function Zt(t,e=[]){for(let n of e){const e=t.file(n,{codec:"auto"});if(await e.exists())return e}n("Can't find a configFile: ",e.join(", "))}async function te(t){for(let e of i(t))for(let t of $.env.PATH.split(":")){const n=b(t).file(e);if(await n.exists())return n.path()}}function ee(t){return g(t.trim()).map((t=>t.match(/^#/)?t:`# ${t}`)).join("\n")}const ne={script:$.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"}};async function oe(t){const{config:e,cmdLine:n}=re(t),o=await n(),{watch:r,restart:i,program:s,programArgs:a}=o,{scanning:c,watching:l,starting:h,stopping:p,failed:u,stopped:g,change:m}=ie({...e,...o});let b,w=!1;c(),l(r);const y=()=>{b||(h(),b=E.spawn(s,a,{stdio:"inherit"}),b.on("exit",((t,e)=>{e||(t?u(t):g(),i?(b=null,d(500).then(y)):Dt(t))})))},$=f((()=>{b||(p(),b.kill(),b=null),y()}),300);k.watch(r).on("ready",(()=>{y(),w=!0})).on("all",((t,e)=>{w&&(m(t,e),$())}))}const re=t=>{const e={...ne,...t},n=e.colors=N({...ne.colors,...e.colors}),o=se(e),r=()=>Pt(o()),i=t=>qt(o(t));return{config:e,colors:n,helpText:o,help:r,barf:i,cmdLine:async()=>{const{flags:t,args:e}=kt({options:"watch restart verbose help",others:"keep",short:{w:"watch",r:"restart",v:"verbose",h:"help"},on:{help:r,watch:(t,e,n,o)=>(o.watch||=[],n.length||i("The -w option expects an argument!"),o.watch.push(n.shift()),!0)}}),[n,...o]=e,s=e.join(" ");return e.length<1&&i("No program specified to run!"),t.watch?.length||i("Nothing specified to watch!"),await y(n).exists()||i(`Program not found: ${n}`),{...t,progText:s,program:n,programArgs:o}}}},ie=({verbose:t,colors:n,prefix:o,progText:r})=>({scanning:()=>t?console.log(n.prefix(o),n.scanning("scanning...")):e,watching:r=>t?r.forEach((t=>console.log(n.prefix(o),n.watching("watching "),n.command(t)))):e,change:(r,i)=>t?console.log(n.prefix(o),n.change(`${r}`.padEnd(9)),n.command(i)):e,starting:()=>t?console.log(n.prefix(o),n.starting("starting "),n.command(r)):e,stopping:()=>t?console.log(n.prefix(o),n.stopping("stopping "),n.command(r)):e,failed:i=>t?console.log(n.prefix(o),n.failed(`failed ${i}`),n.command(r)):e,stopped:()=>t?console.log(n.prefix(o),n.stopped("stopped "),n.command(r)):e}),se=({colors:t,script:e})=>{const{watcher:n,arg:o,section:r,program:i,args:s,error:a}=t,c=n(e);return t=>`${c}\n${t?`\n${a(t)}\n`:""}\n${r("Usage")}\n\n $ ${c} [${o("options")}] ${i("program")} [${s("arg1 arg2 ...")}]\n\n${r("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 ${i("program")} should follow, along with any additional\n ${s("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${r("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${r("Examples")}\n\n $ ${c} ${o("-w .")} ${i("bin/foo.js")}\n $ ${c} ${o("-w lib -w config")} ${i("bin/foo.js")}\n $ ${c} ${o("-w lib -w config")} ${i("bin/foo.js")} ${s("bar baz")}\n $ ${c} ${o("-w lib -w config -v")} ${i("bin/foo.js")} ${s("bar baz")}\n $ ${c} ${o("-w lib -w config -v -r")} ${i("bin/foo.js")} ${s("bar baz")}\n`},ae={dir:"config"},ce={dir:"lib library src components"},le={};class he{constructor(t,e={}){const n=b(t),o=i(e.config?.dir||ae.dir).map((t=>n.dir(t))),r={...ae,...e.config||{}},s=new dt(o,r),a=i(e.library?.dir||ce.dir).map((t=>n.dir(t))),c={...ce,...e.library||{}},l=new wt(a,c);this.case={...le,...e.case||{}},this.state={rootDir:n,config:s,library:l},at(this,e.debug,e.debugPrefix,e.debugColor),this.debug("root dir: ",n.path()),this.debug("config dir: ",o.map((t=>t.path()))),this.debug("libDirs: ",a),this.debug("libOpts: ",c)}dir(t,e){return this.debug("dir(%s, %o)",t,e),l(t)?this.state.rootDir.dir(t,e):this.state.rootDir}file(t,e){return this.debug("file(%s, %o)",t,e),this.state.rootDir.file(t,e)}read(t,e){return this.debug("read(%s, %o)",t,e),this.file(t,e).read()}write(t,e,n){return this.debug("write(%s, %o, %o)",t,e,n),this.file(t,n).write(e)}configDir(t,e){return this.debug("configDir(%s, %o)",t,e),l(t)?this.state.configDir.dir(t,e):this.state.configDir}async config(t,e){return this.debug("config(%s, %o)",t,e),l(t)?this.state.config.config(t,e):this.state.config}async library(t){return this.debug("library(%s, %o)",t),l(t)?this.state.library.library(t):this.state.library}async component(t,e){const[o,r]=t.split("#",2),i=this.convertCase("config",o),s=await this.config(i,{}),a=s.component?.library||this.convertCase("library",o),c=await this.library(a),l=r||s.component?.export||"default";return new(c[l]||n("No '",l,"' export from component library: ",t))(this,{...s,...e})}convertCase(t,e){const n=this.case[t];return n?n(e):e}}const pe=(t,e)=>new he(t,e);export{P as ANSIescape,D as ANSIescapeCode,q as ANSIreset,ct as Component,dt as Config,st as Debugger,wt as Library,Qt as Progress,he as Workspace,qt as abort,at as addDebug,Lt as allParams,At as answer,Mt as anyParams,$t as appStatus,Ft as args,S as black,I as blue,G as brightBlack,B as brightBlue,Q as brightCyan,V as brightGreen,_ as brightGrey,H as brightMagenta,R as brightRed,J as brightWhite,Y as brightYellow,Ot as charTypes,jt as cmdLine,Et as cmdLineArg,Tt as cmdLineArgs,kt as cmdLineFlags,F as color,Ut as colours,mt as config,xt as confirm,M as cyan,K as darkBlack,et as darkBlue,ot as darkCyan,Z as darkGreen,rt as darkGrey,nt as darkMagenta,X as darkRed,it as darkWhite,tt as darkYellow,gt as dataPath,Nt as defaults,Dt as exit,Zt as findFirstFile,te as findProgram,Ht as formatElapsed,Bt as formatPicture,A as green,O as grey,yt as library,L as magenta,ht as matchDoubleQuotedString,pt as matchSingleQuotedString,St as options,N as palette,Gt as picture,Yt as prepareColours,Vt as preparePicture,_t as progress,vt as prompt,Pt as quit,z as red,Wt as requiredParam,It as requiredParams,Xt as runSetup,zt as section,Ct as select,Kt as setup,ut as splitDataPath,oe as watch,re as watcherFunctions,se as watcherHelpText,ie as watcherStatus,U as white,pe as workspace,W as yellow};
2
2
  //# sourceMappingURL=badger.esm.js.map