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