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