@stacksjs/cli 0.74.37 → 0.74.38
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/dist/index.js +7 -7
- package/dist/prompts.d.ts +14 -0
- package/dist/terminal.d.ts +9 -13
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import
|
|
2
|
+
import Re from"process";async function Me(e,t={silent:!0}){let n=t.packageManager??"bun",r=[n==="npm"?"install":"add"];if(t.dev)r.push("-D");if(t.preferOffline&&n!=="bun")r.push("--prefer-offline");if(t.additionalArgs)r.push(...t.additionalArgs);r.push(e);let s=await Bun.spawn([n,...r],{cwd:t.cwd??Re.cwd(),stdout:t.silent?"ignore":"inherit",stderr:t.silent?"ignore":"inherit",stdin:"ignore",env:Re.env}).exited;if(s!==0)throw Error(`Failed to install ${e} (exit code ${s})`)}async function Nt(e,t){return Me(e,t??{silent:!0})}async function Dt(e,t){return Me(`@stacksjs/${e}`,t??{silent:!0})}import{CLI as qt,cli as et,onUnknownSubcommand as Kt}from"@stacksjs/clapp";function Ht(e,t){if(typeof e==="object")t=e,e=t.name;return et(e||"buddy")}import{existsSync as U,readdirSync as tt}from"fs";import{join as Ie}from"path";var nt=/(?:\.test|\.spec|\.bench|\.d)\.ts$/;function rt(e){return e.endsWith(".ts")&&!nt.test(e)&&!e.startsWith("_")}function ot(e){if(!U(e))return[];let t=[],n=(r,o)=>{for(let s of tt(r,{withFileTypes:!0})){if(s.name.startsWith(".")||s.name==="node_modules")continue;if(s.isDirectory()){n(Ie(r,s.name),`${o}${s.name}/`);continue}if(rt(s.name))t.push(`${o}${s.name.slice(0,-3)}`)}};return n(e,""),t.sort()}async function Te(e){if(!e||!U(e))return{};try{let n=(await import(e)).default;if(!n||typeof n!=="object")return{error:Error(`${e} must default-export a command registry object.`)};return{registry:n}}catch(t){return{error:t}}}async function st(e){let{commandsDir:t}=e,n=e.registry??(await Te(e.registryPath)).registry,r=ot(t),o=new Map;for(let l of r)o.set(l,{file:l,path:Ie(t,`${l}.ts`),aliases:[],enabled:!0,source:"auto"});let s=[];for(let[l,a]of Object.entries(n??{})){let i=typeof a==="string"?{file:a}:a,d=o.get(i.file);if(!d)continue;if(d.signature=l,d.aliases=i.aliases??[],d.enabled=i.enabled!==!1,d.source="registry",!s.includes(d))s.push(d)}for(let l of r){let a=o.get(l);if(a&&!s.includes(a))s.push(a)}return s}function it(e,t,n){let r=t.trim().split(/\s+/)[0],s=e?.commands?.find((l)=>l.name===r);if(!s||typeof s.alias!=="function")return!1;for(let l of n)s.alias(l);return!0}async function Qt(e,t){let n=t.onError??(()=>{}),r=t.onDebug??(()=>{});if(!U(t.commandsDir))return r(`No ${t.commandsDir} directory, skipping application commands.`),[];let o=t.registry?{registry:t.registry}:await Te(t.registryPath);if(o.error)n(`Could not read the command registry at ${t.registryPath}`,o.error);let s=await st({...t,registry:o.registry}),l=[];for(let a of s){if(!a.enabled){r(`Skipping disabled command ${a.file}.`);continue}try{let i=await import(a.path);if(i.enabled===!1){r(`Skipping ${a.file}: the module exports \`enabled = false\`.`);continue}if(typeof i.default!=="function"){n(`Expected a default export function in ${a.file}.ts, but got: ${typeof i.default}`);continue}let d=e.commands?.length??0;i.default(e);let m=[...a.aliases,...i.aliases??[]];if(m.length)at(e,a.signature,d,m,r);l.push(a)}catch(i){n(`Failed to load command ${a.file}`,i)}}return l}function at(e,t,n,r,o){if(t&&it(e,t,r))return;let a=(e.commands?.slice(n)??[])[0];if(!a||typeof a.alias!=="function"){o(`Could not alias '${t??"command"}': no matching command was registered.`);return}for(let i of r)a.alias(i)}function Xt(e){if(typeof e==="function")return e;return(t)=>lt(t,e)}function lt(e,t){let n=e.command(t.name,t.description??"",{allowUnknownOptions:t.allowUnknownOptions});if(t.usage)n.usage(t.usage);for(let[r,o]of Object.entries(t.options??{})){let s=typeof o==="string"?{description:o}:o;n.option(r,s.description??"",{...s.default===void 0?{}:{default:s.default},...s.type?{type:s.type}:{}})}for(let r of t.aliases??[])n.alias(r);for(let r of t.examples??[])n.example(r);return n.action((...r)=>{let o=r[r.length-1];return t.handle(o,...r.slice(0,-1))}),n}function Zt(e){return e}import A from"process";import{err as G,handleError as V,ok as ct}from"@stacksjs/error-handling";import{ExitCode as P}from"@stacksjs/types";async function J(e,t){let n=Array.isArray(e)?e:e.match(/(?:[^\s"]|"[^"]*")+/g);if(!n)return G(V(`Failed to parse command: ${n}`,t));let r=t?.cwd??A.cwd(),o=t?.timeoutMs,s=Bun.spawn(n,{stdin:t?.stdin??"inherit",stdout:t?.silent||t?.quiet?"ignore":t?.stdin?t.stdin:t?.stdout||"inherit",stderr:t?.silent||t?.quiet?"ignore":t?.stderr||"inherit",cwd:r,env:{...A.env,...t?.env},onExit(d,m,y,v){Ee("spawn",d,m,y,v)}});if(t?.stdin==="pipe"&&t.input){if(s.stdin)s.stdin.write(t.input),s.stdin.end()}let l,a=await Promise.race([s.exited,new Promise((d)=>{if(!o)return;l=setTimeout(()=>{try{s.kill()}catch{}d(P.FatalError)},o)})]);if(l)clearTimeout(l);if(o&&a===P.FatalError&&s.exitCode===null)return G(V(`Command timed out after ${o}ms: ${h(n.join(" "))} in ${h(r)}`,t));if(a===P.Success)return ct(s);let i=s.signalCode;if(i==="SIGTERM"||i==="SIGINT"||i==="SIGKILL"||s.exitCode===null&&a!==P.Success)return G(Error(`Command terminated by ${i??"signal"}: ${n.join(" ")}`));return G(V(`Failed to execute command: ${h(n.join(" "))} in ${h(r)}`,t))}async function je(e,t){let n=Array.isArray(e)?e:e.match(/(?:[^\s"]|"[^"]*")+/g);if(!n)throw p.error(`Failed to parse command: ${n}`,t),Error(`Failed to parse command: ${n}`);let r=Bun.spawnSync(n,{...t,stdin:t?.stdin??"inherit",stdout:t?.stdout??"pipe",stderr:t?.stderr??"inherit",cwd:t?.cwd??A.cwd(),env:{...A.env,...t?.env},onExit(s,l,a,i){Ee("spawnSync",s,l,a,i)}}),o=r.stdout?.toString()??"";if(t?.throwOnError&&r.exitCode!==0){let l=((r.stderr?.toString()??"").trim()||o.trim()||"(no output)").split(`
|
|
3
3
|
`).slice(0,5).join(`
|
|
4
4
|
`);throw Error(`Command failed with exit code ${r.exitCode}: ${n.join(" ")}
|
|
5
|
-
${l}`)}return o}function
|
|
6
|
-
`)}function
|
|
7
|
-
`)}var
|
|
8
|
-
`),
|
|
9
|
-
`)}function
|
|
10
|
-
`)},get value(){return o},get total(){return e.total}};return a}async function
|
|
5
|
+
${l}`)}return o}function Ee(e,t,n,r,o){if(p.debug(`exitHandler: ${e}, exitCode: ${n}, signalCode: ${r}`),o)p.debug("Process error:",o.message)}import{handleError as Ct}from"@stacksjs/error-handling";import{log as p}from"@stacksjs/logging";import{ExitCode as Se}from"@stacksjs/types";import{collect as gt}from"@stacksjs/collections";var g=!process.env.NO_COLOR&&(process.env.FORCE_COLOR?process.env.FORCE_COLOR!=="0":!!process.stdout?.isTTY),u={reset:g?"\x1B[0m":"",black:g?"\x1B[30m":"",red:g?"\x1B[31m":"",green:g?"\x1B[32m":"",yellow:g?"\x1B[33m":"",blue:g?"\x1B[34m":"",magenta:g?"\x1B[35m":"",cyan:g?"\x1B[36m":"",white:g?"\x1B[37m":"",gray:g?"\x1B[90m":"",lightRed:g?"\x1B[91m":"",lightGreen:g?"\x1B[92m":"",lightYellow:g?"\x1B[93m":"",lightBlue:g?"\x1B[94m":"",lightMagenta:g?"\x1B[95m":"",lightCyan:g?"\x1B[96m":"",lightGray:g?"\x1B[37m":"",bgBlack:g?"\x1B[40m":"",bgRed:g?"\x1B[41m":"",bgGreen:g?"\x1B[42m":"",bgYellow:g?"\x1B[43m":"",bgBlue:g?"\x1B[44m":"",bgMagenta:g?"\x1B[45m":"",bgCyan:g?"\x1B[46m":"",bgWhite:g?"\x1B[47m":"",bgGray:g?"\x1B[100m":"",bgLightRed:g?"\x1B[101m":"",bgLightGreen:g?"\x1B[102m":"",bgLightYellow:g?"\x1B[103m":"",bgLightBlue:g?"\x1B[104m":"",bgLightMagenta:g?"\x1B[105m":"",bgLightCyan:g?"\x1B[106m":"",bgLightGray:g?"\x1B[47m":"",bold:g?"\x1B[1m":"",dim:g?"\x1B[2m":"",italic:g?"\x1B[3m":"",underline:g?"\x1B[4m":"",inverse:g?"\x1B[7m":"",hidden:g?"\x1B[8m":"",strikethrough:g?"\x1B[9m":""},N="\x1B[",ut="\x1B]8;;",dt="\x1B]8;;\x07",Ge=(e)=>String(e);function C(e,t,n){return Math.min(Math.max(Math.floor(e),t),n)}function c(e,t=u.reset){return(n)=>{if(!g)return String(n);return`${e}${String(n)}${t}`}}function mt(e){return e.replace(/\x1B\]8;;[^\x07]*(?:\x07|\x1B\\)/g,"").replace(/\x1B\]8;;(?:\x07|\x1B\\)/g,"")}function k(e){return mt(e).replace(/\x1B\[[0-?]*[ -/]*[@-~]/g,"")}var Pe=k;function Ae(e){return Array.from(k(e)).length}var Q=c(u.black),X=c(u.red),O=c(u.green),Z=c(u.yellow),ee=c(u.blue),te=c(u.magenta),S=c(u.cyan),ne=c(u.white),x=c(u.gray),re=c(u.lightRed),oe=c(u.lightGreen),se=c(u.lightYellow),ie=c(u.lightBlue),ae=c(u.lightMagenta),le=c(u.lightCyan),Y=c(u.lightGray),ce=c(u.bgBlack),ge=c(u.bgRed),ue=c(u.bgGreen),de=c(u.bgYellow),me=c(u.bgBlue),pe=c(u.bgMagenta),M=c(u.bgCyan),fe=c(u.bgWhite),he=c(u.bgGray),be=c(u.bgLightRed),ye=c(u.bgLightGreen),Ce=c(u.bgLightYellow),xe=c(u.bgLightBlue),we=c(u.bgLightMagenta),ke=c(u.bgLightCyan),W=c(u.bgLightGray),b=c(u.bold),w=c(u.dim),h=c(u.italic),$e=c(u.underline),Fe=c(u.inverse),ve=c(u.hidden),Be=c(u.strikethrough),Oe=c(u.reset,"");function Ye(e){return c(`${N}38;5;${C(e,0,255)}m`)}function We(e){return c(`${N}48;5;${C(e,0,255)}m`)}function Ne(e,t,n){return c(`${N}38;2;${C(e,0,255)};${C(t,0,255)};${C(n,0,255)}m`)}function De(e,t,n){return c(`${N}48;2;${C(e,0,255)};${C(t,0,255)};${C(n,0,255)}m`)}function ze(e,t){let n=(o,s)=>{let l=String(o);if(!g)return l;return`${ut}${s}\x07${l}${dt}`};if(typeof t==="string")return n(e,t);let r=String(e);return(o)=>n(o,r)}var pt={black:Q,red:X,green:O,yellow:Z,blue:ee,magenta:te,cyan:S,white:ne,gray:x,lightRed:re,lightGreen:oe,lightYellow:se,lightBlue:ie,lightMagenta:ae,lightCyan:le,lightGray:Y,bgBlack:ce,bgRed:ge,bgGreen:ue,bgYellow:de,bgBlue:me,bgMagenta:pe,bgCyan:M,bgWhite:fe,bgGray:he,bgLightRed:be,bgLightGreen:ye,bgLightYellow:Ce,bgLightBlue:xe,bgLightMagenta:we,bgLightCyan:ke,bgLightGray:W,bold:b,dim:w,italic:h,underline:$e,inverse:Fe,hidden:ve,strikethrough:Be,reset:Oe};function _e(e){return pt[e]??Ge}function ln(e,t){if(typeof t==="function")return t(e);return _e(t)(e)}function ft(){return g}var cn={black:Q,red:X,green:O,yellow:Z,blue:ee,magenta:te,cyan:S,white:ne,gray:x,lightRed:re,lightGreen:oe,lightYellow:se,lightBlue:ie,lightMagenta:ae,lightCyan:le,lightGray:Y,bgBlack:ce,bgRed:ge,bgGreen:ue,bgYellow:de,bgBlue:me,bgMagenta:pe,bgCyan:M,bgWhite:fe,bgGray:he,bgLightRed:be,bgLightGreen:ye,bgLightYellow:Ce,bgLightBlue:xe,bgLightMagenta:we,bgLightCyan:ke,bgLightGray:W,bold:b,dim:w,italic:h,underline:$e,inverse:Fe,hidden:ve,strikethrough:Be,reset:Oe,ansi256:Ye,ansi256Bg:We,trueColor:Ne,trueColorBg:De,link:ze,stripColors:Pe},gn={black:Q,red:X,green:O,yellow:Z,blue:ee,magenta:te,cyan:S,white:ne,gray:x,lightRed:re,lightGreen:oe,lightYellow:se,lightBlue:ie,lightMagenta:ae,lightCyan:le,lightGray:Y,bgBlack:ce,bgRed:ge,bgGreen:ue,bgYellow:de,bgBlue:me,bgMagenta:pe,bgCyan:M,bgWhite:fe,bgGray:he,bgLightRed:be,bgLightGreen:ye,bgLightYellow:Ce,bgLightBlue:xe,bgLightMagenta:we,bgLightCyan:ke,bgLightGray:W,bold:b,dim:w,italic:h,underline:$e,inverse:Fe,hidden:ve,strikethrough:Be,reset:Oe,ansi256:Ye,ansi256Bg:We,trueColor:Ne,trueColorBg:De,link:ze,stripColors:Pe,grey:x,lightGrey:Y,bgLightGrey:W,supportsColor:ft};function ht(e,t,n,r){let o=Ae(e);if(o>=t)return e;let s=r[0]||" ",l=t-o;if(n==="right")return`${s.repeat(l)}${e}`;if(n==="center"){let a=Math.floor(l/2),i=l-a;return`${s.repeat(a)}${e}${s.repeat(i)}`}return`${e}${s.repeat(l)}`}function D(e){return Math.max(0,...e.map(Ae))}function z(e,t,n="left"){let r=String(e).split(/\r?\n/),o=typeof t==="object"?t:void 0,s=typeof t==="number"?t:o?.width??D(r),l=o?.align??n,a=o?.padChar??" ";return r.map((i)=>ht(i,Math.max(0,s),l,a)).join(`
|
|
6
|
+
`)}function un(e,t){return z(e,t,"left")}function dn(e,t){let n=String(e).split(/\r?\n/);return z(e,t??process.stdout?.columns??D(n),"right")}function mn(e,t){let n=String(e).split(/\r?\n/);return z(e,t??process.stdout?.columns??D(n),"center")}var bt={single:{topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502"},double:{topLeft:"\u2554",topRight:"\u2557",bottomLeft:"\u255A",bottomRight:"\u255D",horizontal:"\u2550",vertical:"\u2551"},round:{topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502"}};function qe(e,t={}){let n=String(e).split(/\r?\n/),r=bt[t.borderStyle??"single"],o=Math.max(0,t.padding??1),s=Math.max(0,t.margin??0),l=t.align??"left",a=D(n),i=a+o*2,d=typeof t.borderColor==="function"?t.borderColor:t.borderColor?_e(t.borderColor):Ge,y=d((()=>{if(!t.title)return`${r.topLeft}${r.horizontal.repeat(i)}${r.topRight}`;let E=` ${k(String(t.title))} `.slice(0,i),H=r.horizontal.repeat(Math.max(0,i-E.length));return`${r.topLeft}${E}${H}${r.topRight}`})()),v=d(`${r.bottomLeft}${r.horizontal.repeat(i)}${r.bottomRight}`),j=n.map((B)=>{let E=z(B,{align:l,width:a}),H=`${" ".repeat(o)}${E}${" ".repeat(o)}`;return`${d(r.vertical)}${H}${d(r.vertical)}`}),K=" ".repeat(s);return[y,...j,v].map((B)=>`${K}${B}`).join(`
|
|
7
|
+
`)}var pn=gt(["The best way to get started is to quit talking and begin doing.","The pessimist sees difficulty in every opportunity. The optimist sees opportunity in every difficulty.","Don\u2019t let yesterday take up too much of today.","You learn more from failure than from success. Don\u2019t let it stop you. Failure builds character.","It\u2019s not whether you get knocked down, it\u2019s whether you get up.","If you are working on something that you really care about, you don\u2019t have to be pushed. The vision pulls you.","People who are crazy enough to think they can change the world, are the ones who do.","Failure will never overtake me if my determination to succeed is strong enough.","Entrepreneurs are great at dealing with uncertainty and also very good at minimizing risk. That\u2019s the classic entrepreneur.","We may encounter many defeats but we must not be defeated.","Knowing is not enough; we must apply. Wishing is not enough; we must do.","Imagine your life is perfect in every respect; what would it look like?","We generate fears while we sit. We overcome them by action.","Whether you think you can or think you can\u2019t, you\u2019re right.","Security is mostly a superstition. Life is either a daring adventure or nothing."]);var Ke="0.74.38";async function kn(e,t){return new Promise((n)=>{if(t?.quiet===!1)console.log(),console.log(S(b("Stacks CLI"))+w(` v${Ke}`)),console.log();if(p.info(`Running ${M(h(b(` ${e} `)))}`),t?.showPerformance===!1||t?.quiet)return n(0);return n(performance.now())})}function $n(e,t,n){let r={type:"success",useSeconds:!0,...t};return r.message=t?.message||e,new Promise((o)=>{if(n)return Ct(n),o(Se.FatalError);if(r?.startTime){let s=performance.now()-r.startTime;if(r.useSeconds)s=s/1000,s=Math.round(s*100)/100;if(r.quiet===!0)return o(Se.Success);if(n)p.error(`[${s.toFixed(2)}${r.useSeconds?"s":"ms"}] Failed`);else if(r.type==="error")p.error(`[${s.toFixed(2)}${r.useSeconds?"s":"ms"}] ${r.message??"Failed"}`);else if(r.type==="warning")p.warn(`[${s.toFixed(2)}${r.useSeconds?"s":"ms"}] ${r.message??"Complete"}`);else if(r.type==="info")p.info(`${w(x(`[${s.toFixed(2)}${r.useSeconds?"s":"ms"}]`))} ${r.message??"Complete"}`);else p.success(`${w(x(b(`[${s.toFixed(2)}${r.useSeconds?"s":"ms"}]`)))} ${b(O(r.message??"Complete"))}`)}else if(r?.type==="info")p.info(e);else if(r?.type==="error")p.error(e);else if(r?.type==="warning")p.warn(e);else if(r?.type==="success"&&r?.quiet!==!0)p.success(e);p.flush().catch(()=>{}).then(()=>o(Se.Success))})}import _ from"process";function He(e){if(!e)return!1;return e.startsWith("--")}function xt(e){return e.startsWith("-")&&!He(e)}function Le(e){if(e==="true")return!0;if(e==="false")return!1;let t=Number.parseFloat(e);if(!Number.isNaN(t))return t;return e.replace(/"/g,"")}function wt(e,t,n,r){let[o,s]=e.slice(2).split("=");if(s!==void 0)r[o]=Le(s);else if(n+1<t.length&&!t[n+1]?.startsWith("-"))r[o]=t[n+1],n++;else r[o]=!0;return n}function kt(e,t,n,r){let[o,s]=e.slice(1).split("=");if(o===void 0)return n;if(s!==void 0&&o!==void 0)for(let l=0;l<o.length;l++)r[o[l]]=Le(s);else for(let l=0;l<o.length;l++)if(n+1<t.length&&l===o.length-1&&!t[n+1]?.startsWith("-"))r[o[l]]=Le(t[n+1]),n++;else r[o[l]]=!0;return n}function $t(e){if(e===void 0)e=_.argv.slice(2);let t=[],n={};for(let r=0;r<e.length;r++){let o=e[r];if(!o)continue;if(He(o))r=wt(o,e,r,n);else if(xt(o))r=kt(o,e,r,n);else t.push(o)}return{args:t,options:n}}function On(e){if(e===void 0)e=_.argv.slice(2);return $t(e).args}function Sn(e){e=e||{};let t={dryRun:!1,quiet:!1,verbose:!1},n=_.argv.slice(2);for(let r=0;r<n.length;r++){let o=n[r];if(o?.startsWith("--")){let l=o.substring(2).replace(/-([a-z])/gi,(a)=>a[1]?a[1].toUpperCase():"");if(r+1<n.length&&!n?.[r+1]?.startsWith("--"))if(n?.[r+1]==="true"||n?.[r+1]==="false")e[l]=n[r+1]==="true",r++;else e[l]=n[r+1],r++;else e[l]=!0}}if(Object.keys(e).length===0)return{};return{...t,...e}}function Ft(e){if(Array.isArray(e)){if(e=Array.from(new Set(e)),Array.isArray(e)&&e[0]&&!e[0].startsWith("-"))e.shift();return e.join(" ")}if(typeof e==="object"&&e!==null)return Object.entries(e).filter(([t,n])=>t!=="--"&&t!=="_"&&n!==!1&&n!==void 0&&n!==null).map(([t,n])=>{if(n===!0)return`--${t}`;return`--${t} ${n}`}).join(" ");return Ft(_.argv.slice(2))}import f from"process";import{createInterface as vt}from"readline";var In=f.stdin.destroy;f.stdin.destroy=function(e){if(e)this.emit("error",e);return this};f.on("SIGINT",()=>{console.log(`
|
|
8
|
+
`),f.exit(130)});var L=null;function Bt(){if(!L){let e=f.stdin.isTTY&&f.stdout.isTTY;if(L=vt({input:f.stdin,output:f.stdout,terminal:e}),e&&typeof f.stdin.setRawMode==="function")L.on("SIGINT",()=>{f.emit("SIGINT")});L.once("close",()=>{L=null})}return L}var q=Symbol("stdin-eof");function Ue(e){return new Promise((t)=>{let n=Bt(),r=!1,o=(l)=>{if(r)return;r=!0,n.off("close",s),t(l)},s=()=>o(q);n.once("close",s);try{n.question(e,o)}catch{o(q)}})}function Ve(){if(f.argv.includes("--no-interaction"))return!1;if(f.env.CI)return!1;return Boolean(f.stdin.isTTY&&f.stdout.isTTY)}async function I(e){if(!Ve())return"";let t=await Ue(e);return t===q?"":t}function Je(e,t){let n=e.toLowerCase().trim();if(!n)return t;if(n==="y"||n==="yes")return!0;if(n==="n"||n==="no")return!1;return t}async function Tn(e){let t=typeof e==="string"?{message:e}:e,n=t.initial??!1,r=n?" (Y/n) ":" (y/N) ";if(!Ve())return null;let o=await Ue(`${t.message}${r}`);if(o===q)return null;return Je(o,n)}async function Ot(e){let t=typeof e==="string"?{message:e}:e,n=t.initial??!1,r=n?" (Y/n) ":" (y/N) ",o=await I(`${t.message}${r}`);return Je(o,n)}async function St(e){let t=typeof e==="string"?{message:e}:e,n=t.placeholder||t.initial||"",r=n?` (${n}) `:" ";return(await I(`${t.message}${r}`)).trim()||t.initial||""}async function Lt(e){console.log(e.message),e.choices.forEach((o,s)=>{let l=s===(e.initial??0)?">":" ";console.log(`${l} ${s+1}. ${o.label}`)});let t=await I("Select (number): "),n=Number.parseInt(t.trim(),10)-1,r=e.choices[n]??e.choices[e.initial??0];if(!r)throw Error("select prompt: no choices available");return r.value}async function Rt(e){console.log(e.message),console.log("(Enter numbers separated by commas)"),e.choices.forEach((o,s)=>{console.log(` ${s+1}. ${o.label}`)});let n=(await I("Select (e.g., 1,3,4): ")).split(",").map((o)=>Number.parseInt(o.trim(),10)-1),r=[];for(let o of n){let s=e.choices[o];if(s)r.push(s.value)}return r}async function Mt(e){return(await I(`${(typeof e==="string"?{message:e}:e).message} `)).trim()}var jn={text:St,confirm:Ot,select:Lt,multiselect:Rt,password:Mt};import{handleError as It}from"@stacksjs/error-handling";async function Tt(e,t){let n={...t,stdin:t?.stdin??"inherit",verbose:t?.verbose??!1};return await J(e,n)}async function An(e,t){let n={...t,stdio:[t?.stdin??"inherit","pipe","pipe"],verbose:t?.verbose??!1};return await J(e,n)}async function Yn(e,t){let n={...t,stdio:[t?.stdin??"inherit","pipe","pipe"],verbose:t?.verbose??!1};return await je(e,n)}async function Wn(e,t){let n=[];for(let r of e){let o=await Tt(r,t);if(o.isErr)throw It("Error during runCommands",o.error),o.error;n.push(o)}return n}import jt from"process";var Et=["SIGINT","SIGTERM","SIGHUP"],R=new Map,Qe=!1;function Gt(){if(Qe)return;Qe=!0;for(let e of Et)jt.on(e,async()=>{for(let[t,n]of R)try{await n()}catch(r){console.error(`[signals] cleanup '${t}' threw:`,r)}})}function zn(e,t){return Gt(),R.set(e,t),()=>{if(R.get(e)===t)R.delete(e)}}function _n(e){R.delete(e)}function qn(){return[...R.keys()]}var Xe=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],T=process.stdout.isTTY&&!process.env.CI;function Pt(e){let t=e||"",n=0,r=null,o=!1,s=()=>{if(T)process.stdout.write("\r\x1B[K")},l=()=>{if(!T)return;s();let a=Xe[n];process.stdout.write(`${a} ${t}`),n=(n+1)%Xe.length};return{start(a){if(a)t=a;if(o)return;if(o=!0,T)l(),r=setInterval(l,80);else if(t)console.log(` ${t}`)},stop(a){if(o=!1,r)clearInterval(r),r=null;if(s(),a)console.log(a)},update(a){if(t=a,!T&&o)console.log(` ${a}`)},succeed(a){let i=a||t;if(o=!1,r)clearInterval(r),r=null;s(),console.log(`\u2713 ${i}`)},fail(a){let i=a||t;if(o=!1,r)clearInterval(r),r=null;s(),console.error(`\u2717 ${i}`)},get text(){return t},set text(a){if(t=a,T&&o)l()},get isSpinning(){return o}}}async function Hn(e,t,n){let r=Pt(e);r.start();try{let o=await t();return r.succeed(n?.successMessage||e),o}catch(o){throw r.fail(n?.failMessage||`Failed: ${e}`),o}}import F from"process";var Ze="\r\x1B[2K";function At(){return{columns:F.stdout.columns??80,rows:F.stdout.rows??24}}function Yt(){return Boolean(F.stdout.isTTY)&&!F.env.CI}function Qn(e,t){console.log(qe(e,t===void 0?{}:{title:t}))}function Xn(e,t={}){let r=(t.columns??[...new Set(e.flatMap((i)=>Object.keys(i)))]).map((i)=>typeof i==="string"?{key:i}:i);if(r.length===0)return"";let o=(i,d)=>{let m=i[d.key];return m===void 0||m===null?"":String(m)},s=r.map((i)=>{let d=t.header===!1?"":i.header??i.key;return Math.max(k(d).length,...e.map((m)=>k(o(m,i)).length))}),l=(i,d,m)=>{let y=Math.max(0,d-k(i).length);return m==="right"?" ".repeat(y)+i:i+" ".repeat(y)},a=[];if(t.header!==!1)a.push(r.map((i,d)=>l(i.header??i.key,s[d],i.align)).join(" ").trimEnd()),a.push(r.map((i,d)=>"-".repeat(s[d])).join(" "));for(let i of e)a.push(r.map((d,m)=>l(o(i,d),s[m],d.align)).join(" ").trimEnd());return a.join(`
|
|
9
|
+
`)}function Zn(e){if(!Number.isFinite(e.total)||e.total<=0)throw TypeError(`progress() needs a positive total; got ${e.total}`);let t=e.format??"|{bar}| {percentage}% | {value}/{total}",n=e.width??Math.max(10,Math.floor(At().columns/3)),r=Yt(),o=0,s=-1,l=(i)=>{let d=Math.min(1,o/e.total),m=Math.round(d*n),y={bar:"\u2588".repeat(m)+"\u2591".repeat(n-m),percentage:Math.round(d*100),value:o,total:e.total,...i},v=t.replace(/\{(\w+)\}/g,(K,B)=>String(y[B]??K));if(r){F.stdout.write(`${Ze}${v}`);return}let j=Math.floor(d*10);if(j>s)s=j,console.log(v)},a={update(i,d={}){o=Math.max(0,Math.min(e.total,i)),l(d)},increment(i=1){a.update(o+i)},stop(i){if(r)F.stdout.write(Ze);if(i)console.log(i);else if(r)F.stdout.write(`
|
|
10
|
+
`)},get value(){return o},get total(){return e.total}};return a}async function er(e){let t=[];for(let n of e){let r=Date.now(),o=n.skip?.();if(o){console.log(`- ${n.title}${typeof o==="string"?` (${o})`:""}`),t.push({title:n.title,status:"skipped",durationMs:0});continue}try{await n.task(),console.log(`\u2713 ${n.title}`),t.push({title:n.title,status:"done",durationMs:Date.now()-r})}catch(s){throw console.log(`\u2717 ${n.title}`),t.push({title:n.title,status:"failed",error:s instanceof Error?s:Error(String(s)),durationMs:Date.now()-r}),s}}return t}export{qt as CLI,z as align,Ye as ansi256,We as ansi256Bg,it as applyAliases,ce as bgBlack,me as bgBlue,M as bgCyan,he as bgGray,ue as bgGreen,xe as bgLightBlue,ke as bgLightCyan,W as bgLightGray,ye as bgLightGreen,we as bgLightMagenta,be as bgLightRed,Ce as bgLightYellow,pe as bgMagenta,ge as bgRed,fe as bgWhite,de as bgYellow,Q as black,ee as blue,b as bold,qe as box,Ft as buddyOptions,mn as centerAlign,Ht as cli,ln as colorize,cn as colors,Ot as confirm,Tn as confirmOrNull,S as cyan,Xt as defineCommand,Zt as defineCommands,w as dim,ot as discoverCommandFiles,J as exec,je as execSync,_e as getColor,At as getTerminalSize,x as gray,O as green,ve as hidden,Nt as installPackage,Dt as installStack,kn as intro,Fe as inverse,Yt as isInteractive,h as italic,gn as kolorist,un as leftAlign,ie as lightBlue,le as lightCyan,Y as lightGray,oe as lightGreen,ae as lightMagenta,re as lightRed,se as lightYellow,ze as link,qn as listSignalHandlers,Te as loadCommandRegistry,Qt as loadCommands,p as log,te as magenta,Rt as multiselect,Qn as note,_n as offSignal,zn as onSignal,Kt as onUnknownSubcommand,$n as outro,On as parseArgs,$t as parseArgv,Sn as parseOptions,Mt as password,Zn as progress,jn as prompts,Ve as promptsAreInteractive,pn as quotes,X as red,Oe as reset,st as resolveCommands,dn as rightAlign,Tt as runCommand,Yn as runCommandSync,Wn as runCommands,An as runProcess,Lt as select,Pt as spinner,Be as strikethrough,k as stripAnsi,Pe as stripColors,Xn as table,er as tasks,St as text,Ne as trueColor,De as trueColorBg,$e as underline,ne as white,Hn as withSpinner,Z as yellow};
|
package/dist/prompts.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether asking a question is possible and permitted right now.
|
|
3
|
+
*
|
|
4
|
+
* `--no-interaction` is registered as a process-wide buddy option and printed
|
|
5
|
+
* in every command's help, and nothing read it (stacksjs/stacks#853). Closed
|
|
6
|
+
* stdin already resolves a prompt to its default rather than hanging, so this
|
|
7
|
+
* was not the CI hang it looks like - but a flag that promises not to prompt
|
|
8
|
+
* and then prompts is still a promise broken, and a runner whose stdin is an
|
|
9
|
+
* open pipe with no data has nothing else to save it.
|
|
10
|
+
*
|
|
11
|
+
* Read from argv rather than from parsed options: prompts are reached from
|
|
12
|
+
* library code that never sees the command's option bag.
|
|
13
|
+
*/
|
|
14
|
+
export declare function promptsAreInteractive(): boolean;
|
|
1
15
|
/**
|
|
2
16
|
* Confirm that reports `null` when stdin ended without an answer, instead of
|
|
3
17
|
* silently returning the default. Use this for any question whose "yes" has
|
package/dist/terminal.d.ts
CHANGED
|
@@ -9,19 +9,6 @@ export declare function getTerminalSize(): { columns: number, rows: number };
|
|
|
9
9
|
export declare function isInteractive(): boolean;
|
|
10
10
|
/** A short boxed aside. Sugar over `box`, which is what it should look like. */
|
|
11
11
|
export declare function note(message: string, title?: string): void;
|
|
12
|
-
/** JSON where it round-trips, `String()` otherwise (a Map, a circular ref). */
|
|
13
|
-
declare function format(value: unknown): string;
|
|
14
|
-
/** Print a value: strings as-is, everything else pretty-printed. */
|
|
15
|
-
export declare function echo(value: unknown): void;
|
|
16
|
-
/**
|
|
17
|
-
* Print a value with its label, for debugging.
|
|
18
|
-
*
|
|
19
|
-
* Goes to stderr, so a command whose stdout is being piped into something can
|
|
20
|
-
* still be debugged without corrupting what the pipe receives.
|
|
21
|
-
*/
|
|
22
|
-
export declare function dump(value: unknown, label?: string): void;
|
|
23
|
-
/** `dump`, then exit non-zero. "Dump and die". */
|
|
24
|
-
export declare function dd(value: unknown, label?: string): never;
|
|
25
12
|
/**
|
|
26
13
|
* Render rows as an aligned text table.
|
|
27
14
|
*
|
|
@@ -49,6 +36,15 @@ export declare function progress(options: ProgressOptions): ProgressBar;
|
|
|
49
36
|
* "build" after a failed "install" would fail differently and confusingly.
|
|
50
37
|
*/
|
|
51
38
|
export declare function tasks(definitions: TaskDefinition[]): Promise<TaskOutcome[]>;
|
|
39
|
+
/*
|
|
40
|
+
* `dump`, `dd` and `echo` are NOT here, though the CLI docs asked for them.
|
|
41
|
+
* `@stacksjs/logging` already exports all three, and this package already
|
|
42
|
+
* re-exports that package's `log`. A second implementation under the same name,
|
|
43
|
+
* in a package that shares exports with the first, is how two functions called
|
|
44
|
+
* `dd` end up exiting with different codes.
|
|
45
|
+
*
|
|
46
|
+
* import { dd, dump, echo } from '@stacksjs/logging'
|
|
47
|
+
*/
|
|
52
48
|
export declare interface TableColumn {
|
|
53
49
|
key: string
|
|
54
50
|
header?: string
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/cli",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.74.
|
|
5
|
+
"version": "0.74.38",
|
|
6
6
|
"description": "TypeScript framework for CLI artisans. Build beautiful console apps with ease.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -70,16 +70,16 @@
|
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@stacksjs/clapp": "^0.2.12",
|
|
73
|
-
"@stacksjs/collections": "0.74.
|
|
74
|
-
"@stacksjs/error-handling": "0.74.
|
|
75
|
-
"@stacksjs/logging": "0.74.
|
|
76
|
-
"@stacksjs/types": "0.74.
|
|
73
|
+
"@stacksjs/collections": "0.74.38",
|
|
74
|
+
"@stacksjs/error-handling": "0.74.38",
|
|
75
|
+
"@stacksjs/logging": "0.74.38",
|
|
76
|
+
"@stacksjs/types": "0.74.38"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@stacksjs/config": "0.74.
|
|
80
|
-
"@stacksjs/path": "0.74.
|
|
81
|
-
"@stacksjs/utils": "0.74.
|
|
82
|
-
"@stacksjs/validation": "0.74.
|
|
79
|
+
"@stacksjs/config": "0.74.38",
|
|
80
|
+
"@stacksjs/path": "0.74.38",
|
|
81
|
+
"@stacksjs/utils": "0.74.38",
|
|
82
|
+
"@stacksjs/validation": "0.74.38",
|
|
83
83
|
"better-dx": "^0.2.24"
|
|
84
84
|
}
|
|
85
85
|
}
|