UNPKG

@decaf-ts/utils

Version:

module management utils for decaf-ts

1 lines 111 kB
var e,t;e=this,t=function(e,t,o,r,s,n,i,a,c,l,d,u,g,h,f,p,m,y,S,v,b,w){"use strict";function T(e){var t=Object.create(null);return e&&Object.keys(e).forEach(o=>{if("default"!==o){var r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:()=>e[o]})}}),t.default=e,Object.freeze(t)}var k=T(y);class C{static{this.logger=r.Logging.for(C)}constructor(e){this.type="text",this.name=e}setType(e){return C.logger.verbose("Setting type to: "+e),this.type=e,this}setMessage(e){return C.logger.verbose("Setting message to: "+e),this.message=e,this}setInitial(e){return C.logger.verbose("Setting initial value to: "+e),this.initial=e,this}setStyle(e){return C.logger.verbose("Setting style to: "+e),this.style=e,this}setFormat(e){return C.logger.verbose("Setting format function"),this.format=e,this}setValidate(e){return C.logger.verbose("Setting validate function"),this.validate=e,this}setOnState(e){return C.logger.verbose("Setting onState callback"),this.onState=e,this}setMin(e){return C.logger.verbose("Setting min value to: "+e),this.min=e,this}setMax(e){return C.logger.verbose("Setting max value to: "+e),this.max=e,this}setFloat(e){return C.logger.verbose("Setting float to: "+e),this.float=e,this}setRound(e){return C.logger.verbose("Setting round to: "+e),this.round=e,this}setInstructions(e){return C.logger.verbose("Setting instructions to: "+e),this.instructions=e,this}setIncrement(e){return C.logger.verbose("Setting increment to: "+e),this.increment=e,this}setSeparator(e){return C.logger.verbose("Setting separator to: "+e),this.separator=e,this}setActive(e){return C.logger.verbose("Setting active style to: "+e),this.active=e,this}setInactive(e){return C.logger.verbose("Setting inactive style to: "+e),this.inactive=e,this}setChoices(e){return C.logger.verbose("Setting choices: "+JSON.stringify(e)),this.choices=e,this}setHint(e){return C.logger.verbose("Setting hint to: "+e),this.hint=e,this}setWarn(e){return C.logger.verbose("Setting warn to: "+e),this.warn=e,this}setSuggest(e){return C.logger.verbose("Setting suggest function"),this.suggest=e,this}setLimit(e){return C.logger.verbose("Setting limit to: "+e),this.limit=e,this}setMask(e){return C.logger.verbose("Setting mask to: "+e),this.mask=e,this}setStdout(e){return C.logger.verbose("Setting stdout stream"),this.stdout=e,this}setStdin(e){return this.stdin=e,this}async ask(){return(await C.ask(this))[this.name]}static async ask(e){const o=C.logger.for(this.ask);let r;Array.isArray(e)||(e=[e]);try{o.verbose("Asking questions: "+e.map(e=>e.name).join(", ")),r=await t(e),o.verbose("Received answers: "+JSON.stringify(r,null,2))}catch(e){throw Error("Error while getting input: "+e)}return r}static async askNumber(e,t,o,r,s){C.logger.for(this.askNumber).verbose(`Asking number input: undefined, question: ${t}, min: ${o}, max: ${r}, initial: ${s}`);const n=new C(e).setMessage(t).setType("number");return"number"==typeof o&&n.setMin(o),"number"==typeof r&&n.setMax(r),"number"==typeof s&&n.setInitial(s),(await this.ask(n))[e]}static async askText(e,t,o=void 0,r){C.logger.for(this.askText).verbose(`Asking text input: undefined, question: ${t}, mask: ${o}, initial: ${r}`);const s=new C(e).setMessage(t);return o&&s.setMask(o),"string"==typeof r&&s.setInitial(r),(await this.ask(s))[e]}static async askConfirmation(e,t,o){C.logger.for(this.askConfirmation).verbose(`Asking confirmation input: undefined, question: ${t}, initial: ${o}`);const r=new C(e).setMessage(t).setType("confirm");return void 0!==o&&r.setInitial(o),(await this.ask(r))[e]}static async insist(e,t,o,r=1){const s=C.logger.for(this.insist);let n;s.verbose(`Insisting on input: ${e.name}, test: ${t.toString()}, defaultConfirmation: ${o}, limit: ${r}`);let i,a=0;try{do{n=(await C.ask(e))[e.name],t(n)?(i=await C.askConfirmation(e.name+"-confirm",`Is the ${e.type} correct?`,o),i||(n=void 0)):n=void 0}while(void 0===n&&r>1&&a++<r)}catch(e){throw s.error("Error while insisting: "+e),e}return void 0===n&&s.info("no selection..."),n}static async insistForText(e,t,o,r=void 0,s,n=!1,i=-1){C.logger.for(this.insistForText).verbose(`Insisting for text input: undefined, question: ${t}, test: ${o.toString()}, mask: ${r}, initial: ${s}, defaultConfirmation: ${n}, limit: ${i}`);const a=new C(e).setMessage(t);return r&&a.setMask(r),"string"==typeof s&&a.setInitial(s),await this.insist(a,o,n,i)}static async insistForNumber(e,t,o,r,s,n,i=!1,a=-1){C.logger.for(this.insistForNumber).verbose(`Insisting for number input: undefined, question: ${t}, test: ${o.toString()}, min: ${r}, max: ${s}, initial: ${n}, defaultConfirmation: ${i}, limit: ${a}`);const c=new C(e).setMessage(t).setType("number");return"number"==typeof r&&c.setMin(r),"number"==typeof s&&c.setMax(s),"number"==typeof n&&c.setInitial(n),await this.insist(c,o,i,a)}static parseArgs(e){const t=C.logger.for(this.parseArgs),r={args:process.argv.slice(2),options:e};t.debug("Parsing arguments: "+JSON.stringify(r,null,2));try{return o.parseArgs(r)}catch(o){throw t.debug(`Error while parsing arguments:\n${JSON.stringify(r,null,2)}\n | options\n${JSON.stringify(e,null,2)}\n | ${o}`),Error("Error while parsing arguments: "+o)}}}const E={verbose:{type:"boolean",short:"V",default:void 0},version:{type:"boolean",short:"v",default:void 0},help:{type:"boolean",short:"h",default:!1},logLevel:{type:"string",default:"info"},logStyle:{type:"boolean",default:!0},timestamp:{type:"boolean",default:!0},banner:{type:"boolean",default:!0}},$=Object.keys(E).reduce((e,t)=>(e[t]=E[t].default,e),{}),x="utf-8",D=/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z])))/g;var N;e.SemVersion=void 0,(N=e.SemVersion||(e.SemVersion={})).PATCH="patch",N.MINOR="minor",N.MAJOR="major";const R="-no-ci";var A;e.Tokens=void 0,(A=e.Tokens||(e.Tokens={})).GIT=".token",A.NPM=".npmtoken",A.DOCKER=".dockertoken",A.CONFLUENCE=".confluence-token";const F="Aborted";class O{constructor(e,t,...o){this.cmd=e,this.lock=t,this.logger=r.Logging.for(this.cmd)}log(e,t){t=Buffer.isBuffer(t)?t.toString(x):t;const o="stderr"===e?c.style(t).red.text:t;this.logger.info(o)}data(e){this.log("stdout",e+"")}error(e){this.log("stderr",e+"")}errors(e){this.log("stderr","Error executing command exited : "+e)}exit(e,t){this.log("stdout","command exited code : "+(0===e?c.style(e.toString()).green.text:c.style(null===e?"null":e.toString()).red.text)),0===e?this.resolve(t.map(e=>e.trim()).join("\n")):this.reject(Error(t.length?t.join("\n"):e.toString()))}parseCommand(e){if(Array.isArray(e))return this.cmd=e.join(" "),[e[0],e.slice(1)];const t=l.parse(e).filter(e=>"string"==typeof e).map(String);return this.cmd=t.join(" "),[t[0],t.slice(1)]}resolve(e){this.log("stdout",`${this.cmd} executed successfully: ${c.style(e?"ran to completion":e).green}`),this.lock.resolve(e)}reject(e){e instanceof Error||(e=Error("number"==typeof e?"Exit code "+e:e)),this.log("stderr",`${this.cmd} failed to execute: ${c.style(e.message).red}`),this.lock.reject(e)}}function _(e,...t){let o,r;if(e instanceof AbortSignal?(r=new AbortController,o=[e,...t]):(r=e,o=t),r.signal.aborted)return r;const s=()=>r.abort();for(const e of o){if(e.aborted){r.abort();break}e.addEventListener("abort",s,{once:!0,signal:r.signal})}return r}function I(e,t,o,r,s){function n(t,r){const[n,i]=e.parseCommand(t);s.info("Running command: "+n),s.debug("with args: "+i.join(" "));const c=a.spawn(n,i,{...o,cwd:o.cwd||process.cwd(),env:Object.assign({},process.env,o.env,{PATH:process.env.PATH}),shell:o.shell||!1,signal:r.signal});return s.verbose("pid : "+c.pid),c}const i=t.match(/[<>$#]/g);if(i)throw Error(`Invalid command: ${t}. contains invalid characters: ${i}`);if(t.includes(" | ")){const e=t.split(" | "),o=[],s=Array(e.length);s[0]=r;for(let t=0;t<e.length;t++)0!==t&&(s[t]=_(s[t-1].signal)),o.push(n(e[t],s[t])),0!==t&&o[t-1].stdout.pipe(o[t].stdin);return o[e.length-1]}return n(t,r)}function j(e,t={},o=O,...s){const n=r.Logging.for(j),i=new AbortController,a={abort:i,command:e,logs:[],errs:[]},c=new Promise((r,c)=>{let l;try{l=new o(e,{resolve:r,reject:c},...s),a.cmd=I(l,e,t,i,n)}catch(t){return c(Error(`Error running command ${e}: ${t}`))}a.cmd.stdout.setEncoding("utf8"),a.cmd.stdout.on("data",e=>{e=e.toString(),a.logs.push(e),l.data(e)}),a.cmd.stderr.on("data",e=>{e=e.toString(),a.errs.push(e),l.error(e)}),a.cmd.once("error",e=>{l.exit(e.message,a.errs)}),a.cmd.once("exit",(e=0)=>{i.signal.aborted&&null===e&&(e=F),l.exit(e,0===e?a.logs:a.errs)})});return Object.assign(a,{promise:c,pipe:async t=>{const o=n.for("pipe");try{o.verbose(`Executing pipe function ${e}...`);const r=await c;return o.verbose(`Piping output to ${t.name}: ${r}`),t(r)}catch(e){throw o.error("Error piping command output: "+e),e}}}),a}const M=r.Logging.for("fs"),P=i.createRequire(process.cwd()+"/package.json");function L(e,t,o){const n=M.for(L);if(!s.existsSync(e))throw Error(`File not found at path "${e}".`);let i=U(e);n.verbose(`Patching file "${e}"...`),n.debug("with value: "+JSON.stringify(t));try{i=((e,t,o="g",s)=>(Object.entries(t).forEach(([t,n])=>{const i=RegExp(r.escapeRegExp(t),o);e=e.replace(i,e=>(!s||s(e),n))}),e))(i,t,"g",o)}catch(e){throw Error("Error patching file: "+e)}B(e,i)}function U(e){const t=M.for(U);try{return t.verbose(`Reading file "${e}"...`),s.readFileSync(e,"utf8")}catch(o){throw t.verbose(`Error reading file "${e}": ${o}`),Error(`Error reading file "${e}": ${o}`)}}function B(e,t){const o=M.for(B);try{o.verbose(`Writing file "${e} with ${t.length} bytes...`),s.writeFileSync(e,t,"utf8")}catch(t){throw o.verbose(`Error writing file "${e}": ${t}`),Error(`Error writing file "${e}": ${t}`)}}function H(e,t){const o=M.for(H),r=[];try{return o.verbose(`Retrieving all files from "${e}"...`),s.readdirSync(e).forEach(t=>{const o=n.join(e,t),i=s.statSync(o);i.isFile()?r.push(o):i.isDirectory()&&r.push(...H(o))}),t?r.filter(t):r}catch(t){throw o.verbose(`Error retrieving files from "${e}": ${t}`),Error(`Error retrieving files from "${e}": ${t}`)}}function V(e,t){const o=M.for(V);let r,n;try{r=s.statSync(e)}catch(t){throw o.verbose(`Source path "${e}" does not exist: ${t}`),Error(`Source path "${e}" does not exist: ${t}`)}try{n=s.statSync(t)}catch(e){r.isDirectory()&&(o.verbose(`Dest path "${t}" does not exist. creating`),s.mkdirSync(t,{recursive:!0}))}try{o.verbose(`Copying ${r.isFile()?"file":"directory"} "${e}" to "${t}...`),s.cpSync(e,t,{recursive:!0})}catch(s){throw o.verbose(`Error copying ${r.isFile()?"file":"directory"} "${e}" to "${t}: ${s}`),Error(`Error copying ${r.isFile()?"file":"directory"} "${e}" to "${t}: ${s}`)}}function G(e){const t=M.for(G);try{const o=s.statSync(e);o.isFile()?(t.verbose(`Deleting file "${e}...`),s.rmSync(e,{recursive:!0,force:!0})):o.isDirectory()&&s.rmSync(e,{recursive:!0,force:!0})}catch(o){throw t.verbose(`Error Deleting "${e}": ${o}`),Error(`Error Deleting "${e}": ${o}`)}}function K(e=process.cwd(),t){let o;try{o=JSON.parse(U(n.join(e,"package.json")))}catch(e){throw Error('Failed to retrieve package information" '+e)}if(t){if(!(t in o))throw Error(`Property "${t}" not found in package.json`);return o[t]}return o}function W(e=process.cwd()){return K(e,"version")}async function J(e=process.cwd()){const t=n.join(e,"package.json"),o=n.join(e,"package-lock.json");let r,i;try{r=JSON.parse(U(t))}catch(e){throw Error(`Could not read package.json at ${t}: ${e}`)}if(s.existsSync(o))try{i=JSON.parse(U(o))}catch(e){M.warn(`Unable to parse package-lock.json at ${o}: ${e}`)}const a=(e={})=>Object.entries(e).map(([e,t])=>({name:e,version:q(i,e,t)}));return{prod:a(r.dependencies),dev:a(r.devDependencies),peer:a(r.peerDependencies)}}function q(e,t,o){if(e){const r=e.packages||{},s="node_modules/"+t;if(r[s]&&r[s].version)return r[s].version;if(e.dependencies&&e.dependencies[t])return e.dependencies[t].version||o}return o}async function z(e){const t=M.for(z),o=e.prod||[],r=e.dev||[],s=e.peer||[];o.length&&(t.info(`Installing dependencies ${o.join(", ")}...`),await j("npm install "+o.join(" "),{cwd:process.cwd()}).promise),r.length&&(t.info(`Installing devDependencies ${r.join(", ")}...`),await j("npm install --save-dev "+r.join(" "),{cwd:process.cwd()}).promise),s.length&&(t.info(`Installing peerDependencies ${s.join(", ")}...`),await j("npm install --save-peer "+s.join(" "),{cwd:process.cwd()}).promise)}async function X(e){const t=M.for(X);try{const o=s.readdirSync(e).map(t=>n.join(e,t)).filter(e=>{try{return s.statSync(e).isFile()&&(e.endsWith(".js")||e.endsWith(".cjs")||e.endsWith(".mjs"))}catch{return!1}});if(0===o.length)throw Error("No JS files found in directory "+e);let r=o[0],i=s.statSync(r).size;for(const e of o.slice(1)){const t=s.statSync(e).size;i>t&&(r=e,i=t)}t.verbose(`Selected smallest bundle: ${r} (${i} bytes)`);const a=s.readFileSync(r),c=d.gzipSync(a),l=Number((c.length/1024).toFixed(1));return t.verbose(`Gzipped size: ${c.length} bytes (${l} KB)`),l}catch(o){throw t.verbose(`Failed to compute gzipped size for ${e}: ${o}`),o}}function Y(e=n.join(process.cwd(),"node_modules")){const t=M.for(Y);try{if(!s.existsSync(e))return[];const o=s.readdirSync(e,{withFileTypes:!0}),r=[];for(const i of o)try{if(!i.isDirectory())continue;if(i.name.startsWith("."))continue;if(i.name.startsWith("@")){const o=n.join(e,i.name);try{const e=s.readdirSync(o,{withFileTypes:!0});for(const t of e)t.isDirectory()&&!t.name.startsWith(".")&&r.push(`${i.name}/${t.name}`)}catch(e){t.verbose(`Failed to read scope ${o}: ${e}`)}}else r.push(i.name)}catch(e){t.verbose(`Skipping entry ${i.name} due to error: ${e}`)}return r}catch(o){return t.verbose(`Failed to list node_modules packages at ${e}: ${o}`),[]}}const Z=[{Slogan:"No caffeine, no chaos. Just clean code.",Tags:"Coffee-themed, Calm, Tech"},{Slogan:"Full flavor, no jitters. That's Decaf-TS.",Tags:"Coffee-themed, Cheerful"},{Slogan:"Chill fullstack. Powered by Decaf.",Tags:"Coffee-themed, Fun, Tech"},{Slogan:"Decaf-TS: Brewed for calm code.",Tags:"Coffee-themed, Branding"},{Slogan:"Smooth as your morning Decaf.",Tags:"Coffee-themed, Chill"},{Slogan:"All the kick, none of the crash.",Tags:"Coffee-themed, Energetic"},{Slogan:"Sip back and ship faster.",Tags:"Coffee-themed, Fun"},{Slogan:"Keep calm and code Decaf.",Tags:"Coffee-themed, Playful"},{Slogan:"Code without the caffeine shakes.",Tags:"Coffee-themed, Humorous"},{Slogan:"Your fullstack, decaffeinated.",Tags:"Coffee-themed, Technical"},{Slogan:"No caffeine, no chaos. Just clean code.",Tags:"Coffee-themed, Calm, Tech"},{Slogan:"Full flavor, no jitters. That\u2019s Decaf-TS.",Tags:"Coffee-themed, Cheerful"},{Slogan:"Chill fullstack. Powered by Decaf.",Tags:"Coffee-themed, Fun, Tech"},{Slogan:"Decaf-TS: Brewed for calm code.",Tags:"Coffee-themed, Branding"},{Slogan:"Smooth as your morning Decaf.",Tags:"Coffee-themed, Chill"},{Slogan:"All the kick, none of the crash.",Tags:"Coffee-themed, Energetic"},{Slogan:"Sip back and ship faster.",Tags:"Coffee-themed, Fun"},{Slogan:"Keep calm and code Decaf.",Tags:"Coffee-themed, Playful"},{Slogan:"Code without the caffeine shakes.",Tags:"Coffee-themed, Humorous"},{Slogan:"Your fullstack, decaffeinated.",Tags:"Coffee-themed, Technical"},{Slogan:"No caffeine, no chaos. Just clean code.",Tags:"Coffee-themed, Calm, Tech"},{Slogan:"Full flavor, no jitters. That\u2019s Decaf-TS.",Tags:"Coffee-themed, Cheerful"},{Slogan:"Chill fullstack. Powered by Decaf.",Tags:"Coffee-themed, Fun, Tech"},{Slogan:"Decaf-TS: Brewed for calm code.",Tags:"Coffee-themed, Branding"},{Slogan:"Smooth as your morning Decaf.",Tags:"Coffee-themed, Chill"},{Slogan:"All the kick, none of the crash.",Tags:"Coffee-themed, Energetic"},{Slogan:"Sip back and ship faster.",Tags:"Coffee-themed, Fun"},{Slogan:"Keep calm and code Decaf.",Tags:"Coffee-themed, Playful"},{Slogan:"Code without the caffeine shakes.",Tags:"Coffee-themed, Humorous"},{Slogan:"Your fullstack, decaffeinated.",Tags:"Coffee-themed, Technical"},{Slogan:"No caffeine, no chaos. Just clean code.",Tags:"Coffee-themed, Calm, Tech"},{Slogan:"Full flavor, no jitters. That\u2019s Decaf-TS.",Tags:"Coffee-themed, Cheerful"},{Slogan:"Chill fullstack. Powered by Decaf.",Tags:"Coffee-themed, Fun, Tech"},{Slogan:"Decaf-TS: Brewed for calm code.",Tags:"Coffee-themed, Branding"},{Slogan:"Smooth as your morning Decaf.",Tags:"Coffee-themed, Chill"},{Slogan:"All the kick, none of the crash.",Tags:"Coffee-themed, Energetic"},{Slogan:"Sip back and ship faster.",Tags:"Coffee-themed, Fun"},{Slogan:"Keep calm and code Decaf.",Tags:"Coffee-themed, Playful"},{Slogan:"Code without the caffeine shakes.",Tags:"Coffee-themed, Humorous"},{Slogan:"Your fullstack, decaffeinated.",Tags:"Coffee-themed, Technical"},{Slogan:"No caffeine, no chaos. Just clean code.",Tags:"Coffee-themed, Calm, Tech"},{Slogan:"Full flavor, no jitters. That\u2019s Decaf-TS.",Tags:"Coffee-themed, Cheerful"},{Slogan:"Chill fullstack. Powered by Decaf.",Tags:"Coffee-themed, Fun, Tech"},{Slogan:"Decaf-TS: Brewed for calm code.",Tags:"Coffee-themed, Branding"},{Slogan:"Smooth as your morning Decaf.",Tags:"Coffee-themed, Chill"},{Slogan:"All the kick, none of the crash.",Tags:"Coffee-themed, Energetic"},{Slogan:"Sip back and ship faster.",Tags:"Coffee-themed, Fun"},{Slogan:"Keep calm and code Decaf.",Tags:"Coffee-themed, Playful"},{Slogan:"Code without the caffeine shakes.",Tags:"Coffee-themed, Humorous"},{Slogan:"Your fullstack, decaffeinated.",Tags:"Coffee-themed, Technical"},{Slogan:"No caffeine, no chaos. Just clean code.",Tags:"Coffee-themed, Calm, Tech"},{Slogan:"Full flavor, no jitters. That\u2019s Decaf-TS.",Tags:"Coffee-themed, Cheerful"},{Slogan:"Chill fullstack. Powered by Decaf.",Tags:"Coffee-themed, Fun, Tech"},{Slogan:"Decaf-TS: Brewed for calm code.",Tags:"Coffee-themed, Branding"},{Slogan:"Smooth as your morning Decaf.",Tags:"Coffee-themed, Chill"},{Slogan:"All the kick, none of the crash.",Tags:"Coffee-themed, Energetic"},{Slogan:"Sip back and ship faster.",Tags:"Coffee-themed, Fun"},{Slogan:"Keep calm and code Decaf.",Tags:"Coffee-themed, Playful"},{Slogan:"Code without the caffeine shakes.",Tags:"Coffee-themed, Humorous"},{Slogan:"Your fullstack, decaffeinated.",Tags:"Coffee-themed, Technical"},{Slogan:"No caffeine, no chaos. Just clean code.",Tags:"Coffee-themed, Calm, Tech"},{Slogan:"Full flavor, no jitters. That\u2019s Decaf-TS.",Tags:"Coffee-themed, Cheerful"},{Slogan:"Chill fullstack. Powered by Decaf.",Tags:"Coffee-themed, Fun, Tech"},{Slogan:"Decaf-TS: Brewed for calm code.",Tags:"Coffee-themed, Branding"},{Slogan:"Smooth as your morning Decaf.",Tags:"Coffee-themed, Chill"},{Slogan:"All the kick, none of the crash.",Tags:"Coffee-themed, Energetic"},{Slogan:"Sip back and ship faster.",Tags:"Coffee-themed, Fun"},{Slogan:"Keep calm and code Decaf.",Tags:"Coffee-themed, Playful"},{Slogan:"Code without the caffeine shakes.",Tags:"Coffee-themed, Humorous"},{Slogan:"Your fullstack, decaffeinated.",Tags:"Coffee-themed, Technical"},{Slogan:"No caffeine, no chaos. Just clean code.",Tags:"Coffee-themed, Calm, Tech"},{Slogan:"Full flavor, no jitters. That\u2019s Decaf-TS.",Tags:"Coffee-themed, Cheerful"},{Slogan:"Chill fullstack. Powered by Decaf.",Tags:"Coffee-themed, Fun, Tech"},{Slogan:"Decaf-TS: Brewed for calm code.",Tags:"Coffee-themed, Branding"},{Slogan:"Smooth as your morning Decaf.",Tags:"Coffee-themed, Chill"},{Slogan:"All the kick, none of the crash.",Tags:"Coffee-themed, Energetic"},{Slogan:"Sip back and ship faster.",Tags:"Coffee-themed, Fun"},{Slogan:"Keep calm and code Decaf.",Tags:"Coffee-themed, Playful"},{Slogan:"Code without the caffeine shakes.",Tags:"Coffee-themed, Humorous"},{Slogan:"Your fullstack, decaffeinated.",Tags:"Coffee-themed, Technical"},{Slogan:"No caffeine, no chaos. Just clean code.",Tags:"Coffee-themed, Calm, Tech"},{Slogan:"Full flavor, no jitters. That\u2019s Decaf-TS.",Tags:"Coffee-themed, Cheerful"},{Slogan:"Chill fullstack. Powered by Decaf.",Tags:"Coffee-themed, Fun, Tech"},{Slogan:"Decaf-TS: Brewed for calm code.",Tags:"Coffee-themed, Branding"},{Slogan:"Smooth as your morning Decaf.",Tags:"Coffee-themed, Chill"},{Slogan:"All the kick, none of the crash.",Tags:"Coffee-themed, Energetic"},{Slogan:"Sip back and ship faster.",Tags:"Coffee-themed, Fun"},{Slogan:"Keep calm and code Decaf.",Tags:"Coffee-themed, Playful"},{Slogan:"Code without the caffeine shakes.",Tags:"Coffee-themed, Humorous"},{Slogan:"Your fullstack, decaffeinated.",Tags:"Coffee-themed, Technical"},{Slogan:"No caffeine, no chaos. Just clean code.",Tags:"Coffee-themed, Calm, Tech"},{Slogan:"Full flavor, no jitters. That\u2019s Decaf-TS.",Tags:"Coffee-themed, Cheerful"},{Slogan:"Chill fullstack. Powered by Decaf.",Tags:"Coffee-themed, Fun, Tech"},{Slogan:"Decaf-TS: Brewed for calm code.",Tags:"Coffee-themed, Branding"},{Slogan:"Smooth as your morning Decaf.",Tags:"Coffee-themed, Chill"},{Slogan:"All the kick, none of the crash.",Tags:"Coffee-themed, Energetic"},{Slogan:"Sip back and ship faster.",Tags:"Coffee-themed, Fun"},{Slogan:"Keep calm and code Decaf.",Tags:"Coffee-themed, Playful"},{Slogan:"Code without the caffeine shakes.",Tags:"Coffee-themed, Humorous"},{Slogan:"Your fullstack, decaffeinated.",Tags:"Coffee-themed, Technical"},{Slogan:"Decaf-TS: Where smart contracts meet smart interfaces.",Tags:"Blockchain, Smart Contracts, Tech"},{Slogan:"Ship dApps without the stress.",Tags:"Blockchain, Cheerful, Developer"},{Slogan:"No CRUD, no problem \u2014 Decaf your data.",Tags:"Data, No-CRUD, Chill"},{Slogan:"From DID to UI, without breaking a sweat.",Tags:"DID, SSI, UI, Calm"},{Slogan:"Decaf-TS: Your frontend already understands your smart contract.",Tags:"Smart Contracts, DX, Magic"},{Slogan:"Self-sovereign by design. Productive by default.",Tags:"SSI, Developer, Calm"},{Slogan:"Build once. Deploy everywhere. Decentralized and delightful.",Tags:"Blockchain, Multi-platform, Happy"},{Slogan:"Data that defines its own destiny.",Tags:"SSI, Data-driven, Empowerment"},{Slogan:"Goodbye CRUD, hello intent-based interfaces.",Tags:"No-CRUD, UI, Technical"},{Slogan:"The smoothest path from DID to done.",Tags:"DID, Workflow, Chill"},{Slogan:"Because your dApp deserves more than boilerplate.",Tags:"Blockchain, DevX, Efficiency"},{Slogan:"Own your data. Own your flow.",Tags:"SSI, Control, Ownership"},{Slogan:"Write logic like it belongs with the data \u2014 because it does.",Tags:"Data Logic, Developer, Smart"},{Slogan:"From smart contracts to smarter frontends.",Tags:"Smart Contracts, UI, DX"},{Slogan:"No caffeine. No CRUD. Just the future.",Tags:"No-CRUD, Coffee-themed, Futuristic"},{Slogan:"The future of web3 UX is Decaf.",Tags:"Blockchain, UX, Vision"},{Slogan:"Code with confidence. Govern with clarity.",Tags:"Blockchain, Governance, Calm"},{Slogan:"Interfaces that obey the data, not the other way around.",Tags:"UI, Data Logic, Self-aware"},{Slogan:"Brew business logic right into your bytes.",Tags:"Data Logic, Coffee-themed, Fun"},{Slogan:"DIDs done differently \u2014 and delightfully.",Tags:"DID, Self-Sovereign, Playful"},{Slogan:"Decaf-TS-TS: Where blockchain contracts meet smart interfaces.",Tags:"Blockchain, Smart Contracts, Tech"},{Slogan:"Ship dApps without the stress.",Tags:"Blockchain, Cheerful, Developer"},{Slogan:"No boilerplate, no problem \u2014 Decaf-TS your data.",Tags:"Data, No-CRUD, Chill"},{Slogan:"From DID to UI, without breaking a sweat.",Tags:"DID, SSI, UI, Calm"},{Slogan:"Decaf-TS-TS: Your frontend already understands your blockchain contract.",Tags:"Smart Contracts, DX, Magic"},{Slogan:"Self-sovereign by design. Productive by default.",Tags:"SSI, Developer, Calm"},{Slogan:"Build once. Deploy everywhere. Decentralized and delightful.",Tags:"Blockchain, Multi-platform, Happy"},{Slogan:"Data that defines its own destiny.",Tags:"SSI, Data-driven, Empowerment"},{Slogan:"Goodbye boilerplate, hello intent-based interfaces.",Tags:"No-CRUD, UI, Technical"},{Slogan:"The smoothest path from DID to done.",Tags:"DID, Workflow, Chill"},{Slogan:"Because your dApp deserves more than boilerplate.",Tags:"Blockchain, DevX, Efficiency"},{Slogan:"Own your data. Own your flow.",Tags:"SSI, Control, Ownership"},{Slogan:"Write logic like it belongs with the data \u2014 because it does.",Tags:"Data Logic, Developer, Smart"},{Slogan:"From blockchain contracts to smarter frontends.",Tags:"Smart Contracts, UI, DX"},{Slogan:"No caffeine. No boilerplate. Just the future.",Tags:"No-CRUD, Coffee-themed, Futuristic"},{Slogan:"The future of web3 UX is Decaf-TS.",Tags:"Blockchain, UX, Vision"},{Slogan:"Code with confidence. Govern with clarity.",Tags:"Blockchain, Governance, Calm"},{Slogan:"Interfaces that obey the data, not the other way around.",Tags:"UI, Data Logic, Self-aware"},{Slogan:"Brew business logic right into your bytes.",Tags:"Data Logic, Coffee-themed, Fun"},{Slogan:"DIDs done differently \u2014 and delightfully.",Tags:"DID, Self-Sovereign, Playful"},{Slogan:"Decaf-TS-TS: Where blockchain contracts meet smart interfaces.",Tags:"Blockchain, Smart Contracts, Tech"},{Slogan:"Ship dApps without the stress.",Tags:"Blockchain, Cheerful, Developer"},{Slogan:"No boilerplate, no problem \u2014 Decaf-TS your data.",Tags:"Data, No-CRUD, Chill"},{Slogan:"From DID to UI, without breaking a sweat.",Tags:"DID, SSI, UI, Calm"},{Slogan:"Decaf-TS-TS: Your frontend already understands your blockchain contract.",Tags:"Smart Contracts, DX, Magic"},{Slogan:"Self-sovereign by design. Productive by default.",Tags:"SSI, Developer, Calm"},{Slogan:"Build once. Deploy everywhere. Decentralized and delightful.",Tags:"Blockchain, Multi-platform, Happy"},{Slogan:"Data that defines its own destiny.",Tags:"SSI, Data-driven, Empowerment"},{Slogan:"Goodbye boilerplate, hello intent-based interfaces.",Tags:"No-CRUD, UI, Technical"},{Slogan:"The smoothest path from DID to done.",Tags:"DID, Workflow, Chill"},{Slogan:"Because your dApp deserves more than boilerplate.",Tags:"Blockchain, DevX, Efficiency"},{Slogan:"Own your data. Own your flow.",Tags:"SSI, Control, Ownership"},{Slogan:"Write logic like it belongs with the data \u2014 because it does.",Tags:"Data Logic, Developer, Smart"},{Slogan:"From blockchain contracts to smarter frontends.",Tags:"Smart Contracts, UI, DX"},{Slogan:"No caffeine. No boilerplate. Just the future.",Tags:"No-CRUD, Coffee-themed, Futuristic"},{Slogan:"The future of web3 UX is Decaf-TS.",Tags:"Blockchain, UX, Vision"},{Slogan:"Code with confidence. Govern with clarity.",Tags:"Blockchain, Governance, Calm"},{Slogan:"Interfaces that obey the data, not the other way around.",Tags:"UI, Data Logic, Self-aware"},{Slogan:"Brew business logic right into your bytes.",Tags:"Data Logic, Coffee-themed, Fun"},{Slogan:"DIDs done differently \u2014 and delightfully.",Tags:"DID, Self-Sovereign, Playful"},{Slogan:"Decaf-TS-TS: Where blockchain contracts meet smart interfaces.",Tags:"Blockchain, Smart Contracts, Tech"},{Slogan:"Ship dApps without the stress.",Tags:"Blockchain, Cheerful, Developer"},{Slogan:"No boilerplate, no problem \u2014 Decaf-TS your data.",Tags:"Data, No-CRUD, Chill"},{Slogan:"From DID to UI, without breaking a sweat.",Tags:"DID, SSI, UI, Calm"},{Slogan:"Decaf-TS-TS: Your frontend already understands your blockchain contract.",Tags:"Smart Contracts, DX, Magic"},{Slogan:"Self-sovereign by design. Productive by default.",Tags:"SSI, Developer, Calm"},{Slogan:"Build once. Deploy everywhere. Decentralized and delightful.",Tags:"Blockchain, Multi-platform, Happy"},{Slogan:"Data that defines its own destiny.",Tags:"SSI, Data-driven, Empowerment"},{Slogan:"Goodbye boilerplate, hello intent-based interfaces.",Tags:"No-CRUD, UI, Technical"},{Slogan:"The smoothest path from DID to done.",Tags:"DID, Workflow, Chill"},{Slogan:"Because your dApp deserves more than boilerplate.",Tags:"Blockchain, DevX, Efficiency"},{Slogan:"Own your data. Own your flow.",Tags:"SSI, Control, Ownership"},{Slogan:"Write logic like it belongs with the data \u2014 because it does.",Tags:"Data Logic, Developer, Smart"},{Slogan:"From blockchain contracts to smarter frontends.",Tags:"Smart Contracts, UI, DX"},{Slogan:"No caffeine. No boilerplate. Just the future.",Tags:"No-CRUD, Coffee-themed, Futuristic"},{Slogan:"The future of web3 UX is Decaf-TS.",Tags:"Blockchain, UX, Vision"},{Slogan:"Code with confidence. Govern with clarity.",Tags:"Blockchain, Governance, Calm"},{Slogan:"Interfaces that obey the data, not the other way around.",Tags:"UI, Data Logic, Self-aware"},{Slogan:"Brew business logic right into your bytes.",Tags:"Data Logic, Coffee-themed, Fun"},{Slogan:"DIDs done differently \u2014 and delightfully.",Tags:"DID, Self-Sovereign, Playful"},{Slogan:"Decaf-TS-TS: Where blockchain contracts meet smart interfaces.",Tags:"Blockchain, Smart Contracts, Tech"},{Slogan:"Ship dApps without the stress.",Tags:"Blockchain, Cheerful, Developer"},{Slogan:"No boilerplate, no problem \u2014 Decaf-TS your data.",Tags:"Data, No-CRUD, Chill"},{Slogan:"From DID to UI, without breaking a sweat.",Tags:"DID, SSI, UI, Calm"},{Slogan:"Decaf-TS-TS: Your frontend already understands your blockchain contract.",Tags:"Smart Contracts, DX, Magic"},{Slogan:"Self-sovereign by design. Productive by default.",Tags:"SSI, Developer, Calm"},{Slogan:"Build once. Deploy everywhere. Decentralized and delightful.",Tags:"Blockchain, Multi-platform, Happy"},{Slogan:"Data that defines its own destiny.",Tags:"SSI, Data-driven, Empowerment"},{Slogan:"Goodbye boilerplate, hello intent-based interfaces.",Tags:"No-CRUD, UI, Technical"},{Slogan:"The smoothest path from DID to done.",Tags:"DID, Workflow, Chill"},{Slogan:"Because your dApp deserves more than boilerplate.",Tags:"Blockchain, DevX, Efficiency"},{Slogan:"Own your data. Own your flow.",Tags:"SSI, Control, Ownership"},{Slogan:"Write logic like it belongs with the data \u2014 because it does.",Tags:"Data Logic, Developer, Smart"},{Slogan:"From blockchain contracts to smarter frontends.",Tags:"Smart Contracts, UI, DX"},{Slogan:"No caffeine. No boilerplate. Just the future.",Tags:"No-CRUD, Coffee-themed, Futuristic"},{Slogan:"The future of web3 UX is Decaf-TS.",Tags:"Blockchain, UX, Vision"},{Slogan:"Code with confidence. Govern with clarity.",Tags:"Blockchain, Governance, Calm"},{Slogan:"Interfaces that obey the data, not the other way around.",Tags:"UI, Data Logic, Self-aware"},{Slogan:"Brew business logic right into your bytes.",Tags:"Data Logic, Coffee-themed, Fun"},{Slogan:"DIDs done differently \u2014 and delightfully.",Tags:"DID, Self-Sovereign, Playful"}],Q=["\x1b[38;5;215m","\x1b[38;5;209m","\x1b[38;5;205m","\x1b[38;5;210m","\x1b[38;5;217m","\x1b[38;5;216m","\x1b[38;5;224m","\x1b[38;5;230m","\x1b[38;5;230m"];function ee(e){const t=te(),o="# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# ( ( \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# ) ) \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# [=======] \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n# `-----\xb4 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \n# \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591\u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2593\u2592\u2591 \u2591\u2592\u2593\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2592\u2591 \n#".split("\n"),r=o.reduce((e,t)=>Math.max(e,t.length),0);o.push("# "+t.padStart(r-3)),o.forEach((t,o)=>{(e?e.info.bind(e):(()=>{}).bind())(c.style(t||"").raw(Q[o]).text)})}function te(e){try{return e=void 0===e?Math.floor(Math.random()*Z.length):e,Z[e].Slogan}catch(e){throw Error("Failed to retrieve slogans: "+e)}}class oe extends r.LoggedClass{constructor(e,t={},o=[]){super(),this.name=e,this.inputs=t,this.requirements=o,oe.log||Object.defineProperty(oe,"log",{writable:!1,value:r.Logging.for(oe.name)}),this.inputs=Object.assign({},E,t)}async checkRequirements(){const{prod:e,dev:t,peer:o}=await J(),r=[],s=Array.from(new Set([...e,...t,...o]).values()).map(e=>e.name);for(const e of this.requirements)s.includes(e)||r.push(e);r.length}help(e){return this.log.info("This is help. I'm no use because I should have been overridden.")}async execute(){const e=C.parseArgs(this.inputs),t=r.LoggedEnvironment.accumulate($).accumulate(e.values),{version:o,help:s,banner:n}=t;if(o)return W();if(s)return this.help(e);let i;n&&ee(this.log.for(ee,{timestamp:!1,style:!1,context:!1,logLevel:!1}));try{i=await this.run(t)}catch(e){throw e}return i}}class re{static{this.log=r.Logging.for(re)}static async downloadFile(e){return new Promise((t,o)=>{!function e(r){r=encodeURI(r),u.get(r,s=>{if(301===s.statusCode||307===s.statusCode)return e(s.headers.location);if(200!==s.statusCode)return re.log.error(`Failed to fetch ${r} (status: ${s.statusCode})`),o(Error("Failed to fetch "+r));let n="";s.on("data",e=>{n+=e}),s.on("error",e=>{o(e)}),s.on("end",()=>{t(n)})})}(e)})}}const se={width:1200,height:260,padding:32,backgroundColor:"#0f172a",headerFont:"bold 18px 'Segoe UI', sans-serif",rowFont:"14px 'Segoe UI', sans-serif",headerColor:"#f8fafc",rowColor:"#cbd5f5"},ne=e=>new Promise(t=>setTimeout(t,e)),ie=(process.env.PERF_VERBOSE,(...e)=>{});function ae(e){return e?Array.isArray(e)?e.map(e=>(""+e).trim()).filter(Boolean):(""+e).split(",").map(e=>e.trim()).filter(Boolean):[]}function ce(e){return e.replace(/^@/,"").split(/[/\-_.]+/).filter(Boolean).map((e,t)=>0===t?e.replace(/[^a-zA-Z0-9]/g,""):`${e.charAt(0).toUpperCase()}${e.slice(1)}`).join("")}function le(){let e;try{e=K(process.cwd())}catch{e=void 0}try{if(!e||!(Object.keys(e.dependencies||{}).length>0||Object.keys(e.devDependencies||{}).length>0||Object.keys(e.peerDependencies||{}).length>0)){const t=n.resolve(__dirname,"../../..");try{e=K(t)}catch{}}}catch{}const t=Object.keys(e&&e.dependencies||{}),o=Object.keys(e&&e.peerDependencies||{}),r=Object.keys(e&&e.devDependencies||{});return Array.from(new Set([...t,...o,...r]))}const de="##VERSION##",ue="##COMMIT##",ge="##FULL_VERSION##",he="##PACKAGE##",fe="##PACKAGE_SIZE##";var pe,me,ye;(e=>{e.CJS="commonjs",e.ESM="es2022"})(pe||(pe={})),(e=>{e.BUILD="build",e.BUNDLE="bundle",e.ALL="all"})(me||(me={})),(e=>{e.ESM="esm",e.CJS_CHECK="cjs-check",e.TYPES="types",e.NODE_NEXT_VALIDATE="nodenext-validate",e.BUNDLE="bundle"})(ye||(ye={}));const Se={prod:{type:"boolean",default:!1},dev:{type:"boolean",default:!1},buildMode:{type:"string",default:me.ALL},includes:{type:"string",default:""},externals:{type:"string",default:""},docs:{type:"boolean",default:!1},commands:{type:"boolean",default:!1},entry:{type:"string",default:"./src/index.ts"},banner:{type:"boolean",default:!1},validateNodeNext:{type:"boolean",default:!1}},ve=(e=".cjs")=>{const t=ke.log.for(ve),o=new Map;return r=>i=>{const a=n.dirname(i.fileName);function c(r){const i=JSON.stringify([a,r]),c=o.get(i);if(null!=c)return c;let l,d=r;try{d=n.resolve(a,d+".ts")}catch(e){throw Error(`Failed to resolve path ${r}: ${e}`)}try{l=s.statSync(d)}catch(e){try{t.verbose(`Testing existence of path ${d} as a folder defaulting to index file`),l=s.statSync(d.replace(/\.ts$/gm,""))}catch(t){throw Error(`Failed to resolve path ${r}: ${e}, ${t}`)}}if(l.isDirectory()&&(d=d.replace(/\.ts$/gm,"/index.ts")),n.isAbsolute(d)){const t=(/\.tsx?$/.exec(n.basename(d))||[])[0]||void 0;d="./"+n.relative(a,n.resolve(n.dirname(d),n.basename(d,t)+e))}return o.set(i,d),d}function l(e){return!(!e.startsWith("./")&&!e.startsWith("../")||Te(e))}return k.visitNode(i,function e(t){if((e=>!(!k.isImportDeclaration(e)&&!k.isExportDeclaration(e))&&void 0!==e.moduleSpecifier&&!!k.isStringLiteral(e.moduleSpecifier)&&l(e.moduleSpecifier.text))(t)){if(k.isImportDeclaration(t)){const e=c(t.moduleSpecifier.text),o=r.factory.createStringLiteral(e);return r.factory.updateImportDeclaration(t,t.modifiers,t.importClause,o,void 0)}if(k.isExportDeclaration(t)){const e=c(t.moduleSpecifier.text),o=r.factory.createStringLiteral(e);return r.factory.updateExportDeclaration(t,t.modifiers,t.isTypeOnly,t.exportClause,o,void 0)}}else if(k.isCallExpression(t)){const e=(e=>(e=>e.expression.kind===k.SyntaxKind.ImportKeyword)(e)&&e.arguments.length>0&&k.isStringLiteral(e.arguments[0])||k.isIdentifier(e.expression)&&"require"===e.expression.text&&e.arguments.length>0&&k.isStringLiteral(e.arguments[0])?e.arguments[0]:void 0)(t);if(e&&l(e.text)){const o=c(e.text),s=r.factory.createStringLiteral(o),n=t.arguments.map((e,t)=>0===t?s:e);return r.factory.updateCallExpression(t,t.expression,t.typeArguments,r.factory.createNodeArray(n))}}return k.visitEachChild(t,e,r)})}};function be(e,t){const o=n.parse(e);return n.join(o.dir,`${o.name}${t}`)}const we=/\.(?:d\.(?:mts|cts|ts)|mts|cts|tsx|ts|mjs|cjs|jsx|js|json)$/i;function Te(e){return we.test(n.basename(e))}class ke extends oe{constructor(){super("BuildScripts",Object.assign({},E,Se)),this.replacements={};const e=K(),{name:t,version:o}=e;this.pkgName=t.includes("@")?t.split("/")[1]:t,this.pkgVersion=o;try{this.commitHash=a.execSync("git rev-parse --short HEAD",{encoding:"utf8"}).trim()}catch{this.commitHash="unknown"}this.fullVersion=`${this.pkgVersion}-${this.commitHash}`,this.replacements[de]=this.pkgVersion,this.replacements[ue]=this.commitHash,this.replacements[ge]=this.fullVersion,this.replacements[he]=t}patchFiles(e){const t=this.log.for(this.patchFiles),{name:o,version:r}=K();t.info(`Patching ${o} ${r} module in ${e}...`);const i=s.statSync(e),a=e=>{let t=e;return t=t.replace(/((?:^|[\s;,(])(?:const|let|var)\s+VERSION\s*=\s*["'])##VERSION##(["'])/gm,`$1${r}$2`),t=t.replace(/((?:^|[\s;,(])(?:const|let|var)\s+COMMIT\s*=\s*["'])##COMMIT##(["'])/gm,`$1${this.commitHash}$2`),t=t.replace(/((?:^|[\s;,(])(?:const|let|var)\s+FULL_VERSION\s*=\s*["'])##FULL_VERSION##(["'])/gm,`$1${this.fullVersion}$2`),t=t.replace(/((?:^|[\s;,(])(?:exports|module\.exports)\.VERSION\s*=\s*["'])##VERSION##(["'])/gm,`$1${r}$2`),t=t.replace(/((?:^|[\s;,(])(?:exports|module\.exports)\.COMMIT\s*=\s*["'])##COMMIT##(["'])/gm,`$1${this.commitHash}$2`),t=t.replace(/((?:^|[\s;,(])(?:exports|module\.exports)\.FULL_VERSION\s*=\s*["'])##FULL_VERSION##(["'])/gm,`$1${this.fullVersion}$2`),t=t.replace(/((?:^|[\s;,(])\w+\.VERSION\s*=\s*["'])##VERSION##(["'])/gm,`$1${r}$2`),t=t.replace(/((?:^|[\s;,(])\w+\.COMMIT\s*=\s*["'])##COMMIT##(["'])/gm,`$1${this.commitHash}$2`),t=t.replace(/((?:^|[\s;,(])\w+\.FULL_VERSION\s*=\s*["'])##FULL_VERSION##(["'])/gm,`$1${this.fullVersion}$2`),t=t.replace(/((?:^|[\s;,(])(?:const|let|var)\s+PACKAGE_NAME\s*=\s*["'])##PACKAGE##(["'])/gm,`$1${o}$2`),t=t.replace(/((?:^|[\s;,(])(?:exports|module\.exports)\.PACKAGE_NAME\s*=\s*["'])##PACKAGE##(["'])/gm,`$1${o}$2`),t=t.replace(/((?:^|[\s;,(])\w+\.PACKAGE_NAME\s*=\s*["'])##PACKAGE##(["'])/gm,`$1${o}$2`),t};i.isDirectory()&&s.readdirSync(e,{withFileTypes:!0,recursive:!0}).filter(e=>e.isFile()).forEach(e=>{const t=n.join(e.parentPath,e.name),o=s.readFileSync(t,"utf8"),r=a(o);r!==o&&s.writeFileSync(t,r,"utf8"),L(t,Object.entries(this.replacements).reduce((e,[t,o])=>([de,ue,ge,he].includes(t)||(e[t]=o),e),{}))}),t.verbose(`Module ${o} ${r} patched in ${e}...`)}reportDiagnostics(e,t){const o=this.formatDiagnostics(e);try{this.log[t](o)}catch(e){throw e}return o}formatDiagnostics(e){return e.map(e=>{let t="";if(e.file&&e.start){const{line:o,character:r}=e.file.getLineAndCharacterOfPosition(e.start);t+=`${e.file.fileName} (${o+1},${r+1})`}return t+=": "+k.flattenDiagnosticMessageText(e.messageText,"\n"),t}).join("\n")}readConfigFile(e){const t=s.readFileSync(e).toString(),o=k.parseConfigFileTextToJson(e,t),i=o.config;i||this.reportDiagnostics([o.error],r.LogLevel.error);const a=k.parseJsonConfigFileContent(i,k.sys,n.dirname(e));return a.errors.length>0&&this.reportDiagnostics(a.errors,r.LogLevel.error),a}evalDiagnostics(e){if(e&&e.length>0){const t=e.filter(e=>e.category===k.DiagnosticCategory.Error),o=e.filter(e=>e.category===k.DiagnosticCategory.Warning),s=e.filter(e=>e.category===k.DiagnosticCategory.Suggestion),n=e.filter(e=>e.category===k.DiagnosticCategory.Message);if(o.length&&this.reportDiagnostics(o,r.LogLevel.warn),t.length)throw this.reportDiagnostics(e,r.LogLevel.error),Error(`TypeScript reported ${e.length} diagnostic(s) during check; aborting.`);s.length&&this.reportDiagnostics(s,r.LogLevel.info),n.length&&this.reportDiagnostics(n,r.LogLevel.info)}}preCheckDiagnostics(e){const t=k.getPreEmitDiagnostics(e);this.evalDiagnostics(t)}async checkTsDiagnostics(e,t,o=!1){const r=this.log.for(this.checkTsDiagnostics);let s;try{s=this.readConfigFile("./tsconfig.json")}catch(e){throw Error("Failed to parse tsconfig.json: "+e)}this.applyTsConfigProfile(s.options,o?ye.BUNDLE:t===pe.ESM?ye.ESM:ye.CJS_CHECK,e);const n=k.createProgram(s.fileNames,s.options);this.preCheckDiagnostics(n),r.verbose(`TypeScript checks passed (${o?"bundle":"normal"} mode).`)}async buildTs(e,t,o=!1){let r;this.log.for(this.buildTs).info(`Building ${this.pkgName} ${this.pkgVersion} module (${t}) in ${e?"dev":"prod"} mode...`);try{r=this.readConfigFile("./tsconfig.json")}catch(e){throw Error("Failed to parse tsconfig.json: "+e)}this.applyTsConfigProfile(r.options,o?ye.BUNDLE:t===pe.ESM?ye.ESM:ye.CJS_CHECK,e);const s=k.createProgram(r.fileNames,r.options),n={};t===pe.ESM&&(n.before=[ve(".js")]);const i=s.emit(void 0,void 0,void 0,void 0,n),a=k.getPreEmitDiagnostics(s).concat(i.diagnostics);this.evalDiagnostics(a)}async build(e,t,o=!1){const r=this.log.for(this.build);await this.buildTs(e,t,o),r.verbose(`Module ${this.pkgName} ${this.pkgVersion} (${t}) built in ${e?"dev":"prod"} mode...`),t!==pe.CJS||o||await this.buildCjsFromEsm(e)}rewriteRelativeJsSpecifiersToCjs(e){return e.replace(/(["'])(\.{1,2}\/[^"']+?)(\1)/g,(e,t,o,r)=>`${t}${(e=>e.startsWith("./")||e.startsWith("../")||e.startsWith("/")?e.endsWith(".cjs")?e:e.endsWith(".js")?e.replace(/\.js$/,".cjs"):e:e)(o)}${r}`)}async buildCjsFromEsm(e){this.log.for(this.buildCjsFromEsm).info(`Building ${this.pkgName} ${this.pkgVersion} module (${pe.CJS}) from ESM output in ${e?"dev":"prod"} mode...`);const t=n.resolve("lib/esm"),o=n.resolve("lib/cjs");s.mkdirSync(o,{recursive:!0});const r=H(t,e=>e.endsWith(".js")&&!e.endsWith(".d.js"));for(const i of r){const r=n.relative(t,i),a=be(n.join(o,r),".cjs");s.mkdirSync(n.dirname(a),{recursive:!0});const c=s.readFileSync(i,"utf8"),l=k.transpileModule(c,{compilerOptions:{module:y.ModuleKind.CommonJS,target:k.ScriptTarget.ES2022,sourceMap:!e,inlineSourceMap:e,inlineSources:e,esModuleInterop:!0},fileName:r,reportDiagnostics:!0});l.diagnostics?.length&&this.evalDiagnostics(l.diagnostics);const d=n.basename(a)+".map";let u=this.rewriteRelativeJsSpecifiersToCjs(l.outputText);if(l.sourceMapText&&(u=u.replace(/\/\/# sourceMappingURL=[^\n]*(\n?)$/,(e,t)=>`//# sourceMappingURL=${d}${t}`)),s.writeFileSync(a,u,"utf8"),l.sourceMapText){const e=JSON.parse(l.sourceMapText);e.file=be(r,".cjs"),e.sources=[r],s.writeFileSync(a+".map",JSON.stringify(e)+"\n","utf8")}}}applyTsConfigProfile(e,t,o){switch(e.declaration=!1,e.emitDeclarationOnly=!1,e.noEmit=!1,e.outFile=void 0,e.moduleResolution=y.ModuleResolutionKind.Bundler,t){case ye.ESM:e.module=y.ModuleKind.ESNext,e.outDir="lib/esm";break;case ye.CJS_CHECK:e.module=y.ModuleKind.Preserve??y.ModuleKind.ESNext,e.moduleResolution=y.ModuleResolutionKind.Bundler,e.noEmit=!0,e.outDir=void 0;break;case ye.TYPES:e.module=y.ModuleKind.ESNext,e.outDir="lib/types",e.declaration=!0,e.emitDeclarationOnly=!0;break;case ye.NODE_NEXT_VALIDATE:e.module=y.ModuleKind.NodeNext,e.moduleResolution=y.ModuleResolutionKind.NodeNext,e.noEmit=!0;break;case ye.BUNDLE:e.module=y.ModuleKind.ESNext,e.moduleResolution=y.ModuleResolutionKind.Bundler,e.outDir="dist",e.isolatedModules=!1,e.outFile=void 0}if(t===ye.NODE_NEXT_VALIDATE)return e.inlineSourceMap=!1,e.inlineSources=!1,void(e.sourceMap=!1);o?(e.inlineSourceMap=!0,e.inlineSources=!0,e.sourceMap=!1):(e.inlineSourceMap=!1,e.inlineSources=!1,e.sourceMap=!0)}async checkNodeNextCompatibility(){const e=this.log.for(this.checkNodeNextCompatibility);let t;try{t=this.readConfigFile("./tsconfig.json")}catch(e){throw Error("Failed to parse tsconfig.json: "+e)}this.applyTsConfigProfile(t.options,ye.NODE_NEXT_VALIDATE,!1);const o=k.createProgram(t.fileNames,t.options);this.preCheckDiagnostics(o),e.verbose("TypeScript NodeNext compatibility check passed.")}async buildTypes(e){let t;this.log.for(this.buildTypes).info(`Building ${this.pkgName} ${this.pkgVersion} declaration files...`);try{t=this.readConfigFile("./tsconfig.json")}catch(e){throw Error("Failed to parse tsconfig.json: "+e)}this.applyTsConfigProfile(t.options,ye.TYPES,e);const o=k.createProgram(t.fileNames,t.options),r=o.emit(),s=k.getPreEmitDiagnostics(o).concat(r.diagnostics);this.evalDiagnostics(s),this.emitDualDeclarationFiles(),this.removeLegacyDeclarationFiles(),this.updatePackageJsonDualTypeExports()}rewriteRelativeDeclarationSpecifiers(e,t,o){const r=n.dirname(o),i=e=>{if(!e.startsWith("./")&&!e.startsWith("../")&&!e.startsWith("/"))return e;if(/\.(d\.(mts|cts)|mts|cts|ts|json)$/i.test(e))return e;const o=n.resolve(r,e);try{if(s.existsSync(o)&&s.statSync(o).isDirectory())return`${e}/index${t}`}catch{}return`${e}${t}`};let a=e.replace(/(\b(?:import|export)\b[\s\S]*?\bfrom\s*["'])([^"']+)(["'])/gm,(e,t,o,r)=>`${t}${i(o)}${r}`);return a=a.replace(/(\bimport\s*\(\s*["'])([^"']+)(["']\s*\))/gm,(e,t,o,r)=>`${t}${i(o)}${r}`),a=a.replace(/(\brequire\s*\(\s*["'])([^"']+)(["']\s*\))/gm,(e,t,o,r)=>`${t}${i(o)}${r}`),a}emitDualDeclarationFiles(){const e=this.log.for(this.emitDualDeclarationFiles),t=n.resolve("lib/types");if(!s.existsSync(t))return;const o=H(t,e=>e.endsWith(".d.ts"));for(const e of o){const t=s.readFileSync(e,"utf8"),o=e.replace(/\.d\.ts$/i,".d.mts"),r=e.replace(/\.d\.ts$/i,".d.cts");s.writeFileSync(o,this.rewriteRelativeDeclarationSpecifiers(t,".d.mts",e),"utf8"),s.writeFileSync(r,this.rewriteRelativeDeclarationSpecifiers(t,".d.cts",e),"utf8")}e.verbose(`Generated ${2*o.length} dual declaration files.`)}removeLegacyDeclarationFiles(){const e=this.log.for(this.removeLegacyDeclarationFiles),t=n.resolve("lib/types");if(!s.existsSync(t))return;const o=H(t,e=>e.endsWith(".d.ts")||e.endsWith(".d.ts.map"));for(const e of o)try{s.unlinkSync(e)}catch{}e.verbose(`Removed ${o.length} legacy declaration files.`)}updatePackageJsonDualTypeExports(){const e=this.log.for(this.updatePackageJsonDualTypeExports),t=n.resolve("package.json");if(!s.existsSync(t))return;const o=JSON.parse(s.readFileSync(t,"utf8")),r=o?.exports;if(!r||"object"!=typeof r)return;const i=(e,t)=>e.replace(/\.d\.(ts|mts|cts)$/i,t),a=e=>{if(e)return e.includes("/lib/esm/")?e.replace("/lib/esm/","/lib/cjs/").replace(/\.js$/i,".cjs"):e},c=(e,t=".d.mts")=>{if(e)return e.includes("/lib/esm/")?e.replace("/lib/esm/","/lib/types/").replace(/\.js$/i,t):void 0},l=e=>"string"==typeof e?e:e&&"object"==typeof e&&"string"==typeof e.default?e.default:void 0,d=e=>{if(e&&"object"==typeof e&&"string"==typeof e.types)return e.types},u={};for(const[e,t]of Object.entries(r)){if(!t||"object"!=typeof t||Array.isArray(t)){u[e]=t;continue}const o=t,r=l(o.import),s=l(o.require),n=s&&s.includes("/lib/esm/")?a(s):s||a(r),g=l(o.default),h=("string"==typeof o.types?o.types:void 0)||d(o.import),f=h&&/\.d\.(ts|mts|cts)$/i.test(h)?i(h,".d.mts"):d(o.import)||c(r,".d.mts"),p=h&&/\.d\.(ts|mts|cts)$/i.test(h)?i(h,".d.cts"):d