create-crust 0.3.4 → 0.3.6
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((o)=>` - ${o.path}: ${o.message}`).join(`
|
|
|
16
16
|
`),h(),u(Ue)}else d=F,I()}catch(F){x(),h(),f(F)}})}try{if(k.emitKeypressEvents(a),a.setRawMode)a.setRawMode(!0),m=!0;a.resume(),c.write(Vo);let j=n(d,i);c.write(j),b=gn(j,c.columns||80),a.on("keypress",C)}catch(j){h(),f(j)}})}async function te(e,t,n){if(e.initial!==void 0)return{shortCircuited:!0,value:n?await n(e.initial,"initial"):e.initial};let r=ne(t);if(!pn(r.input)&&e.default!==void 0)return{shortCircuited:!0,value:n?await n(e.default,"default"):e.default};return{shortCircuited:!1,promptIO:r}}function ze(e,t,n){let r=[e];if(t)r.push(t);if(n)r.push(n);return r.join(" ")}function bn(e,t,n,r){let s=t?`${e} ${t}`:e,o=r??"";if(t)return`${s}${o}
|
|
17
17
|
${n}`;return`${s}${o} ${n}`}function Yo(e,t,n,r,s){let o=Math.min(e.length,n),i=[];if(t>0)i.push(s("..."));for(let a=t;a<t+o;a++){let c=e[a];if(c===void 0)break;i.push(r(c,a))}if(t+o<e.length)i.push(s("..."));return i}function wn(e,t,n,r){let s=Math.min(n,r);if(e<t)return e;if(e>=t+s)return e-s+1;return t}function Jo(e,t,n,r,s){let o=n===-1?e<=0?t-1:e-1:e>=t-1?0:e+1;return{cursor:o,scrollOffset:wn(o,r,t,s)}}function Xo(e){return e.map((t)=>{if(typeof t==="string")return{label:t,value:t};return t})}function Zo(e,t){if(e.name==="return")return Be(t.value);if(e.name==="left"||e.name==="right"||e.name==="tab")return{value:!t.value};if(e.name==="h"||e.char==="y"||e.char==="Y")return{value:!0};if(e.name==="l"||e.char==="n"||e.char==="N")return{value:!1};return t}var Qo=" · ";function ei(e,t,n,r,s){let o=t.prefix("┃"),i=t.message(n??"Are you sure?"),a=e.value?`${t.selected("●")} ${t.selected(r)}`:`${t.unselected("○")} ${t.unselected(r)}`,c=e.value?`${t.unselected("○")} ${t.unselected(s)}`:`${t.selected("●")} ${t.selected(s)}`;return bn(o,i,`${a}${Qo}${c}`)}function ti(e,t,n,r,s,o){let i=n.success("✓"),a=n.message(r??"Are you sure?"),c=t?s:o;return ze(i,a,n.success(c))}async function re(e,t){let n=await te(e,t);if(n.shortCircuited)return n.value;let{promptIO:r}=n,s=e.active??"Yes",o=e.inactive??"No";return Le({initialState:{value:e.default??!0},theme:e.theme,render:(i,a)=>ei(i,a,e.message,s,o),handleKey:Zo,renderSubmitted:(i,a,c)=>ti(i,a,c,e.message,s,o)},r)}async function ni(e,t,n){let r=await te(e,n);if(r.shortCircuited)return r;let s=Xo(e.choices),o=e.maxVisible??10,i=e.default===void 0?[]:t==="multiple"?e.default:[e.default],a=new Set(i.flatMap((u)=>{let f=s.findIndex((d)=>d.value===u);return f===-1?[]:[f]})),c=i.length===0?-1:s.findIndex((u)=>u.value===i[0]),l=c===-1?0:c;return{shortCircuited:!1,choices:s,maxVisible:o,cursor:l,scrollOffset:wn(l,0,s.length,o),selected:a,promptIO:r.promptIO}}async function yn(e,t,n){if(t){let r=await t["~standard"].validate(e),s=r.issues?.[0];if(s)return{ok:!1,error:s.message||"Validation failed"};if("value"in r)return{ok:!0,value:r.value};return{ok:!1,error:"Validation failed"}}if(n)try{await n(e)}catch(r){return{ok:!1,error:r instanceof Error?r.message:"Validation failed"}}return{ok:!0,value:e}}async function ri(e,t,n){let r=await yn(t,e,void 0);if(!r.ok)throw Error(`${n} value rejected by schema: ${r.error}`);return r.value}function si(e,t,n,r){if(e==="")return r?n.placeholder(r):n.cursor("│");return`${e.slice(0,t)}${n.cursor("│")}${e.slice(t)}`}function oi(e,t,n){if(e.name==="backspace"){if(n===0)return{text:t,cursorPos:n};return{text:t.slice(0,n-1)+t.slice(n),cursorPos:n-1}}if(e.name==="delete"){if(n>=t.length)return{text:t,cursorPos:n};return{text:t.slice(0,n)+t.slice(n+1),cursorPos:n}}if(e.name==="left"){if(n===0)return{text:t,cursorPos:n};return{text:t,cursorPos:n-1}}if(e.name==="right"){if(n>=t.length)return{text:t,cursorPos:n};return{text:t,cursorPos:n+1}}if(e.name==="home")return{text:t,cursorPos:0};if(e.name==="end")return{text:t,cursorPos:t.length};if(e.char.length===1&&!e.ctrl&&!e.meta){let r=t.slice(0,n),s=t.slice(n);return{text:r+e.char+s,cursorPos:n+1}}return null}function ii(e,t,n){return async(r,s)=>{if(r.name==="return"){let i=await yn(s.value===""&&n!==void 0?n:s.value,e,t);return i.ok?Be(i.value):{...s,error:i.error}}let o=oi(r,s.value,s.cursorPos);return o?{value:o.text,cursorPos:o.cursorPos,error:null}:s}}function ai(e,t,n,r,s){let o=t.prefix("┃"),i=t.message(n??"Enter a value"),a=r??s,c=s!==void 0&&r!==void 0&&e.value===""?` ${t.hint(`(${s})`)}`:"",l=bn(o,i,si(e.value,e.cursorPos,t,a),c);if(e.error!==null)l+=`
|
|
18
18
|
${t.error(e.error)}`;return l}function ci(e,t,n,r){return ze(n.success("✓"),n.message(r??"Enter a value"),n.success(String(t)))}async function vn(e={},t){if(e.schema!==void 0&&e.validate!==void 0)throw Error('input() cannot combine "schema" with "validate"');let n=e.schema,r=n?await te(e,t,(o,i)=>ri(n,o,i)):await te(e,t);if(r.shortCircuited)return r.value;let{promptIO:s}=r;return Le({initialState:{value:"",cursorPos:0,error:null},theme:e.theme,render:(o,i)=>ai(o,i,e.message,e.placeholder,e.default),handleKey:ii(e.schema,e.validate,e.default),renderSubmitted:(o,i,a)=>ci(o,i,a,e.message)},s)}function li(e){return(t,n)=>{let r=n.choices.length;if(t.name==="return"){let s=n.choices[n.cursor];if(s)return Be(s.value);return n}if(["up","down","k","j"].includes(t.name)){let s=t.name==="up"||t.name==="k"?-1:1;return{...n,...Jo(n.cursor,r,s,n.scrollOffset,e)}}return n}}function ui(e,t,n,r){let s=[`${t.prefix("┃")} ${t.message(n??"Pick an option")}`];return s.push(...Yo(e.choices,e.scrollOffset,r,(o,i)=>{let a=o.hint?` ${t.hint(o.hint)}`:"";return i===e.cursor?`${t.cursor("›")} ${t.selected(o.label)}${a}`:` ${t.unselected(o.label)}${a}`},t.hint)),s.join(`
|
|
19
|
-
`)}function fi(e,t,n,r){let s=n.success("✓"),o=n.message(r??"Pick an option"),i=e.choices[e.cursor],a=i?i.label:"";return ze(s,o,n.success(a))}async function Sn(e,t){let n=await ni(e,"single",t);if(n.shortCircuited)return n.value;let{choices:r,cursor:s,maxVisible:o,promptIO:i,scrollOffset:a}=n;return Le({initialState:{cursor:s,choices:r,scrollOffset:a},theme:e.theme,render:(c,l)=>ui(c,l,e.message,o),handleKey:li(o),renderSubmitted:(c,l,u)=>fi(c,l,u,e.message)},i)}var xn={name:"@crustjs/core",version:"0.3.
|
|
19
|
+
`)}function fi(e,t,n,r){let s=n.success("✓"),o=n.message(r??"Pick an option"),i=e.choices[e.cursor],a=i?i.label:"";return ze(s,o,n.success(a))}async function Sn(e,t){let n=await ni(e,"single",t);if(n.shortCircuited)return n.value;let{choices:r,cursor:s,maxVisible:o,promptIO:i,scrollOffset:a}=n;return Le({initialState:{cursor:s,choices:r,scrollOffset:a},theme:e.theme,render:(c,l)=>ui(c,l,e.message,o),handleKey:li(o),renderSubmitted:(c,l,u)=>fi(c,l,u,e.message)},i)}var xn={name:"@crustjs/core",version:"0.3.6",description:"Core library for the Crust CLI framework",type:"module",sideEffects:!1,license:"MIT",author:"chenxin-yan",repository:{type:"git",url:"git+https://github.com/chenxin-yan/crust.git",directory:"packages/core"},homepage:"https://crustjs.com",bugs:{url:"https://github.com/chenxin-yan/crust/issues"},keywords:["cli","command","framework","parser","bun","typescript"],files:["dist"],types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"},"./tooling":{types:"./dist/tooling.d.ts",import:"./dist/tooling.js"}},publishConfig:{access:"public"},scripts:{build:"tsdown",dev:"tsdown --watch","check:types":"tsc --noEmit",test:"bun test",prepack:"cp ../../LICENSE LICENSE",postpack:"rm -f LICENSE"},dependencies:{"@crustjs/utils":"workspace:^"},devDependencies:{"@crustjs/config":"workspace:*",tsdown:"catalog:"},peerDependencies:{typescript:"^7.0.0"},peerDependenciesMeta:{typescript:{optional:!0}},engines:{bun:">=1.4.0",node:">=22",deno:">=2.8"}};var On={name:"@crustjs/crust",version:"0.3.6",description:"CLI tooling for the Crust framework",type:"module",license:"MIT",author:"chenxin-yan",repository:{type:"git",url:"git+https://github.com/chenxin-yan/crust.git",directory:"packages/crust"},homepage:"https://crustjs.com",bugs:{url:"https://github.com/chenxin-yan/crust/issues"},keywords:["cli","build","compile","standalone","bun","typescript"],publishConfig:{access:"public"},crust:{include:["schema"]},bin:{crust:"src/cli.ts"},scripts:{build:"bun src/cli.ts build",release:"bun src/cli.ts publish",dev:"bun src/cli.ts",start:"bun .crust/root/bin/crust.js","check:types":"tsc --noEmit",test:"bun test"},dependencies:{"@crustjs/core":"workspace:^","@crustjs/extensions":"workspace:^","@crustjs/style":"workspace:^"},devDependencies:{"@crustjs/config":"workspace:*","@crustjs/testing":"workspace:*","@crustjs/utils":"workspace:*"},engines:{bun:">=1.4.0"}};var $n={name:"@crustjs/extensions",version:"0.3.6",description:"Official Extensions for the Crust CLI framework",type:"module",sideEffects:!1,license:"MIT",author:"chenxin-yan",repository:{type:"git",url:"git+https://github.com/chenxin-yan/crust.git",directory:"packages/extensions"},homepage:"https://crustjs.com",bugs:{url:"https://github.com/chenxin-yan/crust/issues"},keywords:["cli","extension","help","version","completion","did-you-mean","bun","typescript"],files:["dist"],exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"}},publishConfig:{access:"public"},scripts:{build:"tsdown",dev:"tsdown --watch","check:types":"tsc --noEmit",test:"bun test",prepack:"cp ../../LICENSE LICENSE",postpack:"rm -f LICENSE"},dependencies:{"@crustjs/store":"workspace:^","@crustjs/style":"workspace:^","@crustjs/utils":"workspace:^"},devDependencies:{"@crustjs/config":"workspace:*","@crustjs/core":"workspace:*",tsdown:"catalog:"},peerDependencies:{"@crustjs/core":"workspace:^",typescript:"^7.0.0"},peerDependenciesMeta:{typescript:{optional:!0}},engines:{bun:">=1.4.0",node:">=22",deno:">=2.8"}};var bi={bun:{run:"bun run",shebang:"#!/usr/bin/env bun",tsLib:'"ESNext"',tsTypes:'"bun"'},node:{run:"npm run",shebang:"#!/usr/bin/env node",tsLib:'"ESNext"',tsTypes:'"node"'},deno:{run:"deno task",shebang:"#!/usr/bin/env -S deno run -A",tsLib:'"ESNext", "deno.window"',tsTypes:""}},wi={crustCoreVersion:xn.version,crustExtensionsVersion:$n.version,crustCliVersion:On.version},yi=/^[A-Za-z0-9_~][A-Za-z0-9._~-]*$/;function In(e){if(e==="__proto__"||!yi.test(e))throw Error(`Project name ${JSON.stringify(e)} is not safe for the generated project.
|
|
20
20
|
The directory basename becomes the package and command name: use letters, digits, ".", "_", "~", and "-", not starting with "." or "-"; "__proto__" is reserved.`)}var vi=/[<>:"|?*\\]/;function Si(e){if(!e)throw Error("Project directory cannot be empty");if(vi.test(e))throw Error(`Project directory contains invalid characters: ${e}`);In(En(We(e)))}var xi=new J("create-crust",{description:"Scaffold a new Crust CLI project"}).flags({name:"runtime",type:"string",choices:["bun","node","deno"],description:'Runtime to develop and build for ("bun", "node", or "deno")'},{name:"install",type:"boolean",description:"Install dependencies after scaffolding"},{name:"git",type:"boolean",description:"Initialize a git repository after scaffolding"},{name:"overwrite",type:"boolean",description:"Overwrite the destination directory if it already exists"}).args({name:"directory",type:"string",description:"Project directory to scaffold into"}).action(async({args:e,flags:t})=>{let n=e.directory??await vn({message:"Project directory",default:"my-cli",validate:Si}),r=We(process.cwd(),n),s=En(r);In(s);let o=t.runtime,i=n==="."?hi(r).length>0:Cn(r),a=!1;if(i){if(a=await re({message:n==="."?"Current directory is not empty. Overwrite conflicting files?":`Directory "${s}" already exists. Overwrite?`,default:!1,...t.overwrite!==void 0?{initial:t.overwrite}:{}}),!a){console.log("Aborted.");return}}let c=await Sn({message:"Runtime",choices:[{label:"Bun (recommended)",value:"bun",hint:"standalone binaries per platform, published as npm packages"},{label:"Node.js",value:"node",hint:"one JavaScript bundle, published as a single npm package"},{label:"Deno",value:"deno",hint:"standalone binaries per platform, published as npm packages"}],default:"bun",...o!==void 0?{initial:o}:{}}),l=await re({message:"Install dependencies?",default:!0,...t.install!==void 0?{initial:t.install}:{}}),u=Cn(r)?r:We(r,".."),d=Mt(u)?!1:await re({message:"Initialize a git repository?",default:!0,...t.git!==void 0?{initial:t.git}:{}}),b=s,g=(h)=>pi(oe("templates"),h),m={name:b,...bi[c],...wi};if(await Fe({message:"Scaffolding project...",task:async()=>{await Ce({template:g("base"),dest:r,context:m,...a?{conflict:"overwrite"}:{}}),await Ce({template:g(`runtime/${c}`),dest:r,context:m,conflict:"overwrite"})}}),l)await Ee([c==="deno"?{type:"command",cmd:"deno install"}:{type:"install"}],r);if(d)await Fe({message:"Initializing git repository...",task:()=>Ee([{type:"git-init",commit:"chore: initial commit"}],r)});if(console.log(`
|
|
21
21
|
Created ${b}!
|
|
22
22
|
`),console.log("Next steps:"),n!=="."){let h=n.startsWith("/")?n:`./${n}`;console.log(` cd ${h}`)}console.log(` ${m.run} dev`),console.log(` ${m.run} build`)});await xi.execute();
|