create-crust 0.3.1 → 0.3.3
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/bin/create-crust.js +17 -17
- package/package.json +1 -1
package/bin/create-crust.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{existsSync as wn,readdirSync as bi}from"node:fs";import{basename as yn,join as wi,resolve as ze}from"node:path";import{mkdir as xn,writeFile as re}from"node:fs/promises";import{dirname as M,join as P,posix as Ue,resolve as ue,win32 as Ve}from"node:path";import{existsSync as qe,realpathSync as On,statSync as $n}from"node:fs";import{fileURLToPath as Cn}from"node:url";import{AsyncLocalStorage as En}from"node:async_hooks";import{Writable as In}from"node:stream";import{parseArgs as jn}from"node:util";import{isPromise as Nn}from"node:util/types";import{homedir as kn}from"node:os";var p=class extends Error{code;details;cause;constructor(e,t,...n){super(t);this.name="CrustError",this.code=e,this.details=n[0]}is(e){return Object.is(this.code,e)}withCause(e){return this.cause=e,this}toJSON(){return{code:this.code,message:this.message,details:this.details}}};function se(e,t){if(e==="")throw new p("DEFINITION",`Flag ${t} spellings must be non-empty`,{subject:"flag",name:e,reason:"empty-spelling"});if(t!=="short"&&e.startsWith("no-"))throw new p("DEFINITION",`Flag ${t} "${e}" must not start with "no-"; the prefix is reserved for boolean negation`,{subject:"flag",name:e,reason:"reserved-no-prefix"});if(e==="__proto__")throw new p("DEFINITION",`Flag ${t} "__proto__" is a reserved spelling`,{subject:"flag",name:e,reason:"reserved-spelling"})}function He(e,t){return[e,...t.short===void 0?[]:[t.short],...t.aliases??[]]}function Je(e){return e.type==="boolean"&&e.noNegate!==!0}function Xe(e){if(e.choices&&e.default!==void 0){let t="multiple"in e&&e.multiple?e.default:[e.default];for(let n of t)if(!e.choices.includes(n))throw new p("DEFINITION","default must be one of choices")}return Object.freeze({...e,..."aliases"in e&&e.aliases?{aliases:Object.freeze([...e.aliases])}:{},...e.choices?{choices:Object.freeze([...e.choices])}:{},..."multiple"in e&&e.multiple&&Array.isArray(e.default)?{default:Object.freeze([...e.default])}:{}})}function Ze(e,t){if(se(e,"canonical"),t.short!==void 0)se(t.short,"short");for(let r of t.aliases??[])se(r,"alias");let n=He(e,t);if(new Set(n).size!==n.length)throw new p("DEFINITION",`Flag "${e}" repeats one of its own spellings`,{subject:"flag",name:e,reason:"flag-collision"});if(t.short!==void 0&&t.short.length!==1)throw new p("DEFINITION","Short flags must be one character");return Xe(t)}function Qe(e){if(e.name==="")throw new p("DEFINITION","Argument names must be non-empty",{subject:"argument",name:e.name,reason:"empty-name"});return Xe(e)}var An=Symbol("crust.defining");function q(e){return e[An]}var et=Symbol.for("crust.contextSources");function K(e,t){let n=new Set(e.map((o)=>o.name)),r=new Set,s=(o)=>{if(r.has(o))return;r.add(o);let i="contextName"in o?o.contextName:o.name;if(!n.has(i))throw new p("DEFINITION",`No provider for Context "${i}"`,{subject:"context",name:i,reason:"missing-context"});for(let a of o.uses)s(a)};for(let o of t)s(o)}function Tn(e){return typeof e==="function"}var _n=class{#e=[];#t=!1;#n(){if(this.#t)throw ReferenceError("AsyncDisposableStack is already disposed")}use(e){this.#n();let t=Fn(e)?e[Symbol.asyncDispose]:e[Symbol.dispose];return this.#e.push(()=>t.call(e)),e}defer(e){if(this.#n(),!Tn(e))throw TypeError("defer callback is not callable");this.#e.push(e)}async[Symbol.asyncDispose](){this.#t=!0;let e=[];for(let t=this.#e.length-1;t>=0;t--)try{await this.#e[t]()}catch(n){e.push(n)}if(e.length===1)throw e[0];if(e.length>1)throw AggregateError(e,"Disposal failed")}},Pn=globalThis.AsyncDisposableStack??_n;function Fn(e){return typeof e[Symbol.asyncDispose]==="function"}function Rn(e){if(e===null||typeof e!=="object"&&typeof e!=="function")return!1;let t=e;return typeof t[Symbol.asyncDispose]==="function"||typeof t[Symbol.dispose]==="function"}function Dn(e,t,n){if(!Rn(e)||n.has(e))return;n.add(e),t.use(e)}function Mn(e,t,n){let r=new Map(e.map((d)=>[d.name,d])),s=new Map,o=new WeakSet,i,a=!1;n.defer(()=>{a=!0});let c=(d,m,h=new Set)=>{if(d.name===m)return[d.name];if(h.has(d.name))return;h.add(d.name);for(let w of d.waitingOn){let S=s.get(w);if(!S)continue;let x=c(S,m,h);if(x)return[d.name,...x]}},l=(d)=>{try{let m=new Set;for(let h=d;h!=null&&!m.has(h);h=h.cause)if(m.add(h),h instanceof p&&h.code==="DEFINITION"&&h.details?.reason==="flags-before-validation")return!0;return!1}catch{return!1}};function u(d){let m=Promise.reject(d);return m.catch(()=>{}),m}let f=(d)=>(m)=>{let h=d?` (pulled while constructing Context "${d.name}")`:"";if(a)return u(new p("DEFINITION",`Context "${m}" cannot be pulled from onError because invocation Contexts have already been disposed.`,{subject:"context",name:m,reason:"context-after-disposal"}));let w=r.get(m);if(!w)return u(new p("DEFINITION",`No provider for Context "${m}". Add .provide(${m}(...)) to the app or an ancestor command.${h}`,{subject:"context",name:m,reason:"missing-context"}));if(i===void 0&&Object.keys(w.ownedFlags).length>0)return u(new p("DEFINITION",`Context "${m}" owns flags and cannot be pulled before flag validation${h}. Pull it from an action or a postRun hook after a validated invocation.`,{subject:"context",name:m,reason:"flags-before-validation"}));let S=s.get(m);if(!S){let x=Promise.withResolvers();x.promise.catch(()=>{}),S={name:m,promise:x.promise,resolve:x.resolve,reject:x.reject,waitingOn:new Set,settled:!1},s.set(m,S);let v=S;(async()=>{try{let O=Object.fromEntries(Object.keys(w.ownedFlags).map((E)=>[E,i?.[E]])),I=await w.setup({...t,flags:O,ctx:g(w.uses,v),defer(E){if(v.settled)throw new p("DEFINITION",`Context "${m}" cannot register cleanup after its setup has finished.`,{subject:"context",name:m,reason:"context-defer-after-setup"});n.defer(E)}});Dn(I,n,o),v.resolve(I)}catch(O){if(l(O))s.delete(m);v.reject(O)}finally{v.settled=!0}})()}if(d&&!S.settled){let x=c(S,d.name);if(x)return u(new p("DEFINITION",`Context dependency cycle: ${[d.name,...x].map((v)=>`"${v}"`).join(" -> ")}`,{subject:"context",name:d.name,reason:"context-cycle"}));return d.waitingOn.add(m),S.promise.finally(()=>d.waitingOn.delete(m))}return S.promise},g=(d,m)=>{let h={},w=(S)=>{let x="contextName"in S?S.contextName:S.name;if(Object.hasOwn(h,x))return;Object.defineProperty(h,x,{enumerable:!0,get:()=>f(m)(x)});for(let v of S.uses??[])w(v)};for(let S of d)w(S);return Object.defineProperty(h,et,{value:Object.freeze([...d])}),Object.freeze(h)};return{bag:(d)=>g(d,null),setValidatedFlags(d){i=d},async settle(){for(;;){let d=[...s.values()].filter((m)=>!m.settled);if(d.length===0)return;await Promise.allSettled(d.map((m)=>m.promise))}}}}var Bn=Object.freeze({[Symbol("crust.finished")]:!0});function ae(){return Bn}function tt(e){return{meta:{name:e},localFlags:{},ownedFlags:{},effectiveFlags:{},flagSpellings:new Map,args:[],subCommands:{},contexts:[],demands:[],extensions:[],run:void 0}}function A(e,t,n,r){n=Ze(t,n);let s=He(t,n),o=Object.hasOwn(e.effectiveFlags,t)?t:s.map((a)=>e.flagSpellings.get(a)?.canonicalName).find((a)=>a!==void 0);if(o!==void 0)throw new p("DEFINITION",`Flag "${t}" collides with existing flag "${o}" on command "${e.meta.name}"`,{subject:"flag",name:t,reason:"flag-collision"});(r==="local"?e.localFlags:e.ownedFlags)[t]=n,e.effectiveFlags[t]=n;let i={canonicalName:t,def:n,negatable:Je(n)};if(e.flagSpellings.set(t,{...i,kind:"canonical"}),n.short!==void 0)e.flagSpellings.set(n.short,{...i,kind:"short"});for(let a of n.aliases??[])e.flagSpellings.set(a,{...i,kind:"alias"})}function nt(e,t,n,r){if(A(e,t,n,"owned"),!r)return;for(let s of Object.values(e.subCommands))nt(s,t,n,!0)}function Ln(e,t,n){for(let r of t.commands??[])e.subCommands[r.name]=n(r,e,t.id)}function zn(e,t){for(let[n,r]of Object.entries(t.flags??{})){let{recursive:s=!0,...o}=r;nt(e,n,o,s)}}function T(e){let t={};for(let[n,r]of Object.entries(e.subCommands))t[n]=T(r);return{...e,meta:{...e.meta},localFlags:{...e.localFlags},ownedFlags:{...e.ownedFlags},effectiveFlags:{...e.effectiveFlags},flagSpellings:new Map([...e.flagSpellings].map(([n,r])=>[n,{...r,def:e.effectiveFlags[r.canonicalName]}])),args:[...e.args],subCommands:t,contexts:e.contexts.map((n)=>({...n})),demands:[...e.demands],extensions:[...e.extensions],run:e.run}}function Wn({subject:e,name:t}){return new p("DEFINITION",`${e==="command"?"Command":"Extension"} "${t}" contains invalid documentation sections`,{subject:e,name:t,reason:"invalid-sections"})}function rt(e,t){let{title:n,body:r,only:s,except:o}=e;if(!n.trim()||/[\r\n]/.test(n)||!r.trim()||s?.length===0||o?.length===0||s!==void 0&&o!==void 0)throw Wn(t);let i=(a)=>Object.freeze(a.map((c)=>typeof c==="string"?c:c.id));return Object.freeze({title:n,body:r,...s?{only:i(s)}:o?{except:i(o)}:{}})}function fe(e,t){return t.map((n)=>rt(n,{subject:"command",name:e}))}function Un(e,t,n){let r=e;for(let s of t){let o=Object.hasOwn(r.subCommands,s)?r.subCommands[s]:void 0;if(!o)throw new p("DEFINITION",`Extension "${n.id}" section target "${t.join(" ")}" is not a canonical command path`,{subject:"extension",name:n.id,reason:"invalid-section-path"});r=o}return r}function Vn(e,t,n){if(!t.sections)return;let r={subject:"extension",name:t.id},s=t.sections(n);for(let o of s){let i=rt(o,r),a=Un(e,o.command,t);a.meta.sections=[...a.meta.sections??[],i]}}function st(e,t,n){let r=T(e),s=new Set(t.flatMap((i)=>!n.has(i.id)&&e.extensions.includes(i)?[i.id]:[])),o=(i)=>{i.contexts=i.contexts.filter((u)=>u.extensionId===void 0||s.has(u.extensionId));let a=Object.keys(i.effectiveFlags),c=i.localFlags,l={};for(let{instance:u}of i.contexts)Object.assign(l,u.ownedFlags);i.localFlags={},i.ownedFlags={},i.effectiveFlags={},i.flagSpellings=new Map;for(let u of a){let f=Object.hasOwn(l,u)?"owned":"local",g=f==="owned"?l:c;if(Object.hasOwn(g,u))A(i,u,g[u],f)}for(let u of Object.values(i.subCommands))o(u)};o(r);for(let i of t){if(s.has(i.id))continue;let a=i.provides??[];if(a.length===0)continue;let c=(l,u)=>{let f=a.filter((m)=>!u.has(m.name)),g=f.map((m)=>({instance:m,extensionId:i.id}));l.contexts.push(...g);for(let m of f)for(let[h,w]of Object.entries(m.ownedFlags))A(l,h,w,"owned");let d=new WeakSet(l.contexts.map(({instance:m})=>m));for(let m of Object.values(l.subCommands)){let h=new Set(u);for(let{instance:w}of m.contexts)if(!d.has(w))h.add(w.name);c(m,h)}};c(r,new Set)}return r}function qn(e){let t=ue(e);if(qe(t)&&!$n(t).isDirectory())t=M(t);while(!0){if(qe(P(t,"package.json")))return t;let n=M(t);if(n===t)return null;t=n}}var ot="CRUST_INTERNAL_BUILD_OUT_DIR";function Kn(){let{Bun:e,Deno:t}=globalThis,n=e?.main??"";return n.startsWith("/$bunfs/")||/^[A-Za-z]:[\\/]~BUN[\\/]/.test(n)||t?.build?.standalone===!0}function de(e){if(e===""||e==="."||e===".."||/[\\/]/.test(e))throw Error(`Artifact name must be a single directory name, got ${JSON.stringify(e)}.`);if(Kn())return P(M(process.execPath),e);return ue(Cn(import.meta.url),"..","..",e)}var Yn=Symbol.for("crustjs.terminal.io"),Gn=Symbol.for("crustjs.terminal.ambient-callbacks"),Hn=globalThis,Jn=globalThis,ce=Hn[Yn]??=new En,it=Jn[Gn]??=new WeakMap;function Xn(e,t){let n=ce.getStore();return ce.run({input:e.input??n?.input,output:e.output??n?.output},t)}function Zn(e){let t="",n=new In({decodeStrings:!1,write(r,s,o){t+=r.toString();let i=t.indexOf(`
|
|
2
|
+
import{existsSync as wn,readdirSync as li}from"node:fs";import{basename as yn,join as ui,resolve as Be}from"node:path";import{dirname as Ti,join as _i,posix as Pi,resolve as Wn,win32 as Di}from"node:path";import{existsSync as Le,statSync as xn}from"node:fs";import{dirname as We,isAbsolute as yi,join as On,resolve as $n}from"node:path";function Ue(e){let t=$n(e);if(Le(t)&&!xn(t).isDirectory())t=We(t);while(!0){if(Le(On(t,"package.json")))return t;let n=We(t);if(n===t)return null;t=n}}import{realpathSync as Cn}from"node:fs";import{dirname as En,join as ne,resolve as In}from"node:path";import{fileURLToPath as jn}from"node:url";var Nn="CRUST_INTERNAL_BUILD_OUT_DIR";function kn(){let{Bun:e,Deno:t}=globalThis,n=e?.main??"";return n.startsWith("/$bunfs/")||/^[A-Za-z]:[\\/]~BUN[\\/]/.test(n)||t?.build?.standalone===!0}function re(e){if(e===""||e==="."||e===".."||/[\\/]/.test(e))throw Error(`Artifact name must be a single directory name, got ${JSON.stringify(e)}.`);if(kn())return ne(En(process.execPath),e);return In(jn(import.meta.url),"..","..",e)}import{AsyncLocalStorage as An}from"node:async_hooks";import{Writable as Tn}from"node:stream";var _n=Symbol.for("crustjs.terminal.io"),Pn=Symbol.for("crustjs.terminal.ambient-callbacks"),Dn=globalThis,Fn=globalThis,U=Dn[_n]??=new An,Ve=Fn[Pn]??=new WeakMap;function oe(e,t){let n=U.getStore();return U.run({input:e.input??n?.input,output:e.output??n?.output},t)}function V(){return U.getStore()}function Rn(e){let t="",n=new Tn({decodeStrings:!1,write(r,o,s){t+=r.toString();let i=t.indexOf(`
|
|
3
3
|
`);while(i!==-1)e.stderr(t.slice(0,i)),t=t.slice(i+1),i=t.indexOf(`
|
|
4
|
-
`);o()}});return it.set(n,e),n}function at(e,t){let n=ce.getStore();return Xn({input:n?.input,output:n?.output&&!it.has(n.output)?n.output:Zn(e)},t)}function Qn(e){let t=Number(e);return Number.isNaN(t)?void 0:t}function er(e){return e==="true"||e==="1"}function tr(e){try{return new URL(e)}catch{throw new p("PARSE",`Invalid URL "${e}"${/^[a-z][a-z0-9+.-]*:/i.test(e)?"":" (missing protocol — e.g. https://example.com)"}`)}}function V(e){if(e==="")throw new p("PARSE","Path cannot be empty");let t=e.replace(/^~(?=\/|$)/,kn());return ue(process.cwd(),t)}function nr(e){try{return JSON.parse(e)}catch(t){throw new p("PARSE",`Invalid JSON: ${t instanceof Error?t.message:String(t)}. Tip: wrap JSON in single quotes on the command line, e.g. --flag '{"k":1}'`)}}function rr(e){let t={};for(let[n,r]of e){let s={type:r.def.type==="boolean"?"boolean":"string"};if(r.def.multiple)s.multiple=!0;if(r.kind==="canonical"){if(r.def.short)s.short=r.def.short;t[n]=s;continue}if(r.kind==="alias")t[n]=s}return t}function ct(e,t,n){if(t==="number"){let r=Qn(e);if(r===void 0)throw new p("PARSE",`Expected number for ${n}, got "${e}"`);return r}if(t==="boolean")return er(e);if(t==="url")return tr(e);if(t==="path")return V(e);if(t==="json")return nr(e);return e}function me(e,t,n){if(!t.includes(e))throw new p("PARSE",`Invalid value "${e}" for ${n}. Expected one of: ${t.join(", ")}`)}function B(e,t,n,r){let s=r===void 0?n:`${n} element [${r}]`,o;try{if(o=e(t),Nn(o))throw o.catch(()=>{}),Error("parse must be synchronous")}catch(i){throw new p("PARSE",`Failed to parse ${s}: ${i instanceof Error?i.message:String(i)}`).withCause(i)}return o}function lt(e,t){let{default:n,parse:r}=e;if(n===void 0)return;if(r){if(Array.isArray(n))return n.map((s,o)=>B(r,String(s),t,o));return B(r,String(n),t)}if(e.type==="path"){if(Array.isArray(n))return n.map((s)=>V(String(s)));return V(String(n))}return"multiple"in e&&e.multiple&&Array.isArray(n)?[...n]:n}function sr(e,t,n){if(n.kind==="boolean")return n.value;let r=`--${e}`,s=(o,i)=>{if(t.choices)me(o,t.choices,r);if(t.parse)return B(t.parse,o,r,i);return ct(o,t.type,r)};return Array.isArray(n.value)?n.value.map(s):s(n.value)}function or(e,t){let n={};for(let r of e){if(r.kind!=="option")continue;let{canonicalName:s,def:o}=t.get(r.name),i=n[s];if(o.type==="boolean"){let a=!r.rawName.startsWith("--no-");if(o.multiple&&i?.kind==="boolean"&&Array.isArray(i.value))i.value.push(a);else n[s]={kind:"boolean",value:o.multiple?[a]:a}}else{let a=r.value;if(o.multiple&&i?.kind==="string"&&Array.isArray(i.value))i.value.push(a);else n[s]={kind:"string",value:o.multiple?[a]:a}}}return n}function ir(e,t,n){let r={};for(let s of Object.keys(t))if(!Object.hasOwn(e,s)&&t[s]!==void 0)throw new p("PARSE",`Unknown flag "--${s}"`,{flag:s,reason:"unknown-flag"});for(let[s,o]of Object.entries(e)){let i=Object.hasOwn(t,s)?t[s]:void 0;if(!(i===void 0||o.multiple&&Array.isArray(i)&&i.length===0)){r[s]=n(s,o,i);continue}r[s]=lt(o,`--${s}`)}return r}function ar(e,t){for(let[n,r]of Object.entries(e))if(r.required===!0&&r.default===void 0){if(t[n]===void 0)throw new p("VALIDATION",`Missing required flag "--${n}"`)}}function cr(e,t,n,r){if(e.schema)return t;if(e.choices)me(t,e.choices,n);if(e.parse)return B(e.parse,t,n,r);return ct(t,e.type,n)}function lr(e,t,n){let r={},s=0;for(let o of e){let{name:i}=o,a=`<${i}>`;if(Object.defineProperty(r,i,{value:void 0,writable:!0,enumerable:!0,configurable:!0}),o.variadic)r[i]=t.slice(s).map((c,l)=>n(o,c,a,l)),s=t.length;else if(s<t.length)r[i]=n(o,t[s],a),s++;else r[i]=lt(o,a)}return{args:r,consumed:s}}function ur(e,t){for(let n of e){if(n==="--")return;if(!n.startsWith("--no-"))continue;let r=n.indexOf("="),s=r===-1?n.slice(5):n.slice(5,r),o=t.get(s);if(!o||o.def.type!=="boolean"||o.negatable)continue;throw new p("PARSE",`Flag "--${o.canonicalName}" does not support negation ("--no-${s}")`)}}function fr(e,t){let n=e.flagSpellings,r=rr(n);ur(t,n);let s;try{s=jn({args:t,options:r,strict:!0,allowPositionals:!0,allowNegative:!0,tokens:!0})}catch(c){if(c instanceof Error){let l=c.message.match(/Unknown option '(.+?)'/);if(l)throw new p("PARSE",`Unknown flag "${l[1]}"`).withCause(c);if("code"in c&&c.code==="ERR_PARSE_ARGS_INVALID_OPTION_VALUE"&&c.message.length>0)throw new p("PARSE",c.message).withCause(c)}throw new p("PARSE","Failed to parse command arguments").withCause(c)}let o=[],i=[],a=!1;for(let c of s.tokens){if(c.kind==="option-terminator"){a=!0;continue}if(c.kind==="positional")(a?o:i).push(c.value)}return{positionals:i,flagValues:or(s.tokens,n),rawArgs:o}}function dr(e,t,n){let r=e.schema?e.type==="boolean"?"boolean":"string":e.type,s;if(r==="url")s=t instanceof URL;else if(r==="json"){let o=[t],i=new Set;s=!0;while(o.length>0){let a=o.pop();if(a instanceof URL){s=!1;break}if(Array.isArray(a)&&!i.has(a))i.add(a),o.push(...a)}}else s=typeof t===(r==="path"?"string":r);if(!s)throw new p("PARSE",`Expected ${r} for ${n}`);if(t===!1&&"noNegate"in e&&e.noNegate)throw new p("PARSE",`Flag "${n}" does not support negation`)}function le(e,t,n,r){if(dr(e,t,n),e.choices)me(String(t),e.choices,n);if(e.parse)return B(e.parse,String(t),n,r);if(e.type==="path")return V(String(t));return t}function mr(e,t,n){let r=`--${e}`;if(t.multiple){if(!Array.isArray(n))throw new p("PARSE",`Expected an occurrence array for ${r}`);return n.map((s,o)=>le(t,s,r,o))}return le(t,n,r)}function ut(e,t,n,r,s){let o=ir(e.effectiveFlags,n,s);return{...lr(e.args,t,r),flags:o}}function gr(e,t){let{positionals:n,flagValues:r,rawArgs:s}=fr(e,t),{args:o,flags:i,consumed:a}=ut(e,n,r,cr,sr);return{args:o,flags:i,excessArgs:n.slice(a),rawArgs:s}}function hr(e,t){let{args:n,flags:r,raw:s}=t,o=[],i;for(let l of e.args){let u=n&&Object.hasOwn(n,l.name)?n[l.name]:void 0;if(u===void 0){i=l.name;continue}if(i!==void 0)throw new p("PARSE",`Argument <${l.name}> cannot be provided after omitted argument <${i}>`,{argument:l.name,reason:"positional-gap"});if(l.variadic){if(!Array.isArray(u))throw new p("PARSE",`Expected an occurrence array for <${l.name}>`);o.push(...u)}else o.push(u)}for(let l of Object.keys(n??{}))if(!e.args.some((u)=>u.name===l)&&n?.[l]!==void 0)throw new p("PARSE",`Unknown argument "${l}"`,{argument:l,reason:"unknown-argument"});let{args:a,flags:c}=ut(e,o,r??{},le,mr);return{args:a,flags:c,excessArgs:[],rawArgs:[...s??[]]}}function pr(e,t){let{args:n,effectiveFlags:r}=e,{args:s,flags:o}=t;if(t.excessArgs.length>0)throw new p("VALIDATION",`Unexpected positional argument${t.excessArgs.length===1?"":"s"}: ${t.excessArgs.map((i)=>JSON.stringify(i)).join(", ")}`);for(let i of n){let{name:a}=i,c=`argument "<${a}>"`,l=s[a];if(i.required===!0&&i.default===void 0){if(i.variadic){if(!Array.isArray(l)||l.length===0)throw new p("VALIDATION",`Missing required ${c}`)}else if(l===void 0)throw new p("VALIDATION",`Missing required ${c}`)}}ar(r,o)}function br(e){return typeof e==="number"}function wr(e){return e.map((t,n)=>br(t)?`[${t}]`:n>0?`.${String(t)}`:String(t)).join("")}function yr(e){return typeof e==="object"&&e!==null&&"key"in e}function vr(e){if(!e)return[];return e.map((t)=>yr(t)?t.key:t)}function Sr(e,t=[]){return e.map((n)=>{let r=vr(n.path),s=[...t,...r];return{message:n.message,path:wr(s)}})}async function Ke(e,t,n,r){let s=await e["~standard"].validate(t);if(s.issues)return r.push(...Sr(s.issues,n)),{ok:!1};return{ok:!0,value:s.value}}async function xr(e,t){let n=[],r=new Map(Object.entries(t.args)),s=new Map(Object.entries(t.flags));for(let o of e.args){if(o.schema===void 0)continue;let i=await Ke(o.schema,r.get(o.name),["args",o.name],n);if(i.ok)r.set(o.name,i.value)}for(let[o,i]of Object.entries(e.effectiveFlags)){if(i.schema===void 0)continue;let a=await Ke(i.schema,s.get(o),["flags",o],n);if(a.ok)s.set(o,a.value)}if(n.length>0)throw new p("VALIDATION",`Invalid input:
|
|
5
|
-
${n.map((
|
|
6
|
-
`)}`,{issues:n});return{args:Object.fromEntries(r),flags:Object.fromEntries(
|
|
7
|
-
`),stderr:
|
|
8
|
-
`)}}catch(i){return{status:"failed",error:i,stdout:
|
|
9
|
-
`),stderr:
|
|
10
|
-
`)}}}async function bt(e,t,n){let r=t?.argv??process.argv.slice(2),s={...Ir,...t?.io},o=process.env[jr];if(o){try{let a=gt(e,n),c=()=>j(ht(T(a.rootNode),a.extensions)),l=c(),u=process.env[ot];if(u){let f=[],g=new Map;for(let d of a.extensions){if(!d.build)continue;try{let m=(await d.build({snapshot:l})).map((h)=>{let w=kr(h.path),S=w.toLowerCase();for(let[x,v]of g)if(x===S||x.startsWith(`${S}/`)||S.startsWith(`${x}/`))throw Error(`Artifact path "${w}" collides with "${v.path}" produced by Extension "${v.id}".`);return g.set(S,{id:d.id,path:w}),{path:w,content:h.content}});for(let h of m){let w=P(u,h.path);await xn(M(w),{recursive:!0}),await re(w,h.content)}f.push({id:d.id,files:m.map((h)=>h.path)})}catch(m){let h=m instanceof Error?m.message:String(m);throw Error(`Extension "${d.id}" build failed: ${h}`,{cause:m})}l=c()}await re(P(M(o),"build-report.json"),JSON.stringify({extensions:f}))}await re(o,JSON.stringify(l))}catch(a){let c=a instanceof Error?a.message:String(a);return console.error(c),process.exit(1)}return process.exit(0)}let i=async()=>{let a;try{a=L(e,n)}catch(u){if(oe(u))return process.exitCode=D,D;let f=u instanceof Error?u.message:String(u);return s.stderr(`Error: ${f}`),process.exitCode=1,1}let c,l=!1;try{await pt({argv:r},a,s,(u)=>{c=u},async(u,f)=>{l=!0;let g=oe(u);return process.exitCode=g?D:1,ie(u,r,a,s,f,g)})}catch(u){if(oe(u)){if(!l)await ie(u,r,a,s,c,!0);return process.exitCode=D,D}if(process.exitCode=1,!l)await ie(u,r,a,s,c);return 1}return 0};return await(_r(t?.io)?at(s,i):i())}var ye=Symbol.for("crust.commandDefinition");function F(e,t,n){let r=e[ye],s=e.name,o=n?`Extension "${n}" command "${s}"`:`Command "${s}"`,i=(u)=>({subject:n?"extension":"command",name:n??s,reason:u}),a=new Y(s);for(let[u,f]of Object.entries(t.ownedFlags))A(a._node,u,f,"owned");a._node.contexts=t.contexts.map((u)=>({...u}));let c=r.recipe(a);if(!(c instanceof Y)||c._ancestorOwnedFlags!==a._ancestorOwnedFlags)throw new p("DEFINITION",`${o} definition must return the same command builder it received`,i("foreign-command-builder"));if(c._node.extensions.length>0)throw new p("DEFINITION",`${o} cannot register Extensions inside command definitions`,i("nested-command-extension"));let l=T(c._node);return K(l.contexts.map(({instance:u})=>u),l.demands),l.meta={name:s,...r.meta},l}function we(e,t=[]){if(e.trim()==="")throw new p("DEFINITION","Command name must be a non-empty string",{subject:"command",name:e,reason:"empty-name"});if(e==="__proto__")throw new p("DEFINITION",'Command name "__proto__" is reserved',{subject:"command",name:e,reason:"reserved-name"});if(t.includes(e))throw new p("DEFINITION",`Command "${e}" must not list its own canonical name as an alias`,{subject:"command",name:e,reason:"alias-collision"});return e}function Pr(e){return typeof e==="function"}function Fr(e,t,n){let r=!Pr(t),s=r?t:{},o=r?n:t,i=we(e,s.aliases);for(let d of s.aliases??[])if(d===""||/[ \t\n\r\v\f]/.test(d)||d.startsWith("-"))throw new p("DEFINITION",`Command "${i}" has an invalid alias "${d}"`);let{sections:a,version:c,...l}=s,u={...l,...s.aliases?{aliases:[...s.aliases]}:{},...a?{sections:fe(i,a)}:{}},f={name:i,recipe:o,meta:u},g=(d)=>Object.freeze({name:d,as:(m)=>g(we(m,u.aliases)),[ye]:Object.freeze({...f,name:d})});return g(i)}function Rr(e){return e.filter((t,n)=>e.findLastIndex((r)=>r.id===t.id)===n)}var Y=class{_node;_ancestorOwnedFlags;constructor(e,...t){let n=t[0]??{},r=we(e);if(this._node=tt(r),n.description!==void 0)this._node.meta.description=n.description;if(n.version!==void 0)this._node.meta.version=n.version;if(n.usage!==void 0)this._node.meta.usage=n.usage;if(n.sections!==void 0)this._node.meta.sections=fe(r,n.sections);this._ancestorOwnedFlags={}}_clone(e){let t=Object.create(Object.getPrototypeOf(this));return t._node={...T({...this._node,subCommands:{}}),subCommands:{...this._node.subCommands},...e},t._ancestorOwnedFlags=this._ancestorOwnedFlags,t}flags(...e){let t=this._clone({});for(let n of e){let{name:r,...s}=n;A(t._node,r,s,"local")}return t}args(...e){let t=[...this._node.args,...e.map(Qe)],n=new Set;for(let[r,s]of t.entries()){if(n.has(s.name))throw new p("DEFINITION",`Argument name "${s.name}" is already defined`,{subject:"argument",name:s.name,reason:"duplicate-arg"});if(n.add(s.name),s.variadic===!0&&r!==t.length-1)throw new p("DEFINITION",`Only the last positional argument can be variadic; "${s.name}" is not last`,{subject:"argument",name:s.name,reason:"variadic-position"})}return this._clone({args:t})}use(...e){return this._clone({demands:[...this._node.demands,...e.map(q)]})}provide(...e){let t=e.map(q);K([...this._node.contexts.map(({instance:r})=>r),...t],t);let n=this._clone({contexts:[...this._node.contexts,...t.map((r)=>({instance:r}))]});for(let r of t)for(let[s,o]of Object.entries(r.ownedFlags))A(n._node,s,o,"owned");return n}action(e){return this._clone({run:e})}extend(...e){let t=e.map(q),n=Rr([...this._node.extensions,...t]),r=st(this._node,n,new Set(t.map((s)=>s.id)));return K(r.contexts.map(({instance:s})=>s),n.flatMap((s)=>[...s.uses,...s.provides??[]])),this._clone({...r,extensions:n})}add(...e){return this._addDefinitions(e)}command(e,t){let n=Fr(e,t);return this._addDefinitions([n])}_addDefinitions(e){let t={...this._node.subCommands};for(let n of e){let r=[n.name,...n[ye].meta.aliases??[]];for(let o of Object.values(t))if([o.meta.name,...o.meta.aliases??[]].some((i)=>r.includes(i)))throw new p("DEFINITION",`Command name "${n.name}" is already registered on this command`,{subject:"command",name:n.name,reason:"command-collision"});let s=F(n,this._node);t[n.name]=s}return this._clone({subCommands:t})}async snapshot(){return j(L(this._node,F).rootNode)}async run(e,...t){let n=t[0]??{},r=t[1];return await be(this._node,{path:e,input:n},r,F)}at(e){pe(L(this._node,F).rootNode,e);let t=this._node,n=Object.freeze([...e]);return{path:n,async run(...r){let s=r[0]??{},o=r[1];return await be(t,{path:n,input:s},o,F)}}}async execute(e){return await bt(this._node,e,F)}};import{accessSync as wt,constants as yt,existsSync as xe,lstatSync as $t,mkdirSync as vt,readFileSync as Dr,readdirSync as Ct,realpathSync as Et,statSync as G,writeFileSync as St}from"node:fs";import{delimiter as Mr,dirname as It,extname as Br,isAbsolute as Lr,join as _,relative as zr,resolve as ve,sep as Oe,win32 as Wr}from"node:path";import{fileURLToPath as Ur}from"node:url";import{spawn as jt,spawnSync as Vr}from"node:child_process";import{once as Nt}from"node:events";import{text as xt}from"node:stream/consumers";function qr(e){return e instanceof Error&&"code"in e&&typeof e.code==="string"}function Kr(e,t){let n=zr(e,t);return n===""||!Lr(n)&&n!==".."&&!n.startsWith(`..${Oe}`)}function Yr(e,t){return e.replace(/\{\{\s*(\w+)\s*\}\}/g,(n,r)=>Object.hasOwn(t,r)?t[r]??n:n)}function Gr(e){let t=It(e),n=e.slice(t==="."?0:t.length+1);if(n.startsWith("_")&&!n.startsWith("__")){let r=`.${n.slice(1)}`;return t==="."?r:_(t,r)}return e}function Hr(e){if(!xe(e))return!1;if(!G(e).isDirectory())return!1;return Ct(e).length>0}function Jr(e,t){let n=e;for(let r of t.split(Oe)){n=_(n,r);let s;try{s=$t(n).isSymbolicLink()}catch(i){if(qr(i)&&i.code==="ENOENT")return;throw i}if(!s)continue;let o;try{o=Et(n)}catch{}if(o===void 0||!Kr(e,o))throw Error(`Destination path "${n}" is a symlink${o===void 0?" to a missing target":` to "${o}"`} outside the destination "${e}". Remove the link or choose another destination.`)}}async function $e(e){let{template:t,dest:n,context:r,conflict:s="abort"}=e,o=t instanceof URL?Ur(t):ve(t),i=ve(n);if(!xe(o))throw Error(`Template directory "${o}" does not exist (from template: "${String(t)}").`);if(!G(o).isDirectory())throw Error(`Template path "${o}" is not a directory (from template: "${String(t)}").`);if(s==="abort"&&Hr(i))throw Error(`Destination directory "${i}" already exists and is non-empty. Use conflict: "overwrite" to proceed.`);let a=Ct(o,{recursive:!0,encoding:"utf8"}).filter((f)=>$t(_(o,f)).isFile());vt(i,{recursive:!0});let c=Et(i),l=a.map((f)=>({relFromTemplate:f,destRelPath:Gr(f)}));for(let{destRelPath:f}of l)Jr(c,f);let u=[];for(let{relFromTemplate:f,destRelPath:g}of l){let d=_(o,f),m=_(c,g);vt(It(m),{recursive:!0});let h=Dr(d);if(h.subarray(0,8192).includes(0))St(m,h);else{let w=Yr(h.toString("utf-8"),r);St(m,w,"utf-8")}u.push(g)}return{files:u}}function Xr(e){if(e?.startsWith("bun"))return"bun";if(e?.startsWith("pnpm"))return"pnpm";if(e?.startsWith("yarn"))return"yarn";if(e?.startsWith("npm"))return"npm";return null}var Zr=/[\0\r\n"%!^`<>&|]/,Se=/([()\][%!^"`<>&|;, *?])/g;function Qr(e){let t=e.replace(/(?=(\\+?)?)\1"/g,"$1$1\\\"");return t=t.replace(/(?=(\\+?)?)\1$/g,"$1$1"),t=`"${t}"`.replace(Se,"^$1"),t.replace(Se,"^$1")}function es(e,t,n,r=process.platform){if(n||r!=="win32"||!/\.(cmd|bat)$/i.test(e))return null;let s=Wr.normalize(e);for(let[i,a]of[s,...t].entries())if(Zr.test(a)){let c=i===0?"command":`argument ${i}`;throw Error(`Windows command shim ${c} ${JSON.stringify(a)} contains unsafe shell characters`)}let o=[s.replace(Se,"^$1"),...t.map(Qr)].join(" ");return{command:process.env.ComSpec??"cmd.exe",args:["/d","/s","/c",`"${o}"`],windowsVerbatimArguments:!0}}async function H(e,t=[],n={}){let r=es(e,t,n.shell),s=(n.stdio??"collect")==="collect",o=s&&n.stdout!=="ignore",i=jt(r?.command??e,r?.args??t,{cwd:n.cwd,env:n.env,shell:n.shell,stdio:s?["ignore",o?"pipe":"ignore","pipe"]:"inherit",windowsVerbatimArguments:r?.windowsVerbatimArguments}),[a,c,[l]]=await Promise.all([o?xt(i.stdout):"",s?xt(i.stderr):"",Nt(i,"close")]);return{exitCode:l,stdout:a,stderr:c}}function kt(e){if(e.includes(Oe)||e.includes("/")){try{if(wt(e,yt.X_OK),G(e).isFile())return e}catch{}return null}let t=process.platform==="win32"&&!Br(e)?(process.env.PATHEXT??".EXE;.CMD;.BAT;.COM").split(";"):[""];for(let n of process.env.PATH?.split(Mr)??[])for(let r of t){let s=ve(_(n,e+r));try{if(wt(s,yt.X_OK),G(s).isFile())return s}catch{}}return null}var ts=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];function ns(e){let t=e??process.cwd();for(let[n,r]of ts)if(xe(_(t,n)))return r;return Xr(process.env.npm_config_user_agent)??"npm"}function At(e){try{return Vr("git",["rev-parse","--is-inside-work-tree"],{cwd:e??process.cwd(),stdio:"ignore"}).status===0}catch{return!1}}async function Ce(e,t){for(let n of e)switch(n.type){case"install":await rs(t);break;case"git-init":await ss(t,n.commit);break;case"open-editor":await os(t);break;case"command":await is(n.cmd,n.cwd??t)}}async function rs(e){let t=ns(e),n=kt(t);if(!n)throw Error(`Package manager "${t}" was not found on PATH. Install ${t} and try again.`);let{exitCode:r}=await H(n,["install"],{cwd:e,stdio:"inherit"});if(r!==0)throw Error(`"${t} install" exited with code ${r}`)}async function ss(e,t){let n=kt("git");if(!n)throw Error('"git" was not found on PATH. Install Git and try again.');if(await z([n,"init"],e,"git init"),t)await as(e,n),await z([n,"add","."],e,"git add"),await z([n,"commit","-m",t],e,"git commit")}async function os(e){let t=process.env.EDITOR||"code";try{let n=jt(t,[e],{stdio:"ignore",shell:process.platform==="win32"});n.unref();let r=await Promise.race([Nt(n,"close").then(([s])=>({kind:"exited",code:s})),new Promise((s)=>setTimeout(()=>s({kind:"timeout"}),500))]);if(r.kind==="exited"&&r.code!==0)console.warn(`Warning: could not open editor "${t}" (exit code ${r.code})`)}catch{console.warn(`Warning: could not open editor "${t}"`)}}async function is(e,t){let{exitCode:n}=await H(e,[],{cwd:t,shell:!0,stdio:"inherit"});if(n!==0)throw Error(`Command "${e}" exited with code ${n}`)}async function as(e,t){let n=await Ot(t,"user.name",e)===0,r=await Ot(t,"user.email",e)===0;if(!n)await z([t,"config","user.name","Crust"],e,"git config user.name");if(!r)await z([t,"config","user.email","crust@scaffolded.project"],e,"git config user.email")}async function Ot(e,t,n){let{exitCode:r}=await H(e,["config",t],{cwd:n,stdio:"collect",stdout:"ignore"});return r}async function z(e,t,n){let{exitCode:r,stderr:s}=await H(e[0],e.slice(1),{cwd:t,stdio:"collect",stdout:"ignore"});if(r!==0)throw Error(`"${n}" failed with exit code ${r}${s?`: ${s.trim()}`:""}`)}import{AsyncLocalStorage as Eo}from"node:async_hooks";var Tt=Object.defineProperty,cs=(e,t)=>{let n={};for(var r in e)Tt(n,r,{get:e[r],enumerable:!0});if(!t)Tt(n,Symbol.toStringTag,{value:"Module"});return n},ls=new Intl.Segmenter(void 0,{granularity:"grapheme"}),us=/[\p{Cc}\p{Cf}\p{Mn}\p{Me}]/u,fs=/\p{Emoji_Presentation}|\p{Emoji}\uFE0F/u,ds=new RegExp([String.raw`(?:\x1b\[|\x9b)[^\x1b\x18\x1a\x9c\x40-\x7e]*[\x40-\x7e\x18\x1a\x9c]?`,String.raw`(?:\x1b\]|\x9d)[^\x07\x1b\x18\x1a\x9c]*(?:\x07|\x1b\\|[\x18\x1a\x9c])?`,String.raw`(?:\x1b[PX^_]|[\x90\x98\x9e\x9f])[^\x1b\x18\x1a\x9c]*(?:\x1b\\|[\x18\x1a\x9c])?`,String.raw`\x1b[\x20-\x2f][^\x1b]?`,String.raw`\x1b[\x18\x1a\x9c\x30-\x7e]?`].join("|"),"g");function ms(e){return e>=4352&&(e<=4447||e===9001||e===9002||e>=11904&&e<=42191&&e!==12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=94176&&e<=111355||e>=127488&&e<=127743||e>=131072&&e<=262141)}function gs(e){return us.test(String.fromCodePoint(e))||e>=4448&&e<=4607||e>=55216&&e<=55295}function hs(e){if(!/[^\x20-\x7e]/.test(e))return e.length;let t=0;for(let{segment:n}of ls.segment(e.replace(ds,""))){if(fs.test(n)){let r=n.codePointAt(0);t+=n.length===2&&r>=127462&&r<=127487?1:2;continue}for(let r of n){let s=r.codePointAt(0);if(gs(s))continue;t+=ms(s)?2:1;break}}return t}function Rt(e){return globalThis.Bun?.stringWidth(e,{countAnsiEscapeCodes:!1})??hs(e)}var ps=cs({bgBlack:()=>Ls,bgBlue:()=>Vs,bgBrightBlack:()=>Gs,bgBrightBlue:()=>Zs,bgBrightCyan:()=>eo,bgBrightGreen:()=>Js,bgBrightMagenta:()=>Qs,bgBrightRed:()=>Hs,bgBrightWhite:()=>to,bgBrightYellow:()=>Xs,bgCyan:()=>Ks,bgGreen:()=>Ws,bgMagenta:()=>qs,bgRed:()=>zs,bgWhite:()=>Ys,bgYellow:()=>Us,black:()=>$s,blue:()=>js,bold:()=>bs,brightBlue:()=>Rs,brightCyan:()=>Ms,brightGreen:()=>Ps,brightMagenta:()=>Ds,brightRed:()=>_s,brightWhite:()=>Bs,brightYellow:()=>Fs,cyan:()=>ks,dim:()=>ws,gray:()=>Ts,green:()=>Es,hidden:()=>xs,inverse:()=>Ss,isModifierName:()=>Dt,italic:()=>ys,magenta:()=>Ns,red:()=>Cs,strikethrough:()=>Os,styleMethodNames:()=>Ie,underline:()=>vs,white:()=>As,yellow:()=>Is});function y(e,t){return{open:`\x1B[${e}m`,close:`\x1B[${t}m`}}var bs=y(1,22),ws=y(2,22),ys=y(3,23),vs=y(4,24),Ss=y(7,27),xs=y(8,28),Os=y(9,29),$s=y(30,39),Cs=y(31,39),Es=y(32,39),Is=y(33,39),js=y(34,39),Ns=y(35,39),ks=y(36,39),As=y(37,39),Ts=y(90,39),_s=y(91,39),Ps=y(92,39),Fs=y(93,39),Rs=y(94,39),Ds=y(95,39),Ms=y(96,39),Bs=y(97,39),Ls=y(40,49),zs=y(41,49),Ws=y(42,49),Us=y(43,49),Vs=y(44,49),qs=y(45,49),Ks=y(46,49),Ys=y(47,49),Gs=y(100,49),Hs=y(101,49),Js=y(102,49),Xs=y(103,49),Zs=y(104,49),Qs=y(105,49),eo=y(106,49),to=y(107,49),Ie=Object.freeze(["bold","dim","italic","underline","inverse","hidden","strikethrough","black","red","green","yellow","blue","magenta","cyan","white","gray","brightRed","brightGreen","brightYellow","brightBlue","brightMagenta","brightCyan","brightWhite","bgBlack","bgRed","bgGreen","bgYellow","bgBlue","bgMagenta","bgCyan","bgWhite","bgBrightBlack","bgBrightRed","bgBrightGreen","bgBrightYellow","bgBrightBlue","bgBrightMagenta","bgBrightCyan","bgBrightWhite"]),no=new Set(["bold","dim","italic","underline","inverse","hidden","strikethrough"]);function Dt(e){return no.has(e)}function W(e,t,n){return e!==void 0&&t in e?e[t]:n}function Mt(e){return W(e,"isTTY",process.stdout?.isTTY)??!1}function Bt(e){return W(e,"forceColor",process.env.FORCE_COLOR)}function Lt(e){return e==="0"||e==="false"}function ro(e){let t=e.toLowerCase();return t.includes("24bit")||t.includes("truecolor")||t.endsWith("-direct")}function zt(e,t){if(e!==void 0){let n=e.toLowerCase();if(n==="truecolor"||n==="24bit")return!0}return t!==void 0&&ro(t)}function _t(e,t){if(zt(e,t))return"truecolor";if(t!==void 0&&t.toLowerCase().includes("256color"))return"256";return"16"}function so(e,t){if(e==="never")return"none";if(e==="always")return"truecolor";let n=W(t,"colorTerm",process.env.COLORTERM),r=W(t,"term",process.env.TERM),s=Bt(t);if(s!==void 0){if(Lt(s))return"none";if(s==="1")return"16";if(s==="2")return"256";if(s==="3")return"truecolor";return _t(n,r)}if(!Mt(t))return"none";let o=W(t,"noColor",process.env.NO_COLOR);if(o!==void 0&&o!=="")return"none";if(r!==void 0&&r.toLowerCase()==="dumb"&&!zt(n,r))return"none";return _t(n,r)}function oo(e,t){if(e==="always")return!0;if(e==="never")return!1;let n=Bt(t);if(n!==void 0)return!Lt(n);return Mt(t)}var Wt={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]};function je(e,t){if(e==null)return"";let n=String(e);if(n==="")return"";let{open:r,close:s}=t;if(n.includes(s))n=n.replaceAll(s,s+r);return r+n+s}var io="\x1B[39m",ao="\x1B[49m",co="\x1B[38;",lo="\x1B[48;";function uo(e){try{return JSON.stringify(e)??String(e)}catch{return String(e)}}function fo(e){return Object.hasOwn(Wt,e)}function Ne(e){if(Array.isArray(e)){if(e.length===3&&e.every((t)=>Number.isInteger(t)&&t>=0&&t<=255))return[e[0],e[1],e[2]]}else if(typeof e==="string"){let t=e.toLowerCase();if(fo(t))return Wt[t];let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t)?.[1];if(n){let s=n.length===3?n.split("").map((o)=>o+o).join(""):n;return[Number.parseInt(s.slice(0,2),16),Number.parseInt(s.slice(2,4),16),Number.parseInt(s.slice(4,6),16)]}let r=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/.exec(t)??/^rgb\(\s*(\d{1,3})\s+(\d{1,3})\s+(\d{1,3})\s*\)$/.exec(t);if(r){let s=[Number(r[1]),Number(r[2]),Number(r[3])];if(s.every((o)=>o<=255))return s}}throw TypeError(`Invalid color input: ${uo(e)}`)}function mo(e,t,n){let r=[0,95,135,175,215,255],s=(f)=>r.reduce((g,d,m)=>Math.abs(d-f)<Math.abs(r[g]-f)?m:g,0),[o,i,a]=[s(e),s(t),s(n)],c=Math.min(23,Math.max(0,Math.round(((e+t+n)/3-8)/10))),l=8+c*10,u=(f,g,d)=>(e-f)**2+(t-g)**2+(n-d)**2;return u(l,l,l)<u(r[o],r[i],r[a])?232+c:16+36*o+6*i+a}function Ut(e,t,n){let r=Math.round(Math.max(e,t,n)/127.5);if(r===0)return 30;let s=30+((Math.round(n/255)<<2|Math.round(t/255)<<1|Math.round(e/255))&7);if(r===2)s+=60;return s}function Vt(e,t){let[n,r,s]=Ne(e);if(t==="16")return`\x1B[${Ut(n,r,s)}m`;if(t==="256")return`\x1B[38;5;${mo(n,r,s)}m`;return`\x1B[38;2;${n};${r};${s}m`}function go(e,t){if(t==="16"){let[n,r,s]=Ne(e);return`\x1B[${Ut(n,r,s)+10}m`}return Vt(e,t).replace(co,lo)}function ke(e,t,n){if(n==="none")return Ne(t),{open:"",close:""};return{open:e==="fg"?Vt(t,n):go(t,n),close:e==="fg"?io:ao}}function qt(e,t){return ke("fg",e,t)}function Kt(e,t){return ke("bg",e,t)}function Yt(e,t,n,r){let s=ke(e,n,r);return r==="none"?t:je(t,s)}function ho(e,t,n="truecolor"){return Yt("fg",e,t,n)}function po(e,t,n="truecolor"){return Yt("bg",e,t,n)}var Gt="\x1B]",Ht="\x1B\\",bo=`${Gt}8;;${Ht}`;function Jt(e,t,n,r=""){if(!n.test(e))throw TypeError(`Invalid ${t}: ${JSON.stringify(e)} must contain only printable ASCII characters${r}.`)}function wo(e){let t=e?.id;if(t===void 0||t==="")return"";if(Jt(t,"hyperlink id",/^[\x20-\x7e]*$/),t.includes(":")||t.includes(";"))throw TypeError('Invalid hyperlink id: ":" and ";" are reserved by the OSC 8 format.');return`id=${t}`}function Xt(e,t){Jt(e,"hyperlink URL",/^[\x21-\x7e]*$/," without spaces");let n=wo(t);return{open:`${Gt}8;${n};${e}${Ht}`,close:bo}}function yo(e,t,n){return je(e,Xt(t,n))}var Zt=[["fg",qt,ho],["bg",Kt,po]],vo=ps;function So(e){return e.kind==="named"&&Dt(e.name)}function Ee(e,t){if(e.kind==="named")return vo[e.name];return e.kind==="fg"?qt(e.input,t):Kt(e.input,t)}function Pt(e,t,n){if(e==null)return"";let r=String(e);if(r==="")return r;let s=n(),{modifiersEnabled:o,colorsEnabled:i}=s;for(let a=t.length-1;a>=0;a--){let c=t[a];if(c===void 0)continue;if(So(c)?!o:!i)continue;r=je(r,Ee(c,s.colorDepth))}return r}function xo(e){return Array.isArray(e)&&"raw"in e&&Array.isArray(e.raw)}function Oo(e,t){let n=new Map,r=t?"truecolor":e().colorDepth;function s(o){let i=o.map((f)=>f.kind==="named"?f.name:`~${Ee(f,"truecolor").open}`).join("|"),a=n.get(i);if(a)return a;let c=(f,...g)=>{if(xo(f)){let d="";for(let m=0;m<f.length;m++)if(d+=f[m]??"",m<g.length)d+=String(g[m]);return Pt(d,o,e)}return Pt(f,o,e)};if(n.size>=1024)n.delete(n.keys().next().value);n.set(i,c);for(let f of Ie)Object.defineProperty(c,f,{configurable:!1,enumerable:!0,get(){return s([...o,{kind:"named",name:f}])}});for(let[f,g]of Zt)Object.defineProperty(c,f,{configurable:!1,enumerable:!0,value:(d)=>(g(d,"truecolor"),s([...o,{kind:f,input:d}])),writable:!1});let l="",u="";for(let f of o){let g=Ee(f,r);l+=g.open,u=g.close+u}return Object.defineProperty(c,"open",{value:l,writable:!1,configurable:!1,enumerable:!0}),Object.defineProperty(c,"close",{value:u,writable:!1,configurable:!1,enumerable:!0}),Object.freeze(c)}return s}function $o(e){let t={};for(let n of Ie)t[n]=e([{kind:"named",name:n}]);return t}function Ft(e){let t=e?.mode??"auto",n=oo(t,e?.overrides),r=so(t,e?.overrides);return{modifiersEnabled:n,colorDepth:r,colorsEnabled:r!=="none",trueColorEnabled:r==="truecolor"}}function Co(e,t){let n=t?Ft:(()=>{let i=Ft(e);return()=>i})(),r=Oo(n,t),s=$o(r),o={get enabled(){let{modifiersEnabled:i,colorsEnabled:a}=n();return i||a},get colorsEnabled(){return n().colorsEnabled},get trueColorEnabled(){return n().trueColorEnabled},get colorDepth(){return n().colorDepth},link(i,a,c){if(n().modifiersEnabled)return yo(i,a,c);return Xt(a,c),i},...Object.fromEntries(Zt.map(([i,a,c])=>[i,(...l)=>{let u=n();if(l.length===1)return a(l[0],"truecolor"),r([{kind:i,input:l[0]}]);return c(l[0],l[1],u.colorDepth)}])),...s};return Object.freeze(o)}var b=Co(void 0,!0),{black:Hi,red:J,green:X,yellow:Ji,blue:Xi,magenta:Qt,cyan:U,white:Zi,gray:Qi,brightRed:ea,brightGreen:ta,brightYellow:na,brightBlue:ra,brightMagenta:sa,brightCyan:oa,brightWhite:ia,bgBlack:aa,bgRed:ca,bgGreen:la,bgYellow:ua,bgBlue:fa,bgMagenta:da,bgCyan:ma,bgWhite:ga,bgBrightBlack:ha,bgBrightRed:pa,bgBrightGreen:ba,bgBrightYellow:wa,bgBrightBlue:ya,bgBrightMagenta:va,bgBrightCyan:Sa,bgBrightWhite:xa,bold:Z,dim:Q,italic:Oa,underline:$a,inverse:Ca,hidden:Ea,strikethrough:Ia,link:ja,fg:Na,bg:ka}=b;var Io=Symbol.for("crustjs.terminal.io"),jo=Symbol.for("crustjs.terminal.ambient-callbacks"),No=globalThis,ko=globalThis,Ao=No[Io]??=new Eo;ko[jo]??=new WeakMap;function To(){return Ao.getStore()}var en={spinner:Qt,message:Z,success:X,error:J},_e="\x1B[",_o=`${_e}?25l`,tn=`${_e}?25h`,rn=`${_e}2K`,sn="\r",nn={dots:{frames:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],interval:80},line:{frames:["-","\\","|","/"],interval:130},arc:{frames:["◐","◓","◑","◒"],interval:100},bounce:{frames:["⠁","⠂","⠄","⡀","⢀","⠠","⠐","⠈"],interval:120}},Po="✓",Fo="✗";function Ro(e){if(e===void 0)return nn.dots;if(typeof e==="string")return nn[e];if(e.frames.length===0)throw Error("A custom spinner requires at least one frame");return e}function Ae(e,t){let n=e[t];if(n===void 0)throw Error("Spinner frame index is out of bounds");return n}function Te(e,t,n){return`${rn}${sn}${n.spinner(e)} ${n.message(t)}`}function Do(e,t,n,r){let s=n==="success"?Po:Fo,o=`${(n==="success"?t.success:t.error)(s)} ${t.message(e)}
|
|
11
|
-
`;return r?rn+
|
|
12
|
-
`),r=0;for(let
|
|
13
|
-
`),
|
|
14
|
-
`),
|
|
15
|
-
${n}`;return`${
|
|
16
|
-
${t.error(e.error)}`;return l}function
|
|
17
|
-
`)}function
|
|
18
|
-
The directory basename becomes the package and command name: use letters, digits, ".", "_", "~", and "-", not starting with "." or "-"; "__proto__" is reserved.`)}var
|
|
4
|
+
`);s()}});return Ve.set(n,e),n}function se(e,t){let n=U.getStore();return oe({input:n?.input,output:n?.output&&!Ve.has(n.output)?n.output:Rn(e)},t)}import{parseArgs as Un}from"node:util";import{isPromise as Vn}from"node:util/types";function qe(e){let t=Number(e);return Number.isNaN(t)?void 0:t}function He(e){return e==="true"||e==="1"}import{homedir as qn}from"node:os";function Mn(e){return typeof e==="number"}function Bn(e){return e.map((t,n)=>Mn(t)?`[${t}]`:n>0?`.${String(t)}`:String(t)).join("")}function zn(e){return typeof e==="object"&&e!==null&&"key"in e}function Ln(e){if(!e)return[];return e.map((t)=>zn(t)?t.key:t)}function Ke(e,t=[]){return e.map((n)=>{let r=Ln(n.path),o=[...t,...r];return{message:n.message,path:Bn(o)}})}var h=class extends Error{code;details;cause;constructor(e,t,...n){super(t);this.name="CrustError",this.code=e,this.details=n[0]}is(e){return Object.is(this.code,e)}withCause(e){return this.cause=e,this}toJSON(){return{code:this.code,message:this.message,details:this.details}}};function ie(e,t){if(e==="")throw new h("DEFINITION",`Flag ${t} spellings must be non-empty`,{subject:"flag",name:e,reason:"empty-spelling"});if(t!=="short"&&e.startsWith("no-"))throw new h("DEFINITION",`Flag ${t} "${e}" must not start with "no-"; the prefix is reserved for boolean negation`,{subject:"flag",name:e,reason:"reserved-no-prefix"});if(e==="__proto__")throw new h("DEFINITION",`Flag ${t} "__proto__" is a reserved spelling`,{subject:"flag",name:e,reason:"reserved-spelling"})}function Xe(e,t){return[e,...t.short===void 0?[]:[t.short],...t.aliases??[]]}function Ze(e){return e.type==="boolean"&&e.noNegate!==!0}function Qe(e){if(e.choices&&e.default!==void 0){let t="multiple"in e&&e.multiple?e.default:[e.default];for(let n of t)if(!e.choices.includes(n))throw new h("DEFINITION","default must be one of choices")}return Object.freeze({...e,..."aliases"in e&&e.aliases?{aliases:Object.freeze([...e.aliases])}:{},...e.choices?{choices:Object.freeze([...e.choices])}:{},..."multiple"in e&&e.multiple&&Array.isArray(e.default)?{default:Object.freeze([...e.default])}:{}})}function et(e,t){if(ie(e,"canonical"),t.short!==void 0)ie(t.short,"short");for(let r of t.aliases??[])ie(r,"alias");let n=Xe(e,t);if(new Set(n).size!==n.length)throw new h("DEFINITION",`Flag "${e}" repeats one of its own spellings`,{subject:"flag",name:e,reason:"flag-collision"});if(t.short!==void 0&&t.short.length!==1)throw new h("DEFINITION","Short flags must be one character");return Qe(t)}function tt(e){if(e.name==="")throw new h("DEFINITION","Argument names must be non-empty",{subject:"argument",name:e.name,reason:"empty-name"});return Qe(e)}var Hn=Symbol("crust.defining");function H(e){return e[Hn]}var nt=Symbol.for("crust.contextSources");function K(e,t){let n=new Set(e.map((s)=>s.name)),r=new Set,o=(s)=>{if(r.has(s))return;r.add(s);let i="contextName"in s?s.contextName:s.name;if(!n.has(i))throw new h("DEFINITION",`No provider for Context "${i}"`,{subject:"context",name:i,reason:"missing-context"});for(let a of s.uses)o(a)};for(let s of t)o(s)}function Kn(e){return typeof e==="function"}var Gn=class{#e=[];#t=!1;#n(){if(this.#t)throw ReferenceError("AsyncDisposableStack is already disposed")}use(e){this.#n();let t=Jn(e)?e[Symbol.asyncDispose]:e[Symbol.dispose];return this.#e.push(()=>t.call(e)),e}defer(e){if(this.#n(),!Kn(e))throw TypeError("defer callback is not callable");this.#e.push(e)}async[Symbol.asyncDispose](){this.#t=!0;let e=[];for(let t=this.#e.length-1;t>=0;t--)try{await this.#e[t]()}catch(n){e.push(n)}if(e.length===1)throw e[0];if(e.length>1)throw AggregateError(e,"Disposal failed")}},Yn=globalThis.AsyncDisposableStack??Gn;function Jn(e){return typeof e[Symbol.asyncDispose]==="function"}function Xn(e){if(e===null||typeof e!=="object"&&typeof e!=="function")return!1;let t=e;return typeof t[Symbol.asyncDispose]==="function"||typeof t[Symbol.dispose]==="function"}function Zn(e,t,n){if(!Xn(e)||n.has(e))return;n.add(e),t.use(e)}function Qn(e,t,n){let r=new Map(e.map((d)=>[d.name,d])),o=new Map,s=new WeakSet,i,a=!1;n.defer(()=>{a=!0});let c=(d,m,p=new Set)=>{if(d.name===m)return[d.name];if(p.has(d.name))return;p.add(d.name);for(let y of d.waitingOn){let S=o.get(y);if(!S)continue;let x=c(S,m,p);if(x)return[d.name,...x]}},l=(d)=>{try{let m=new Set;for(let p=d;p!=null&&!m.has(p);p=p.cause)if(m.add(p),p instanceof h&&p.code==="DEFINITION"&&p.details?.reason==="flags-before-validation")return!0;return!1}catch{return!1}};function u(d){let m=Promise.reject(d);return m.catch(()=>{}),m}let f=(d)=>(m)=>{let p=d?` (pulled while constructing Context "${d.name}")`:"";if(a)return u(new h("DEFINITION",`Context "${m}" cannot be pulled from onError because invocation Contexts have already been disposed.`,{subject:"context",name:m,reason:"context-after-disposal"}));let y=r.get(m);if(!y)return u(new h("DEFINITION",`No provider for Context "${m}". Add .provide(${m}(...)) to the app or an ancestor command.${p}`,{subject:"context",name:m,reason:"missing-context"}));if(i===void 0&&Object.keys(y.ownedFlags).length>0)return u(new h("DEFINITION",`Context "${m}" owns flags and cannot be pulled before flag validation${p}. Pull it from an action or a postRun hook after a validated invocation.`,{subject:"context",name:m,reason:"flags-before-validation"}));let S=o.get(m);if(!S){let x=Promise.withResolvers();x.promise.catch(()=>{}),S={name:m,promise:x.promise,resolve:x.resolve,reject:x.reject,waitingOn:new Set,settled:!1},o.set(m,S);let v=S;(async()=>{try{let O=Object.fromEntries(Object.keys(y.ownedFlags).map((E)=>[E,i?.[E]])),I=await y.setup({...t,flags:O,ctx:g(y.uses,v),defer(E){if(v.settled)throw new h("DEFINITION",`Context "${m}" cannot register cleanup after its setup has finished.`,{subject:"context",name:m,reason:"context-defer-after-setup"});n.defer(E)}});Zn(I,n,s),v.resolve(I)}catch(O){if(l(O))o.delete(m);v.reject(O)}finally{v.settled=!0}})()}if(d&&!S.settled){let x=c(S,d.name);if(x)return u(new h("DEFINITION",`Context dependency cycle: ${[d.name,...x].map((v)=>`"${v}"`).join(" -> ")}`,{subject:"context",name:d.name,reason:"context-cycle"}));return d.waitingOn.add(m),S.promise.finally(()=>d.waitingOn.delete(m))}return S.promise},g=(d,m)=>{let p={},y=(S)=>{let x="contextName"in S?S.contextName:S.name;if(Object.hasOwn(p,x))return;Object.defineProperty(p,x,{enumerable:!0,get:()=>f(m)(x)});for(let v of S.uses??[])y(v)};for(let S of d)y(S);return Object.defineProperty(p,nt,{value:Object.freeze([...d])}),Object.freeze(p)};return{bag:(d)=>g(d,null),setValidatedFlags(d){i=d},async settle(){for(;;){let d=[...o.values()].filter((m)=>!m.settled);if(d.length===0)return;await Promise.allSettled(d.map((m)=>m.promise))}}}}var er=Object.freeze({[Symbol("crust.finished")]:!0});function le(){return er}function rt(e){return{meta:{name:e},localFlags:{},ownedFlags:{},effectiveFlags:{},flagSpellings:new Map,args:[],subCommands:{},contexts:[],demands:[],extensions:[],run:void 0}}function A(e,t,n,r){n=et(t,n);let o=Xe(t,n),s=Object.hasOwn(e.effectiveFlags,t)?t:o.map((a)=>e.flagSpellings.get(a)?.canonicalName).find((a)=>a!==void 0);if(s!==void 0)throw new h("DEFINITION",`Flag "${t}" collides with existing flag "${s}" on command "${e.meta.name}"`,{subject:"flag",name:t,reason:"flag-collision"});(r==="local"?e.localFlags:e.ownedFlags)[t]=n,e.effectiveFlags[t]=n;let i={canonicalName:t,def:n,negatable:Ze(n)};if(e.flagSpellings.set(t,{...i,kind:"canonical"}),n.short!==void 0)e.flagSpellings.set(n.short,{...i,kind:"short"});for(let a of n.aliases??[])e.flagSpellings.set(a,{...i,kind:"alias"})}function ot(e,t,n,r){if(A(e,t,n,"owned"),!r)return;for(let o of Object.values(e.subCommands))ot(o,t,n,!0)}function tr(e,t,n){for(let r of t.commands??[])e.subCommands[r.name]=n(r,e,t.id)}function nr(e,t){for(let[n,r]of Object.entries(t.flags??{})){let{recursive:o=!0,...s}=r;ot(e,n,s,o)}}function T(e){let t={};for(let[n,r]of Object.entries(e.subCommands))t[n]=T(r);return{...e,meta:{...e.meta},localFlags:{...e.localFlags},ownedFlags:{...e.ownedFlags},effectiveFlags:{...e.effectiveFlags},flagSpellings:new Map([...e.flagSpellings].map(([n,r])=>[n,{...r,def:e.effectiveFlags[r.canonicalName]}])),args:[...e.args],subCommands:t,contexts:e.contexts.map((n)=>({...n})),demands:[...e.demands],extensions:[...e.extensions],run:e.run}}function rr({subject:e,name:t}){return new h("DEFINITION",`${e==="command"?"Command":"Extension"} "${t}" contains invalid documentation sections`,{subject:e,name:t,reason:"invalid-sections"})}function st(e,t){let{title:n,body:r,only:o,except:s}=e;if(!n.trim()||/[\r\n]/.test(n)||!r.trim()||o?.length===0||s?.length===0||o!==void 0&&s!==void 0)throw rr(t);let i=(a)=>Object.freeze(a.map((c)=>typeof c==="string"?c:c.id));return Object.freeze({title:n,body:r,...o?{only:i(o)}:s?{except:i(s)}:{}})}function fe(e,t){return t.map((n)=>st(n,{subject:"command",name:e}))}function or(e,t,n){let r=e;for(let o of t){let s=Object.hasOwn(r.subCommands,o)?r.subCommands[o]:void 0;if(!s)throw new h("DEFINITION",`Extension "${n.id}" section target "${t.join(" ")}" is not a canonical command path`,{subject:"extension",name:n.id,reason:"invalid-section-path"});r=s}return r}function sr(e,t,n){if(!t.sections)return;let r={subject:"extension",name:t.id},o=t.sections(n);for(let s of o){let i=st(s,r),a=or(e,s.command,t);a.meta.sections=[...a.meta.sections??[],i]}}function it(e,t,n){let r=T(e),o=new Set(t.flatMap((i)=>!n.has(i.id)&&e.extensions.includes(i)?[i.id]:[])),s=(i)=>{i.contexts=i.contexts.filter((u)=>u.extensionId===void 0||o.has(u.extensionId));let a=Object.keys(i.effectiveFlags),c=i.localFlags,l={};for(let{instance:u}of i.contexts)Object.assign(l,u.ownedFlags);i.localFlags={},i.ownedFlags={},i.effectiveFlags={},i.flagSpellings=new Map;for(let u of a){let f=Object.hasOwn(l,u)?"owned":"local",g=f==="owned"?l:c;if(Object.hasOwn(g,u))A(i,u,g[u],f)}for(let u of Object.values(i.subCommands))s(u)};s(r);for(let i of t){if(o.has(i.id))continue;let a=i.provides??[];if(a.length===0)continue;let c=(l,u)=>{let f=a.filter((m)=>!u.has(m.name)),g=f.map((m)=>({instance:m,extensionId:i.id}));l.contexts.push(...g);for(let m of f)for(let[p,y]of Object.entries(m.ownedFlags))A(l,p,y,"owned");let d=new WeakSet(l.contexts.map(({instance:m})=>m));for(let m of Object.values(l.subCommands)){let p=new Set(u);for(let{instance:y}of m.contexts)if(!d.has(y))p.add(y.name);c(m,p)}};c(r,new Set)}return r}function ir(e){try{return new URL(e)}catch{throw new h("PARSE",`Invalid URL "${e}"${/^[a-z][a-z0-9+.-]*:/i.test(e)?"":" (missing protocol — e.g. https://example.com)"}`)}}function q(e){if(e==="")throw new h("PARSE","Path cannot be empty");let t=e.replace(/^~(?=\/|$)/,qn());return Wn(process.cwd(),t)}function ar(e){try{return JSON.parse(e)}catch(t){throw new h("PARSE",`Invalid JSON: ${t instanceof Error?t.message:String(t)}. Tip: wrap JSON in single quotes on the command line, e.g. --flag '{"k":1}'`)}}function cr(e){let t={};for(let[n,r]of e){let o={type:r.def.type==="boolean"?"boolean":"string"};if(r.def.multiple)o.multiple=!0;if(r.kind==="canonical"){if(r.def.short)o.short=r.def.short;t[n]=o;continue}if(r.kind==="alias")t[n]=o}return t}function at(e,t,n){if(t==="number"){let r=qe(e);if(r===void 0)throw new h("PARSE",`Expected number for ${n}, got "${e}"`);return r}if(t==="boolean")return He(e);if(t==="url")return ir(e);if(t==="path")return q(e);if(t==="json")return ar(e);return e}function de(e,t,n){if(!t.includes(e))throw new h("PARSE",`Invalid value "${e}" for ${n}. Expected one of: ${t.join(", ")}`)}function R(e,t,n,r){let o=r===void 0?n:`${n} element [${r}]`,s;try{if(s=e(t),Vn(s))throw s.catch(()=>{}),Error("parse must be synchronous")}catch(i){throw new h("PARSE",`Failed to parse ${o}: ${i instanceof Error?i.message:String(i)}`).withCause(i)}return s}function ct(e,t){let{default:n,parse:r}=e;if(n===void 0)return;if(r){if(Array.isArray(n))return n.map((o,s)=>R(r,String(o),t,s));return R(r,String(n),t)}if(e.type==="path"){if(Array.isArray(n))return n.map((o)=>q(String(o)));return q(String(n))}return"multiple"in e&&e.multiple&&Array.isArray(n)?[...n]:n}function lr(e,t,n){if(n.kind==="boolean")return n.value;let r=`--${e}`,o=(s,i)=>{if(t.choices)de(s,t.choices,r);if(t.parse)return R(t.parse,s,r,i);return at(s,t.type,r)};return Array.isArray(n.value)?n.value.map(o):o(n.value)}function ur(e,t){let n={};for(let r of e){if(r.kind!=="option")continue;let{canonicalName:o,def:s}=t.get(r.name),i=n[o];if(s.type==="boolean"){let a=!r.rawName.startsWith("--no-");if(s.multiple&&i?.kind==="boolean"&&Array.isArray(i.value))i.value.push(a);else n[o]={kind:"boolean",value:s.multiple?[a]:a}}else{let a=r.value;if(s.multiple&&i?.kind==="string"&&Array.isArray(i.value))i.value.push(a);else n[o]={kind:"string",value:s.multiple?[a]:a}}}return n}function fr(e,t,n){let r={};for(let o of Object.keys(t))if(!Object.hasOwn(e,o)&&t[o]!==void 0)throw new h("PARSE",`Unknown flag "--${o}"`,{flag:o,reason:"unknown-flag"});for(let[o,s]of Object.entries(e)){let i=Object.hasOwn(t,o)?t[o]:void 0;if(!(i===void 0||s.multiple&&Array.isArray(i)&&i.length===0)){r[o]=n(o,s,i);continue}r[o]=ct(s,`--${o}`)}return r}function dr(e,t){for(let[n,r]of Object.entries(e))if(r.required===!0&&r.default===void 0){if(t[n]===void 0)throw new h("VALIDATION",`Missing required flag "--${n}"`)}}function mr(e,t,n,r){if(e.schema)return t;if(e.choices)de(t,e.choices,n);if(e.parse)return R(e.parse,t,n,r);return at(t,e.type,n)}function gr(e,t,n){let r={},o=0;for(let s of e){let{name:i}=s,a=`<${i}>`;if(Object.defineProperty(r,i,{value:void 0,writable:!0,enumerable:!0,configurable:!0}),s.variadic)r[i]=t.slice(o).map((c,l)=>n(s,c,a,l)),o=t.length;else if(o<t.length)r[i]=n(s,t[o],a),o++;else r[i]=ct(s,a)}return{args:r,consumed:o}}function hr(e,t){for(let n of e){if(n==="--")return;if(!n.startsWith("--no-"))continue;let r=n.indexOf("="),o=r===-1?n.slice(5):n.slice(5,r),s=t.get(o);if(!s||s.def.type!=="boolean"||s.negatable)continue;throw new h("PARSE",`Flag "--${s.canonicalName}" does not support negation ("--no-${o}")`)}}function pr(e,t){let n=e.flagSpellings,r=cr(n);hr(t,n);let o;try{o=Un({args:t,options:r,strict:!0,allowPositionals:!0,allowNegative:!0,tokens:!0})}catch(c){if(c instanceof Error){let l=c.message.match(/Unknown option '(.+?)'/);if(l)throw new h("PARSE",`Unknown flag "${l[1]}"`).withCause(c);if("code"in c&&c.code==="ERR_PARSE_ARGS_INVALID_OPTION_VALUE"&&c.message.length>0)throw new h("PARSE",c.message).withCause(c)}throw new h("PARSE","Failed to parse command arguments").withCause(c)}let s=[],i=[],a=!1;for(let c of o.tokens){if(c.kind==="option-terminator"){a=!0;continue}if(c.kind==="positional")(a?s:i).push(c.value)}return{positionals:i,flagValues:ur(o.tokens,n),rawArgs:s}}function br(e,t,n){let r=e.schema?e.type==="boolean"?"boolean":"string":e.type,o;if(r==="url")o=t instanceof URL;else if(r==="json"){let s=[t],i=new Set;o=!0;while(s.length>0){let a=s.pop();if(a instanceof URL){o=!1;break}if(Array.isArray(a)&&!i.has(a))i.add(a),s.push(...a)}}else o=typeof t===(r==="path"?"string":r);if(!o)throw new h("PARSE",`Expected ${r} for ${n}`);if(t===!1&&"noNegate"in e&&e.noNegate)throw new h("PARSE",`Flag "${n}" does not support negation`)}function ue(e,t,n,r){if(br(e,t,n),e.choices)de(String(t),e.choices,n);if(e.parse)return R(e.parse,String(t),n,r);if(e.type==="path")return q(String(t));return t}function wr(e,t,n){let r=`--${e}`;if(t.multiple){if(!Array.isArray(n))throw new h("PARSE",`Expected an occurrence array for ${r}`);return n.map((o,s)=>ue(t,o,r,s))}return ue(t,n,r)}function lt(e,t,n,r,o){let s=fr(e.effectiveFlags,n,o);return{...gr(e.args,t,r),flags:s}}function yr(e,t){let{positionals:n,flagValues:r,rawArgs:o}=pr(e,t),{args:s,flags:i,consumed:a}=lt(e,n,r,mr,lr);return{args:s,flags:i,excessArgs:n.slice(a),rawArgs:o}}function vr(e,t){let{args:n,flags:r,raw:o}=t,s=[],i;for(let l of e.args){let u=n&&Object.hasOwn(n,l.name)?n[l.name]:void 0;if(u===void 0){i=l.name;continue}if(i!==void 0)throw new h("PARSE",`Argument <${l.name}> cannot be provided after omitted argument <${i}>`,{argument:l.name,reason:"positional-gap"});if(l.variadic){if(!Array.isArray(u))throw new h("PARSE",`Expected an occurrence array for <${l.name}>`);s.push(...u)}else s.push(u)}for(let l of Object.keys(n??{}))if(!e.args.some((u)=>u.name===l)&&n?.[l]!==void 0)throw new h("PARSE",`Unknown argument "${l}"`,{argument:l,reason:"unknown-argument"});let{args:a,flags:c}=lt(e,s,r??{},ue,wr);return{args:a,flags:c,excessArgs:[],rawArgs:[...o??[]]}}function Sr(e,t){let{args:n,effectiveFlags:r}=e,{args:o,flags:s}=t;if(t.excessArgs.length>0)throw new h("VALIDATION",`Unexpected positional argument${t.excessArgs.length===1?"":"s"}: ${t.excessArgs.map((i)=>JSON.stringify(i)).join(", ")}`);for(let i of n){let{name:a}=i,c=`argument "<${a}>"`,l=o[a];if(i.required===!0&&i.default===void 0){if(i.variadic){if(!Array.isArray(l)||l.length===0)throw new h("VALIDATION",`Missing required ${c}`)}else if(l===void 0)throw new h("VALIDATION",`Missing required ${c}`)}}dr(r,s)}async function Ge(e,t,n,r){let o=await e["~standard"].validate(t);if(o.issues)return r.push(...Ke(o.issues,n)),{ok:!1};return{ok:!0,value:o.value}}async function xr(e,t){let n=[],r=new Map(Object.entries(t.args)),o=new Map(Object.entries(t.flags));for(let s of e.args){if(s.schema===void 0)continue;let i=await Ge(s.schema,r.get(s.name),["args",s.name],n);if(i.ok)r.set(s.name,i.value)}for(let[s,i]of Object.entries(e.effectiveFlags)){if(i.schema===void 0)continue;let a=await Ge(i.schema,o.get(s),["flags",s],n);if(a.ok)o.set(s,a.value)}if(n.length>0)throw new h("VALIDATION",`Invalid input:
|
|
5
|
+
${n.map((s)=>` - ${s.path}: ${s.message}`).join(`
|
|
6
|
+
`)}`,{issues:n});return{args:Object.fromEntries(r),flags:Object.fromEntries(o)}}function ut(e){return e.meta.hidden!==!0}function me(e){for(let t of Object.keys(e))if(e[t]===void 0)delete e[t];return Object.freeze(e)}function ge(e){if(e instanceof URL)return e.href;if(Array.isArray(e))return Object.freeze(e.map(ge));return e}function Or(e){return me({name:e.name,type:e.type,description:e.description,required:e.required,variadic:e.variadic,choices:e.choices?Object.freeze([...e.choices]):void 0,default:ge(e.default)})}function $r(e){return me({type:e.type,description:e.description,short:e.short,aliases:e.aliases?Object.freeze([...e.aliases]):void 0,required:e.required,multiple:e.multiple,negatable:Ze(e),noNegate:"noNegate"in e?e.noNegate:void 0,choices:e.choices?Object.freeze([...e.choices]):void 0,default:ge(e.default)})}function j(e){let t={};for(let[r,o]of Object.entries(e.effectiveFlags))t[r]=$r(o);let n={};for(let[r,o]of Object.entries(e.subCommands))n[r]=j(o);return Object.freeze({meta:me({name:e.meta.name,description:e.meta.description,version:e.meta.version,usage:e.meta.usage,sections:e.meta.sections?Object.freeze(e.meta.sections.map((r)=>Object.freeze({...r}))):void 0,aliases:e.meta.aliases?Object.freeze([...e.meta.aliases]):void 0,hidden:e.meta.hidden}),hasAction:e.run!==void 0,args:Object.freeze(e.args.map(Or)),flags:Object.freeze(t),subCommands:Object.freeze(n)})}function Cr(e,t){for(let[n,r]of Object.entries(e)){let o=r.meta.aliases;if(!o)continue;if(o.includes(t))return{canonicalName:n,node:r}}return null}function Ye(e,t){if(t==="--")return null;if(t.startsWith("--")){let r=t.indexOf("="),o=r===-1?t.slice(2):t.slice(2,r),s=e.get(o);if(s)return{consumesValue:s.def.type!=="boolean"&&r===-1};if(o.startsWith("no-")){if(e.get(o.slice(3))?.negatable)return{consumesValue:!1}}return null}let n=t.slice(1);if(n.length===0)return null;for(let r=0;r<n.length;r++){let o=e.get(n[r]);if(!o)return null;if(o.def.type!=="boolean")return{consumesValue:r===n.length-1}}return{consumesValue:!1}}function ft(e,t){let n=[e.meta.name],r=e,o=t,s=[],i=[],a=(c,l)=>{if(i.length===0)return;let u=c.flagSpellings;for(let{token:f,consumesValue:g}of i){let d=Ye(u,f);if(d!==null&&d.consumesValue===g)continue;throw new h("PARSE",`Flag "${f}" cannot be used before subcommand "${l}" because "${l}" does not accept it.`,{flag:f,reason:"flag-not-forwardable"})}};while(o.length>0){let c=r.subCommands;if(Object.keys(c).length===0)break;let l=o[0];if(!l)break;if(l.startsWith("-")){let g=Ye(r.flagSpellings,l);if(!g)break;s.push(l),i.push({token:l,consumesValue:g.consumesValue}),o=o.slice(1);let d=o[0];if(g.consumesValue&&d!==void 0)s.push(d),o=o.slice(1);continue}if(Object.hasOwn(c,l)&&c[l]){a(c[l],l),r=c[l],n.push(l),o=o.slice(1);continue}let u=Cr(c,l);if(u){a(u.node,l),r=u.node,n.push(u.canonicalName),o=o.slice(1);continue}if(r.run)break;let f=j(r);throw new h("COMMAND_NOT_FOUND",`Unknown command "${l}".`,{input:l,available:Object.entries(f.subCommands).flatMap(([g,d])=>ut(d)?[g]:[]),commandPath:[...n],parentCommand:f})}return{command:r,argv:[...s,...o],commandPath:n}}function Er(){var e=typeof SuppressedError=="function"?SuppressedError:function(o,s){var i=Error();return i.name="SuppressedError",i.error=o,i.suppressed=s,i},t={},n=[];function r(o,s){if(s!=null){if(Object(s)!==s)throw TypeError("using declarations can only be used with objects, functions, null, or undefined.");if(o)var i=s[Symbol.asyncDispose||Symbol.for("Symbol.asyncDispose")];if(i===void 0&&(i=s[Symbol.dispose||Symbol.for("Symbol.dispose")],o))var a=i;if(typeof i!="function")throw TypeError("Object is not disposable.");a&&(i=function(){try{a.call(s)}catch(l){return Promise.reject(l)}}),n.push({v:s,d:i,a:o})}else o&&n.push({d:s,a:o});return s}return{e:t,u:r.bind(null,!1),a:r.bind(null,!0),d:function(){var s,i=this.e,a=0;function c(){for(;s=n.pop();)try{if(!s.a&&a===1)return a=0,n.push(s),Promise.resolve().then(c);if(s.d){var u=s.d.call(s.v);if(s.a)return a|=2,Promise.resolve(u).then(c,l)}else a|=1}catch(f){return l(f)}if(a===1)return i!==t?Promise.reject(i):Promise.resolve();if(i!==t)throw i}function l(u){return i=i!==t?new e(u,i):u,c()}return c()}}}var Ir={stdout:(e)=>console.log(e),stderr:(e)=>console.error(e)};var F=130;function ae(e){if(!(e instanceof Error))return!1;return e.name==="AbortError"}function dt(e){if(Object.freeze(e),Object.freeze(e.localFlags),Object.freeze(e.ownedFlags),Object.freeze(e.effectiveFlags),e.meta.sections)Object.freeze(e.meta.sections);Object.freeze(e.meta),Object.freeze(e.contexts),Object.freeze(e.extensions),Object.freeze(e.args);for(let t of Object.values(e.subCommands))dt(t);Object.freeze(e.subCommands)}function jr(e){return typeof e==="symbol"}var Je=new WeakMap;function Nr(e,t){let n=T(e),r=Object.freeze([...e.extensions]);for(let o of r)tr(n,o,t);for(let o of r)nr(n,o);return{rootNode:n,extensions:r}}function kr(e,t){let n=j(e);for(let r of t)sr(e,r,n);return dt(e),e}function M(e,t){let n=Je.get(e);if(n)return n;let r=Nr(e,t);return kr(r.rootNode,r.extensions),Je.set(e,r),r}function Ar(e,t){let n=ft(e,[...t]);return{argv:t,route:n,parsed:yr(n.command,n.argv)}}function he(e,t){let n=ft(e,[...t]);if(n.argv.length>0){let r=n.argv[0],o=j(n.command);throw new h("COMMAND_NOT_FOUND",`Unknown command "${r}".`,{input:r,available:Object.entries(o.subCommands).flatMap(([s,i])=>ut(i)?[s]:[]),commandPath:n.commandPath,parentCommand:o})}return n}function Tr(e,t,n){let r=he(e,t);return{argv:t,route:r,parsed:vr(r.command,n)}}async function mt(e,t,n,r,o){try{var s=Er();let{rootNode:i,extensions:a}=t,{argv:c,route:l,parsed:u}="argv"in e?Ar(i,e.argv):Tr(i,e.path,e.input),f=l.command,g=s.a(new Yn),d=f.contexts.map(({instance:O})=>O),m=Qn(d,n,g),p=j(i),y=Object.freeze({argv:[...c],rootCommand:p,command:f===i?p:j(f),commandPath:Object.freeze([...l.commandPath]),args:u.args,flags:u.flags,rawArgs:u.rawArgs,ctx:m.bag(a.flatMap((O)=>O.uses??[])),finish:le,stdout:n.stdout,stderr:n.stderr});r?.(y);let S=async()=>{Sr(f,u);let O=await xr(f,u);if(m.setValidatedFlags(O.flags),!f.run)return;let I={args:O.args,flags:O.flags,ctx:m.bag(d),rawArgs:u.rawArgs,command:y.command,rootCommand:p,stdout:n.stdout,stderr:n.stderr};return await f.run(I)},x,v={status:"completed"};try{try{for(let E of a)if(await E.hooks?.preRun?.(y)===le()){v={status:"finished",by:E.id};break}if(v.status!=="finished")x=await S()}catch(E){let C=await o?.(E,y);v={status:"failed",error:E,...C===void 0?{}:{by:C}}}Object.freeze(v);let O=!1,I;for(let E of a.toReversed())try{await E.hooks?.postRun?.(y,v)}catch(C){if(v.status!=="failed"&&!O)O=!0,I=C}if(v.status==="failed")throw v.error;if(O)throw I}finally{await m.settle()}return v.status==="finished"?{status:"finished",by:v.by}:{status:"completed",result:x}}catch(i){s.e=i}finally{await s.d()}}async function ce(e,t,n,r,o,s=!1){let i=()=>{if(s)return;let u=e instanceof Error?e.message:String(e);r.stderr(`Error: ${u}`)};function a(u){return Promise.reject(new h("DEFINITION",`Context "${String(u)}" cannot be pulled from onError because invocation Contexts have already been disposed.`,{subject:"context",name:String(u),reason:"context-after-disposal"}))}let c=new Proxy({},{get:(u,f)=>f==="then"||jr(f)?void 0:a(f)}),l=o??Object.freeze({argv:[...t],rootCommand:j(n.rootNode),command:j(n.rootNode),commandPath:Object.freeze([n.rootNode.meta.name]),args:Object.freeze({}),flags:Object.freeze({}),rawArgs:[],finish:le,stdout:r.stdout,stderr:r.stderr,ctx:c});try{for(let u of n.extensions)if(await u.hooks?.onError?.(e,l))return u.id}catch{}i()}function _r(e){return e!==void 0&&Object.keys(e).length>0}async function pe(e,t,n,r){let o=[],s=[];try{let i={...n},a={stdout(c){o.push(c),i.stdout?.(c)},stderr(c){s.push(c),i.stderr?.(c)}};return{...await se(a,async()=>await mt(t,M(e,r),a)),stdout:o.join(`
|
|
7
|
+
`),stderr:s.join(`
|
|
8
|
+
`)}}catch(i){return{status:"failed",error:i,stdout:o.join(`
|
|
9
|
+
`),stderr:s.join(`
|
|
10
|
+
`)}}}async function gt(e,t,n){let r=t?.argv??process.argv.slice(2),o={...Ir,...t?.io},s=void 0,i=async()=>{let a;try{a=M(e,n)}catch(u){if(ae(u))return process.exitCode=F,F;let f=u instanceof Error?u.message:String(u);return o.stderr(`Error: ${f}`),process.exitCode=1,1}let c,l=!1;try{await mt({argv:r},a,o,(u)=>{c=u},async(u,f)=>{l=!0;let g=ae(u);return process.exitCode=g?F:1,ce(u,r,a,o,f,g)})}catch(u){if(ae(u)){if(!l)await ce(u,r,a,o,c,!0);return process.exitCode=F,F}if(process.exitCode=1,!l)await ce(u,r,a,o,c);return 1}return 0};return await(_r(t?.io)?se(o,i):i())}var we=Symbol.for("crust.commandDefinition");function _(e,t,n){let r=e[we],o=e.name,s=n?`Extension "${n}" command "${o}"`:`Command "${o}"`,i=(u)=>({subject:n?"extension":"command",name:n??o,reason:u}),a=new G(o);for(let[u,f]of Object.entries(t.ownedFlags))A(a._node,u,f,"owned");a._node.contexts=t.contexts.map((u)=>({...u}));let c=r.recipe(a);if(!(c instanceof G)||c._ancestorOwnedFlags!==a._ancestorOwnedFlags)throw new h("DEFINITION",`${s} definition must return the same command builder it received`,i("foreign-command-builder"));if(c._node.extensions.length>0)throw new h("DEFINITION",`${s} cannot register Extensions inside command definitions`,i("nested-command-extension"));let l=T(c._node);return K(l.contexts.map(({instance:u})=>u),l.demands),l.meta={name:o,...r.meta},l}function be(e,t=[]){if(e.trim()==="")throw new h("DEFINITION","Command name must be a non-empty string",{subject:"command",name:e,reason:"empty-name"});if(e==="__proto__")throw new h("DEFINITION",'Command name "__proto__" is reserved',{subject:"command",name:e,reason:"reserved-name"});if(t.includes(e))throw new h("DEFINITION",`Command "${e}" must not list its own canonical name as an alias`,{subject:"command",name:e,reason:"alias-collision"});return e}function Pr(e){return typeof e==="function"}function Dr(e,t,n){let r=!Pr(t),o=r?t:{},s=r?n:t,i=be(e,o.aliases);for(let d of o.aliases??[])if(d===""||/[ \t\n\r\v\f]/.test(d)||d.startsWith("-"))throw new h("DEFINITION",`Command "${i}" has an invalid alias "${d}"`);let{sections:a,version:c,...l}=o,u={...l,...o.aliases?{aliases:[...o.aliases]}:{},...a?{sections:fe(i,a)}:{}},f={name:i,recipe:s,meta:u},g=(d)=>Object.freeze({name:d,as:(m)=>g(be(m,u.aliases)),[we]:Object.freeze({...f,name:d})});return g(i)}function Fr(e){return e.filter((t,n)=>e.findLastIndex((r)=>r.id===t.id)===n)}var G=class{_node;_ancestorOwnedFlags;constructor(e,...t){let n=t[0]??{},r=be(e);if(this._node=rt(r),n.description!==void 0)this._node.meta.description=n.description;if(n.version!==void 0)this._node.meta.version=n.version;if(n.usage!==void 0)this._node.meta.usage=n.usage;if(n.sections!==void 0)this._node.meta.sections=fe(r,n.sections);this._ancestorOwnedFlags={}}_clone(e){let t=Object.create(Object.getPrototypeOf(this));return t._node={...T({...this._node,subCommands:{}}),subCommands:{...this._node.subCommands},...e},t._ancestorOwnedFlags=this._ancestorOwnedFlags,t}flags(...e){let t=this._clone({});for(let n of e){let{name:r,...o}=n;A(t._node,r,o,"local")}return t}args(...e){let t=[...this._node.args,...e.map(tt)],n=new Set;for(let[r,o]of t.entries()){if(n.has(o.name))throw new h("DEFINITION",`Argument name "${o.name}" is already defined`,{subject:"argument",name:o.name,reason:"duplicate-arg"});if(n.add(o.name),o.variadic===!0&&r!==t.length-1)throw new h("DEFINITION",`Only the last positional argument can be variadic; "${o.name}" is not last`,{subject:"argument",name:o.name,reason:"variadic-position"})}return this._clone({args:t})}use(...e){return this._clone({demands:[...this._node.demands,...e.map(H)]})}provide(...e){let t=e.map(H);K([...this._node.contexts.map(({instance:r})=>r),...t],t);let n=this._clone({contexts:[...this._node.contexts,...t.map((r)=>({instance:r}))]});for(let r of t)for(let[o,s]of Object.entries(r.ownedFlags))A(n._node,o,s,"owned");return n}action(e){return this._clone({run:e})}extend(...e){let t=e.map(H),n=Fr([...this._node.extensions,...t]),r=it(this._node,n,new Set(t.map((o)=>o.id)));return K(r.contexts.map(({instance:o})=>o),n.flatMap((o)=>[...o.uses,...o.provides??[]])),this._clone({...r,extensions:n})}add(...e){return this._addDefinitions(e)}command(e,t){let n=Dr(e,t);return this._addDefinitions([n])}_addDefinitions(e){let t={...this._node.subCommands};for(let n of e){let r=[n.name,...n[we].meta.aliases??[]];for(let s of Object.values(t))if([s.meta.name,...s.meta.aliases??[]].some((i)=>r.includes(i)))throw new h("DEFINITION",`Command name "${n.name}" is already registered on this command`,{subject:"command",name:n.name,reason:"command-collision"});let o=_(n,this._node);t[n.name]=o}return this._clone({subCommands:t})}async snapshot(){return j(M(this._node,_).rootNode)}async run(e,...t){let n=t[0]??{},r=t[1];return await pe(this._node,{path:e,input:n},r,_)}at(e){he(M(this._node,_).rootNode,e);let t=this._node,n=Object.freeze([...e]);return{path:n,async run(...r){let o=r[0]??{},s=r[1];return await pe(t,{path:n,input:o},s,_)}}}async execute(e){return await gt(this._node,e,_)}};import{existsSync as Se,lstatSync as Et,mkdirSync as xt,readFileSync as Xr,readdirSync as It,realpathSync as jt,statSync as Nt,writeFileSync as Ot}from"node:fs";import{dirname as kt,join as P,resolve as $t,sep as Zr}from"node:path";import{fileURLToPath as Qr}from"node:url";function ht(e){return e instanceof Error&&"code"in e&&typeof e.code==="string"}import{isAbsolute as Rr,relative as Mr,sep as Br}from"node:path";function pt(e,t){let n=Mr(e,t);return n===""||!Rr(n)&&n!==".."&&!n.startsWith(`..${Br}`)}import{spawn as eo,spawnSync as to}from"node:child_process";import{once as no}from"node:events";import{accessSync as bt,constants as wt,statSync as yt}from"node:fs";import{delimiter as zr,extname as Lr,join as Wr,resolve as Ur,sep as Vr,win32 as qr}from"node:path";import{spawn as Hr}from"node:child_process";import{once as Kr}from"node:events";import{text as vt}from"node:stream/consumers";function St(e){if(e?.startsWith("bun"))return"bun";if(e?.startsWith("pnpm"))return"pnpm";if(e?.startsWith("yarn"))return"yarn";if(e?.startsWith("npm"))return"npm";return null}var Gr=/[\0\r\n"%!^`<>&|]/,ye=/([()\][%!^"`<>&|;, *?])/g;function Yr(e){let t=e.replace(/(?=(\\+?)?)\1"/g,"$1$1\\\"");return t=t.replace(/(?=(\\+?)?)\1$/g,"$1$1"),t=`"${t}"`.replace(ye,"^$1"),t.replace(ye,"^$1")}function Jr(e,t,n,r=process.platform){if(n||r!=="win32"||!/\.(cmd|bat)$/i.test(e))return null;let o=qr.normalize(e);for(let[i,a]of[o,...t].entries())if(Gr.test(a)){let c=i===0?"command":`argument ${i}`;throw Error(`Windows command shim ${c} ${JSON.stringify(a)} contains unsafe shell characters`)}let s=[o.replace(ye,"^$1"),...t.map(Yr)].join(" ");return{command:process.env.ComSpec??"cmd.exe",args:["/d","/s","/c",`"${s}"`],windowsVerbatimArguments:!0}}async function B(e,t=[],n={}){let r=Jr(e,t,n.shell),o=(n.stdio??"collect")==="collect",s=o&&n.stdout!=="ignore",i=Hr(r?.command??e,r?.args??t,{cwd:n.cwd,env:n.env,shell:n.shell,stdio:o?["ignore",s?"pipe":"ignore","pipe"]:"inherit",windowsVerbatimArguments:r?.windowsVerbatimArguments}),[a,c,[l]]=await Promise.all([s?vt(i.stdout):"",o?vt(i.stderr):"",Kr(i,"close")]);return{exitCode:l,stdout:a,stderr:c}}function ve(e){if(e.includes(Vr)||e.includes("/")){try{if(bt(e,wt.X_OK),yt(e).isFile())return e}catch{}return null}let t=process.platform==="win32"&&!Lr(e)?(process.env.PATHEXT??".EXE;.CMD;.BAT;.COM").split(";"):[""];for(let n of process.env.PATH?.split(zr)??[])for(let r of t){let o=Ur(Wr(n,e+r));try{if(bt(o,wt.X_OK),yt(o).isFile())return o}catch{}}return null}function ro(e,t){return e.replace(/\{\{\s*(\w+)\s*\}\}/g,(n,r)=>Object.hasOwn(t,r)?t[r]??n:n)}function oo(e){let t=kt(e),n=e.slice(t==="."?0:t.length+1);if(n.startsWith("_")&&!n.startsWith("__")){let r=`.${n.slice(1)}`;return t==="."?r:P(t,r)}return e}function so(e){if(!Se(e))return!1;if(!Nt(e).isDirectory())return!1;return It(e).length>0}function io(e,t){let n=e;for(let r of t.split(Zr)){n=P(n,r);let o;try{o=Et(n).isSymbolicLink()}catch(i){if(ht(i)&&i.code==="ENOENT")return;throw i}if(!o)continue;let s;try{s=jt(n)}catch{}if(s===void 0||!pt(e,s))throw Error(`Destination path "${n}" is a symlink${s===void 0?" to a missing target":` to "${s}"`} outside the destination "${e}". Remove the link or choose another destination.`)}}async function xe(e){let{template:t,dest:n,context:r,conflict:o="abort"}=e,s=t instanceof URL?Qr(t):$t(t),i=$t(n);if(!Se(s))throw Error(`Template directory "${s}" does not exist (from template: "${String(t)}").`);if(!Nt(s).isDirectory())throw Error(`Template path "${s}" is not a directory (from template: "${String(t)}").`);if(o==="abort"&&so(i))throw Error(`Destination directory "${i}" already exists and is non-empty. Use conflict: "overwrite" to proceed.`);let a=It(s,{recursive:!0,encoding:"utf8"}).filter((f)=>Et(P(s,f)).isFile());xt(i,{recursive:!0});let c=jt(i),l=a.map((f)=>({relFromTemplate:f,destRelPath:oo(f)}));for(let{destRelPath:f}of l)io(c,f);let u=[];for(let{relFromTemplate:f,destRelPath:g}of l){let d=P(s,f),m=P(c,g);xt(kt(m),{recursive:!0});let p=Xr(d);if(p.subarray(0,8192).includes(0))Ot(m,p);else{let y=ro(p.toString("utf-8"),r);Ot(m,y,"utf-8")}u.push(g)}return{files:u}}var ao=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];function co(e){let t=e??process.cwd();for(let[n,r]of ao)if(Se(P(t,n)))return r;return St(process.env.npm_config_user_agent)??"npm"}function At(e){try{return to("git",["rev-parse","--is-inside-work-tree"],{cwd:e??process.cwd(),stdio:"ignore"}).status===0}catch{return!1}}async function Oe(e,t){for(let n of e)switch(n.type){case"install":await lo(t);break;case"git-init":await uo(t,n.commit);break;case"open-editor":await fo(t);break;case"command":await mo(n.cmd,n.cwd??t)}}async function lo(e){let t=co(e),n=ve(t);if(!n)throw Error(`Package manager "${t}" was not found on PATH. Install ${t} and try again.`);let{exitCode:r}=await B(n,["install"],{cwd:e,stdio:"inherit"});if(r!==0)throw Error(`"${t} install" exited with code ${r}`)}async function uo(e,t){let n=ve("git");if(!n)throw Error('"git" was not found on PATH. Install Git and try again.');if(await z([n,"init"],e,"git init"),t)await go(e,n),await z([n,"add","."],e,"git add"),await z([n,"commit","-m",t],e,"git commit")}async function fo(e){let t=process.env.EDITOR||"code";try{let n=eo(t,[e],{stdio:"ignore",shell:process.platform==="win32"});n.unref();let r=await Promise.race([no(n,"close").then(([o])=>({kind:"exited",code:o})),new Promise((o)=>setTimeout(()=>o({kind:"timeout"}),500))]);if(r.kind==="exited"&&r.code!==0)console.warn(`Warning: could not open editor "${t}" (exit code ${r.code})`)}catch{console.warn(`Warning: could not open editor "${t}"`)}}async function mo(e,t){let{exitCode:n}=await B(e,[],{cwd:t,shell:!0,stdio:"inherit"});if(n!==0)throw Error(`Command "${e}" exited with code ${n}`)}async function go(e,t){let n=await Ct(t,"user.name",e)===0,r=await Ct(t,"user.email",e)===0;if(!n)await z([t,"config","user.name","Crust"],e,"git config user.name");if(!r)await z([t,"config","user.email","crust@scaffolded.project"],e,"git config user.email")}async function Ct(e,t,n){let{exitCode:r}=await B(e,["config",t],{cwd:n,stdio:"collect",stdout:"ignore"});return r}async function z(e,t,n){let{exitCode:r,stderr:o}=await B(e[0],e.slice(1),{cwd:t,stdio:"collect",stdout:"ignore"});if(r!==0)throw Error(`"${n}" failed with exit code ${r}${o?`: ${o.trim()}`:""}`)}var Tt=Object.defineProperty,ho=(e,t)=>{let n={};for(var r in e)Tt(n,r,{get:e[r],enumerable:!0});if(!t)Tt(n,Symbol.toStringTag,{value:"Module"});return n},po=new Intl.Segmenter(void 0,{granularity:"grapheme"}),bo=/[\p{Cc}\p{Cf}\p{Mn}\p{Me}]/u,wo=/\p{Emoji_Presentation}|\p{Emoji}\uFE0F/u,yo=new RegExp([String.raw`(?:\x1b\[|\x9b)[^\x1b\x18\x1a\x9c\x40-\x7e]*[\x40-\x7e\x18\x1a\x9c]?`,String.raw`(?:\x1b\]|\x9d)[^\x07\x1b\x18\x1a\x9c]*(?:\x07|\x1b\\|[\x18\x1a\x9c])?`,String.raw`(?:\x1b[PX^_]|[\x90\x98\x9e\x9f])[^\x1b\x18\x1a\x9c]*(?:\x1b\\|[\x18\x1a\x9c])?`,String.raw`\x1b[\x20-\x2f][^\x1b]?`,String.raw`\x1b[\x18\x1a\x9c\x30-\x7e]?`].join("|"),"g");function vo(e){return e>=4352&&(e<=4447||e===9001||e===9002||e>=11904&&e<=42191&&e!==12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=94176&&e<=111355||e>=127488&&e<=127743||e>=131072&&e<=262141)}function So(e){return bo.test(String.fromCodePoint(e))||e>=4448&&e<=4607||e>=55216&&e<=55295}function xo(e){if(!/[^\x20-\x7e]/.test(e))return e.length;let t=0;for(let{segment:n}of po.segment(e.replace(yo,""))){if(wo.test(n)){let r=n.codePointAt(0);t+=n.length===2&&r>=127462&&r<=127487?1:2;continue}for(let r of n){let o=r.codePointAt(0);if(So(o))continue;t+=vo(o)?2:1;break}}return t}function Ft(e){return globalThis.Bun?.stringWidth(e,{countAnsiEscapeCodes:!1})??xo(e)}var Oo=ho({bgBlack:()=>Ko,bgBlue:()=>Xo,bgBrightBlack:()=>ts,bgBrightBlue:()=>ss,bgBrightCyan:()=>as,bgBrightGreen:()=>rs,bgBrightMagenta:()=>is,bgBrightRed:()=>ns,bgBrightWhite:()=>cs,bgBrightYellow:()=>os,bgCyan:()=>Qo,bgGreen:()=>Yo,bgMagenta:()=>Zo,bgRed:()=>Go,bgWhite:()=>es,bgYellow:()=>Jo,black:()=>Ao,blue:()=>Do,bold:()=>$o,brightBlue:()=>Uo,brightCyan:()=>qo,brightGreen:()=>Lo,brightMagenta:()=>Vo,brightRed:()=>zo,brightWhite:()=>Ho,brightYellow:()=>Wo,cyan:()=>Ro,dim:()=>Co,gray:()=>Bo,green:()=>_o,hidden:()=>No,inverse:()=>jo,isModifierName:()=>Rt,italic:()=>Eo,magenta:()=>Fo,red:()=>To,strikethrough:()=>ko,styleMethodNames:()=>Ce,underline:()=>Io,white:()=>Mo,yellow:()=>Po});function w(e,t){return{open:`\x1B[${e}m`,close:`\x1B[${t}m`}}var $o=w(1,22),Co=w(2,22),Eo=w(3,23),Io=w(4,24),jo=w(7,27),No=w(8,28),ko=w(9,29),Ao=w(30,39),To=w(31,39),_o=w(32,39),Po=w(33,39),Do=w(34,39),Fo=w(35,39),Ro=w(36,39),Mo=w(37,39),Bo=w(90,39),zo=w(91,39),Lo=w(92,39),Wo=w(93,39),Uo=w(94,39),Vo=w(95,39),qo=w(96,39),Ho=w(97,39),Ko=w(40,49),Go=w(41,49),Yo=w(42,49),Jo=w(43,49),Xo=w(44,49),Zo=w(45,49),Qo=w(46,49),es=w(47,49),ts=w(100,49),ns=w(101,49),rs=w(102,49),os=w(103,49),ss=w(104,49),is=w(105,49),as=w(106,49),cs=w(107,49),Ce=Object.freeze(["bold","dim","italic","underline","inverse","hidden","strikethrough","black","red","green","yellow","blue","magenta","cyan","white","gray","brightRed","brightGreen","brightYellow","brightBlue","brightMagenta","brightCyan","brightWhite","bgBlack","bgRed","bgGreen","bgYellow","bgBlue","bgMagenta","bgCyan","bgWhite","bgBrightBlack","bgBrightRed","bgBrightGreen","bgBrightYellow","bgBrightBlue","bgBrightMagenta","bgBrightCyan","bgBrightWhite"]),ls=new Set(["bold","dim","italic","underline","inverse","hidden","strikethrough"]);function Rt(e){return ls.has(e)}function L(e,t,n){return e!==void 0&&t in e?e[t]:n}function Mt(e){return L(e,"isTTY",process.stdout?.isTTY)??!1}function Bt(e){return L(e,"forceColor",process.env.FORCE_COLOR)}function zt(e){return e==="0"||e==="false"}function us(e){let t=e.toLowerCase();return t.includes("24bit")||t.includes("truecolor")||t.endsWith("-direct")}function Lt(e,t){if(e!==void 0){let n=e.toLowerCase();if(n==="truecolor"||n==="24bit")return!0}return t!==void 0&&us(t)}function _t(e,t){if(Lt(e,t))return"truecolor";if(t!==void 0&&t.toLowerCase().includes("256color"))return"256";return"16"}function fs(e,t){if(e==="never")return"none";if(e==="always")return"truecolor";let n=L(t,"colorTerm",process.env.COLORTERM),r=L(t,"term",process.env.TERM),o=Bt(t);if(o!==void 0){if(zt(o))return"none";if(o==="1")return"16";if(o==="2")return"256";if(o==="3")return"truecolor";return _t(n,r)}if(!Mt(t))return"none";let s=L(t,"noColor",process.env.NO_COLOR);if(s!==void 0&&s!=="")return"none";if(r!==void 0&&r.toLowerCase()==="dumb"&&!Lt(n,r))return"none";return _t(n,r)}function ds(e,t){if(e==="always")return!0;if(e==="never")return!1;let n=Bt(t);if(n!==void 0)return!zt(n);return Mt(t)}var Wt={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]};function Ee(e,t){if(e==null)return"";let n=String(e);if(n==="")return"";let{open:r,close:o}=t;if(n.includes(o))n=n.replaceAll(o,o+r);return r+n+o}var ms="\x1B[39m",gs="\x1B[49m",hs="\x1B[38;",ps="\x1B[48;";function bs(e){try{return JSON.stringify(e)??String(e)}catch{return String(e)}}function ws(e){return Object.hasOwn(Wt,e)}function Ie(e){if(Array.isArray(e)){if(e.length===3&&e.every((t)=>Number.isInteger(t)&&t>=0&&t<=255))return[e[0],e[1],e[2]]}else if(typeof e==="string"){let t=e.toLowerCase();if(ws(t))return Wt[t];let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t)?.[1];if(n){let o=n.length===3?n.split("").map((s)=>s+s).join(""):n;return[Number.parseInt(o.slice(0,2),16),Number.parseInt(o.slice(2,4),16),Number.parseInt(o.slice(4,6),16)]}let r=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/.exec(t)??/^rgb\(\s*(\d{1,3})\s+(\d{1,3})\s+(\d{1,3})\s*\)$/.exec(t);if(r){let o=[Number(r[1]),Number(r[2]),Number(r[3])];if(o.every((s)=>s<=255))return o}}throw TypeError(`Invalid color input: ${bs(e)}`)}function ys(e,t,n){let r=[0,95,135,175,215,255],o=(f)=>r.reduce((g,d,m)=>Math.abs(d-f)<Math.abs(r[g]-f)?m:g,0),[s,i,a]=[o(e),o(t),o(n)],c=Math.min(23,Math.max(0,Math.round(((e+t+n)/3-8)/10))),l=8+c*10,u=(f,g,d)=>(e-f)**2+(t-g)**2+(n-d)**2;return u(l,l,l)<u(r[s],r[i],r[a])?232+c:16+36*s+6*i+a}function Ut(e,t,n){let r=Math.round(Math.max(e,t,n)/127.5);if(r===0)return 30;let o=30+((Math.round(n/255)<<2|Math.round(t/255)<<1|Math.round(e/255))&7);if(r===2)o+=60;return o}function Vt(e,t){let[n,r,o]=Ie(e);if(t==="16")return`\x1B[${Ut(n,r,o)}m`;if(t==="256")return`\x1B[38;5;${ys(n,r,o)}m`;return`\x1B[38;2;${n};${r};${o}m`}function vs(e,t){if(t==="16"){let[n,r,o]=Ie(e);return`\x1B[${Ut(n,r,o)+10}m`}return Vt(e,t).replace(hs,ps)}function je(e,t,n){if(n==="none")return Ie(t),{open:"",close:""};return{open:e==="fg"?Vt(t,n):vs(t,n),close:e==="fg"?ms:gs}}function qt(e,t){return je("fg",e,t)}function Ht(e,t){return je("bg",e,t)}function Kt(e,t,n,r){let o=je(e,n,r);return r==="none"?t:Ee(t,o)}function Ss(e,t,n="truecolor"){return Kt("fg",e,t,n)}function xs(e,t,n="truecolor"){return Kt("bg",e,t,n)}var Gt="\x1B]",Yt="\x1B\\",Os=`${Gt}8;;${Yt}`;function Jt(e,t,n,r=""){if(!n.test(e))throw TypeError(`Invalid ${t}: ${JSON.stringify(e)} must contain only printable ASCII characters${r}.`)}function $s(e){let t=e?.id;if(t===void 0||t==="")return"";if(Jt(t,"hyperlink id",/^[\x20-\x7e]*$/),t.includes(":")||t.includes(";"))throw TypeError('Invalid hyperlink id: ":" and ";" are reserved by the OSC 8 format.');return`id=${t}`}function Xt(e,t){Jt(e,"hyperlink URL",/^[\x21-\x7e]*$/," without spaces");let n=$s(t);return{open:`${Gt}8;${n};${e}${Yt}`,close:Os}}function Cs(e,t,n){return Ee(e,Xt(t,n))}var Zt=[["fg",qt,Ss],["bg",Ht,xs]],Es=Oo;function Is(e){return e.kind==="named"&&Rt(e.name)}function $e(e,t){if(e.kind==="named")return Es[e.name];return e.kind==="fg"?qt(e.input,t):Ht(e.input,t)}function Pt(e,t,n){if(e==null)return"";let r=String(e);if(r==="")return r;let o=n(),{modifiersEnabled:s,colorsEnabled:i}=o;for(let a=t.length-1;a>=0;a--){let c=t[a];if(c===void 0)continue;if(Is(c)?!s:!i)continue;r=Ee(r,$e(c,o.colorDepth))}return r}function js(e){return Array.isArray(e)&&"raw"in e&&Array.isArray(e.raw)}function Ns(e,t){let n=new Map,r=t?"truecolor":e().colorDepth;function o(s){let i=s.map((f)=>f.kind==="named"?f.name:`~${$e(f,"truecolor").open}`).join("|"),a=n.get(i);if(a)return a;let c=(f,...g)=>{if(js(f)){let d="";for(let m=0;m<f.length;m++)if(d+=f[m]??"",m<g.length)d+=String(g[m]);return Pt(d,s,e)}return Pt(f,s,e)};if(n.size>=1024)n.delete(n.keys().next().value);n.set(i,c);for(let f of Ce)Object.defineProperty(c,f,{configurable:!1,enumerable:!0,get(){return o([...s,{kind:"named",name:f}])}});for(let[f,g]of Zt)Object.defineProperty(c,f,{configurable:!1,enumerable:!0,value:(d)=>(g(d,"truecolor"),o([...s,{kind:f,input:d}])),writable:!1});let l="",u="";for(let f of s){let g=$e(f,r);l+=g.open,u=g.close+u}return Object.defineProperty(c,"open",{value:l,writable:!1,configurable:!1,enumerable:!0}),Object.defineProperty(c,"close",{value:u,writable:!1,configurable:!1,enumerable:!0}),Object.freeze(c)}return o}function ks(e){let t={};for(let n of Ce)t[n]=e([{kind:"named",name:n}]);return t}function Dt(e){let t=e?.mode??"auto",n=ds(t,e?.overrides),r=fs(t,e?.overrides);return{modifiersEnabled:n,colorDepth:r,colorsEnabled:r!=="none",trueColorEnabled:r==="truecolor"}}function As(e,t){let n=t?Dt:(()=>{let i=Dt(e);return()=>i})(),r=Ns(n,t),o=ks(r),s={get enabled(){let{modifiersEnabled:i,colorsEnabled:a}=n();return i||a},get colorsEnabled(){return n().colorsEnabled},get trueColorEnabled(){return n().trueColorEnabled},get colorDepth(){return n().colorDepth},link(i,a,c){if(n().modifiersEnabled)return Cs(i,a,c);return Xt(a,c),i},...Object.fromEntries(Zt.map(([i,a,c])=>[i,(...l)=>{let u=n();if(l.length===1)return a(l[0],"truecolor"),r([{kind:i,input:l[0]}]);return c(l[0],l[1],u.colorDepth)}])),...o};return Object.freeze(s)}var b=As(void 0,!0),{black:ha,red:Y,green:J,yellow:pa,blue:ba,magenta:Qt,cyan:W,white:wa,gray:ya,brightRed:va,brightGreen:Sa,brightYellow:xa,brightBlue:Oa,brightMagenta:$a,brightCyan:Ca,brightWhite:Ea,bgBlack:Ia,bgRed:ja,bgGreen:Na,bgYellow:ka,bgBlue:Aa,bgMagenta:Ta,bgCyan:_a,bgWhite:Pa,bgBrightBlack:Da,bgBrightRed:Fa,bgBrightGreen:Ra,bgBrightYellow:Ma,bgBrightBlue:Ba,bgBrightMagenta:za,bgBrightCyan:La,bgBrightWhite:Wa,bold:X,dim:Z,italic:Ua,underline:Va,inverse:qa,hidden:Ha,strikethrough:Ka,link:Ga,fg:Ya,bg:Ja}=b;var en={spinner:Qt,message:X,success:J,error:Y},Ae="\x1B[",Ts=`${Ae}?25l`,tn=`${Ae}?25h`,rn=`${Ae}2K`,on="\r",nn={dots:{frames:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],interval:80},line:{frames:["-","\\","|","/"],interval:130},arc:{frames:["◐","◓","◑","◒"],interval:100},bounce:{frames:["⠁","⠂","⠄","⡀","⢀","⠠","⠐","⠈"],interval:120}},_s="✓",Ps="✗";function Ds(e){if(e===void 0)return nn.dots;if(typeof e==="string")return nn[e];if(e.frames.length===0)throw Error("A custom spinner requires at least one frame");return e}function Ne(e,t){let n=e[t];if(n===void 0)throw Error("Spinner frame index is out of bounds");return n}function ke(e,t,n){return`${rn}${on}${n.spinner(e)} ${n.message(t)}`}function Fs(e,t,n,r){let o=n==="success"?_s:Ps,s=`${(n==="success"?t.success:t.error)(o)} ${t.message(e)}
|
|
11
|
+
`;return r?rn+on+s:s}function Rs(e){let t=e.sink??V()?.output??process.stderr,n=e.theme?{...en,...e.theme}:en,r=t.isTTY??!1,{frames:o,interval:s}=Ds(e.spinner),i=e.sigint??"exit",a=e.message,c=0,l=!1,u=!1,f,g;function d(){if(f!==void 0)clearInterval(f),f=void 0;if(g)process.removeListener("SIGINT",g),g=void 0}return{start(){if(l||u)return;if(l=!0,!r)return;if(t.write(Ts),t.write(ke(Ne(o,0),a,n)),f=setInterval(()=>{c=(c+1)%o.length,t.write(ke(Ne(o,c),a,n))},s),i==="exit")g=()=>{if(d(),u=!0,t.write(tn),process.listenerCount("SIGINT")===0)process.kill(process.pid,"SIGINT")},process.once("SIGINT",g)},updateMessage(m){if(u)return;if(a=m,l&&r)t.write(ke(Ne(o,c),a,n))},stop(m="success",p){if(u)return;if(u=!0,p!==void 0)a=p;if(d(),t.write(Fs(a,n,m,l&&r)),l&&r)t.write(tn)}}}function Te(e){let t=Rs(e),{task:n}=e;if(!n)return t;return t.start(),Promise.resolve().then(()=>n(t)).then((r)=>(t.stop("success"),r),(r)=>{throw t.stop("error"),r})}import*as k from"node:readline";var sn={prefix:W,message:X,placeholder:Z,cursor:W,selected:W,unselected:Z,error:Y,success:J,hint:Z,filterMatch:W};function ee(e){let t=V();return{input:e?.input??t?.input??process.stdin,output:e?.output??t?.output??process.stderr}}var De=Symbol("submit");function Fe(e){return{[De]:e}}var _e=new WeakSet,Pe=new WeakSet,cn="\x1B[",Ms=`${cn}?25l`,Bs=`${cn}?25h`;function an(e,t){let n=e.split(`
|
|
12
|
+
`),r=0;for(let o of n){let s=Ft(o);r+=s===0?1:Math.ceil(s/t)}return r}var zs=class extends Error{constructor(e){super(e??"Prompts require an interactive terminal (TTY).");this.name="NonInteractiveError"}};function ln(e=ee().input){return!!e.isTTY}function Ls(e=ee().input){if(!ln(e))throw new zs}function Ws(e){return typeof e==="object"&&e!==null&&De in e}function Re(e,t){let{render:n,handleKey:r,initialState:o,renderSubmitted:s}=e,i=e.theme?{...sn,...e.theme}:sn,{input:a,output:c}=ee(t),l=c;return new Promise((u,f)=>{if(_e.has(a)||Pe.has(c)){f(Error("Cannot run multiple prompts concurrently on the same input or output stream. Await each prompt before starting the next."));return}Ls(a),_e.add(a),Pe.add(c);let g=o,d=0,m=!1,p=!1;function y(){if(m)return;if(m=!0,_e.delete(a),Pe.delete(c),a.removeListener("keypress",E),p)a.setRawMode?.(!1);a.pause(),c.write(Bs)}function S(C){let N=c.columns||80;if(d>0)k.cursorTo(l,0),k.moveCursor(l,0,-(d-1)),k.clearScreenDown(l);c.write(C),d=an(C,N)}let x=Promise.resolve(),v=null;function O(){if(v!==null)return;v=setTimeout(()=>{if(v=null,m)return;try{S(n(g,i))}catch(C){y(),f(C)}},0)}function I(){if(v!==null)clearTimeout(v),v=null}function E(C,N){if(N?.ctrl&&N.name==="c"){I(),c.write(`
|
|
13
|
+
`),y(),f(new DOMException("Prompt was cancelled.","AbortError"));return}let Sn={char:C??"",name:N?.name??"",ctrl:N?.ctrl??!1,meta:N?.meta??!1,shift:N?.shift??!1};x=x.then(async()=>{if(m)return;try{let D=await r(Sn,g);if(m)return;if(Ws(D)){I();let ze=D[De];if(s)S(s(g,ze,i));c.write(`
|
|
14
|
+
`),y(),u(ze)}else g=D,O()}catch(D){I(),y(),f(D)}})}try{if(k.emitKeypressEvents(a),a.setRawMode)a.setRawMode(!0),p=!0;a.resume(),c.write(Ms);let C=n(g,i);c.write(C),d=an(C,c.columns||80),a.on("keypress",E)}catch(C){y(),f(C)}})}async function Q(e,t,n){if(e.initial!==void 0)return{shortCircuited:!0,value:n?await n(e.initial,"initial"):e.initial};let r=ee(t);if(!ln(r.input)&&e.default!==void 0)return{shortCircuited:!0,value:n?await n(e.default,"default"):e.default};return{shortCircuited:!1,promptIO:r}}function Me(e,t,n){let r=[e];if(t)r.push(t);if(n)r.push(n);return r.join(" ")}function un(e,t,n,r){let o=t?`${e} ${t}`:e,s=r??"";if(t)return`${o}${s}
|
|
15
|
+
${n}`;return`${o}${s} ${n}`}function Us(e,t,n,r,o){let s=Math.min(e.length,n),i=[];if(t>0)i.push(o("..."));for(let a=t;a<t+s;a++){let c=e[a];if(c===void 0)break;i.push(r(c,a))}if(t+s<e.length)i.push(o("..."));return i}function fn(e,t,n,r){let o=Math.min(n,r);if(e<t)return e;if(e>=t+o)return e-o+1;return t}function Vs(e,t,n,r,o){let s=n===-1?e<=0?t-1:e-1:e>=t-1?0:e+1;return{cursor:s,scrollOffset:fn(s,r,t,o)}}function qs(e){return e.map((t)=>{if(typeof t==="string")return{label:t,value:t};return t})}function Hs(e,t){if(e.name==="return")return Fe(t.value);if(e.name==="left"||e.name==="right"||e.name==="tab")return{value:!t.value};if(e.name==="h"||e.char==="y"||e.char==="Y")return{value:!0};if(e.name==="l"||e.char==="n"||e.char==="N")return{value:!1};return t}var Ks=" · ";function Gs(e,t,n,r,o){let s=t.prefix("┃"),i=t.message(n??"Are you sure?"),a=e.value?`${t.selected("●")} ${t.selected(r)}`:`${t.unselected("○")} ${t.unselected(r)}`,c=e.value?`${t.unselected("○")} ${t.unselected(o)}`:`${t.selected("●")} ${t.selected(o)}`;return un(s,i,`${a}${Ks}${c}`)}function Ys(e,t,n,r,o,s){let i=n.success("✓"),a=n.message(r??"Are you sure?"),c=t?o:s;return Me(i,a,n.success(c))}async function te(e,t){let n=await Q(e,t);if(n.shortCircuited)return n.value;let{promptIO:r}=n,o=e.active??"Yes",s=e.inactive??"No";return Re({initialState:{value:e.default??!0},theme:e.theme,render:(i,a)=>Gs(i,a,e.message,o,s),handleKey:Hs,renderSubmitted:(i,a,c)=>Ys(i,a,c,e.message,o,s)},r)}async function Js(e,t,n){let r=await Q(e,n);if(r.shortCircuited)return r;let o=qs(e.choices),s=e.maxVisible??10,i=e.default===void 0?[]:t==="multiple"?e.default:[e.default],a=new Set(i.flatMap((u)=>{let f=o.findIndex((g)=>g.value===u);return f===-1?[]:[f]})),c=i.length===0?-1:o.findIndex((u)=>u.value===i[0]),l=c===-1?0:c;return{shortCircuited:!1,choices:o,maxVisible:s,cursor:l,scrollOffset:fn(l,0,o.length,s),selected:a,promptIO:r.promptIO}}async function dn(e,t,n){if(t){let r=await t["~standard"].validate(e),o=r.issues?.[0];if(o)return{ok:!1,error:o.message||"Validation failed"};if("value"in r)return{ok:!0,value:r.value};return{ok:!1,error:"Validation failed"}}if(n)try{await n(e)}catch(r){return{ok:!1,error:r instanceof Error?r.message:"Validation failed"}}return{ok:!0,value:e}}async function Xs(e,t,n){let r=await dn(t,e,void 0);if(!r.ok)throw Error(`${n} value rejected by schema: ${r.error}`);return r.value}function Zs(e,t,n,r){if(e==="")return r?n.placeholder(r):n.cursor("│");return`${e.slice(0,t)}${n.cursor("│")}${e.slice(t)}`}function Qs(e,t,n){if(e.name==="backspace"){if(n===0)return{text:t,cursorPos:n};return{text:t.slice(0,n-1)+t.slice(n),cursorPos:n-1}}if(e.name==="delete"){if(n>=t.length)return{text:t,cursorPos:n};return{text:t.slice(0,n)+t.slice(n+1),cursorPos:n}}if(e.name==="left"){if(n===0)return{text:t,cursorPos:n};return{text:t,cursorPos:n-1}}if(e.name==="right"){if(n>=t.length)return{text:t,cursorPos:n};return{text:t,cursorPos:n+1}}if(e.name==="home")return{text:t,cursorPos:0};if(e.name==="end")return{text:t,cursorPos:t.length};if(e.char.length===1&&!e.ctrl&&!e.meta){let r=t.slice(0,n),o=t.slice(n);return{text:r+e.char+o,cursorPos:n+1}}return null}function ei(e,t,n){return async(r,o)=>{if(r.name==="return"){let i=await dn(o.value===""&&n!==void 0?n:o.value,e,t);return i.ok?Fe(i.value):{...o,error:i.error}}let s=Qs(r,o.value,o.cursorPos);return s?{value:s.text,cursorPos:s.cursorPos,error:null}:o}}function ti(e,t,n,r,o){let s=t.prefix("┃"),i=t.message(n??"Enter a value"),a=r??o,c=o!==void 0&&r!==void 0&&e.value===""?` ${t.hint(`(${o})`)}`:"",l=un(s,i,Zs(e.value,e.cursorPos,t,a),c);if(e.error!==null)l+=`
|
|
16
|
+
${t.error(e.error)}`;return l}function ni(e,t,n,r){return Me(n.success("✓"),n.message(r??"Enter a value"),n.success(String(t)))}async function mn(e={},t){if(e.schema!==void 0&&e.validate!==void 0)throw Error('input() cannot combine "schema" with "validate"');let n=e.schema,r=n?await Q(e,t,(s,i)=>Xs(n,s,i)):await Q(e,t);if(r.shortCircuited)return r.value;let{promptIO:o}=r;return Re({initialState:{value:"",cursorPos:0,error:null},theme:e.theme,render:(s,i)=>ti(s,i,e.message,e.placeholder,e.default),handleKey:ei(e.schema,e.validate,e.default),renderSubmitted:(s,i,a)=>ni(s,i,a,e.message)},o)}function ri(e){return(t,n)=>{let r=n.choices.length;if(t.name==="return"){let o=n.choices[n.cursor];if(o)return Fe(o.value);return n}if(["up","down","k","j"].includes(t.name)){let o=t.name==="up"||t.name==="k"?-1:1;return{...n,...Vs(n.cursor,r,o,n.scrollOffset,e)}}return n}}function oi(e,t,n,r){let o=[`${t.prefix("┃")} ${t.message(n??"Pick an option")}`];return o.push(...Us(e.choices,e.scrollOffset,r,(s,i)=>{let a=s.hint?` ${t.hint(s.hint)}`:"";return i===e.cursor?`${t.cursor("›")} ${t.selected(s.label)}${a}`:` ${t.unselected(s.label)}${a}`},t.hint)),o.join(`
|
|
17
|
+
`)}function si(e,t,n,r){let o=n.success("✓"),s=n.message(r??"Pick an option"),i=e.choices[e.cursor],a=i?i.label:"";return Me(o,s,n.success(a))}async function gn(e,t){let n=await Js(e,"single",t);if(n.shortCircuited)return n.value;let{choices:r,cursor:o,maxVisible:s,promptIO:i,scrollOffset:a}=n;return Re({initialState:{cursor:o,choices:r,scrollOffset:a},theme:e.theme,render:(c,l)=>oi(c,l,e.message,s),handleKey:ri(s),renderSubmitted:(c,l,u)=>si(c,l,u,e.message)},i)}var hn={name:"@crustjs/core",version:"0.3.3",description:"Core library for the Crust CLI framework",type:"module",sideEffects:!1,license:"MIT",author:"chenxin-yan",repository:{type:"git",url:"git+https://github.com/chenxin-yan/crust.git",directory:"packages/core"},homepage:"https://crustjs.com",bugs:{url:"https://github.com/chenxin-yan/crust/issues"},keywords:["cli","command","framework","parser","bun","typescript"],files:["dist"],types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"},"./tooling":{types:"./dist/tooling.d.ts",import:"./dist/tooling.js"}},publishConfig:{access:"public"},scripts:{build:"tsdown",dev:"tsdown --watch","check:types":"tsc --noEmit",test:"bun test",prepack:"cp ../../LICENSE LICENSE",postpack:"rm -f LICENSE"},dependencies:{"@crustjs/utils":"workspace:^"},devDependencies:{"@crustjs/config":"workspace:*",tsdown:"catalog:"},peerDependencies:{typescript:"^7.0.0"},peerDependenciesMeta:{typescript:{optional:!0}},engines:{bun:">=1.4.0",node:">=22",deno:">=2.8"}};var pn={name:"@crustjs/crust",version:"0.3.3",description:"CLI tooling for the Crust framework",type:"module",license:"MIT",author:"chenxin-yan",repository:{type:"git",url:"git+https://github.com/chenxin-yan/crust.git",directory:"packages/crust"},homepage:"https://crustjs.com",bugs:{url:"https://github.com/chenxin-yan/crust/issues"},keywords:["cli","build","compile","standalone","bun","typescript"],publishConfig:{access:"public"},crust:{include:["schema"]},bin:{crust:"src/cli.ts"},scripts:{build:"bun src/cli.ts build",release:"bun src/cli.ts publish",dev:"bun src/cli.ts",start:"bun .crust/root/bin/crust.js","check:types":"tsc --noEmit",test:"bun test"},dependencies:{"@crustjs/core":"workspace:^","@crustjs/extensions":"workspace:^","@crustjs/style":"workspace:^"},devDependencies:{"@crustjs/config":"workspace:*","@crustjs/testing":"workspace:*","@crustjs/utils":"workspace:*"},engines:{bun:">=1.4.0"}};var bn={name:"@crustjs/extensions",version:"0.3.3",description:"Official Extensions for the Crust CLI framework",type:"module",sideEffects:!1,license:"MIT",author:"chenxin-yan",repository:{type:"git",url:"git+https://github.com/chenxin-yan/crust.git",directory:"packages/extensions"},homepage:"https://crustjs.com",bugs:{url:"https://github.com/chenxin-yan/crust/issues"},keywords:["cli","extension","help","version","completion","did-you-mean","bun","typescript"],files:["dist"],exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"}},publishConfig:{access:"public"},scripts:{build:"tsdown",dev:"tsdown --watch","check:types":"tsc --noEmit",test:"bun test",prepack:"cp ../../LICENSE LICENSE",postpack:"rm -f LICENSE"},dependencies:{"@crustjs/store":"workspace:^","@crustjs/style":"workspace:^","@crustjs/utils":"workspace:^"},devDependencies:{"@crustjs/config":"workspace:*","@crustjs/core":"workspace:*",tsdown:"catalog:"},peerDependencies:{"@crustjs/core":"workspace:^",typescript:"^7.0.0"},peerDependenciesMeta:{typescript:{optional:!0}},engines:{bun:">=1.4.0",node:">=22",deno:">=2.8"}};var fi={bun:{run:"bun run",shebang:"#!/usr/bin/env bun",tsLib:'"ESNext"',tsTypes:'"bun"'},node:{run:"npm run",shebang:"#!/usr/bin/env node",tsLib:'"ESNext"',tsTypes:'"node"'},deno:{run:"deno task",shebang:"#!/usr/bin/env -S deno run -A",tsLib:'"ESNext", "deno.window"',tsTypes:""}},di={crustCoreVersion:hn.version,crustExtensionsVersion:bn.version,crustCliVersion:pn.version},mi=/^[A-Za-z0-9_~][A-Za-z0-9._~-]*$/;function vn(e){if(e==="__proto__"||!mi.test(e))throw Error(`Project name ${JSON.stringify(e)} is not safe for the generated project.
|
|
18
|
+
The directory basename becomes the package and command name: use letters, digits, ".", "_", "~", and "-", not starting with "." or "-"; "__proto__" is reserved.`)}var gi=/[<>:"|?*\\]/;function hi(e){if(!e)throw Error("Project directory cannot be empty");if(gi.test(e))throw Error(`Project directory contains invalid characters: ${e}`);vn(yn(Be(e)))}var pi=new G("create-crust",{description:"Scaffold a new Crust CLI project"}).flags({name:"runtime",type:"string",choices:["bun","node","deno"],description:'Runtime to develop and build for ("bun", "node", or "deno")'},{name:"install",type:"boolean",description:"Install dependencies after scaffolding"},{name:"git",type:"boolean",description:"Initialize a git repository after scaffolding"},{name:"overwrite",type:"boolean",description:"Overwrite the destination directory if it already exists"}).args({name:"directory",type:"string",description:"Project directory to scaffold into"}).action(async({args:e,flags:t})=>{let n=e.directory??await mn({message:"Project directory",default:"my-cli",validate:hi}),r=Be(process.cwd(),n),o=yn(r);vn(o);let s=t.runtime,i=n==="."?li(r).length>0:wn(r),a=!1;if(i){if(a=await te({message:n==="."?"Current directory is not empty. Overwrite conflicting files?":`Directory "${o}" already exists. Overwrite?`,default:!1,...t.overwrite!==void 0?{initial:t.overwrite}:{}}),!a){console.log("Aborted.");return}}let c=await gn({message:"Runtime",choices:[{label:"Bun (recommended)",value:"bun",hint:"standalone binaries per platform, published as npm packages"},{label:"Node.js",value:"node",hint:"one JavaScript bundle, published as a single npm package"},{label:"Deno",value:"deno",hint:"standalone binaries per platform, published as npm packages"}],default:"bun",...s!==void 0?{initial:s}:{}}),l=await te({message:"Install dependencies?",default:!0,...t.install!==void 0?{initial:t.install}:{}}),u=wn(r)?r:Be(r,".."),g=At(u)?!1:await te({message:"Initialize a git repository?",default:!0,...t.git!==void 0?{initial:t.git}:{}}),d=o,m=(y)=>ui(re("templates"),y),p={name:d,...fi[c],...di};if(await Te({message:"Scaffolding project...",task:async()=>{await xe({template:m("base"),dest:r,context:p,...a?{conflict:"overwrite"}:{}}),await xe({template:m(`runtime/${c}`),dest:r,context:p,conflict:"overwrite"})}}),l)await Oe([c==="deno"?{type:"command",cmd:"deno install"}:{type:"install"}],r);if(g)await Te({message:"Initializing git repository...",task:()=>Oe([{type:"git-init",commit:"chore: initial commit"}],r)});if(console.log(`
|
|
19
19
|
Created ${d}!
|
|
20
|
-
`),console.log("Next steps:"),n!=="."){let
|
|
20
|
+
`),console.log("Next steps:"),n!=="."){let y=n.startsWith("/")?n:`./${n}`;console.log(` cd ${y}`)}console.log(` ${p.run} dev`),console.log(` ${p.run} build`)});await pi.execute();
|