create-crust 0.4.0 → 0.4.1
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 +1 -1
- package/package.json +1 -1
package/bin/create-crust.js
CHANGED
|
@@ -16,7 +16,7 @@ ${n.map((s)=>` - ${s.path}: ${s.message}`).join(`
|
|
|
16
16
|
`),p(),u(Ve)}else d=P,I()}catch(P){x(),p(),f(P)}})}try{if(k.emitKeypressEvents(a),a.setRawMode)a.setRawMode(!0),m=!0;a.resume(),c.write(Ks);let j=n(d,i);c.write(j),b=pn(j,c.columns||80),a.on("keypress",C)}catch(j){p(),f(j)}})}async function ne(e,t,n){if(e.initial!==void 0)return{shortCircuited:!0,value:n?await n(e.initial,"initial"):e.initial};let r=re(t);if(!bn(r.input)&&e.default!==void 0)return{shortCircuited:!0,value:n?await n(e.default,"default"):e.default};return{shortCircuited:!1,promptIO:r}}function We(e,t,n){let r=[e];if(t)r.push(t);if(n)r.push(n);return r.join(" ")}function wn(e,t,n,r){let o=t?`${e} ${t}`:e,s=r??"";if(t)return`${o}${s}
|
|
17
17
|
${n}`;return`${o}${s} ${n}`}function Qs(e,t,n,r,o){let s=Math.min(e.length,n),i=[];if(t>0)i.push(o("..."));for(let a=t;a<t+s;a++){let c=e[a];if(c===void 0)break;i.push(r(c,a))}if(t+s<e.length)i.push(o("..."));return i}function yn(e,t,n,r){let o=Math.min(n,r);if(e<t)return e;if(e>=t+o)return e-o+1;return t}function ei(e,t,n,r,o){let s=n===-1?e<=0?t-1:e-1:e>=t-1?0:e+1;return{cursor:s,scrollOffset:yn(s,r,t,o)}}function ti(e){return e.map((t)=>{if(typeof t==="string")return{label:t,value:t};return t})}function ni(e,t){if(e.name==="return")return Le(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 ri=" · ";function oi(e,t,n,r,o){let s=t.prefix("┃"),i=t.message(n??"Are you sure?"),a=e.value?`${t.selected("●")} ${t.selected(r)}`:`${t.unselected("○")} ${t.unselected(r)}`,c=e.value?`${t.unselected("○")} ${t.unselected(o)}`:`${t.selected("●")} ${t.selected(o)}`;return wn(s,i,`${a}${ri}${c}`)}function si(e,t,n,r,o,s){let i=n.success("✓"),a=n.message(r??"Are you sure?"),c=t?o:s;return We(i,a,n.success(c))}async function oe(e,t){let n=await ne(e,t);if(n.shortCircuited)return n.value;let{promptIO:r}=n,o=e.active??"Yes",s=e.inactive??"No";return ze({initialState:{value:e.default??!0},theme:e.theme,render:(i,a)=>oi(i,a,e.message,o,s),handleKey:ni,renderSubmitted:(i,a,c)=>si(i,a,c,e.message,o,s)},r)}async function ii(e,t,n){let r=await ne(e,n);if(r.shortCircuited)return r;let o=ti(e.choices),s=e.maxVisible??10,i=e.default===void 0?[]:t==="multiple"?e.default:[e.default],a=new Set(i.flatMap((u)=>{let f=o.findIndex((d)=>d.value===u);return f===-1?[]:[f]})),c=i.length===0?-1:o.findIndex((u)=>u.value===i[0]),l=c===-1?0:c;return{shortCircuited:!1,choices:o,maxVisible:s,cursor:l,scrollOffset:yn(l,0,o.length,s),selected:a,promptIO:r.promptIO}}async function vn(e,t,n){if(t){let r=await t["~standard"].validate(e),o=r.issues?.[0];if(o)return{ok:!1,error:o.message||"Validation failed"};if("value"in r)return{ok:!0,value:r.value};return{ok:!1,error:"Validation failed"}}if(n)try{await n(e)}catch(r){return{ok:!1,error:r instanceof Error?r.message:"Validation failed"}}return{ok:!0,value:e}}async function ai(e,t,n){let r=await vn(t,e,void 0);if(!r.ok)throw Error(`${n} value rejected by schema: ${r.error}`);return r.value}function ci(e,t,n,r){if(e==="")return r?n.placeholder(r):n.cursor("│");return`${e.slice(0,t)}${n.cursor("│")}${e.slice(t)}`}function li(e,t,n){if(e.name==="backspace"){if(n===0)return{text:t,cursorPos:n};return{text:t.slice(0,n-1)+t.slice(n),cursorPos:n-1}}if(e.name==="delete"){if(n>=t.length)return{text:t,cursorPos:n};return{text:t.slice(0,n)+t.slice(n+1),cursorPos:n}}if(e.name==="left"){if(n===0)return{text:t,cursorPos:n};return{text:t,cursorPos:n-1}}if(e.name==="right"){if(n>=t.length)return{text:t,cursorPos:n};return{text:t,cursorPos:n+1}}if(e.name==="home")return{text:t,cursorPos:0};if(e.name==="end")return{text:t,cursorPos:t.length};if(e.char.length===1&&!e.ctrl&&!e.meta){let r=t.slice(0,n),o=t.slice(n);return{text:r+e.char+o,cursorPos:n+1}}return null}function ui(e,t,n){return async(r,o)=>{if(r.name==="return"){let i=await vn(o.value===""&&n!==void 0?n:o.value,e,t);return i.ok?Le(i.value):{...o,error:i.error}}let s=li(r,o.value,o.cursorPos);return s?{value:s.text,cursorPos:s.cursorPos,error:null}:o}}function fi(e,t,n,r,o){let s=t.prefix("┃"),i=t.message(n??"Enter a value"),a=r??o,c=o!==void 0&&r!==void 0&&e.value===""?` ${t.hint(`(${o})`)}`:"",l=wn(s,i,ci(e.value,e.cursorPos,t,a),c);if(e.error!==null)l+=`
|
|
18
18
|
${t.error(e.error)}`;return l}function di(e,t,n,r){return We(n.success("✓"),n.message(r??"Enter a value"),n.success(String(t)))}async function Sn(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 ne(e,t,(s,i)=>ai(n,s,i)):await ne(e,t);if(r.shortCircuited)return r.value;let{promptIO:o}=r;return ze({initialState:{value:"",cursorPos:0,error:null},theme:e.theme,render:(s,i)=>fi(s,i,e.message,e.placeholder,e.default),handleKey:ui(e.schema,e.validate,e.default),renderSubmitted:(s,i,a)=>di(s,i,a,e.message)},o)}function mi(e){return(t,n)=>{let r=n.choices.length;if(t.name==="return"){let o=n.choices[n.cursor];if(o)return Le(o.value);return n}if(["up","down","k","j"].includes(t.name)){let o=t.name==="up"||t.name==="k"?-1:1;return{...n,...ei(n.cursor,r,o,n.scrollOffset,e)}}return n}}function gi(e,t,n,r){let o=[`${t.prefix("┃")} ${t.message(n??"Pick an option")}`];return o.push(...Qs(e.choices,e.scrollOffset,r,(s,i)=>{let a=s.hint?` ${t.hint(s.hint)}`:"";return i===e.cursor?`${t.cursor("›")} ${t.selected(s.label)}${a}`:` ${t.unselected(s.label)}${a}`},t.hint)),o.join(`
|
|
19
|
-
`)}function pi(e,t,n,r){let o=n.success("✓"),s=n.message(r??"Pick an option"),i=e.choices[e.cursor],a=i?i.label:"";return We(o,s,n.success(a))}async function xn(e,t){let n=await ii(e,"single",t);if(n.shortCircuited)return n.value;let{choices:r,cursor:o,maxVisible:s,promptIO:i,scrollOffset:a}=n;return ze({initialState:{cursor:o,choices:r,scrollOffset:a},theme:e.theme,render:(c,l)=>gi(c,l,e.message,s),handleKey:mi(s),renderSubmitted:(c,l,u)=>pi(c,l,u,e.message)},i)}var On={name:"@crustjs/core",version:"0.4.
|
|
19
|
+
`)}function pi(e,t,n,r){let o=n.success("✓"),s=n.message(r??"Pick an option"),i=e.choices[e.cursor],a=i?i.label:"";return We(o,s,n.success(a))}async function xn(e,t){let n=await ii(e,"single",t);if(n.shortCircuited)return n.value;let{choices:r,cursor:o,maxVisible:s,promptIO:i,scrollOffset:a}=n;return ze({initialState:{cursor:o,choices:r,scrollOffset:a},theme:e.theme,render:(c,l)=>gi(c,l,e.message,s),handleKey:mi(s),renderSubmitted:(c,l,u)=>pi(c,l,u,e.message)},i)}var On={name:"@crustjs/core",version:"0.4.1",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 $n={name:"@crustjs/crust",version:"0.4.1",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"},exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"}},crust:{include:["schema","dist"]},bin:{crust:"src/cli.ts"},scripts:{build:"tsdown && 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:^"},peerDependencies:{"@crustjs/core":"^0.4.0"},devDependencies:{"@arethetypeswrong/core":"^0.18.5","@crustjs/config":"workspace:*","@crustjs/testing":"workspace:*","@crustjs/utils":"workspace:*",publint:"^0.3.24",tsdown:"catalog:"},engines:{bun:">=1.4.0"}};var Cn={name:"@crustjs/extensions",version:"0.4.1",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 Si={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:""}},xi={crustCoreVersion:On.version,crustExtensionsVersion:Cn.version,crustCliVersion:$n.version},Oi=/^[A-Za-z0-9_~][A-Za-z0-9._~-]*$/;function jn(e){if(e==="__proto__"||!Oi.test(e))throw Error(`Project name ${JSON.stringify(e)} is not safe for the generated project.
|
|
20
20
|
The directory basename becomes the package and command name: use letters, digits, ".", "_", "~", and "-", not starting with "." or "-"; "__proto__" is reserved.`)}var $i=/[<>:"|?*\\]/;function Ci(e){if(!e)throw Error("Project directory cannot be empty");if($i.test(e))throw Error(`Project directory contains invalid characters: ${e}`);jn(In(Ue(e)))}var Ei=new X("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 Sn({message:"Project directory",default:"my-cli",validate:Ci}),r=Ue(process.cwd(),n),o=In(r);jn(o);let s=t.runtime,i=n==="."?yi(r).length>0:En(r),a=!1;if(i){if(a=await oe({message:n==="."?"Current directory is not empty. Overwrite conflicting files?":`Directory "${o}" already exists. Overwrite?`,default:!1,...t.overwrite!==void 0?{initial:t.overwrite}:{}}),!a){console.log("Aborted.");return}}let c=await xn({message:"Runtime",choices:[{label:"Bun (recommended)",value:"bun",hint:"standalone binaries per platform, published as npm packages"},{label:"Node.js",value:"node",hint:"one JavaScript bundle, published as a single npm package"},{label:"Deno",value:"deno",hint:"standalone binaries per platform, published as npm packages"}],default:"bun",...s!==void 0?{initial:s}:{}}),l=await oe({message:"Install dependencies?",default:!0,...t.install!==void 0?{initial:t.install}:{}}),u=En(r)?r:Ue(r,".."),d=Bt(u)?!1:await oe({message:"Initialize a git repository?",default:!0,...t.git!==void 0?{initial:t.git}:{}}),b=o,g=(p)=>vi(ie("templates"),p),m={name:b,...Si[c],...xi};if(await De({message:"Scaffolding project...",task:async()=>{await Ee({template:g("base"),dest:r,context:m,...a?{conflict:"overwrite"}:{}}),await Ee({template:g(`runtime/${c}`),dest:r,context:m,conflict:"overwrite"})}}),l)await Ie([c==="deno"?{type:"command",cmd:"deno install"}:{type:"install"}],r);if(d)await De({message:"Initializing git repository...",task:()=>Ie([{type:"git-init",commit:"chore: initial commit"}],r)});if(console.log(`
|
|
21
21
|
Created ${b}!
|
|
22
22
|
`),console.log("Next steps:"),n!=="."){let p=n.startsWith("/")?n:`./${n}`;console.log(` cd ${p}`)}console.log(` ${m.run} dev`),console.log(` ${m.run} build`)});await Ei.execute();
|