create-crust 0.3.2 → 0.3.4
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 +16 -14
- package/package.json +1 -1
package/bin/create-crust.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{existsSync as
|
|
2
|
+
import{existsSync as Cn,readdirSync as hi}from"node:fs";import{basename as En,join as pi,resolve as We}from"node:path";import{dirname as Mi,join as Bi,posix as Li,resolve as Kn,win32 as zi}from"node:path";import{existsSync as Ve,statSync as jn}from"node:fs";import{dirname as qe,isAbsolute as Ci,join as Nn,resolve as kn}from"node:path";function Ge(e){let t=kn(e);if(Ve(t)&&!jn(t).isDirectory())t=qe(t);while(!0){if(Ve(Nn(t,"package.json")))return t;let n=qe(t);if(n===t)return null;t=n}}import{realpathSync as An}from"node:fs";import{dirname as Tn,join as se,resolve as _n}from"node:path";import{fileURLToPath as Pn}from"node:url";var Fn="CRUST_INTERNAL_BUILD_OUT_DIR";function Dn(){let{Bun:e,Deno:t}=globalThis,n=e?.main??"";return n.startsWith("/$bunfs/")||/^[A-Za-z]:[\\/]~BUN[\\/]/.test(n)||t?.build?.standalone===!0}function oe(e){if(e===""||e==="."||e===".."||/[\\/]/.test(e))throw Error(`Artifact name must be a single directory name, got ${JSON.stringify(e)}.`);if(Dn())return se(Tn(process.execPath),e);return _n(Pn(import.meta.url),"..","..",e)}import{AsyncLocalStorage as Rn}from"node:async_hooks";import{Writable as Mn}from"node:stream";var Bn=Symbol.for("crustjs.terminal.io"),Ln=Symbol.for("crustjs.terminal.ambient-callbacks"),zn=globalThis,Wn=globalThis,V=zn[Bn]??=new Rn,He=Wn[Ln]??=new WeakMap;function ie(e,t){let n=V.getStore();return V.run({input:e.input??n?.input,output:e.output??n?.output},t)}function q(){return V.getStore()}function Un(e){let t="",n=new Mn({decodeStrings:!1,write(r,s,o){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 He.set(n,e),n}function ie(e,t){let n=U.getStore();return oe({input:n?.input,output:n?.output&&!He.has(n.output)?n.output:Vn(e)},t)}import{parseArgs as Xn}from"node:util";import{isPromise as Zn}from"node:util/types";function Ge(e){let t=Number(e);return Number.isNaN(t)?void 0:t}function Ye(e){return e==="true"||e==="1"}import{homedir as Qn}from"node:os";function qn(e){return typeof e==="number"}function Hn(e){return e.map((t,n)=>qn(t)?`[${t}]`:n>0?`.${String(t)}`:String(t)).join("")}function Gn(e){return typeof e==="object"&&e!==null&&"key"in e}function Yn(e){if(!e)return[];return e.map((t)=>Gn(t)?t.key:t)}function Ke(e,t=[]){return e.map((n)=>{let r=Yn(n.path),s=[...t,...r];return{message:n.message,path:Hn(s)}})}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 ce(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 rt(e,t){return[e,...t.short===void 0?[]:[t.short],...t.aliases??[]]}function st(e){return e.type==="boolean"&&e.noNegate!==!0}function ot(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 it(e,t){if(ce(e,"canonical"),t.short!==void 0)ce(t.short,"short");for(let r of t.aliases??[])ce(r,"alias");let n=rt(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 ot(t)}function at(e){if(e.name==="")throw new p("DEFINITION","Argument names must be non-empty",{subject:"argument",name:e.name,reason:"empty-name"});return ot(e)}var er=Symbol("crust.defining");function H(e){return e[er]}var ct=Symbol.for("crust.contextSources");function G(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 tr(e){return typeof e==="function"}var nr=class{#e=[];#t=!1;#n(){if(this.#t)throw ReferenceError("AsyncDisposableStack is already disposed")}use(e){this.#n();let t=sr(e)?e[Symbol.asyncDispose]:e[Symbol.dispose];return this.#e.push(()=>t.call(e)),e}defer(e){if(this.#n(),!tr(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")}},rr=globalThis.AsyncDisposableStack??nr;function sr(e){return typeof e[Symbol.asyncDispose]==="function"}function or(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 ir(e,t,n){if(!or(e)||n.has(e))return;n.add(e),t.use(e)}function ar(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)}});ir(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,ct,{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 cr=Object.freeze({[Symbol("crust.finished")]:!0});function fe(){return cr}function lt(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=it(t,n);let s=rt(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:st(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 ut(e,t,n,r){if(A(e,t,n,"owned"),!r)return;for(let s of Object.values(e.subCommands))ut(s,t,n,!0)}function lr(e,t,n){for(let r of t.commands??[])e.subCommands[r.name]=n(r,e,t.id)}function ur(e,t){for(let[n,r]of Object.entries(t.flags??{})){let{recursive:s=!0,...o}=r;ut(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 fr({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 ft(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 fr(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 me(e,t){return t.map((n)=>ft(n,{subject:"command",name:e}))}function dr(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 mr(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=ft(o,r),a=dr(e,o.command,t);a.meta.sections=[...a.meta.sections??[],i]}}function dt(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 gr(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 q(e){if(e==="")throw new p("PARSE","Path cannot be empty");let t=e.replace(/^~(?=\/|$)/,Qn());return Jn(process.cwd(),t)}function hr(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 pr(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 mt(e,t,n){if(t==="number"){let r=Ge(e);if(r===void 0)throw new p("PARSE",`Expected number for ${n}, got "${e}"`);return r}if(t==="boolean")return Ye(e);if(t==="url")return gr(e);if(t==="path")return q(e);if(t==="json")return hr(e);return e}function ge(e,t,n){if(!t.includes(e))throw new p("PARSE",`Invalid value "${e}" for ${n}. Expected one of: ${t.join(", ")}`)}function D(e,t,n,r){let s=r===void 0?n:`${n} element [${r}]`,o;try{if(o=e(t),Zn(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 gt(e,t){let{default:n,parse:r}=e;if(n===void 0)return;if(r){if(Array.isArray(n))return n.map((s,o)=>D(r,String(s),t,o));return D(r,String(n),t)}if(e.type==="path"){if(Array.isArray(n))return n.map((s)=>q(String(s)));return q(String(n))}return"multiple"in e&&e.multiple&&Array.isArray(n)?[...n]:n}function br(e,t,n){if(n.kind==="boolean")return n.value;let r=`--${e}`,s=(o,i)=>{if(t.choices)ge(o,t.choices,r);if(t.parse)return D(t.parse,o,r,i);return mt(o,t.type,r)};return Array.isArray(n.value)?n.value.map(s):s(n.value)}function wr(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 yr(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]=gt(o,`--${s}`)}return r}function vr(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 Sr(e,t,n,r){if(e.schema)return t;if(e.choices)ge(t,e.choices,n);if(e.parse)return D(e.parse,t,n,r);return mt(t,e.type,n)}function xr(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]=gt(o,a)}return{args:r,consumed:s}}function Or(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 $r(e,t){let n=e.flagSpellings,r=pr(n);Or(t,n);let s;try{s=Xn({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:wr(s.tokens,n),rawArgs:o}}function Cr(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 de(e,t,n,r){if(Cr(e,t,n),e.choices)ge(String(t),e.choices,n);if(e.parse)return D(e.parse,String(t),n,r);if(e.type==="path")return q(String(t));return t}function Er(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)=>de(t,s,r,o))}return de(t,n,r)}function ht(e,t,n,r,s){let o=yr(e.effectiveFlags,n,s);return{...xr(e.args,t,r),flags:o}}function Ir(e,t){let{positionals:n,flagValues:r,rawArgs:s}=$r(e,t),{args:o,flags:i,consumed:a}=ht(e,n,r,Sr,br);return{args:o,flags:i,excessArgs:n.slice(a),rawArgs:s}}function jr(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}=ht(e,o,r??{},de,Er);return{args:a,flags:c,excessArgs:[],rawArgs:[...s??[]]}}function Nr(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}`)}}vr(r,o)}async function et(e,t,n,r){let s=await e["~standard"].validate(t);if(s.issues)return r.push(...Ke(s.issues,n)),{ok:!1};return{ok:!0,value:s.value}}async function kr(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 et(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 et(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:
|
|
4
|
+
`);o()}});return He.set(n,e),n}function ae(e,t){let n=V.getStore();return ie({input:n?.input,output:n?.output&&!He.has(n.output)?n.output:Un(e)},t)}import{parseArgs as Yn}from"node:util";import{isPromise as Jn}from"node:util/types";function Ke(e){let t=Number(e);return Number.isNaN(t)?void 0:t}function Ye(e){return e==="true"||e==="1"}import{homedir as Xn}from"node:os";function Vn(e){return typeof e==="number"}function qn(e){return e.map((t,n)=>Vn(t)?`[${t}]`:n>0?`.${String(t)}`:String(t)).join("")}function Gn(e){return typeof e==="object"&&e!==null&&"key"in e}function Hn(e){if(!e)return[];return e.map((t)=>Gn(t)?t.key:t)}function Je(e,t=[]){return e.map((n)=>{let r=Hn(n.path),s=[...t,...r];return{message:n.message,path:qn(s)}})}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 ce(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 nt(e,t){return[e,...t.short===void 0?[]:[t.short],...t.aliases??[]]}function rt(e){return e.type==="boolean"&&e.noNegate!==!0}function st(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 ot(e,t){if(ce(e,"canonical"),t.short!==void 0)ce(t.short,"short");for(let r of t.aliases??[])ce(r,"alias");let n=nt(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 st(t)}function it(e){if(e.name==="")throw new p("DEFINITION","Argument names must be non-empty",{subject:"argument",name:e.name,reason:"empty-name"});return st(e)}var Zn=Symbol("crust.defining");function H(e){return e[Zn]}var at=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 Qn(e){return typeof e==="function"}var er=class{#e=[];#t=!1;#n(){if(this.#t)throw ReferenceError("AsyncDisposableStack is already disposed")}use(e){this.#n();let t=nr(e)?e[Symbol.asyncDispose]:e[Symbol.dispose];return this.#e.push(()=>t.call(e)),e}defer(e){if(this.#n(),!Qn(e))throw TypeError("defer callback is not callable");this.#e.push(e)}async[Symbol.asyncDispose](){if(this.#t)return;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")}},tr=globalThis.AsyncDisposableStack??er;function nr(e){return typeof e[Symbol.asyncDispose]==="function"}function rr(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 sr(e,t,n){if(!rr(e)||n.has(e))return;n.add(e),t.use(e)}function or(e,t,n,r){let s=new Map(e.map((m)=>[m.name,m])),o=new Map,i=new WeakSet,a,c=!0,l=!1;n.defer(()=>{l=!0});let u=(m,h,v=new Set)=>{if(m.name===h)return[m.name];if(v.has(m.name))return;v.add(m.name);for(let O of m.waitingOn){let S=o.get(O);if(!S)continue;let I=u(S,h,v);if(I)return[m.name,...I]}},f=(m)=>{try{let h=new Set;for(let v=m;v!=null&&!h.has(v);v=v.cause)if(h.add(v),v instanceof p&&v.code==="DEFINITION"&&v.details?.reason==="flags-before-validation")return!0;return!1}catch{return!1}};function d(m){let h=Promise.reject(m);return h.catch(()=>{}),h}let b=(m)=>(h)=>{let v=m?` (pulled while constructing Context "${m.name}")`:"";if(l)return d(new p("DEFINITION",`Context "${h}" cannot be pulled from onError because invocation Contexts have already been disposed.`,{subject:"context",name:h,reason:"context-after-disposal"}));let O=s.get(h);if(!O)return d(new p("DEFINITION",`No provider for Context "${h}". Add .provide(${h}(...)) to the app or an ancestor command.${v}`,{subject:"context",name:h,reason:"missing-context"}));if(!c&&!o.has(h))return d(new p("DEFINITION",`Context "${h}" cannot be constructed during invocation cleanup. Read it while setting up the Context whose cleanup needs it.`,{subject:"context",name:h,reason:"context-during-disposal"}));if(a===void 0&&Object.keys(O.ownedFlags).length>0)return d(new p("DEFINITION",`Context "${h}" owns flags and cannot be pulled before flag validation${v}. Pull it from an action or a postRun hook after a validated invocation.`,{subject:"context",name:h,reason:"flags-before-validation"}));let S=o.get(h);if(!S){let I=Promise.withResolvers();I.promise.catch(()=>{}),S={name:h,promise:I.promise,resolve:I.resolve,reject:I.reject,waitingOn:new Set,settled:!1},o.set(h,S);let x=S;(async()=>{try{let C=Object.fromEntries(Object.keys(O.ownedFlags).map((E)=>[E,a?.[E]])),j=await O.setup({...t,signal:r,flags:C,ctx:g(O.uses,x),defer(E){if(x.settled)throw new p("DEFINITION",`Context "${h}" cannot register cleanup after its setup has finished.`,{subject:"context",name:h,reason:"context-defer-after-setup"});n.defer(E)}});sr(j,n,i),x.resolve(j)}catch(C){if(f(C))o.delete(h);x.reject(C)}finally{x.settled=!0}})()}if(m&&!S.settled){let I=u(S,m.name);if(I)return d(new p("DEFINITION",`Context dependency cycle: ${[m.name,...I].map((x)=>`"${x}"`).join(" -> ")}`,{subject:"context",name:m.name,reason:"context-cycle"}));return m.waitingOn.add(h),S.promise.finally(()=>m.waitingOn.delete(h))}return S.promise},g=(m,h)=>{let v={},O=(S)=>{let I="contextName"in S?S.contextName:S.name;if(Object.hasOwn(v,I))return;Object.defineProperty(v,I,{enumerable:!0,get:()=>b(h)(I)});for(let x of S.uses??[])O(x)};for(let S of m)O(S);return Object.defineProperty(v,at,{value:Object.freeze([...m])}),Object.freeze(v)};return{bag:(m)=>g(m,null),setValidatedFlags(m){a=m},async settle(){for(;;){let m=[...o.values()].filter((h)=>!h.settled);if(m.length===0){c=!1;return}await Promise.allSettled(m.map((h)=>h.promise))}}}}var ir=Object.freeze({[Symbol("crust.finished")]:!0});function fe(){return ir}function ct(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=ot(t,n);let s=nt(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:rt(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 lt(e,t,n,r){if(A(e,t,n,"owned"),!r)return;for(let s of Object.values(e.subCommands))lt(s,t,n,!0)}function ar(e,t,n){for(let r of t.commands??[])e.subCommands[r.name]=n(r,e,t.id)}function cr(e,t){for(let[n,r]of Object.entries(t.flags??{})){let{recursive:s=!0,...o}=r;lt(e,n,o,s)}}function Y(e){return{localFlags:{...e.localFlags},ownedFlags:{...e.ownedFlags},effectiveFlags:{...e.effectiveFlags},flagSpellings:new Map(e.flagSpellings)}}function M(e){let t={};for(let[n,r]of Object.entries(e.subCommands))t[n]=M(r);return{...e,meta:{...e.meta},...Y(e),args:[...e.args],subCommands:t,contexts:e.contexts.map((n)=>({...n})),demands:[...e.demands],extensions:[...e.extensions],run:e.run}}function lr({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 ut(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 lr(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 ge(e,t){return t.map((n)=>ut(n,{subject:"command",name:e}))}function ur(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 fr(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=ut(o,r),a=ur(e,o.command,t);a.meta.sections=[...a.meta.sections??[],i]}}function ft(e,t,n){let r=M(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",d=f==="owned"?l:c;if(Object.hasOwn(d,u))A(i,u,d[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((g)=>!u.has(g.name)),d=f.map((g)=>({instance:g,extensionId:i.id}));l.contexts.push(...d);for(let g of f)for(let[m,h]of Object.entries(g.ownedFlags))A(l,m,h,"owned");let b=new WeakSet(l.contexts.map(({instance:g})=>g));for(let g of Object.values(l.subCommands)){let m=new Set(u);for(let{instance:h}of g.contexts)if(!b.has(h))m.add(h.name);c(g,m)}};c(r,new Set)}return r}function dr(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 G(e){if(e==="")throw new p("PARSE","Path cannot be empty");let t=e.replace(/^~(?=\/|$)/,Xn());return Kn(process.cwd(),t)}function mr(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 gr(e){let t={};for(let[n,r]of e){if(r.kind==="short")continue;let s={type:r.def.type==="boolean"?"boolean":"string"};if(r.def.multiple)s.multiple=!0;if(r.kind==="canonical"&&r.def.short)s.short=r.def.short;t[n]=s}return t}function dt(e,t,n){if(t==="number"){let r=Ke(e);if(r===void 0)throw new p("PARSE",`Expected number for ${n}, got "${e}"`);return r}if(t==="boolean")return Ye(e);if(t==="url")return dr(e);if(t==="path")return G(e);if(t==="json")return mr(e);return e}function he(e,t,n){if(!t.includes(e))throw new p("PARSE",`Invalid value "${e}" for ${n}. Expected one of: ${t.join(", ")}`)}function R(e,t,n,r){let s=r===void 0?n:`${n} element [${r}]`,o;try{if(o=e(t),Jn(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 mt(e,t){let{default:n,parse:r}=e;if(n===void 0)return;if(r){if(Array.isArray(n))return n.map((s,o)=>R(r,String(s),t,o));return R(r,String(n),t)}if(e.type==="path"){if(Array.isArray(n))return n.map((s)=>G(String(s)));return G(String(n))}return"multiple"in e&&e.multiple&&Array.isArray(n)?[...n]:n}function hr(e,t,n){if(n.kind==="boolean")return n.value;let r=`--${e}`,s=(o,i)=>{if(t.choices)he(o,t.choices,r);if(t.parse)return R(t.parse,o,r,i);return dt(o,t.type,r)};return Array.isArray(n.value)?n.value.map(s):s(n.value)}function pr(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 br(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]=mt(o,`--${s}`)}return r}function wr(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 yr(e,t,n,r){if(e.schema)return t;if(e.choices)he(t,e.choices,n);if(e.parse)return R(e.parse,t,n,r);return dt(t,e.type,n)}function vr(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]=mt(o,a)}return{args:r,consumed:s}}function Sr(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 xr(e,t){let n=e.flagSpellings,r=gr(n);Sr(t,n);let s;try{s=Yn({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:pr(s.tokens,n),rawArgs:o}}function Or(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 de(e,t,n,r){if(Or(e,t,n),e.choices)he(String(t),e.choices,n);if(e.parse)return R(e.parse,String(t),n,r);if(e.type==="path")return G(String(t));return t}function $r(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)=>de(t,s,r,o))}return de(t,n,r)}function gt(e,t,n,r,s){let o=br(e.effectiveFlags,n,s);return{...vr(e.args,t,r),flags:o}}function Cr(e,t){let{positionals:n,flagValues:r,rawArgs:s}=xr(e,t),{args:o,flags:i,consumed:a}=gt(e,n,r,yr,hr);return{args:o,flags:i,excessArgs:n.slice(a),rawArgs:s}}function Er(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}=gt(e,o,r??{},de,$r);return{args:a,flags:c,excessArgs:[],rawArgs:[...s??[]]}}function Ir(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}`)}}wr(r,o)}async function Xe(e,t,n,r){let s=await e["~standard"].validate(t);if(s.issues)return r.push(...Je(s.issues,n)),{ok:!1};return{ok:!0,value:s.value}}async function jr(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 Xe(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 Xe(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
5
|
${n.map((o)=>` - ${o.path}: ${o.message}`).join(`
|
|
6
|
-
`)}`,{issues:n});return{args:Object.fromEntries(r),flags:Object.fromEntries(s)}}function
|
|
6
|
+
`)}`,{issues:n});return{args:Object.fromEntries(r),flags:Object.fromEntries(s)}}function ht(e){return e.meta.hidden!==!0}function pe(e){for(let t of Object.keys(e))if(e[t]===void 0)delete e[t];return Object.freeze(e)}function be(e){if(e instanceof URL)return e.href;if(Array.isArray(e))return Object.freeze(e.map(be));return e}function Nr(e){return pe({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:be(e.default)})}function kr(e){return pe({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:rt(e),noNegate:"noNegate"in e?e.noNegate:void 0,choices:e.choices?Object.freeze([...e.choices]):void 0,default:be(e.default)})}function N(e){let t={};for(let[r,s]of Object.entries(e.effectiveFlags))t[r]=kr(s);let n={};for(let[r,s]of Object.entries(e.subCommands))n[r]=N(s);return Object.freeze({meta:pe({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(Nr)),flags:Object.freeze(t),subCommands:Object.freeze(n)})}function Ar(e,t){for(let[n,r]of Object.entries(e)){let s=r.meta.aliases;if(!s)continue;if(s.includes(t))return{canonicalName:n,node:r}}return null}function Ze(e,t){if(t==="--")return null;if(t.startsWith("--")){let r=t.indexOf("="),s=r===-1?t.slice(2):t.slice(2,r),o=e.get(s);if(o)return{consumesValue:o.def.type!=="boolean"&&r===-1};if(s.startsWith("no-")){if(e.get(s.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 s=e.get(n[r]);if(!s)return null;if(s.def.type!=="boolean")return{consumesValue:r===n.length-1}}return{consumesValue:!1}}function pt(e,t){let n=[e.meta.name],r=e,s=t,o=[],i=[],a=(c,l)=>{if(i.length===0)return;let u=c.flagSpellings;for(let{token:f,consumesValue:d}of i){let b=Ze(u,f);if(b!==null&&b.consumesValue===d)continue;throw new p("PARSE",`Flag "${f}" cannot be used before subcommand "${l}" because "${l}" does not accept it.`,{flag:f,reason:"flag-not-forwardable"})}};while(s.length>0){let c=r.subCommands;if(Object.keys(c).length===0)break;let l=s[0];if(!l)break;if(l.startsWith("-")){let d=Ze(r.flagSpellings,l);if(!d)break;o.push(l),i.push({token:l,consumesValue:d.consumesValue}),s=s.slice(1);let b=s[0];if(d.consumesValue&&b!==void 0)o.push(b),s=s.slice(1);continue}if(Object.hasOwn(c,l)&&c[l]){a(c[l],l),r=c[l],n.push(l),s=s.slice(1);continue}let u=Ar(c,l);if(u){a(u.node,l),r=u.node,n.push(u.canonicalName),s=s.slice(1);continue}if(r.run)break;let f=N(r);throw new p("COMMAND_NOT_FOUND",`Unknown command "${l}".`,{input:l,available:Object.entries(f.subCommands).flatMap(([d,b])=>ht(b)?[d]:[]),commandPath:[...n],parentCommand:f})}return{command:r,argv:[...o,...s],commandPath:n}}function Tr(){var e=typeof SuppressedError=="function"?SuppressedError:function(s,o){var i=Error();return i.name="SuppressedError",i.error=s,i.suppressed=o,i},t={},n=[];function r(s,o){if(o!=null){if(Object(o)!==o)throw TypeError("using declarations can only be used with objects, functions, null, or undefined.");if(s)var i=o[Symbol.asyncDispose||Symbol.for("Symbol.asyncDispose")];if(i===void 0&&(i=o[Symbol.dispose||Symbol.for("Symbol.dispose")],s))var a=i;if(typeof i!="function")throw TypeError("Object is not disposable.");a&&(i=function(){try{a.call(o)}catch(l){return Promise.reject(l)}}),n.push({v:o,d:i,a:s})}else s&&n.push({d:o,a:s});return o}return{e:t,u:r.bind(null,!1),a:r.bind(null,!0),d:function(){var o,i=this.e,a=0;function c(){for(;o=n.pop();)try{if(!o.a&&a===1)return a=0,n.push(o),Promise.resolve().then(c);if(o.d){var u=o.d.call(o.v);if(o.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 Qe=()=>{};function et(e,t){let n=()=>{if(e.listenerCount("error")===0)e.once("error",Qe)};try{n(),e.write(`${t}
|
|
7
|
+
`,(r)=>{if(r)n()})}catch{}finally{e.removeListener("error",Qe)}}var _r={stdout:(e)=>et(process.stdout,e),stderr:(e)=>et(process.stderr,e)};var D=130;function le(e){if(!(e instanceof Error))return!1;return e.name==="AbortError"}function bt(e){return wt(e)&&"error"in e&&"suppressed"in e&&e.name==="SuppressedError"}function wt(e){return typeof e==="object"&&e!==null}function me(e,t="Error"){let n=[],r=new Set,s=256,o=!1,i=(c)=>{if(o)return;if(s===0){o=!0,n.push("[additional failures omitted]");return}s--;let l;try{l=c()}catch{n.push("[unreadable failure]");return}a(l)},a=(c)=>{try{if(wt(c)){if(r.has(c))return;r.add(c)}let l=n.length;if(bt(c)){if(i(()=>c.error),i(()=>c.suppressed),n.length>l)return}else if(c instanceof AggregateError){let u=c.errors;if(Array.isArray(u)){for(let f=0;f<u.length;f++)if(i(()=>u[f]),o)break;if(n.length>l)return}}n.push(String(c instanceof Error&&c.message||c))}catch{n.push("[unreadable failure]")}};return i(()=>e),n.map((c)=>`${t}: ${c}`).join(`
|
|
8
|
+
`)}function yt(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))yt(t);Object.freeze(e.subCommands)}function Pr(e){return typeof e==="symbol"}var tt=new WeakMap;function Fr(e,t){let n=M(e),r=Object.freeze([...e.extensions]);for(let s of r)ar(n,s,t);for(let s of r)cr(n,s);return{rootNode:n,extensions:r}}function Dr(e,t){if(t.some((n)=>n.sections!==void 0)){let n=N(e);for(let r of t)fr(e,r,n)}return yt(e),e}function B(e,t){let n=tt.get(e);if(n)return n;let r=Fr(e,t);return Dr(r.rootNode,r.extensions),tt.set(e,r),r}function Rr(e,t){let n=pt(e,[...t]);return{argv:t,route:n,parsed:Cr(n.command,n.argv)}}function we(e,t){let n=pt(e,[...t]);if(n.argv.length>0){let r=n.argv[0],s=N(n.command);throw new p("COMMAND_NOT_FOUND",`Unknown command "${r}".`,{input:r,available:Object.entries(s.subCommands).flatMap(([o,i])=>ht(i)?[o]:[]),commandPath:n.commandPath,parentCommand:s})}return n}function Mr(e,t,n){let r=we(e,t);return{argv:t,route:r,parsed:Er(r.command,n)}}async function vt(e,t,n,r,s,o){try{var i=Tr();let{rootNode:a,extensions:c}=t,{argv:l,route:u,parsed:f}="argv"in e?Rr(a,e.argv):Mr(a,e.path,e.input),d=u.command,b=i.a(new tr),g=d.contexts.map(({instance:C})=>C),m=or(g,n,b,r),h=N(a),v=h;for(let C of u.commandPath.slice(1))v=v.subCommands[C];let O=Object.freeze({argv:[...l],rootCommand:h,command:v,commandPath:Object.freeze([...u.commandPath]),args:f.args,flags:f.flags,rawArgs:f.rawArgs,signal:r,ctx:m.bag(c.flatMap((C)=>C.uses??[])),finish:fe,stdout:n.stdout,stderr:n.stderr});s?.(O);let S=async()=>{Ir(d,f);let C=await jr(d,f);if(m.setValidatedFlags(C.flags),!d.run)return;let j={args:C.args,flags:C.flags,ctx:m.bag(g),rawArgs:f.rawArgs,signal:r,command:O.command,rootCommand:h,stdout:n.stdout,stderr:n.stderr};return await d.run(j)},I,x={status:"completed"};try{try{for(let E of c)if(await E.hooks?.preRun?.(O)===fe()){x={status:"finished",by:E.id};break}if(x.status!=="finished")I=await S()}catch(E){let T=await o?.(E,O);x={status:"failed",error:E,...T===void 0?{}:{by:T}}}Object.freeze(x);let C=!1,j;for(let E of c.toReversed())try{await E.hooks?.postRun?.(O,x)}catch(T){if(x.status!=="failed"&&!C)C=!0,j=T}if(x.status==="failed")throw x.error;if(C)throw j}finally{await m.settle()}return x.status==="finished"?{status:"finished",by:x.by}:{status:"completed",result:I}}catch(a){i.e=a}finally{await i.d()}}async function ue(e,t,n,r,s,o,i=!1){let a=()=>{if(i)return;r.stderr(me(e))};function c(f){return Promise.reject(new p("DEFINITION",`Context "${String(f)}" cannot be pulled from onError because invocation Contexts have already been disposed.`,{subject:"context",name:String(f),reason:"context-after-disposal"}))}let l=new Proxy({},{get:(f,d)=>d==="then"||Pr(d)?void 0:c(d)}),u=o;if(!u){let f=N(n.rootNode);u=Object.freeze({argv:[...t],rootCommand:f,command:f,commandPath:Object.freeze([n.rootNode.meta.name]),args:Object.freeze({}),flags:Object.freeze({}),rawArgs:[],signal:s,finish:fe,stdout:r.stdout,stderr:r.stderr,ctx:l})}try{for(let f of n.extensions)if(await f.hooks?.onError?.(e,u))return f.id}catch{}a()}function Br(e){return e!==void 0&&Object.keys(e).length>0}async function ye(e,t,n,r){let s=[],o=[];try{let{signal:i=new AbortController().signal,...a}=n??{},c={stdout(l){s.push(l),a.stdout?.(l)},stderr(l){o.push(l),a.stderr?.(l)}};return{...await ae(c,async()=>await vt(t,B(e,r),c,i)),stdout:s.join(`
|
|
7
9
|
`),stderr:o.join(`
|
|
8
10
|
`)}}catch(i){return{status:"failed",error:i,stdout:s.join(`
|
|
9
11
|
`),stderr:o.join(`
|
|
10
|
-
`)}}}async function xt(e,t,n){let r=t?.argv??process.argv.slice(2),s={...Fr,...t?.io},o=process.env[Rr];if(o){try{let a=yt(e,n),c=()=>j(vt(T(a.rootNode),a.extensions)),l=c(),u=process.env[re];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=Mr(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=Xe(u,h.path);await Kn(Je(w),{recursive:!0}),await ae(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 ae(Xe(Je(o),"build-report.json"),JSON.stringify({extensions:f}))}await ae(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=M(e,n)}catch(u){if(le(u))return process.exitCode=R,R;let f=u instanceof Error?u.message:String(u);return s.stderr(`Error: ${f}`),process.exitCode=1,1}let c,l=!1;try{await St({argv:r},a,s,(u)=>{c=u},async(u,f)=>{l=!0;let g=le(u);return process.exitCode=g?R:1,ue(u,r,a,s,f,g)})}catch(u){if(le(u)){if(!l)await ue(u,r,a,s,c,!0);return process.exitCode=R,R}if(process.exitCode=1,!l)await ue(u,r,a,s,c);return 1}return 0};return await(zr(t?.io)?ie(s,i):i())}var ve=Symbol.for("crust.commandDefinition");function _(e,t,n){let r=e[ve],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 G(l.contexts.map(({instance:u})=>u),l.demands),l.meta={name:s,...r.meta},l}function ye(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 Wr(e){return typeof e==="function"}function Ur(e,t,n){let r=!Wr(t),s=r?t:{},o=r?n:t,i=ye(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:me(i,a)}:{}},f={name:i,recipe:o,meta:u},g=(d)=>Object.freeze({name:d,as:(m)=>g(ye(m,u.aliases)),[ve]:Object.freeze({...f,name:d})});return g(i)}function Vr(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=ye(e);if(this._node=lt(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=me(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(at)],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(H)]})}provide(...e){let t=e.map(H);G([...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(H),n=Vr([...this._node.extensions,...t]),r=dt(this._node,n,new Set(t.map((s)=>s.id)));return G(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=Ur(e,t);return this._addDefinitions([n])}_addDefinitions(e){let t={...this._node.subCommands};for(let n of e){let r=[n.name,...n[ve].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=_(n,this._node);t[n.name]=s}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 we(this._node,{path:e,input:n},r,_)}at(e){be(M(this._node,_).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 we(t,{path:n,input:s},o,_)}}}async execute(e){return await xt(this._node,e,_)}};import{existsSync as Oe,lstatSync as Pt,mkdirSync as kt,readFileSync as os,readdirSync as Ft,realpathSync as Rt,statSync as Dt,writeFileSync as At}from"node:fs";import{dirname as Mt,join as P,resolve as Tt,sep as is}from"node:path";import{fileURLToPath as as}from"node:url";function Ot(e){return e instanceof Error&&"code"in e&&typeof e.code==="string"}import{isAbsolute as qr,relative as Hr,sep as Gr}from"node:path";function $t(e,t){let n=Hr(e,t);return n===""||!qr(n)&&n!==".."&&!n.startsWith(`..${Gr}`)}import{spawn as cs,spawnSync as ls}from"node:child_process";import{once as us}from"node:events";import{accessSync as Ct,constants as Et,statSync as It}from"node:fs";import{delimiter as Yr,extname as Kr,join as Jr,resolve as Xr,sep as Zr,win32 as Qr}from"node:path";import{spawn as es}from"node:child_process";import{once as ts}from"node:events";import{text as jt}from"node:stream/consumers";function Nt(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 ns=/[\0\r\n"%!^`<>&|]/,Se=/([()\][%!^"`<>&|;, *?])/g;function rs(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 ss(e,t,n,r=process.platform){if(n||r!=="win32"||!/\.(cmd|bat)$/i.test(e))return null;let s=Qr.normalize(e);for(let[i,a]of[s,...t].entries())if(ns.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(rs)].join(" ");return{command:process.env.ComSpec??"cmd.exe",args:["/d","/s","/c",`"${o}"`],windowsVerbatimArguments:!0}}async function B(e,t=[],n={}){let r=ss(e,t,n.shell),s=(n.stdio??"collect")==="collect",o=s&&n.stdout!=="ignore",i=es(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?jt(i.stdout):"",s?jt(i.stderr):"",ts(i,"close")]);return{exitCode:l,stdout:a,stderr:c}}function xe(e){if(e.includes(Zr)||e.includes("/")){try{if(Ct(e,Et.X_OK),It(e).isFile())return e}catch{}return null}let t=process.platform==="win32"&&!Kr(e)?(process.env.PATHEXT??".EXE;.CMD;.BAT;.COM").split(";"):[""];for(let n of process.env.PATH?.split(Yr)??[])for(let r of t){let s=Xr(Jr(n,e+r));try{if(Ct(s,Et.X_OK),It(s).isFile())return s}catch{}}return null}function fs(e,t){return e.replace(/\{\{\s*(\w+)\s*\}\}/g,(n,r)=>Object.hasOwn(t,r)?t[r]??n:n)}function ds(e){let t=Mt(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 ms(e){if(!Oe(e))return!1;if(!Dt(e).isDirectory())return!1;return Ft(e).length>0}function gs(e,t){let n=e;for(let r of t.split(is)){n=P(n,r);let s;try{s=Pt(n).isSymbolicLink()}catch(i){if(Ot(i)&&i.code==="ENOENT")return;throw i}if(!s)continue;let o;try{o=Rt(n)}catch{}if(o===void 0||!$t(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?as(t):Tt(t),i=Tt(n);if(!Oe(o))throw Error(`Template directory "${o}" does not exist (from template: "${String(t)}").`);if(!Dt(o).isDirectory())throw Error(`Template path "${o}" is not a directory (from template: "${String(t)}").`);if(s==="abort"&&ms(i))throw Error(`Destination directory "${i}" already exists and is non-empty. Use conflict: "overwrite" to proceed.`);let a=Ft(o,{recursive:!0,encoding:"utf8"}).filter((f)=>Pt(P(o,f)).isFile());kt(i,{recursive:!0});let c=Rt(i),l=a.map((f)=>({relFromTemplate:f,destRelPath:ds(f)}));for(let{destRelPath:f}of l)gs(c,f);let u=[];for(let{relFromTemplate:f,destRelPath:g}of l){let d=P(o,f),m=P(c,g);kt(Mt(m),{recursive:!0});let h=os(d);if(h.subarray(0,8192).includes(0))At(m,h);else{let w=fs(h.toString("utf-8"),r);At(m,w,"utf-8")}u.push(g)}return{files:u}}var hs=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];function ps(e){let t=e??process.cwd();for(let[n,r]of hs)if(Oe(P(t,n)))return r;return Nt(process.env.npm_config_user_agent)??"npm"}function Bt(e){try{return ls("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 bs(t);break;case"git-init":await ws(t,n.commit);break;case"open-editor":await ys(t);break;case"command":await vs(n.cmd,n.cwd??t)}}async function bs(e){let t=ps(e),n=xe(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 ws(e,t){let n=xe("git");if(!n)throw Error('"git" was not found on PATH. Install Git and try again.');if(await L([n,"init"],e,"git init"),t)await Ss(e,n),await L([n,"add","."],e,"git add"),await L([n,"commit","-m",t],e,"git commit")}async function ys(e){let t=process.env.EDITOR||"code";try{let n=cs(t,[e],{stdio:"ignore",shell:process.platform==="win32"});n.unref();let r=await Promise.race([us(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 vs(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 Ss(e,t){let n=await _t(t,"user.name",e)===0,r=await _t(t,"user.email",e)===0;if(!n)await L([t,"config","user.name","Crust"],e,"git config user.name");if(!r)await L([t,"config","user.email","crust@scaffolded.project"],e,"git config user.email")}async function _t(e,t,n){let{exitCode:r}=await B(e,["config",t],{cwd:n,stdio:"collect",stdout:"ignore"});return r}async function L(e,t,n){let{exitCode:r,stderr:s}=await B(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()}`:""}`)}var Lt=Object.defineProperty,xs=(e,t)=>{let n={};for(var r in e)Lt(n,r,{get:e[r],enumerable:!0});if(!t)Lt(n,Symbol.toStringTag,{value:"Module"});return n},Os=new Intl.Segmenter(void 0,{granularity:"grapheme"}),$s=/[\p{Cc}\p{Cf}\p{Mn}\p{Me}]/u,Cs=/\p{Emoji_Presentation}|\p{Emoji}\uFE0F/u,Es=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 Is(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 js(e){return $s.test(String.fromCodePoint(e))||e>=4448&&e<=4607||e>=55216&&e<=55295}function Ns(e){if(!/[^\x20-\x7e]/.test(e))return e.length;let t=0;for(let{segment:n}of Os.segment(e.replace(Es,""))){if(Cs.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(js(s))continue;t+=Is(s)?2:1;break}}return t}function Vt(e){return globalThis.Bun?.stringWidth(e,{countAnsiEscapeCodes:!1})??Ns(e)}var ks=xs({bgBlack:()=>eo,bgBlue:()=>so,bgBrightBlack:()=>co,bgBrightBlue:()=>mo,bgBrightCyan:()=>ho,bgBrightGreen:()=>uo,bgBrightMagenta:()=>go,bgBrightRed:()=>lo,bgBrightWhite:()=>po,bgBrightYellow:()=>fo,bgCyan:()=>io,bgGreen:()=>no,bgMagenta:()=>oo,bgRed:()=>to,bgWhite:()=>ao,bgYellow:()=>ro,black:()=>Ms,blue:()=>Ws,bold:()=>As,brightBlue:()=>Js,brightCyan:()=>Zs,brightGreen:()=>Ys,brightMagenta:()=>Xs,brightRed:()=>Gs,brightWhite:()=>Qs,brightYellow:()=>Ks,cyan:()=>Vs,dim:()=>Ts,gray:()=>Hs,green:()=>Ls,hidden:()=>Rs,inverse:()=>Fs,isModifierName:()=>qt,italic:()=>_s,magenta:()=>Us,red:()=>Bs,strikethrough:()=>Ds,styleMethodNames:()=>Ie,underline:()=>Ps,white:()=>qs,yellow:()=>zs});function y(e,t){return{open:`\x1B[${e}m`,close:`\x1B[${t}m`}}var As=y(1,22),Ts=y(2,22),_s=y(3,23),Ps=y(4,24),Fs=y(7,27),Rs=y(8,28),Ds=y(9,29),Ms=y(30,39),Bs=y(31,39),Ls=y(32,39),zs=y(33,39),Ws=y(34,39),Us=y(35,39),Vs=y(36,39),qs=y(37,39),Hs=y(90,39),Gs=y(91,39),Ys=y(92,39),Ks=y(93,39),Js=y(94,39),Xs=y(95,39),Zs=y(96,39),Qs=y(97,39),eo=y(40,49),to=y(41,49),no=y(42,49),ro=y(43,49),so=y(44,49),oo=y(45,49),io=y(46,49),ao=y(47,49),co=y(100,49),lo=y(101,49),uo=y(102,49),fo=y(103,49),mo=y(104,49),go=y(105,49),ho=y(106,49),po=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"]),bo=new Set(["bold","dim","italic","underline","inverse","hidden","strikethrough"]);function qt(e){return bo.has(e)}function z(e,t,n){return e!==void 0&&t in e?e[t]:n}function Ht(e){return z(e,"isTTY",process.stdout?.isTTY)??!1}function Gt(e){return z(e,"forceColor",process.env.FORCE_COLOR)}function Yt(e){return e==="0"||e==="false"}function wo(e){let t=e.toLowerCase();return t.includes("24bit")||t.includes("truecolor")||t.endsWith("-direct")}function Kt(e,t){if(e!==void 0){let n=e.toLowerCase();if(n==="truecolor"||n==="24bit")return!0}return t!==void 0&&wo(t)}function zt(e,t){if(Kt(e,t))return"truecolor";if(t!==void 0&&t.toLowerCase().includes("256color"))return"256";return"16"}function yo(e,t){if(e==="never")return"none";if(e==="always")return"truecolor";let n=z(t,"colorTerm",process.env.COLORTERM),r=z(t,"term",process.env.TERM),s=Gt(t);if(s!==void 0){if(Yt(s))return"none";if(s==="1")return"16";if(s==="2")return"256";if(s==="3")return"truecolor";return zt(n,r)}if(!Ht(t))return"none";let o=z(t,"noColor",process.env.NO_COLOR);if(o!==void 0&&o!=="")return"none";if(r!==void 0&&r.toLowerCase()==="dumb"&&!Kt(n,r))return"none";return zt(n,r)}function vo(e,t){if(e==="always")return!0;if(e==="never")return!1;let n=Gt(t);if(n!==void 0)return!Yt(n);return Ht(t)}var Jt={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 So="\x1B[39m",xo="\x1B[49m",Oo="\x1B[38;",$o="\x1B[48;";function Co(e){try{return JSON.stringify(e)??String(e)}catch{return String(e)}}function Eo(e){return Object.hasOwn(Jt,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(Eo(t))return Jt[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: ${Co(e)}`)}function Io(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 Xt(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 Zt(e,t){let[n,r,s]=Ne(e);if(t==="16")return`\x1B[${Xt(n,r,s)}m`;if(t==="256")return`\x1B[38;5;${Io(n,r,s)}m`;return`\x1B[38;2;${n};${r};${s}m`}function jo(e,t){if(t==="16"){let[n,r,s]=Ne(e);return`\x1B[${Xt(n,r,s)+10}m`}return Zt(e,t).replace(Oo,$o)}function ke(e,t,n){if(n==="none")return Ne(t),{open:"",close:""};return{open:e==="fg"?Zt(t,n):jo(t,n),close:e==="fg"?So:xo}}function Qt(e,t){return ke("fg",e,t)}function en(e,t){return ke("bg",e,t)}function tn(e,t,n,r){let s=ke(e,n,r);return r==="none"?t:je(t,s)}function No(e,t,n="truecolor"){return tn("fg",e,t,n)}function ko(e,t,n="truecolor"){return tn("bg",e,t,n)}var nn="\x1B]",rn="\x1B\\",Ao=`${nn}8;;${rn}`;function sn(e,t,n,r=""){if(!n.test(e))throw TypeError(`Invalid ${t}: ${JSON.stringify(e)} must contain only printable ASCII characters${r}.`)}function To(e){let t=e?.id;if(t===void 0||t==="")return"";if(sn(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 on(e,t){sn(e,"hyperlink URL",/^[\x21-\x7e]*$/," without spaces");let n=To(t);return{open:`${nn}8;${n};${e}${rn}`,close:Ao}}function _o(e,t,n){return je(e,on(t,n))}var an=[["fg",Qt,No],["bg",en,ko]],Po=ks;function Fo(e){return e.kind==="named"&&qt(e.name)}function Ee(e,t){if(e.kind==="named")return Po[e.name];return e.kind==="fg"?Qt(e.input,t):en(e.input,t)}function Wt(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(Fo(c)?!o:!i)continue;r=je(r,Ee(c,s.colorDepth))}return r}function Ro(e){return Array.isArray(e)&&"raw"in e&&Array.isArray(e.raw)}function Do(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(Ro(f)){let d="";for(let m=0;m<f.length;m++)if(d+=f[m]??"",m<g.length)d+=String(g[m]);return Wt(d,o,e)}return Wt(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 an)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 Mo(e){let t={};for(let n of Ie)t[n]=e([{kind:"named",name:n}]);return t}function Ut(e){let t=e?.mode??"auto",n=vo(t,e?.overrides),r=yo(t,e?.overrides);return{modifiersEnabled:n,colorDepth:r,colorsEnabled:r!=="none",trueColorEnabled:r==="truecolor"}}function Bo(e,t){let n=t?Ut:(()=>{let i=Ut(e);return()=>i})(),r=Do(n,t),s=Mo(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 _o(i,a,c);return on(a,c),i},...Object.fromEntries(an.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=Bo(void 0,!0),{black:Sa,red:K,green:J,yellow:xa,blue:Oa,magenta:cn,cyan:W,white:$a,gray:Ca,brightRed:Ea,brightGreen:Ia,brightYellow:ja,brightBlue:Na,brightMagenta:ka,brightCyan:Aa,brightWhite:Ta,bgBlack:_a,bgRed:Pa,bgGreen:Fa,bgYellow:Ra,bgBlue:Da,bgMagenta:Ma,bgCyan:Ba,bgWhite:La,bgBrightBlack:za,bgBrightRed:Wa,bgBrightGreen:Ua,bgBrightYellow:Va,bgBrightBlue:qa,bgBrightMagenta:Ha,bgBrightCyan:Ga,bgBrightWhite:Ya,bold:X,dim:Z,italic:Ka,underline:Ja,inverse:Xa,hidden:Za,strikethrough:Qa,link:ec,fg:tc,bg:nc}=b;var ln={spinner:cn,message:X,success:J,error:K},_e="\x1B[",Lo=`${_e}?25l`,un=`${_e}?25h`,dn=`${_e}2K`,mn="\r",fn={dots:{frames:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],interval:80},line:{frames:["-","\\","|","/"],interval:130},arc:{frames:["◐","◓","◑","◒"],interval:100},bounce:{frames:["⠁","⠂","⠄","⡀","⢀","⠠","⠐","⠈"],interval:120}},zo="✓",Wo="✗";function Uo(e){if(e===void 0)return fn.dots;if(typeof e==="string")return fn[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`${dn}${mn}${n.spinner(e)} ${n.message(t)}`}function Vo(e,t,n,r){let s=n==="success"?zo:Wo,o=`${(n==="success"?t.success:t.error)(s)} ${t.message(e)}
|
|
11
|
-
`;return r?dn+
|
|
12
|
-
`),r=0;for(let s of n){let o=
|
|
13
|
-
`),
|
|
14
|
-
`),
|
|
15
|
-
${n}`;return`${s}${o} ${n}`}function
|
|
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
|
|
19
|
-
Created ${
|
|
20
|
-
`),console.log("Next steps:"),n!=="."){let
|
|
12
|
+
`)}}}async function St(e,t,n){let r=t?.argv??process.argv.slice(2),s={..._r,...t?.io},o=new AbortController,i=t?.signal?AbortSignal.any([t.signal,o.signal]):o.signal,a=void 0,c=async()=>{let l;try{l=B(e,n)}catch(g){if(le(g))return process.exitCode=D,D;return s.stderr(me(g)),process.exitCode=1,1}let u=()=>{if(!o.signal.aborted){o.abort(new DOMException("Interrupted by SIGINT.","AbortError"));return}if(process.removeListener("SIGINT",u),process.listenerCount("SIGINT")===0)process.kill(process.pid,"SIGINT")};process.on("SIGINT",u);let f,d=!1,b;try{await vt({argv:r},l,s,i,(g)=>{f=g},async(g,m)=>{d=!0,b=g;let h=le(g);return process.exitCode=h?D:1,ue(g,r,l,s,i,m,h)})}catch(g){let m;try{if(d&&!Object.is(g,b)&&bt(g)&&Object.is(g.suppressed,b))m={error:g.error}}catch{}if(m)s.stderr(me(m.error,"Cleanup failed"));if(le(g)){if(!d)await ue(g,r,l,s,i,f,!0);return process.exitCode=D,D}if(process.exitCode=1,!d)await ue(g,r,l,s,i,f);return 1}finally{process.removeListener("SIGINT",u)}return 0};return await(Br(t?.io)?ae(s,c):c())}var Se=Symbol.for("crust.commandDefinition");function _(e,t,n){let r=e[Se],s=e.name,o=n?`Extension "${n}" command "${s}"`:`Command "${s}"`,i=(u)=>({subject:n?"extension":"command",name:n??s,reason:u}),a=new J(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 J)||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=M(c._node);return K(l.contexts.map(({instance:u})=>u),l.demands),l.meta={name:s,...r.meta},l}function ve(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 Lr(e){return typeof e==="function"}function zr(e,t,n){let r=!Lr(t),s=r?t:{},o=r?n:t,i=ve(e,s.aliases);for(let b of s.aliases??[])if(b===""||/[ \t\n\r\v\f]/.test(b)||b.startsWith("-"))throw new p("DEFINITION",`Command "${i}" has an invalid alias "${b}"`);let{sections:a,version:c,...l}=s,u={...l,...s.aliases?{aliases:[...s.aliases]}:{},...a?{sections:ge(i,a)}:{}},f={name:i,recipe:o,meta:u},d=(b)=>Object.freeze({name:b,as:(g)=>d(ve(g,u.aliases)),[Se]:Object.freeze({...f,name:b})});return d(i)}function Wr(e){return e.filter((t,n)=>e.findLastIndex((r)=>r.id===t.id)===n)}var J=class{_node;_ancestorOwnedFlags;constructor(e,...t){let n=t[0]??{},r=ve(e);if(this._node=ct(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=ge(r,n.sections);this._ancestorOwnedFlags={}}_clone(e){let t=Object.create(Object.getPrototypeOf(this));return t._node={...this._node,...e},t._ancestorOwnedFlags=this._ancestorOwnedFlags,t}flags(...e){let t=this._clone(Y(this._node));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(it)],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(H)]})}provide(...e){let t=e.map(H);K([...this._node.contexts.map(({instance:r})=>r),...t],t);let n=this._clone({...Y(this._node),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(H),n=Wr([...this._node.extensions,...t]),r=ft(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=zr(e,t);return this._addDefinitions([n])}_addDefinitions(e){let t={...this._node.subCommands};for(let n of e){let r=[n.name,...n[Se].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=_(n,this._node);t[n.name]=s}return this._clone({subCommands:t})}async snapshot(){return N(B(this._node,_).rootNode)}async run(e,...t){let n=t[0]??{},r=t[1];return await ye(this._node,{path:e,input:n},r,_)}at(e){we(B(this._node,_).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 ye(t,{path:n,input:s},o,_)}}}async execute(e){return await St(this._node,e,_)}};import{existsSync as $e,lstatSync as _t,mkdirSync as Nt,readFileSync as rs,readdirSync as Pt,realpathSync as Ft,statSync as Dt,writeFileSync as kt}from"node:fs";import{dirname as Rt,join as P,resolve as At,sep as ss}from"node:path";import{fileURLToPath as os}from"node:url";function xt(e){return e instanceof Error&&"code"in e&&typeof e.code==="string"}import{isAbsolute as Ur,relative as Vr,sep as qr}from"node:path";function Ot(e,t){let n=Vr(e,t);return n===""||!Ur(n)&&n!==".."&&!n.startsWith(`..${qr}`)}import{spawn as is,spawnSync as as}from"node:child_process";import{once as cs}from"node:events";import{accessSync as $t,constants as Ct,statSync as Et}from"node:fs";import{delimiter as Gr,extname as Hr,join as Kr,resolve as Yr,sep as Jr,win32 as Xr}from"node:path";import{spawn as Zr}from"node:child_process";import{once as Qr}from"node:events";import{text as It}from"node:stream/consumers";function jt(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 es=/[\0\r\n"%!^`<>&|]/,xe=/([()\][%!^"`<>&|;, *?])/g;function ts(e){let t=e.replace(/(?=(\\+?)?)\1"/g,"$1$1\\\"");return t=t.replace(/(?=(\\+?)?)\1$/g,"$1$1"),t=`"${t}"`.replace(xe,"^$1"),t.replace(xe,"^$1")}function ns(e,t,n,r=process.platform){if(n||r!=="win32"||!/\.(cmd|bat)$/i.test(e))return null;let s=Xr.normalize(e);for(let[i,a]of[s,...t].entries())if(es.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(xe,"^$1"),...t.map(ts)].join(" ");return{command:process.env.ComSpec??"cmd.exe",args:["/d","/s","/c",`"${o}"`],windowsVerbatimArguments:!0}}async function L(e,t=[],n={}){let r=ns(e,t,n.shell),s=(n.stdio??"collect")==="collect",o=s&&n.stdout!=="ignore",i=Zr(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?It(i.stdout):"",s?It(i.stderr):"",Qr(i,"close")]);return{exitCode:l,stdout:a,stderr:c}}function Oe(e){if(e.includes(Jr)||e.includes("/")){try{if($t(e,Ct.X_OK),Et(e).isFile())return e}catch{}return null}let t=process.platform==="win32"&&!Hr(e)?(process.env.PATHEXT??".EXE;.CMD;.BAT;.COM").split(";"):[""];for(let n of process.env.PATH?.split(Gr)??[])for(let r of t){let s=Yr(Kr(n,e+r));try{if($t(s,Ct.X_OK),Et(s).isFile())return s}catch{}}return null}function ls(e,t){return e.replace(/\{\{\s*(\w+)\s*\}\}/g,(n,r)=>Object.hasOwn(t,r)?t[r]??n:n)}function us(e){let t=Rt(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 fs(e){if(!$e(e))return!1;if(!Dt(e).isDirectory())return!1;return Pt(e).length>0}function ds(e,t){let n=e;for(let r of t.split(ss)){n=P(n,r);let s;try{s=_t(n).isSymbolicLink()}catch(i){if(xt(i)&&i.code==="ENOENT")return;throw i}if(!s)continue;let o;try{o=Ft(n)}catch{}if(o===void 0||!Ot(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 Ce(e){let{template:t,dest:n,context:r,conflict:s="abort"}=e,o=t instanceof URL?os(t):At(t),i=At(n);if(!$e(o))throw Error(`Template directory "${o}" does not exist (from template: "${String(t)}").`);if(!Dt(o).isDirectory())throw Error(`Template path "${o}" is not a directory (from template: "${String(t)}").`);if(s==="abort"&&fs(i))throw Error(`Destination directory "${i}" already exists and is non-empty. Use conflict: "overwrite" to proceed.`);let a=Pt(o,{recursive:!0,encoding:"utf8"}).filter((f)=>_t(P(o,f)).isFile());Nt(i,{recursive:!0});let c=Ft(i),l=a.map((f)=>({relFromTemplate:f,destRelPath:us(f)}));for(let{destRelPath:f}of l)ds(c,f);let u=[];for(let{relFromTemplate:f,destRelPath:d}of l){let b=P(o,f),g=P(c,d);Nt(Rt(g),{recursive:!0});let m=rs(b);if(m.subarray(0,8192).includes(0))kt(g,m);else{let h=ls(m.toString("utf-8"),r);kt(g,h,"utf-8")}u.push(d)}return{files:u}}var ms=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];function gs(e){let t=e??process.cwd();for(let[n,r]of ms)if($e(P(t,n)))return r;return jt(process.env.npm_config_user_agent)??"npm"}function Mt(e){try{return as("git",["rev-parse","--is-inside-work-tree"],{cwd:e??process.cwd(),stdio:"ignore"}).status===0}catch{return!1}}async function Ee(e,t){for(let n of e)switch(n.type){case"install":await hs(t);break;case"git-init":await ps(t,n.commit);break;case"open-editor":await bs(t);break;case"command":await ws(n.cmd,n.cwd??t)}}async function hs(e){let t=gs(e),n=Oe(t);if(!n)throw Error(`Package manager "${t}" was not found on PATH. Install ${t} and try again.`);let{exitCode:r}=await L(n,["install"],{cwd:e,stdio:"inherit"});if(r!==0)throw Error(`"${t} install" exited with code ${r}`)}async function ps(e,t){let n=Oe("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 ys(e,n),await z([n,"add","."],e,"git add"),await z([n,"commit","-m",t],e,"git commit")}async function bs(e){let t=process.env.EDITOR||"code";try{let n=is(t,[e],{stdio:"ignore",shell:process.platform==="win32"});n.unref();let r=await Promise.race([cs(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 ws(e,t){let{exitCode:n}=await L(e,[],{cwd:t,shell:!0,stdio:"inherit"});if(n!==0)throw Error(`Command "${e}" exited with code ${n}`)}async function ys(e,t){let n=await Tt(t,"user.name",e)===0,r=await Tt(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 Tt(e,t,n){let{exitCode:r}=await L(e,["config",t],{cwd:n,stdio:"collect",stdout:"ignore"});return r}async function z(e,t,n){let{exitCode:r,stderr:s}=await L(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()}`:""}`)}var Bt=Object.defineProperty,vs=(e,t)=>{let n={};for(var r in e)Bt(n,r,{get:e[r],enumerable:!0});if(!t)Bt(n,Symbol.toStringTag,{value:"Module"});return n},Ss=new Intl.Segmenter(void 0,{granularity:"grapheme"}),xs=/[\p{Cc}\p{Cf}\p{Mn}\p{Me}]/u,Os=/\p{Emoji_Presentation}|\p{Emoji}\uFE0F/u,$s=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 Cs(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 Es(e){return xs.test(String.fromCodePoint(e))||e>=4448&&e<=4607||e>=55216&&e<=55295}function Is(e){if(!/[^\x20-\x7e]/.test(e))return e.length;let t=0;for(let{segment:n}of Ss.segment(e.replace($s,""))){if(Os.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(Es(s))continue;t+=Cs(s)?2:1;break}}return t}function Ut(e){return globalThis.Bun?.stringWidth(e,{countAnsiEscapeCodes:!1})??Is(e)}var js=vs({bgBlack:()=>Zs,bgBlue:()=>no,bgBrightBlack:()=>io,bgBrightBlue:()=>uo,bgBrightCyan:()=>mo,bgBrightGreen:()=>co,bgBrightMagenta:()=>fo,bgBrightRed:()=>ao,bgBrightWhite:()=>go,bgBrightYellow:()=>lo,bgCyan:()=>so,bgGreen:()=>eo,bgMagenta:()=>ro,bgRed:()=>Qs,bgWhite:()=>oo,bgYellow:()=>to,black:()=>Ds,blue:()=>Ls,bold:()=>Ns,brightBlue:()=>Ks,brightCyan:()=>Js,brightGreen:()=>Gs,brightMagenta:()=>Ys,brightRed:()=>qs,brightWhite:()=>Xs,brightYellow:()=>Hs,cyan:()=>Ws,dim:()=>ks,gray:()=>Vs,green:()=>Ms,hidden:()=>Ps,inverse:()=>_s,isModifierName:()=>Vt,italic:()=>As,magenta:()=>zs,red:()=>Rs,strikethrough:()=>Fs,styleMethodNames:()=>je,underline:()=>Ts,white:()=>Us,yellow:()=>Bs});function y(e,t){return{open:`\x1B[${e}m`,close:`\x1B[${t}m`}}var Ns=y(1,22),ks=y(2,22),As=y(3,23),Ts=y(4,24),_s=y(7,27),Ps=y(8,28),Fs=y(9,29),Ds=y(30,39),Rs=y(31,39),Ms=y(32,39),Bs=y(33,39),Ls=y(34,39),zs=y(35,39),Ws=y(36,39),Us=y(37,39),Vs=y(90,39),qs=y(91,39),Gs=y(92,39),Hs=y(93,39),Ks=y(94,39),Ys=y(95,39),Js=y(96,39),Xs=y(97,39),Zs=y(40,49),Qs=y(41,49),eo=y(42,49),to=y(43,49),no=y(44,49),ro=y(45,49),so=y(46,49),oo=y(47,49),io=y(100,49),ao=y(101,49),co=y(102,49),lo=y(103,49),uo=y(104,49),fo=y(105,49),mo=y(106,49),go=y(107,49),je=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"]),ho=new Set(["bold","dim","italic","underline","inverse","hidden","strikethrough"]);function Vt(e){return ho.has(e)}function W(e,t,n){return e!==void 0&&t in e?e[t]:n}function qt(e){return W(e,"isTTY",process.stdout?.isTTY)??!1}function Gt(e){return W(e,"forceColor",process.env.FORCE_COLOR)}function Ht(e){return e==="0"||e==="false"}function po(e){let t=e.toLowerCase();return t.includes("24bit")||t.includes("truecolor")||t.endsWith("-direct")}function Kt(e,t){if(e!==void 0){let n=e.toLowerCase();if(n==="truecolor"||n==="24bit")return!0}return t!==void 0&&po(t)}function Lt(e,t){if(Kt(e,t))return"truecolor";if(t!==void 0&&t.toLowerCase().includes("256color"))return"256";return"16"}function bo(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=Gt(t);if(s!==void 0){if(Ht(s))return"none";if(s==="1")return"16";if(s==="2")return"256";if(s==="3")return"truecolor";return Lt(n,r)}if(!qt(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"&&!Kt(n,r))return"none";return Lt(n,r)}function wo(e,t){if(e==="always")return!0;if(e==="never")return!1;let n=Gt(t);if(n!==void 0)return!Ht(n);return qt(t)}var Yt={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 Ne(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 yo="\x1B[39m",vo="\x1B[49m",So="\x1B[38;",xo="\x1B[48;";function Oo(e){try{return JSON.stringify(e)??String(e)}catch{return String(e)}}function $o(e){return Object.hasOwn(Yt,e)}function ke(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($o(t))return Yt[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: ${Oo(e)}`)}function Co(e,t,n){let r=[0,95,135,175,215,255],s=(f)=>r.reduce((d,b,g)=>Math.abs(b-f)<Math.abs(r[d]-f)?g:d,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,d,b)=>(e-f)**2+(t-d)**2+(n-b)**2;return u(l,l,l)<u(r[o],r[i],r[a])?232+c:16+36*o+6*i+a}function Jt(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 Xt(e,t){let[n,r,s]=ke(e);if(t==="16")return`\x1B[${Jt(n,r,s)}m`;if(t==="256")return`\x1B[38;5;${Co(n,r,s)}m`;return`\x1B[38;2;${n};${r};${s}m`}function Eo(e,t){if(t==="16"){let[n,r,s]=ke(e);return`\x1B[${Jt(n,r,s)+10}m`}return Xt(e,t).replace(So,xo)}function Ae(e,t,n){if(n==="none")return ke(t),{open:"",close:""};return{open:e==="fg"?Xt(t,n):Eo(t,n),close:e==="fg"?yo:vo}}function Zt(e,t){return Ae("fg",e,t)}function Qt(e,t){return Ae("bg",e,t)}function en(e,t,n,r){let s=Ae(e,n,r);return r==="none"?t:Ne(t,s)}function Io(e,t,n="truecolor"){return en("fg",e,t,n)}function jo(e,t,n="truecolor"){return en("bg",e,t,n)}var tn="\x1B]",nn="\x1B\\",No=`${tn}8;;${nn}`;function rn(e,t,n,r=""){if(!n.test(e))throw TypeError(`Invalid ${t}: ${JSON.stringify(e)} must contain only printable ASCII characters${r}.`)}function ko(e){let t=e?.id;if(t===void 0||t==="")return"";if(rn(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 sn(e,t){rn(e,"hyperlink URL",/^[\x21-\x7e]*$/," without spaces");let n=ko(t);return{open:`${tn}8;${n};${e}${nn}`,close:No}}function Ao(e,t,n){return Ne(e,sn(t,n))}var on=[["fg",Zt,Io],["bg",Qt,jo]],To=js;function _o(e){return e.kind==="named"&&Vt(e.name)}function Ie(e,t){if(e.kind==="named")return To[e.name];return e.kind==="fg"?Zt(e.input,t):Qt(e.input,t)}function zt(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(_o(c)?!o:!i)continue;r=Ne(r,Ie(c,s.colorDepth))}return r}function Po(e){return Array.isArray(e)&&"raw"in e&&Array.isArray(e.raw)}function Fo(e,t){let n=new Map,r=t?"truecolor":e().colorDepth;function s(o){let i=o.map((f)=>f.kind==="named"?f.name:`~${Ie(f,"truecolor").open}`).join("|"),a=n.get(i);if(a)return a;let c=(f,...d)=>{if(Po(f)){let b="";for(let g=0;g<f.length;g++)if(b+=f[g]??"",g<d.length)b+=String(d[g]);return zt(b,o,e)}return zt(f,o,e)};if(n.size>=1024)n.delete(n.keys().next().value);n.set(i,c);for(let f of je)Object.defineProperty(c,f,{configurable:!1,enumerable:!0,get(){return s([...o,{kind:"named",name:f}])}});for(let[f,d]of on)Object.defineProperty(c,f,{configurable:!1,enumerable:!0,value:(b)=>(d(b,"truecolor"),s([...o,{kind:f,input:b}])),writable:!1});let l="",u="";for(let f of o){let d=Ie(f,r);l+=d.open,u=d.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 Do(e){let t={};for(let n of je)t[n]=e([{kind:"named",name:n}]);return t}function Wt(e){let t=e?.mode??"auto",n=wo(t,e?.overrides),r=bo(t,e?.overrides);return{modifiersEnabled:n,colorDepth:r,colorsEnabled:r!=="none",trueColorEnabled:r==="truecolor"}}function Ro(e,t){let n=t?Wt:(()=>{let i=Wt(e);return()=>i})(),r=Fo(n,t),s=Do(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 Ao(i,a,c);return sn(a,c),i},...Object.fromEntries(on.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 w=Ro(void 0,!0),{black:Sa,red:X,green:Z,yellow:xa,blue:Oa,magenta:an,cyan:U,white:$a,gray:Ca,brightRed:Ea,brightGreen:Ia,brightYellow:ja,brightBlue:Na,brightMagenta:ka,brightCyan:Aa,brightWhite:Ta,bgBlack:_a,bgRed:Pa,bgGreen:Fa,bgYellow:Da,bgBlue:Ra,bgMagenta:Ma,bgCyan:Ba,bgWhite:La,bgBrightBlack:za,bgBrightRed:Wa,bgBrightGreen:Ua,bgBrightYellow:Va,bgBrightBlue:qa,bgBrightMagenta:Ga,bgBrightCyan:Ha,bgBrightWhite:Ka,bold:Q,dim:ee,italic:Ya,underline:Ja,inverse:Xa,hidden:Za,strikethrough:Qa,link:ec,fg:tc,bg:nc}=w;var cn={spinner:an,message:Q,success:Z,error:X},Pe="\x1B[",Mo=`${Pe}?25l`,ln=`${Pe}?25h`,fn=`${Pe}2K`,dn="\r",un={dots:{frames:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],interval:80},line:{frames:["-","\\","|","/"],interval:130},arc:{frames:["◐","◓","◑","◒"],interval:100},bounce:{frames:["⠁","⠂","⠄","⡀","⢀","⠠","⠐","⠈"],interval:120}},Bo="✓",Lo="✗";function zo(e){if(e===void 0)return un.dots;if(typeof e==="string")return un[e];if(e.frames.length===0)throw Error("A custom spinner requires at least one frame");return e}function Te(e,t){let n=e[t];if(n===void 0)throw Error("Spinner frame index is out of bounds");return n}function _e(e,t,n){return`${fn}${dn}${n.spinner(e)} ${n.message(t)}`}function Wo(e,t,n,r){let s=n==="success"?Bo:Lo,o=`${(n==="success"?t.success:t.error)(s)} ${t.message(e)}
|
|
13
|
+
`;return r?fn+dn+o:o}function Uo(e){let t=e.sink??q()?.output??process.stderr,n=e.theme?{...cn,...e.theme}:cn,r=t.isTTY??!1,{frames:s,interval:o}=zo(e.spinner),i=e.sigint??"exit",a=e.message,c=0,l=!1,u=!1,f,d;function b(){if(f!==void 0)clearInterval(f),f=void 0;if(d)process.removeListener("SIGINT",d),d=void 0}return{start(){if(l||u)return;if(l=!0,!r)return;if(t.write(Mo),t.write(_e(Te(s,0),a,n)),f=setInterval(()=>{c=(c+1)%s.length,t.write(_e(Te(s,c),a,n))},o),i==="exit")d=()=>{if(b(),u=!0,t.write(ln),process.listenerCount("SIGINT")===0)process.kill(process.pid,"SIGINT")},process.once("SIGINT",d)},updateMessage(g){if(u)return;if(a=g,l&&r)t.write(_e(Te(s,c),a,n))},stop(g="success",m){if(u)return;if(u=!0,m!==void 0)a=m;if(b(),t.write(Wo(a,n,g,l&&r)),l&&r)t.write(ln)}}}function Fe(e){let t=Uo(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 mn={prefix:U,message:Q,placeholder:ee,cursor:U,selected:U,unselected:ee,error:X,success:Z,hint:ee,filterMatch:U};function ne(e){let t=q();return{input:e?.input??t?.input??process.stdin,output:e?.output??t?.output??process.stderr}}var Me=Symbol("submit");function Be(e){return{[Me]:e}}var De=new WeakSet,Re=new WeakSet,hn="\x1B[",Vo=`${hn}?25l`,qo=`${hn}?25h`;function gn(e,t){let n=e.split(`
|
|
14
|
+
`),r=0;for(let s of n){let o=Ut(s);r+=o===0?1:Math.ceil(o/t)}return r}var Go=class extends Error{constructor(e){super(e??"Prompts require an interactive terminal (TTY).");this.name="NonInteractiveError"}};function pn(e=ne().input){return!!e.isTTY}function Ho(e=ne().input){if(!pn(e))throw new Go}function Ko(e){return typeof e==="object"&&e!==null&&Me in e}function Le(e,t){let{render:n,handleKey:r,initialState:s,renderSubmitted:o}=e,i=e.theme?{...mn,...e.theme}:mn,{input:a,output:c}=ne(t),l=c;return new Promise((u,f)=>{if(De.has(a)||Re.has(c)){f(Error("Cannot run multiple prompts concurrently on the same input or output stream. Await each prompt before starting the next."));return}Ho(a),De.add(a),Re.add(c);let d=s,b=0,g=!1,m=!1;function h(){if(g)return;if(g=!0,De.delete(a),Re.delete(c),a.removeListener("keypress",C),m)a.setRawMode?.(!1);a.pause(),c.write(qo)}function v(j){let E=c.columns||80;if(b>0)k.cursorTo(l,0),k.moveCursor(l,0,-(b-1)),k.clearScreenDown(l);c.write(j),b=gn(j,E)}let O=Promise.resolve(),S=null;function I(){if(S!==null)return;S=setTimeout(()=>{if(S=null,g)return;try{v(n(d,i))}catch(j){h(),f(j)}},0)}function x(){if(S!==null)clearTimeout(S),S=null}function C(j,E){if(E?.ctrl&&E.name==="c"){x(),c.write(`
|
|
15
|
+
`),h(),f(new DOMException("Prompt was cancelled.","AbortError"));return}let T={char:j??"",name:E?.name??"",ctrl:E?.ctrl??!1,meta:E?.meta??!1,shift:E?.shift??!1};O=O.then(async()=>{if(g)return;try{let F=await r(T,d);if(g)return;if(Ko(F)){x();let Ue=F[Me];if(o)v(o(d,Ue,i));c.write(`
|
|
16
|
+
`),h(),u(Ue)}else d=F,I()}catch(F){x(),h(),f(F)}})}try{if(k.emitKeypressEvents(a),a.setRawMode)a.setRawMode(!0),m=!0;a.resume(),c.write(Vo);let j=n(d,i);c.write(j),b=gn(j,c.columns||80),a.on("keypress",C)}catch(j){h(),f(j)}})}async function te(e,t,n){if(e.initial!==void 0)return{shortCircuited:!0,value:n?await n(e.initial,"initial"):e.initial};let r=ne(t);if(!pn(r.input)&&e.default!==void 0)return{shortCircuited:!0,value:n?await n(e.default,"default"):e.default};return{shortCircuited:!1,promptIO:r}}function ze(e,t,n){let r=[e];if(t)r.push(t);if(n)r.push(n);return r.join(" ")}function bn(e,t,n,r){let s=t?`${e} ${t}`:e,o=r??"";if(t)return`${s}${o}
|
|
17
|
+
${n}`;return`${s}${o} ${n}`}function Yo(e,t,n,r,s){let o=Math.min(e.length,n),i=[];if(t>0)i.push(s("..."));for(let a=t;a<t+o;a++){let c=e[a];if(c===void 0)break;i.push(r(c,a))}if(t+o<e.length)i.push(s("..."));return i}function wn(e,t,n,r){let s=Math.min(n,r);if(e<t)return e;if(e>=t+s)return e-s+1;return t}function Jo(e,t,n,r,s){let o=n===-1?e<=0?t-1:e-1:e>=t-1?0:e+1;return{cursor:o,scrollOffset:wn(o,r,t,s)}}function Xo(e){return e.map((t)=>{if(typeof t==="string")return{label:t,value:t};return t})}function Zo(e,t){if(e.name==="return")return Be(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 Qo=" · ";function ei(e,t,n,r,s){let o=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(s)}`:`${t.selected("●")} ${t.selected(s)}`;return bn(o,i,`${a}${Qo}${c}`)}function ti(e,t,n,r,s,o){let i=n.success("✓"),a=n.message(r??"Are you sure?"),c=t?s:o;return ze(i,a,n.success(c))}async function re(e,t){let n=await te(e,t);if(n.shortCircuited)return n.value;let{promptIO:r}=n,s=e.active??"Yes",o=e.inactive??"No";return Le({initialState:{value:e.default??!0},theme:e.theme,render:(i,a)=>ei(i,a,e.message,s,o),handleKey:Zo,renderSubmitted:(i,a,c)=>ti(i,a,c,e.message,s,o)},r)}async function ni(e,t,n){let r=await te(e,n);if(r.shortCircuited)return r;let s=Xo(e.choices),o=e.maxVisible??10,i=e.default===void 0?[]:t==="multiple"?e.default:[e.default],a=new Set(i.flatMap((u)=>{let f=s.findIndex((d)=>d.value===u);return f===-1?[]:[f]})),c=i.length===0?-1:s.findIndex((u)=>u.value===i[0]),l=c===-1?0:c;return{shortCircuited:!1,choices:s,maxVisible:o,cursor:l,scrollOffset:wn(l,0,s.length,o),selected:a,promptIO:r.promptIO}}async function yn(e,t,n){if(t){let r=await t["~standard"].validate(e),s=r.issues?.[0];if(s)return{ok:!1,error:s.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 ri(e,t,n){let r=await yn(t,e,void 0);if(!r.ok)throw Error(`${n} value rejected by schema: ${r.error}`);return r.value}function si(e,t,n,r){if(e==="")return r?n.placeholder(r):n.cursor("│");return`${e.slice(0,t)}${n.cursor("│")}${e.slice(t)}`}function oi(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),s=t.slice(n);return{text:r+e.char+s,cursorPos:n+1}}return null}function ii(e,t,n){return async(r,s)=>{if(r.name==="return"){let i=await yn(s.value===""&&n!==void 0?n:s.value,e,t);return i.ok?Be(i.value):{...s,error:i.error}}let o=oi(r,s.value,s.cursorPos);return o?{value:o.text,cursorPos:o.cursorPos,error:null}:s}}function ai(e,t,n,r,s){let o=t.prefix("┃"),i=t.message(n??"Enter a value"),a=r??s,c=s!==void 0&&r!==void 0&&e.value===""?` ${t.hint(`(${s})`)}`:"",l=bn(o,i,si(e.value,e.cursorPos,t,a),c);if(e.error!==null)l+=`
|
|
18
|
+
${t.error(e.error)}`;return l}function ci(e,t,n,r){return ze(n.success("✓"),n.message(r??"Enter a value"),n.success(String(t)))}async function vn(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 te(e,t,(o,i)=>ri(n,o,i)):await te(e,t);if(r.shortCircuited)return r.value;let{promptIO:s}=r;return Le({initialState:{value:"",cursorPos:0,error:null},theme:e.theme,render:(o,i)=>ai(o,i,e.message,e.placeholder,e.default),handleKey:ii(e.schema,e.validate,e.default),renderSubmitted:(o,i,a)=>ci(o,i,a,e.message)},s)}function li(e){return(t,n)=>{let r=n.choices.length;if(t.name==="return"){let s=n.choices[n.cursor];if(s)return Be(s.value);return n}if(["up","down","k","j"].includes(t.name)){let s=t.name==="up"||t.name==="k"?-1:1;return{...n,...Jo(n.cursor,r,s,n.scrollOffset,e)}}return n}}function ui(e,t,n,r){let s=[`${t.prefix("┃")} ${t.message(n??"Pick an option")}`];return s.push(...Yo(e.choices,e.scrollOffset,r,(o,i)=>{let a=o.hint?` ${t.hint(o.hint)}`:"";return i===e.cursor?`${t.cursor("›")} ${t.selected(o.label)}${a}`:` ${t.unselected(o.label)}${a}`},t.hint)),s.join(`
|
|
19
|
+
`)}function fi(e,t,n,r){let s=n.success("✓"),o=n.message(r??"Pick an option"),i=e.choices[e.cursor],a=i?i.label:"";return ze(s,o,n.success(a))}async function Sn(e,t){let n=await ni(e,"single",t);if(n.shortCircuited)return n.value;let{choices:r,cursor:s,maxVisible:o,promptIO:i,scrollOffset:a}=n;return Le({initialState:{cursor:s,choices:r,scrollOffset:a},theme:e.theme,render:(c,l)=>ui(c,l,e.message,o),handleKey:li(o),renderSubmitted:(c,l,u)=>fi(c,l,u,e.message)},i)}var xn={name:"@crustjs/core",version:"0.3.4",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 On={name:"@crustjs/crust",version:"0.3.4",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 $n={name:"@crustjs/extensions",version:"0.3.4",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 bi={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:""}},wi={crustCoreVersion:xn.version,crustExtensionsVersion:$n.version,crustCliVersion:On.version},yi=/^[A-Za-z0-9_~][A-Za-z0-9._~-]*$/;function In(e){if(e==="__proto__"||!yi.test(e))throw Error(`Project name ${JSON.stringify(e)} is not safe for the generated project.
|
|
20
|
+
The directory basename becomes the package and command name: use letters, digits, ".", "_", "~", and "-", not starting with "." or "-"; "__proto__" is reserved.`)}var vi=/[<>:"|?*\\]/;function Si(e){if(!e)throw Error("Project directory cannot be empty");if(vi.test(e))throw Error(`Project directory contains invalid characters: ${e}`);In(En(We(e)))}var xi=new J("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 vn({message:"Project directory",default:"my-cli",validate:Si}),r=We(process.cwd(),n),s=En(r);In(s);let o=t.runtime,i=n==="."?hi(r).length>0:Cn(r),a=!1;if(i){if(a=await re({message:n==="."?"Current directory is not empty. Overwrite conflicting files?":`Directory "${s}" already exists. Overwrite?`,default:!1,...t.overwrite!==void 0?{initial:t.overwrite}:{}}),!a){console.log("Aborted.");return}}let c=await Sn({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",...o!==void 0?{initial:o}:{}}),l=await re({message:"Install dependencies?",default:!0,...t.install!==void 0?{initial:t.install}:{}}),u=Cn(r)?r:We(r,".."),d=Mt(u)?!1:await re({message:"Initialize a git repository?",default:!0,...t.git!==void 0?{initial:t.git}:{}}),b=s,g=(h)=>pi(oe("templates"),h),m={name:b,...bi[c],...wi};if(await Fe({message:"Scaffolding project...",task:async()=>{await Ce({template:g("base"),dest:r,context:m,...a?{conflict:"overwrite"}:{}}),await Ce({template:g(`runtime/${c}`),dest:r,context:m,conflict:"overwrite"})}}),l)await Ee([c==="deno"?{type:"command",cmd:"deno install"}:{type:"install"}],r);if(d)await Fe({message:"Initializing git repository...",task:()=>Ee([{type:"git-init",commit:"chore: initial commit"}],r)});if(console.log(`
|
|
21
|
+
Created ${b}!
|
|
22
|
+
`),console.log("Next steps:"),n!=="."){let h=n.startsWith("/")?n:`./${n}`;console.log(` cd ${h}`)}console.log(` ${m.run} dev`),console.log(` ${m.run} build`)});await xi.execute();
|