forge-terminal 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.
Files changed (104) hide show
  1. package/README.md +40 -4
  2. package/dist/chunks/{about-credits-6D6B2JTS.js → about-credits-GRSA5RLZ.js} +1 -1
  3. package/dist/chunks/args-VJZHLGIY.js +3 -0
  4. package/dist/chunks/{available-HYL2YE56.js → available-GYIHVSRX.js} +1 -1
  5. package/dist/chunks/boot-HVIAAJMY.js +3 -0
  6. package/dist/chunks/{catalog-U7IF2BH2.js → catalog-YSMT3PXT.js} +1 -1
  7. package/dist/chunks/{check-INHBJOBB.js → check-KAR72Y4X.js} +1 -1
  8. package/dist/chunks/chunk-3UEQ2OX6.js +3 -0
  9. package/dist/chunks/{chunk-SS7HNRZ5.js → chunk-5B5XXH22.js} +1 -1
  10. package/dist/chunks/chunk-5IS7O673.js +6 -0
  11. package/dist/chunks/chunk-6FUVEO3A.js +78 -0
  12. package/dist/chunks/chunk-6L6C3GJU.js +3 -0
  13. package/dist/chunks/{chunk-5GJK5LP5.js → chunk-AAXBN572.js} +2 -2
  14. package/dist/chunks/chunk-CKUIRXDS.js +4 -0
  15. package/dist/chunks/{chunk-6TERL22R.js → chunk-DERIWZAT.js} +1 -1
  16. package/dist/chunks/chunk-DOWMSJ6R.js +3 -0
  17. package/dist/chunks/chunk-EEQSUBBL.js +3 -0
  18. package/dist/chunks/{chunk-MHW4OOQW.js → chunk-EGIKV2GZ.js} +2 -2
  19. package/dist/chunks/{chunk-C2OZ5ERA.js → chunk-EX7KZBI6.js} +1 -1
  20. package/dist/chunks/chunk-EXLXSKRH.js +3 -0
  21. package/dist/chunks/{chunk-BLPVRO4J.js → chunk-FH3R2YYD.js} +1 -1
  22. package/dist/chunks/{chunk-SVDVVRVP.js → chunk-FHORNIVW.js} +1 -1
  23. package/dist/chunks/{chunk-CLQHW4EF.js → chunk-GJ2GZHRI.js} +1 -1
  24. package/dist/chunks/chunk-HZDYZ5RD.js +3 -0
  25. package/dist/chunks/chunk-I63TO22X.js +3 -0
  26. package/dist/chunks/{chunk-ILWGG424.js → chunk-IGF6ZFTM.js} +1 -1
  27. package/dist/chunks/{chunk-Z2LELLNV.js → chunk-IWFVEMDN.js} +1 -1
  28. package/dist/chunks/{chunk-4LTI6JHW.js → chunk-JFJ3ZJQL.js} +2 -2
  29. package/dist/chunks/{chunk-OVILZLVA.js → chunk-JSMGNA55.js} +1 -1
  30. package/dist/chunks/chunk-KAHWYWNT.js +3 -0
  31. package/dist/chunks/chunk-LDKF7KIZ.js +6 -0
  32. package/dist/chunks/chunk-LNB5D67B.js +3 -0
  33. package/dist/chunks/chunk-M66BUNYO.js +3 -0
  34. package/dist/chunks/chunk-MKVBI37R.js +63 -0
  35. package/dist/chunks/chunk-QR6QHTC3.js +3 -0
  36. package/dist/chunks/chunk-SMBK6BTC.js +3 -0
  37. package/dist/chunks/chunk-TDW6KQH6.js +3 -0
  38. package/dist/chunks/chunk-TMQDQLY7.js +21 -0
  39. package/dist/chunks/chunk-VGS5Z5RD.js +66 -0
  40. package/dist/chunks/chunk-YWKMG5WO.js +3 -0
  41. package/dist/chunks/{chunk-FKPXXNKX.js → chunk-YYB3TTGT.js} +1 -1
  42. package/dist/chunks/clip-command-264DPO6I.js +3 -0
  43. package/dist/chunks/colour-4NH6H4HA.js +3 -0
  44. package/dist/chunks/command-I5M275ZV.js +3 -0
  45. package/dist/chunks/config-command-TYNYVUMP.js +3 -0
  46. package/dist/chunks/entry-26YSXWT4.js +6 -0
  47. package/dist/chunks/execute-GSC2NMDW.js +3 -0
  48. package/dist/chunks/extensions-ADGECS5U.js +3 -0
  49. package/dist/chunks/{extensions-command-AITZYSMM.js → extensions-command-TGOF36YW.js} +1 -1
  50. package/dist/chunks/ffmpeg-PF3VLTHK.js +3 -0
  51. package/dist/chunks/image-J4FT4ACZ.js +3 -0
  52. package/dist/chunks/install-2A5BGKQU.js +3 -0
  53. package/dist/chunks/install-V62EEK54.js +3 -0
  54. package/dist/chunks/launch-KBYCYAZR.js +5 -0
  55. package/dist/chunks/lock-KN7CF4YN.js +3 -0
  56. package/dist/chunks/manager-J7377NNA.js +4 -0
  57. package/dist/chunks/{paths-KTXPDCDD.js → paths-5XI5L4KW.js} +1 -1
  58. package/dist/chunks/pdf-compress-U2E3CNXG.js +3 -0
  59. package/dist/chunks/{preferences-AUFJSKMJ.js → preferences-4VETUGMN.js} +1 -1
  60. package/dist/chunks/preset-command-HORY7KZQ.js +3 -0
  61. package/dist/chunks/{run-4Z6CRNHJ.js → run-6BK4REXK.js} +1 -1
  62. package/dist/chunks/{server-RM4YA6UL.js → server-OAJFUZDM.js} +6 -6
  63. package/dist/chunks/{theme-LR72ACFF.js → theme-WGCMV4T4.js} +1 -1
  64. package/dist/chunks/transcribe-command-YUSBCQEQ.js +3 -0
  65. package/dist/chunks/{update-command-2SHKIIQD.js → update-command-GMBG7BK6.js} +1 -1
  66. package/dist/chunks/{update-note-UH2TQPJ6.js → update-note-6YGNGYUB.js} +1 -1
  67. package/dist/chunks/watch-command-HOG4TM3X.js +3 -0
  68. package/dist/helpers/forge-transcribe +0 -0
  69. package/dist/index.js +15 -72
  70. package/package.json +11 -17
  71. package/dist/chunks/boot-IQ4NYHEG.js +0 -3
  72. package/dist/chunks/chunk-26NDEWOQ.js +0 -3
  73. package/dist/chunks/chunk-2CK4RFPI.js +0 -3
  74. package/dist/chunks/chunk-3A43GEIR.js +0 -4
  75. package/dist/chunks/chunk-6V6WEBUI.js +0 -66
  76. package/dist/chunks/chunk-6VOCIMXQ.js +0 -3
  77. package/dist/chunks/chunk-7ZI3PFFX.js +0 -3
  78. package/dist/chunks/chunk-BXJ2HTKI.js +0 -3
  79. package/dist/chunks/chunk-CBE73ZWA.js +0 -3
  80. package/dist/chunks/chunk-D6JPP65L.js +0 -3
  81. package/dist/chunks/chunk-DW2EJIUX.js +0 -3
  82. package/dist/chunks/chunk-FWMFN36F.js +0 -3
  83. package/dist/chunks/chunk-HBDVKP3X.js +0 -5
  84. package/dist/chunks/chunk-HCN4BH2H.js +0 -3
  85. package/dist/chunks/chunk-IMC5NRDC.js +0 -3
  86. package/dist/chunks/chunk-JBSYGB3F.js +0 -3
  87. package/dist/chunks/chunk-PGG2OTK6.js +0 -3
  88. package/dist/chunks/chunk-XNNTF6FW.js +0 -3
  89. package/dist/chunks/chunk-ZONIA7SX.js +0 -21
  90. package/dist/chunks/clip-command-Q6SLD4U4.js +0 -3
  91. package/dist/chunks/colour-JPG24QYI.js +0 -3
  92. package/dist/chunks/config-command-R7QOBYF4.js +0 -3
  93. package/dist/chunks/execute-B7UL5RCU.js +0 -3
  94. package/dist/chunks/extensions-UR4GS47P.js +0 -3
  95. package/dist/chunks/image-KWRJIHQQ.js +0 -3
  96. package/dist/chunks/install-WBAFPZ2Q.js +0 -3
  97. package/dist/chunks/launch-RM5ZVXSU.js +0 -4
  98. package/dist/chunks/lock-GOOLFLSO.js +0 -3
  99. package/dist/chunks/manager-KZJ7WC34.js +0 -4
  100. package/dist/chunks/pdf-compress-IMRFBLZF.js +0 -3
  101. package/dist/chunks/preset-command-AXYFLVYA.js +0 -3
  102. package/dist/chunks/restart-TL76JEPU.js +0 -3
  103. package/dist/chunks/transcribe-command-6YTLVSMW.js +0 -3
  104. package/dist/chunks/watch-command-NU7QY6QU.js +0 -3
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v}from"./chunk-MHW4OOQW.js";import"./chunk-TMUK2DD3.js";export{t as BAR,c as DARK,d as LIGHT,g as MODE_KEYS,j as MODE_MARKERS,f as MODE_ORDER,e as NEUTRAL,b as SYMBOLS,a as VERSION,v as applyColourPreference,u as colourEnabled,s as colourProp,n as dotGradient,o as menuPalette,k as modeColours,i as modeForKey,l as modeGradient,p as modePalette,m as modeWash,q as paintsCanvas,r as paletteFor,h as tabStep};
3
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v}from"./chunk-EGIKV2GZ.js";import"./chunk-TMUK2DD3.js";export{t as BAR,c as DARK,d as LIGHT,g as MODE_KEYS,j as MODE_MARKERS,f as MODE_ORDER,e as NEUTRAL,b as SYMBOLS,a as VERSION,v as applyColourPreference,u as colourEnabled,s as colourProp,n as dotGradient,o as menuPalette,k as modeColours,i as modeForKey,l as modeGradient,p as modePalette,m as modeWash,q as paintsCanvas,r as paletteFor,h as tabStep};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{a as I,b as $,c as P,d as L,e as m,f as U,h as j}from"./chunk-5IS7O673.js";import{c as F}from"./chunk-DOWMSJ6R.js";import"./chunk-LNB5D67B.js";import"./chunk-BZXDNDPG.js";import"./chunk-EX7KZBI6.js";import"./chunk-HZDYZ5RD.js";import"./chunk-QR6QHTC3.js";import"./chunk-6L6C3GJU.js";import"./chunk-EEQSUBBL.js";import"./chunk-KAHWYWNT.js";import{e as A}from"./chunk-SMBK6BTC.js";import{a as x}from"./chunk-EXLXSKRH.js";import{c as w,d as y,e as v,ia as T,ka as k,la as u,ma as S,na as E,x as p}from"./chunk-3UEQ2OX6.js";import"./chunk-J7FLFHQJ.js";import"./chunk-LDKF7KIZ.js";import"./chunk-AAXBN572.js";import"./chunk-HON4OV7M.js";import"./chunk-M66BUNYO.js";import"./chunk-5B5XXH22.js";import"./chunk-TMUK2DD3.js";import{existsSync as B}from"node:fs";import{stat as K}from"node:fs/promises";import{basename as C,dirname as M,extname as O,join as N,resolve as f}from"node:path";function g(r,n,t){let e=`${r}.md`;return t===void 0?N(n,e):x(t)?N(f(t),e):f(t)}var R=r=>r.segments.reduce((n,t)=>n+t.text.split(/\s+/).filter(Boolean).length,0);async function er(r,n){try{let t=I(r.input);if(t?.kind==="playlist")throw k("This is a playlist.",void 0,{hint:"Pass one video's link.",shellHint:"Paste one video's link."});let e,o,s,l;if(t===void 0){if(e=f(r.input),!(await K(e).catch(()=>{}))?.isFile())throw v(e);let i=await F(e);if(i!=="video"&&i!=="audio")throw T(e)}let d=await U(r.language?{locale:r.language}:{});if(d===void 0||!d.speech)throw u("Transcribe needs macOS 26 or later on Apple silicon.");let b=r.notes&&d.notes==="available";if(r.notes&&!b){if(!r.transcript)throw u("Summary and notes need Apple Intelligence, and it is off.");n.err("\u26A0 Apple Intelligence is off, so this is the transcript only.")}if(t===void 0){if(e=f(r.input),o={title:C(e,O(e)),from:C(e)},s=g(o.title,M(e),r.output),B(s)&&!r.force)throw p(s)}else{let c=new AbortController;n.signal?.addEventListener("abort",()=>c.abort(n.signal?.reason),{once:!0});let i;l=await $(t.url,{signal:c.signal,onEvent:h=>{h.kind==="facts"&&(i=g(m(h.facts.title),process.cwd(),r.output),B(i)&&!r.force&&c.abort(p(i)))}}),e=l.path,o={title:l.facts.title,from:t.url},s=i??g(m(l.facts.title),process.cwd(),r.output)}let a;try{a=await j(e,{notes:b,detail:r.detail,locale:r.language,signal:n.signal,onEvent:n.onProgress})}finally{await l?.dispose()}let D=L(a,o,{transcript:r.transcript});await A(s,Buffer.from(D,"utf8"));let H=a.notes?` \xB7 ${a.notes.parts.length} parts`:"";return n.out(`\u2713 ${w(s)} ${P(a.seconds)} \u2192 ${R(a).toLocaleString("en-US")} words${H}`),0}catch(t){let e=y(t)?t:S(t);for(let o of E(e,{debug:r.debug}))n.err(o);return 1}}export{er as runTranscribeCommand};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{R as a}from"./chunk-DW2EJIUX.js";import"./chunk-J7FLFHQJ.js";import"./chunk-BXJ2HTKI.js";import"./chunk-TMUK2DD3.js";async function d(i,n={}){let e=n.check??(async()=>(await import("./check-INHBJOBB.js")).checkNow()),s=n.install??(async r=>(await import("./install-WBAFPZ2Q.js")).installUpdate(r)),t=await e();if(t===void 0)throw a();let{isNewer:o}=await import("./check-INHBJOBB.js");return o(t,i)?(n.onInstalling?.(t),await s(t),{stdout:[`\u2713 Forge ${t} is installed. It runs from your next forge.`],data:{current:i,latest:t,installed:!0}}):{stdout:[`\u2713 Forge ${i} is the latest.`],data:{current:i,latest:t,installed:!1}}}export{d as runUpdate};
3
+ import{R as a}from"./chunk-3UEQ2OX6.js";import"./chunk-J7FLFHQJ.js";import"./chunk-M66BUNYO.js";import"./chunk-TMUK2DD3.js";async function d(i,n={}){let e=n.check??(async()=>(await import("./check-KAR72Y4X.js")).checkNow()),s=n.install??(async r=>(await import("./install-V62EEK54.js")).installUpdate(r)),t=await e();if(t===void 0)throw a();let{isNewer:o}=await import("./check-KAR72Y4X.js");return o(t,i)?(n.onInstalling?.(t),await s(t),{stdout:[`\u2713 Forge ${t} is installed. It runs from your next forge.`],data:{current:i,latest:t,installed:!0}}):{stdout:[`\u2713 Forge ${i} is the latest.`],data:{current:i,latest:t,installed:!1}}}export{d as runUpdate};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{b as m,c as w,d as h,i as l,j as p,k as b}from"./chunk-ILWGG424.js";import{c as u,d as $}from"./chunk-MHW4OOQW.js";import{f as g}from"./chunk-5GJK5LP5.js";import"./chunk-HON4OV7M.js";import"./chunk-BXJ2HTKI.js";import"./chunk-TMUK2DD3.js";import{spawn as x}from"node:child_process";var P=60;function v(t,n){let e=Number.parseInt(t.slice(1),16);return`\x1B[${n};2;${e>>16&255};${e>>8&255};${e&255}m`}function C(t,n,e){let i=[" \u2191 ",`Forge ${t} is available`,` \xB7 your version ${n}`],r=[" In terminal: ","forge update"];if(e===void 0)return[i.join(""),r.join("")];let s=v(e.newTagBg,48),o=f=>v(f,38),c="\x1B[1m",a="\x1B[0m",d=f=>" ".repeat(Math.max(0,P-f.join("").length));return[`${s}${o(e.newTag)}${c}${i[0]}${o(e.fg)}${i[1]}${a}${s}${o(e.dim)}${i[2]}${d(i)}${a}`,`${s}${o(e.dim)}${r[0]}${o(e.fg)}${c}${r[1]}${a}${s}${d(r)}${a}`]}async function I(t,n){let e=n.now??Date.now(),{prefs:i}=await g();if(!h(i,n.env??process.env))return[];let r=await l();b(r,e)&&n.refresh();let s=r?.latest;if(r===void 0||s===void 0||!w(s,t))return[];let o=r.notifiedAt;if(o!==void 0&&o<=e&&e-o<=m)return[];await p({...r,notifiedAt:e}).catch(()=>{});let c=n.colour?i.theme==="light"?$:u:void 0;return C(s,t,c)}function N(t,n=process.platform,e=x){if(t!==void 0)try{e(process.execPath,[...process.execArgv,t,"__update-check"],{detached:!0,stdio:"ignore",...n==="win32"?{windowsHide:!0}:{}}).unref()}catch{}}export{I as afterCommand,C as noteLines,N as spawnRefresh};
3
+ import{b as m,c as w,d as h,i as l,j as p,k as b}from"./chunk-IGF6ZFTM.js";import{c as u,d as $}from"./chunk-EGIKV2GZ.js";import{f as g}from"./chunk-AAXBN572.js";import"./chunk-HON4OV7M.js";import"./chunk-M66BUNYO.js";import"./chunk-TMUK2DD3.js";import{spawn as x}from"node:child_process";var P=60;function v(t,n){let e=Number.parseInt(t.slice(1),16);return`\x1B[${n};2;${e>>16&255};${e>>8&255};${e&255}m`}function C(t,n,e){let i=[" \u2191 ",`Forge ${t} is available`,` \xB7 your version ${n}`],r=[" In terminal: ","forge update"];if(e===void 0)return[i.join(""),r.join("")];let s=v(e.newTagBg,48),o=f=>v(f,38),c="\x1B[1m",a="\x1B[0m",d=f=>" ".repeat(Math.max(0,P-f.join("").length));return[`${s}${o(e.newTag)}${c}${i[0]}${o(e.fg)}${i[1]}${a}${s}${o(e.dim)}${i[2]}${d(i)}${a}`,`${s}${o(e.dim)}${r[0]}${o(e.fg)}${c}${r[1]}${a}${s}${d(r)}${a}`]}async function I(t,n){let e=n.now??Date.now(),{prefs:i}=await g();if(!h(i,n.env??process.env))return[];let r=await l();b(r,e)&&n.refresh();let s=r?.latest;if(r===void 0||s===void 0||!w(s,t))return[];let o=r.notifiedAt;if(o!==void 0&&o<=e&&e-o<=m)return[];await p({...r,notifiedAt:e}).catch(()=>{});let c=n.colour?i.theme==="light"?$:u:void 0;return C(s,t,c)}function N(t,n=process.platform,e=x){if(t!==void 0)try{e(process.execPath,[...process.execArgv,t,"__update-check"],{detached:!0,stdio:"ignore",...n==="win32"?{windowsHide:!0}:{}}).unref()}catch{}}export{I as afterCommand,C as noteLines,N as spawnRefresh};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{b as R,c as k}from"./chunk-TDW6KQH6.js";import"./chunk-YWKMG5WO.js";import{a as W,d as N}from"./chunk-DOWMSJ6R.js";import"./chunk-LNB5D67B.js";import"./chunk-BZXDNDPG.js";import{c as w,d as h}from"./chunk-EHARO6IS.js";import"./chunk-PSEIJXGT.js";import"./chunk-QR6QHTC3.js";import"./chunk-6L6C3GJU.js";import"./chunk-EEQSUBBL.js";import"./chunk-KAHWYWNT.js";import"./chunk-SMBK6BTC.js";import"./chunk-EXLXSKRH.js";import{F as L,c as a,d as M,e as I,na as E}from"./chunk-3UEQ2OX6.js";import{a as A}from"./chunk-J7FLFHQJ.js";import"./chunk-LDKF7KIZ.js";import{a as S}from"./chunk-EGIKV2GZ.js";import"./chunk-AAXBN572.js";import"./chunk-HON4OV7M.js";import{a as F}from"./chunk-M66BUNYO.js";import"./chunk-TMUK2DD3.js";import{readdir as T,stat as B}from"node:fs/promises";import{join as C,resolve as y}from"node:path";function K(r,t,s,n){return[`\u2713 ${r} converted${n?` to ${n}`:""}`,...t?[`${t} failed`]:[],...s?[`${s} left alone`]:[]].join(" \xB7 ")}var P=r=>{let[t,...s]=r.job.outputs,n=`${a(t??"")}${s.length?` + ${s.length} more`:""}`;return`\u2713 ${a(r.job.sources[0].path)} \u2192 ${n} ${A(r.outputBytes)}`},O=(r,t)=>`\u2715 ${a(r)} ${t.title.toLowerCase()}`,D=r=>`\u2013 ${a(r.path)} ${r.reason}`;async function v(r,t){let s=y(r.folder),n=(e,o)=>t.out(JSON.stringify({forge:S,event:e,...o}));try{let e=await B(s).catch(()=>{});if(!e)throw I(s);if(!e.isDirectory())throw L(`${a(s)} is not a folder.`,`forge watch watches a folder. Try: forge watch ${a(y(s,".."))} --to ${r.target}`)}catch(e){if(!M(e))throw e;if(t.json)n("error",{ok:!1,failures:[h({error:e})]});else for(let o of E(e,{debug:r.debug}))t.out(o);return 2}let m={target:r.target,...r.quality===void 0?{}:{quality:r.quality},dpi:r.dpi??150},$={images:m,pdfs:m,documents:m},c=r.output===void 0?void 0:y(r.output),q=F[r.target].label,p=0,i=[],u=[],b=new Set,g;if(r.newOnly)g=(await T(s,{withFileTypes:!0})).filter(o=>o.isFile()&&!W(o.name)).map(o=>C(s,o.name));else{let e=await N(s);g=e.paths;let o=await R(e,$,{destination:c});b=o.claimed;let f=[...e.failures,...o.outcome.refusals,...o.outcome.failures],j=e.kinds.flatMap(l=>l.why?[{count:l.count,why:l.why}]:[]),J=o.left.length+j.reduce((l,d)=>l+d.count,0);if(p+=o.outcome.results.length,i.push(...f),u.push(...o.left),t.json)n("converted-existing",{ok:f.length===0,results:o.outcome.results.map(w),failures:f.map(h),leftAlone:o.left});else if(e.paths.length>0){t.out(K(o.outcome.results.length,f.length,J,q));for(let l of f)t.out(O(l.path,l.error))}for(let l of j)for(let d=0;d<l.count;d++)u.push({path:"",reason:l.why})}t.json?n("watching",{folder:s,...c?{output:c}:{}}):t.out(`Watching ${a(s)} \xB7 any new files you add will be converted \xB7 ctrl-c to stop`);let x=k({dir:s,answers:$,known:g,claimed:b,destination:c,...t.settleMs===void 0?{}:{settleMs:t.settleMs},...t.pollMs===void 0?{}:{pollMs:t.pollMs},onEvent:e=>{e.type==="converted"?(p++,t.json?n("converted",{result:w(e.result)}):t.out(P(e.result))):e.type==="failed"?(i.push({path:e.path,error:e.error}),t.json?n("failed",{failure:h({path:e.path,error:e.error})}):t.out(O(e.path,e.error))):e.type==="left"&&(u.push({path:e.path,reason:e.reason}),t.json?n("left-alone",{path:e.path,reason:e.reason}):t.out(D({path:e.path,reason:e.reason})))}});return await new Promise(e=>{t.signal.aborted?e():t.signal.addEventListener("abort",()=>e(),{once:!0})}),await x.stop(),t.json?n("stopped",{converted:p,failed:i.length,leftAlone:u.length}):t.out(K(p,i.length,u.length)),i.length>0?1:0}export{v as runWatch};
Binary file
package/dist/index.js CHANGED
@@ -1,81 +1,24 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __forgeCreateRequire } from 'node:module';
3
3
  const require = __forgeCreateRequire(import.meta.url);
4
- import{a as J}from"./chunks/chunk-U5TEGDGH.js";import{b as W}from"./chunks/chunk-CBE73ZWA.js";import"./chunks/chunk-IMC5NRDC.js";import{b as q,d as B}from"./chunks/chunk-IBPGC4N2.js";import{f as G}from"./chunks/chunk-EHARO6IS.js";import"./chunks/chunk-PSEIJXGT.js";import"./chunks/chunk-QVACE4IE.js";import"./chunks/chunk-6VOCIMXQ.js";import{l as Q,n as Z}from"./chunks/chunk-D6JPP65L.js";import"./chunks/chunk-7ZI3PFFX.js";import{a as v}from"./chunks/chunk-MHW4OOQW.js";import{a as D}from"./chunks/chunk-FKPXXNKX.js";import{F as p,I as H,d as I,ka as X,la as N}from"./chunks/chunk-DW2EJIUX.js";import{d as K}from"./chunks/chunk-J7FLFHQJ.js";import"./chunks/chunk-5GJK5LP5.js";import"./chunks/chunk-HON4OV7M.js";import{b as Y}from"./chunks/chunk-BXJ2HTKI.js";import"./chunks/chunk-TMUK2DD3.js";import*as ue from"node:module";var y=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},C=class extends y{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};var S=class{constructor(e,t){switch(this.description=t||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case"<":this.required=!0,this._name=e.slice(1,-1);break;case"[":this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new C(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(t,n):t},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function V(s){let e=s.name()+(s.variadic===!0?"...":"");return s.required?"<"+e+">":"["+e+"]"}import{EventEmitter as me}from"node:events";import z from"node:child_process";import x from"node:path";import P from"node:fs";import g from"node:process";import{stripVTControlCharacters as ge}from"node:util";import{stripVTControlCharacters as pe}from"node:util";var E=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(i=>!i._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((i,r)=>i.name().localeCompare(r.name())),t}compareOptions(e,t){let n=i=>i.short?i.short.replace(/^-/,""):i.long.replace(/^--/,"");return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(i=>!i.hidden),n=e._getHelpOption();if(n&&!n.hidden){let i=n.short&&e._findOption(n.short),r=n.long&&e._findOption(n.long);!i&&!r?t.push(n):n.long&&!r?t.push(e.createOption(n.long,n.description)):n.short&&!i&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let i=n.options.filter(r=>!r.hidden);t.push(...i)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||""}),e.registeredArguments.find(t=>t.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(n=>V(n)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(t?" "+t:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(i)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleOptionTerm(t.optionTerm(i)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleOptionTerm(t.optionTerm(i)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(i)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+"|"+e._aliases[0]);let n="";for(let i=e.parent;i;i=i.parent)n=i.name()+" "+n;return n+t+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue=="boolean")&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,""]}groupItems(e,t,n){let i=new Map;return e.forEach(r=>{let o=n(r);i.has(o)||i.set(o,[])}),t.forEach(r=>{let o=n(r);i.has(o)||i.set(o,[]),i.get(o).push(r)}),i}formatHelp(e,t){let n=t.padWidth(e,t),i=t.helpWidth??80;function r(u,d){return t.formatItem(u,n,d,t)}let o=[`${t.styleTitle("Usage:")} ${t.styleUsage(t.commandUsage(e))}`,""],l=t.commandDescription(e);l.length>0&&(o=o.concat([t.boxWrap(t.styleCommandDescription(l),i),""]));let c=t.visibleArguments(e).map(u=>r(t.styleArgumentTerm(t.argumentTerm(u)),t.styleArgumentDescription(t.argumentDescription(u))));if(o=o.concat(this.formatItemList("Arguments:",c,t)),this.groupItems(e.options,t.visibleOptions(e),u=>u.helpGroupHeading??"Options:").forEach((u,d)=>{let f=u.map(m=>r(t.styleOptionTerm(t.optionTerm(m)),t.styleOptionDescription(t.optionDescription(m))));o=o.concat(this.formatItemList(d,f,t))}),t.showGlobalOptions){let u=t.visibleGlobalOptions(e).map(d=>r(t.styleOptionTerm(t.optionTerm(d)),t.styleOptionDescription(t.optionDescription(d))));o=o.concat(this.formatItemList("Global Options:",u,t))}return this.groupItems(e.commands,t.visibleCommands(e),u=>u.helpGroup()||"Commands:").forEach((u,d)=>{let f=u.map(m=>r(t.styleSubcommandTerm(t.subcommandTerm(m)),t.styleSubcommandDescription(t.subcommandDescription(m))));o=o.concat(this.formatItemList(d,f,t))}),o.join(`
5
- `)}displayWidth(e){return pe(e).length}styleTitle(e){return e}styleUsage(e){return e.split(" ").map(t=>t==="[options]"?this.styleOptionText(t):t==="[command]"?this.styleSubcommandText(t):t[0]==="["||t[0]==="<"?this.styleArgumentText(t):this.styleCommandText(t)).join(" ")}styleCommandDescription(e){return this.styleDescriptionText(e)}styleOptionDescription(e){return this.styleDescriptionText(e)}styleSubcommandDescription(e){return this.styleDescriptionText(e)}styleArgumentDescription(e){return this.styleDescriptionText(e)}styleDescriptionText(e){return e}styleOptionTerm(e){return this.styleOptionText(e)}styleSubcommandTerm(e){return e.split(" ").map(t=>t==="[options]"?this.styleOptionText(t):t[0]==="["||t[0]==="<"?this.styleArgumentText(t):this.styleSubcommandText(t)).join(" ")}styleArgumentTerm(e){return this.styleArgumentText(e)}styleOptionText(e){return e}styleArgumentText(e){return e}styleSubcommandText(e){return e}styleCommandText(e){return e}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}preformatted(e){return/\n[^\S\r\n]/.test(e)}formatItem(e,t,n,i){let o=" ".repeat(2);if(!n)return o+e;let l=e.padEnd(t+e.length-i.displayWidth(e)),c=2,a=(this.helpWidth??80)-t-c-2,u;return a<this.minWidthToWrap||i.preformatted(n)?u=n:u=i.boxWrap(n,a).replace(/\n/g,`
6
- `+" ".repeat(t+c)),o+l+" ".repeat(c)+u.replace(/\n/g,`
7
- ${o}`)}boxWrap(e,t){if(t<this.minWidthToWrap)return e;let n=e.split(/\r\n|\n/),i=/[\s]*[^\s]+/g,r=[];return n.forEach(o=>{let l=o.match(i);if(l===null){r.push("");return}let c=[l.shift()],h=this.displayWidth(c[0]);l.forEach(a=>{let u=this.displayWidth(a);if(h+u<=t){c.push(a),h+=u;return}r.push(c.join(""));let d=a.trimStart();c=[d],h=this.displayWidth(d)}),r.push(c.join(""))}),r.join(`
8
- `)}};var k=class{constructor(e,t){this.flags=e,this.description=t||"",this.required=e.includes("<"),this.optional=e.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let n=de(e);this.short=n.shortFlag,this.long=n.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith("--no-")),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e=="string"&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new C(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(t,n):t},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?ee(this.name().replace(/^no-/,"")):ee(this.name())}helpGroup(e){return this.helpGroupHeading=e,this}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},F=class{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)}),this.negativeOptions.forEach((t,n)=>{this.positiveOptions.has(n)&&this.dualOptions.add(n)})}valueFromOption(e,t){let n=t.attributeName();if(!this.dualOptions.has(n))return!0;let i=this.negativeOptions.get(n).presetArg,r=i!==void 0?i:!1;return t.negate===(r===e)}};function ee(s){return s.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function de(s){let e,t,n=/^-[^-]$/,i=/^--[^-]/,r=s.split(/[ |,]+/).concat("guard");if(n.test(r[0])&&(e=r.shift()),i.test(r[0])&&(t=r.shift()),!e&&n.test(r[0])&&(e=r.shift()),!e&&i.test(r[0])&&(e=t,t=r.shift()),r[0].startsWith("-")){let o=r[0],l=`option creation failed due to '${o}' in option flags '${s}'`;throw/^-[^-][^-]/.test(o)?new Error(`${l}
9
- - a short flag is a single dash and a single character
10
- - either use a single dash and a single character (for a short flag)
11
- - or use a double dash for a long option (and can have two, like '--ws, --workspace')`):n.test(o)?new Error(`${l}
12
- - too many short flags`):i.test(o)?new Error(`${l}
13
- - too many long flags`):new Error(`${l}
14
- - unrecognised flag format`)}if(e===void 0&&t===void 0)throw new Error(`option creation failed due to no flags found in '${s}'.`);return{shortFlag:e,longFlag:t}}function fe(s,e){if(Math.abs(s.length-e.length)>3)return Math.max(s.length,e.length);let t=[];for(let n=0;n<=s.length;n++)t[n]=[n];for(let n=0;n<=e.length;n++)t[0][n]=n;for(let n=1;n<=e.length;n++)for(let i=1;i<=s.length;i++){let r;s[i-1]===e[n-1]?r=0:r=1,t[i][n]=Math.min(t[i-1][n]+1,t[i][n-1]+1,t[i-1][n-1]+r),i>1&&n>1&&s[i-1]===e[n-2]&&s[i-2]===e[n-1]&&(t[i][n]=Math.min(t[i][n],t[i-2][n-2]+1))}return t[s.length][e.length]}function M(s,e){if(!e||e.length===0)return"";e=Array.from(new Set(e));let t=s.startsWith("--");t&&(s=s.slice(2),e=e.map(o=>o.slice(2)));let n=[],i=3,r=.4;return e.forEach(o=>{if(o.length<=1)return;let l=fe(s,o),c=Math.max(s.length,o.length);(c-l)/c>r&&(l<i?(i=l,n=[o]):l===i&&n.push(o))}),n.sort((o,l)=>o.localeCompare(l)),t&&(n=n.map(o=>`--${o}`)),n.length>1?`
15
- (Did you mean one of ${n.join(", ")}?)`:n.length===1?`
16
- (Did you mean ${n[0]}?)`:""}var A=class s extends me{constructor(e){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=e||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:t=>g.stdout.write(t),writeErr:t=>g.stderr.write(t),outputError:(t,n)=>n(t),getOutHelpWidth:()=>g.stdout.isTTY?g.stdout.columns:void 0,getErrHelpWidth:()=>g.stderr.isTTY?g.stderr.columns:void 0,getOutHasColors:()=>ne()??(g.stdout.isTTY&&g.stdout.hasColors?.()),getErrHasColors:()=>ne()??(g.stderr.isTTY&&g.stderr.hasColors?.()),stripColor:t=>ge(t)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){let e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,n){let i=t,r=n;typeof i=="object"&&i!==null&&(r=i,i=null),r=r||{};let[,o,l]=e.match(/([^ ]+) *(.*)/),c=this.createCommand(o);return i&&(c.description(i),c._executableHandler=!0),r.isDefault&&(this._defaultCommandName=c._name),c._hidden=!!(r.noHelp||r.hidden),c._executableFile=r.executableFile||null,l&&c.arguments(l),this._registerCommand(c),c.parent=this,c.copyInheritedSettings(this),i?this:c}createCommand(e){return new s(e)}createHelp(){return Object.assign(new E,this.configureHelp())}configureHelp(e){return e===void 0?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return e===void 0?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...e},this)}showHelpAfterError(e=!0){return typeof e!="string"&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw new Error(`Command passed to .addCommand() must have a name
17
- - specify the name in Command constructor or using .name()`);return t=t||{},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new S(e,t)}argument(e,t,n,i){let r=this.createArgument(e,t);return typeof n=="function"?r.default(i).argParser(n):r.default(n),this.addArgument(r),this}arguments(e){return e.trim().split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(e){let t=this.registeredArguments.slice(-1)[0];if(t?.variadic)throw new Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if(typeof e=="boolean")return this._addImplicitHelpCommand=e,e&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;let n=e??"help [command]",[,i,r]=n.match(/([^ ]+) *(.*)/),o=t??"display help for command",l=this.createCommand(i);return l.helpOption(!1),r&&l.arguments(r),o&&l.description(o),this._addImplicitHelpCommand=!0,this._helpCommand=l,(e||t)&&this._initCommandGroup(l),this}addHelpCommand(e,t){return typeof e!="object"?(this.helpCommand(e,t),this):(this._addImplicitHelpCommand=!0,this._helpCommand=e,this._initCommandGroup(e),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(e,t){let n=["preSubcommand","preAction","postAction"];if(!n.includes(e))throw new Error(`Unexpected value for event passed to hook : '${e}'.
18
- Expecting one of '${n.join("', '")}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return e?this._exitCallback=e:this._exitCallback=t=>{if(t.code!=="commander.executeSubCommandAsync")throw t},this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new y(e,t,n)),g.exit(e)}action(e){let t=n=>{let i=this.registeredArguments.length,r=n.slice(0,i);return this._storeOptionsAsProperties?r[i]=this:r[i]=this.opts(),r.push(this),e.apply(this,r)};return this._actionHandler=t,this}createOption(e,t){return new k(e,t)}_callParseArg(e,t,n,i){try{return e.parseArg(t,n)}catch(r){if(r.code==="commander.invalidArgument"){let o=`${i} ${r.message}`;this.error(o,{exitCode:r.exitCode,code:r.code})}throw r}}_registerOption(e){let t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){let n=e.long&&this._findOption(e.long)?e.long:e.short;throw new Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${n}'
19
- - already used by option '${t.flags}'`)}this._initOptionGroup(e),this.options.push(e)}_registerCommand(e){let t=i=>[i.name()].concat(i.aliases()),n=t(e).find(i=>this._findCommand(i));if(n){let i=t(this._findCommand(n)).join("|"),r=t(e).join("|");throw new Error(`cannot add command '${r}' as already have command '${i}'`)}this._initCommandGroup(e),this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),n=e.attributeName();e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,"default");let i=(r,o,l)=>{r==null&&e.presetArg!==void 0&&(r=e.presetArg);let c=this.getOptionValue(n);r!==null&&e.parseArg?r=this._callParseArg(e,r,c,o):r!==null&&e.variadic&&(r=e._collectValue(r,c)),r==null&&(e.negate?r=!1:e.isBoolean()||e.optional?r=!0:r=""),this.setOptionValueWithSource(n,r,l)};return this.on("option:"+t,r=>{let o=`error: option '${e.flags}' argument '${r}' is invalid.`;i(r,o,"cli")}),e.envVar&&this.on("optionEnv:"+t,r=>{let o=`error: option '${e.flags}' value '${r}' from env '${e.envVar}' is invalid.`;i(r,o,"env")}),this}_optionEx(e,t,n,i,r){if(typeof t=="object"&&t instanceof k)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let o=this.createOption(t,n);if(o.makeOptionMandatory(!!e.mandatory),typeof i=="function")o.default(r).argParser(i);else if(i instanceof RegExp){let l=i;i=(c,h)=>{let a=l.exec(c);return a?a[0]:h},o.default(r).argParser(i)}else o.default(i);return this.addOption(o)}option(e,t,n,i){return this._optionEx({},e,t,n,i)}requiredOption(e,t,n,i){return this._optionEx({mandatory:!0},e,t,n,i)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw new Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,n){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=n,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(n=>{n.getOptionValueSource(e)!==void 0&&(t=n.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw new Error("first parameter to parse must be array or undefined");if(t=t||{},e===void 0&&t.from===void 0){g.versions?.electron&&(t.from="electron");let i=g.execArgv??[];(i.includes("-e")||i.includes("--eval")||i.includes("-p")||i.includes("--print"))&&(t.from="eval")}e===void 0&&(e=g.argv),this.rawArgs=e.slice();let n;switch(t.from){case void 0:case"node":this._scriptPath=e[1],n=e.slice(2);break;case"electron":g.defaultApp?(this._scriptPath=e[1],n=e.slice(2)):n=e.slice(1);break;case"user":n=e.slice(0);break;case"eval":n=e.slice(1);break;default:throw new Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",n}parse(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return this._parseCommand([],n),this}async parseAsync(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return await this._parseCommand([],n),this}_prepareForParse(){this._savedState===null?(this.options.filter(e=>e.negate&&e.defaultValue===void 0&&this.getOptionValue(e.attributeName())===void 0).forEach(e=>{let t=e.long.replace(/^--no-/,"--");this._findOption(t)||this.setOptionValueWithSource(e.attributeName(),!0,"default")}),this.saveStateBeforeParse()):this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
20
- - either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(e,t,n){if(P.existsSync(e))return;let i=t?`searched for local subcommand relative to directory '${t}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",r=`'${e}' does not exist
21
- - if '${n}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
22
- - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
23
- - ${i}`;throw new Error(r)}_executeSubCommand(e,t){t=t.slice();let n=[".js",".ts",".tsx",".mjs",".cjs"];function i(a,u){let d=x.resolve(a,u);if(P.existsSync(d))return d;if(n.includes(x.extname(u)))return;let f=n.find(m=>P.existsSync(`${d}${m}`));if(f)return`${d}${f}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=e._executableFile||`${this._name}-${e._name}`,o=this._executableDir||"";if(this._scriptPath){let a;try{a=P.realpathSync(this._scriptPath)}catch{a=this._scriptPath}o=x.resolve(x.dirname(a),o)}if(o){let a=i(o,r);if(!a&&!e._executableFile&&this._scriptPath){let u=x.basename(this._scriptPath,x.extname(this._scriptPath));u!==this._name&&(a=i(o,`${u}-${e._name}`))}r=a||r}let l=n.includes(x.extname(r)),c;g.platform!=="win32"?l?(t.unshift(r),t=te(g.execArgv).concat(t),c=z.spawn(g.argv[0],t,{stdio:"inherit"})):c=z.spawn(r,t,{stdio:"inherit"}):(this._checkForMissingExecutable(r,o,e._name),t.unshift(r),t=te(g.execArgv).concat(t),c=z.spawn(g.execPath,t,{stdio:"inherit"})),c.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(u=>{g.on(u,()=>{c.killed===!1&&c.exitCode===null&&c.kill(u)})});let h=this._exitCallback;c.on("close",a=>{a=a??1,h?h(new y(a,"commander.executeSubCommandAsync","(close)")):g.exit(a)}),c.on("error",a=>{if(a.code==="ENOENT")this._checkForMissingExecutable(r,o,e._name);else if(a.code==="EACCES")throw new Error(`'${r}' not executable`);if(!h)g.exit(1);else{let u=new y(1,"commander.executeSubCommandAsync","(error)");u.nestedError=a,h(u)}}),this.runningCommand=c}_dispatchSubcommand(e,t,n){let i=this._findCommand(e);i||this.help({error:!0}),i._prepareForParse();let r;return r=this._chainOrCallSubCommandHook(r,i,"preSubcommand"),r=this._chainOrCall(r,()=>{if(i._executableHandler)this._executeSubCommand(i,t.concat(n));else return i._parseCommand(t,n)}),r}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(n,i,r)=>{let o=i;if(i!==null&&n.parseArg){let l=`error: command-argument value '${i}' is invalid for argument '${n.name()}'.`;o=this._callParseArg(n,i,r,l)}return o};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,i)=>{let r=n.defaultValue;n.variadic?i<this.args.length?(r=this.args.slice(i),n.parseArg&&(r=r.reduce((o,l)=>e(n,l,o),n.defaultValue))):r===void 0&&(r=[]):i<this.args.length&&(r=this.args[i],n.parseArg&&(r=e(n,r,n.defaultValue))),t[i]=r}),this.processedArgs=t}_chainOrCall(e,t){return e?.then&&typeof e.then=="function"?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e,i=[];return this._getCommandAndAncestors().reverse().filter(r=>r._lifeCycleHooks[t]!==void 0).forEach(r=>{r._lifeCycleHooks[t].forEach(o=>{i.push({hookedCommand:r,callback:o})})}),t==="postAction"&&i.reverse(),i.forEach(r=>{n=this._chainOrCall(n,()=>r.callback(r.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let i=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(r=>{i=this._chainOrCall(i,()=>r(this,t))}),i}_parseCommand(e,t){let n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},r=`command:${this.name()}`;if(this._actionHandler){i(),this._processArguments();let o;return o=this._chainOrCallHooks(o,"preAction"),o=this._chainOrCall(o,()=>this._actionHandler(this.processedArgs)),this.parent&&(o=this._chainOrCall(o,()=>{this.parent.emit(r,e,t)})),o=this._chainOrCallHooks(o,"postAction"),o}if(this.parent?.listenerCount(r))i(),this._processArguments(),this.parent.emit(r,e,t);else if(e.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",e,t);this.listenerCount("command:*")?this.emit("command:*",e,t):this.commands.length?this.unknownCommand():(i(),this._processArguments())}else this.commands.length?(i(),this.help({error:!0})):(i(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(n=>{let i=n.attributeName();return this.getOptionValue(i)===void 0?!1:this.getOptionValueSource(i)!=="default"});e.filter(n=>n.conflictsWith.length>0).forEach(n=>{let i=e.find(r=>n.conflictsWith.includes(r.attributeName()));i&&this._conflictingOption(n,i)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],i=t;function r(a){return a.length>1&&a[0]==="-"}let o=a=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(a)?!this._getCommandAndAncestors().some(u=>u.options.map(d=>d.short).some(d=>/^-\d$/.test(d))):!1,l=null,c=null,h=0;for(;h<e.length||c;){let a=c??e[h++];if(c=null,a==="--"){i===n&&i.push(a),i.push(...e.slice(h));break}if(l&&(!r(a)||o(a))){this.emit(`option:${l.name()}`,a);continue}if(l=null,r(a)){let u=this._findOption(a);if(u){if(u.required){let d=e[h++];d===void 0&&this.optionMissingArgument(u),this.emit(`option:${u.name()}`,d)}else if(u.optional){let d=null;h<e.length&&(!r(e[h])||o(e[h]))&&(d=e[h++]),this.emit(`option:${u.name()}`,d)}else this.emit(`option:${u.name()}`);l=u.variadic?u:null;continue}}if(a.length>2&&a[0]==="-"&&a[1]!=="-"){let u=this._findOption(`-${a[1]}`);if(u){u.required||u.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${u.name()}`,a.slice(2)):(this.emit(`option:${u.name()}`),c=`-${a.slice(2)}`);continue}}if(/^--[^=]+=/.test(a)){let u=a.indexOf("="),d=this._findOption(a.slice(0,u));if(d&&(d.required||d.optional)){this.emit(`option:${d.name()}`,a.slice(u+1));continue}}if(i===t&&r(a)&&!(this.commands.length===0&&o(a))&&(i=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(a)){t.push(a),n.push(...e.slice(h));break}else if(this._getHelpCommand()&&a===this._getHelpCommand().name()){t.push(a,...e.slice(h));break}else if(this._defaultCommandName){n.push(a,...e.slice(h));break}}if(this._passThroughOptions){i.push(a,...e.slice(h));break}i.push(a)}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let n=0;n<t;n++){let i=this.options[n].attributeName();e[i]=i===this._versionOptionName?this._version:this[i]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}
24
- `,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
25
- `):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
26
- `),this.outputHelp({error:!0}));let n=t||{},i=n.exitCode||1,r=n.code||"commander.error";this._exit(i,r,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in g.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,g.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new F(this.options),t=n=>this.getOptionValue(n)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(n));this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(n=>{Object.keys(n.implied).filter(i=>!t(i)).forEach(i=>{this.setOptionValueWithSource(i,n.implied[i],"implied")})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:"commander.missingArgument"})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,t){let n=o=>{let l=o.attributeName(),c=this.getOptionValue(l),h=this.options.find(u=>u.negate&&l===u.attributeName()),a=this.options.find(u=>!u.negate&&l===u.attributeName());return h&&(h.presetArg===void 0&&c===!1||h.presetArg!==void 0&&c===h.presetArg)?h:a||o},i=o=>{let l=n(o),c=l.attributeName();return this.getOptionValueSource(c)==="env"?`environment variable '${l.envVar}'`:`option '${l.flags}'`},r=`error: ${i(e)} cannot be used with ${i(t)}`;this.error(r,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let i=[],r=this;do{let o=r.createHelp().visibleOptions(r).filter(l=>l.long).map(l=>l.long);i=i.concat(o),r=r.parent}while(r&&!r._enablePositionalOptions);t=M(e,i)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?"":"s",i=e.length,r=this.parent?` for '${this.name()}'`:"",o=e.join(", "),l=`error: too many arguments${r}. Expected ${t} argument${n} but got ${i}: ${o}.`;this.error(l,{code:"commander.excessArguments"})}unknownCommand(){let e=this.args[0],t="";if(this._showSuggestionAfterError){let i=[];this.createHelp().visibleCommands(this).forEach(r=>{i.push(r.name()),r.alias()&&i.push(r.alias())}),t=M(e,i)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:"commander.unknownCommand"})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t=t||"-V, --version",n=n||"output the version number";let i=this.createOption(t,n);return this._versionOptionName=i.attributeName(),this._registerOption(i),this.on("option:"+i.name(),()=>{this._outputConfiguration.writeOut(`${e}
27
- `),this._exit(0,"commander.version",e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw new Error("Command alias can't be the same as its name");let n=this.parent?._findCommand(e);if(n){let i=[n.name()].concat(n.aliases()).join("|");throw new Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${i}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(t=>this.alias(t)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let t=this.registeredArguments.map(n=>V(n));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}helpGroup(e){return e===void 0?this._helpGroupHeading??"":(this._helpGroupHeading=e,this)}commandsGroup(e){return e===void 0?this._defaultCommandGroup??"":(this._defaultCommandGroup=e,this)}optionsGroup(e){return e===void 0?this._defaultOptionGroup??"":(this._defaultOptionGroup=e,this)}_initOptionGroup(e){this._defaultOptionGroup&&!e.helpGroupHeading&&e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){this._defaultCommandGroup&&!e.helpGroup()&&e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=x.basename(e,x.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let i=t.formatHelp(this,t);return n.hasColors?i:this._outputConfiguration.stripColor(i)}_getOutputContext(e){e=e||{};let t=!!e.error,n,i,r;return t?(n=l=>this._outputConfiguration.writeErr(l),i=this._outputConfiguration.getErrHasColors(),r=this._outputConfiguration.getErrHelpWidth()):(n=l=>this._outputConfiguration.writeOut(l),i=this._outputConfiguration.getOutHasColors(),r=this._outputConfiguration.getOutHelpWidth()),{error:t,write:l=>(i||(l=this._outputConfiguration.stripColor(l)),n(l)),hasColors:i,helpWidth:r}}outputHelp(e){let t;typeof e=="function"&&(t=e,e=void 0);let n=this._getOutputContext(e),i={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(o=>o.emit("beforeAllHelp",i)),this.emit("beforeHelp",i);let r=this.helpInformation({error:n.error});if(t&&(r=t(r),typeof r!="string"&&!Buffer.isBuffer(r)))throw new Error("outputHelp callback must return a string or a Buffer");n.write(r),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",i),this._getCommandAndAncestors().forEach(o=>o.emit("afterAllHelp",i))}helpOption(e,t){return typeof e=="boolean"?(e?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(e??"-h, --help",t??"display help for command"),(e||t)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(e){this.outputHelp(e);let t=Number(g.exitCode??0);t===0&&e&&typeof e!="function"&&e.error&&(t=1),this._exit(t,"commander.help","(outputHelp)")}addHelpText(e,t){let n=["beforeAll","before","after","afterAll"];if(!n.includes(e))throw new Error(`Unexpected value for position to addHelpText.
28
- Expecting one of '${n.join("', '")}'`);let i=`${e}Help`;return this.on(i,r=>{let o;typeof t=="function"?o=t({error:r.error,command:r.command}):o=t,o&&r.write(`${o}
29
- `)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(i=>t.is(i))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}};function te(s){return s.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",i="9229",r;return(r=e.match(/^(--inspect(-brk)?)$/))!==null?t=r[1]:(r=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=r[1],/^\d+$/.test(r[3])?i=r[3]:n=r[3]):(r=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=r[1],n=r[3],i=r[4]),t&&i!=="0"?`${t}=${n}:${parseInt(i)+1}`:e})}function ne(){if(g.env.NO_COLOR||g.env.FORCE_COLOR==="0"||g.env.FORCE_COLOR==="false")return!1;if(g.env.FORCE_COLOR||g.env.CLICOLOR_FORCE!==void 0)return!0}var st=new A;function be(s){let[,e,t,...n]=s;if(e===void 0||e==="list")return{kind:"config",action:"list"};if(e==="path")return{kind:"config",action:"path"};if(e==="set"){if(t===void 0||!D.includes(t))throw p(`Unknown config setting ${t??"(none)"}.`,`Try one of: ${D.join(", ")}.`);let i=n.join(" ");if(i.length===0)throw p(`forge config set ${t} needs a value.`);return{kind:"config",action:"set",key:t,value:i}}throw p(`Unknown config action ${e}.`,"Try: forge config list, forge config set <setting> <value>, or forge config path.")}var _e={jpg:"jpeg",tif:"tiff",heif:"heic"};function T(s){let e=s.toLowerCase().replace(/^\./,""),t=Y(_e[e]??e);if(!t)throw p(`${s} is not a format Forge knows.`,"Run forge --formats to see what is available.");return t.id}function $(s){let e=Number(s);if(!Number.isInteger(e)||e<1||e>100)throw p(`Quality must be a whole number between 1 and 100, not ${s}.`);return e}function ie(s,e){let t=/^\d+$/.test(String(e))?Number(e):Number.NaN;if(!Number.isInteger(t)||t<1)throw p(`${s} takes a whole number of pixels, at least 1, not ${e}.`);return t}function we(s){let e=String(s),t=/^\d+(\.\d+)?%?$/.test(e)?Number.parseFloat(e):Number.NaN;if(!(t>=1&&t<=W))throw p(`--resize takes a percent from 1 to ${W}, not ${s}.`,"Try --resize 50% to halve, or --width 1200 for an exact width.");return t}function j(s){let e=Number(s);if(!Number.isInteger(e)||e<1)throw p(`Concurrency must be a positive whole number, not ${s}.`);return e}var ye=`
30
- Exit codes:
31
- 0 every input succeeded
32
- 1 the command was understood, and at least one input failed or was refused
33
- 2 the command itself was invalid: an unknown flag, a missing argument, contradictory flags`,xe=`
34
- Other commands:
35
- forge probe <files...> what each file is and what Forge can do with it
36
- forge palette <image> an image's main colours (--json, --svg, --inside <hex>)
37
- forge scale <colour> 50\u2013950 from one colour, with it at 500 (--json, --svg)
38
- forge clip compress the copied image and put it back (--to, --quality,
39
- --max-size, --save [folder], --undo)
40
- forge transcribe <file | link>
41
- a video or sound file, or a YouTube link, into Markdown
42
- (--to notes | transcript, --language <id>, -o <path>, --force)
43
- forge watch <folder> --to <format>
44
- convert the folder, then every file added to it, until ctrl-c
45
- (--quality, --dpi, -o <folder>, --new-only, --json)
46
- forge config [list | path | set <setting> <value>]
47
- forge extensions [add | remove <id>] optional extras, such as boost and remove-background
48
- forge update install a newer Forge, if there is one
49
- forge mcp run as a local MCP server over stdio, for AI agents`;function R(s){let e=K(String(s));if(e===void 0)throw p(`${s} is not a size.`,"Try a number with a unit, for example 500kb, 2mb or 1.5mb.");return e}function Oe(s){let e=s.slice(1).filter(n=>n!=="--json"),t=e.find(n=>n.startsWith("-"));if(t!==void 0)throw p(`forge probe takes files, not ${t}.`,"Try: forge probe photo.jpg --json");if(e.length===0)throw p("No files given.","Name a file, for example: forge probe scan.pdf --json");return{kind:"probe",inputs:e}}function Ce(s){let e={kind:"clip",undo:!1,debug:!1},t=s.slice(1),n=(i,r)=>{let o=t[r+1];if(o===void 0||o.startsWith("-"))throw p(`${i} needs a value.`);return o};for(let i=0;i<t.length;i++){let r=t[i];if(r!=="--json")if(r==="--debug")e.debug=!0;else if(r==="--undo")e.undo=!0;else if(r==="--to"||r==="-t")e.target=T(n(r,i++));else if(r==="--quality"||r==="-q")e.quality=$(n(r,i++));else if(r==="--max-size")e.maxBytes=R(n(r,i++));else if(r==="--save"){let o=t[i+1];e.save=o===void 0||o.startsWith("-")?!0:t[++i]}else throw r.startsWith("-")?p(`forge clip does not take ${r}.`,"Try: forge --help"):p(`forge clip takes no files: it reads the clipboard, not ${r}.`,`To compress a file, try: forge ${r} --quality 80`)}if(e.undo&&Object.keys(e).some(i=>!["kind","undo","debug"].includes(i)))throw p("--undo takes no other flag.","Try: forge clip --undo");if(e.quality!==void 0&&e.maxBytes!==void 0)throw p("Use either --quality or --max-size, not both.","They are two ways of asking for the same thing, and Forge will not guess which wins.");return e}function ve(s){let e=s.slice(1),t=[],n={kind:"transcribe",input:"",notes:!0,force:!1,debug:!1},i=(c,h)=>{let a=e[h+1];if(a===void 0||a.startsWith("-"))throw p(`${c} needs a value.`);return a},r="Try: forge transcribe talk.mp4";for(let c=0;c<e.length;c++){let h=e[c];if(h==="--debug")n.debug=!0;else if(h==="--force"||h==="-f")n.force=!0;else if(h==="--language"||h==="-l")n.language=i(h,c++);else if(h==="--output"||h==="-o")n.output=i(h,c++);else if(h==="--to"||h==="-t"){let a=i(h,c++).toLowerCase();if(a!=="notes"&&a!=="transcript")throw p(`forge transcribe makes notes or a transcript, not ${a}.`,"Try: forge transcribe talk.mp4 --to transcript");n.notes=a==="notes"}else{if(h.startsWith("-"))throw p(`forge transcribe does not take ${h}.`,r);t.push(h)}}let[o,...l]=t;if(o===void 0)throw p("forge transcribe needs a file or a link.",r);if(l.length>0)throw p("forge transcribe takes one file or link at a time.",r);return{...n,input:o}}function ke(s){let e=s.slice(1),t=[],n,i={kind:"watch",newOnly:!1,debug:!1},r={},o=(h,a)=>{let u=e[a+1];if(u===void 0||u.startsWith("-"))throw p(`${h} needs a value.`);return u};for(let h=0;h<e.length;h++){let a=e[h];if(a!=="--json")if(a==="--debug")i.debug=!0;else if(a==="--new-only")i.newOnly=!0;else if(a==="--to"||a==="-t")n=T(o(a,h++));else if(a==="--quality"||a==="-q")r.quality=$(o(a,h++));else if(a==="--output"||a==="-o")r.output=o(a,h++);else if(a==="--dpi"){let u=o(a,h++),d=Number(u);if(!Number.isInteger(d)||d<36||d>600)throw H(u);r.dpi=d}else{if(a.startsWith("-"))throw p(`forge watch does not take ${a}.`,"Try: forge watch ./images --to webp");t.push(a)}}let[l,...c]=t;if(l===void 0)throw p("forge watch needs a folder.","Try: forge watch ./images --to webp");if(c.length>0)throw p("forge watch watches one folder at a time.",`Try: forge watch ${l} --to webp`);if(n===void 0)throw p("forge watch needs a format to convert to.",`Try: forge watch ${l} --to webp`);return{kind:"watch",folder:l,target:n,...r.quality===void 0?{}:{quality:r.quality},...r.dpi===void 0?{}:{dpi:r.dpi},...r.output===void 0?{}:{output:r.output},newOnly:i.newOnly,debug:i.debug}}function Ae(s){let e=s.slice(1).filter(o=>o!=="--json"),t=e.find(o=>o.startsWith("-"));if(t!==void 0)throw p(`forge extensions does not take ${t}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");let[n,i,...r]=e;if(n===void 0)return{kind:"extensions",action:"list"};if(n!=="add"&&n!=="remove")throw p(`Unknown extensions action ${n}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");if(i===void 0||r.length>0)throw p(`forge extensions ${n} takes exactly one extension.`,`Try: forge extensions ${n} boost`);return{kind:"extensions",action:n,id:i}}function re(s){if(s===void 0)throw p("No colour given.","Try: forge scale 6579FD \u2014 or quote it, '#6579FD', because an unquoted # starts a comment in the shell.");let e=J(s)?.rgb;if(!e)throw p(`${s} is not a colour.`,"Try a hex code (6579FD), rgb(), hsl(), oklch() or a colour name, quoted: 'rgb(101 121 253)'.");return e}var $e={palette:`Usage: forge palette <image> [--json] [--svg] [--inside <hex>]
50
-
51
- An image's main colours, most of the image first.
52
- --json one JSON document: palette.colours[] with hex, rgb, oklch, share
53
- --svg a card of swatches; pipe to pbcopy and paste into Figma
54
- --inside <hex> the shades of the palette colour nearest <hex>
55
- `,scale:`Usage: forge scale <colour> [--json] [--svg]
56
-
57
- 50\u2013950 built in OKLCH, with <colour> at 500. Pass the hex without #, or quote it.
58
- --json one JSON document: scale.steps[] with hex, oklch, white, black
59
- --svg a card of swatches; pipe to pbcopy and paste into Figma
60
- `};function Se(s){let[e,...t]=s;if(t.includes("--help")||t.includes("-h"))throw process.stdout.write($e[e==="scale"?"scale":"palette"]),new y(0,"commander.helpDisplayed","(outputHelp)");let n=t.filter(c=>c!=="--json"&&c!=="--svg"),i=t.includes("--svg"),r=n.indexOf("--inside"),o=r===-1?void 0:n[r+1];r!==-1&&n.splice(r,2);let l=n.find(c=>c.startsWith("-"));if(l!==void 0)throw p(`forge ${e} does not take ${l}.`,`Try: forge ${e} --help`);if(e==="scale"){if(r!==-1)throw p("--inside is for forge palette.","Try: forge palette photo.jpg --inside F26E69");if(n.length>1)throw p("forge scale takes one colour.","Try: forge scale 6579FD");return{kind:"scale",colour:re(n[0]),svg:i}}if(n.length!==1)throw p(n.length===0?"No image given.":"forge palette takes one image.","Try: forge palette photo.jpg");return{kind:"palette",input:n[0],svg:i,...r===-1?{}:{inside:re(o)}}}function L(s){let e=s.indexOf("--");return(e===-1?s:s.slice(0,e)).includes("--json")}function Ee(s){let e=s.indexOf("--"),t=e===-1?s:s.slice(0,e),n=e===-1?[]:s.slice(e),i=[],r;for(let o=0;o<t.length;o++){let l=t[o],c=l.startsWith("--boost=")?l.slice(8):void 0;if(l!=="--boost"&&c===void 0){i.push(l);continue}let h=c;if(h===void 0&&/^\d+$/.test(t[o+1]??"")&&(h=t[++o]),h!==void 0&&h!=="2"&&h!=="3"&&h!=="4")throw p(`--boost takes 2, 3 or 4, not ${h}.`,"Try --boost, --boost 2, --boost 3 or --boost 4.");r=h==="4"?4:h==="3"?3:2}return{rest:[...i,...n],...r===void 0?{}:{scale:r}}}function oe(s){let e=s;if(e[0]==="clip"||e[0]==="watch"||e[0]==="transcribe"||e[0]==="config"||e[0]==="probe"||e[0]==="extensions"||e[0]==="palette"||e[0]==="scale"||e[0]==="update")return Te(e);let t=Ee(e);return Ie(t.rest,t.scale)}function Te(s){if(s[0]==="update"){let e=s.slice(1).filter(t=>t!=="--json");if(e.length>0)throw p(`forge update takes nothing else, got: ${e.join(" ")}.`,"Try: forge update");return{kind:"update"}}return s[0]==="clip"?Ce(s):s[0]==="watch"?ke(s):s[0]==="transcribe"?ve(s):s[0]==="config"?be(s.filter(e=>e!=="--json")):s[0]==="probe"?Oe(s):s[0]==="palette"||s[0]==="scale"?Se(s):Ae(s)}function Ie(s,e){let t=new A().name("forge").description("Convert \u2014 transform your files from the terminal").argument("[inputs...]","files, folders or globs").option("-t, --to <format>","target format").option("-o, --output <path>","output file or directory").option("-q, --quality <n>","quality for lossy formats, 1-100").option("--background <colour>","fill colour when flattening transparency","#ffffff").option("--keep-metadata","preserve EXIF and GPS data",!1).option("--recursive","descend into subfolders",!1).option("--force","allow overwriting existing files",!1).option("--max-size <size>","compress until the file fits, e.g. 500kb").option("--concurrency <n>","how many files to convert at once").option("--debug","show underlying errors",!1).option("--formats","list supported formats",!1).option("--merge","combine several PDFs into one").option("--split <mode>","every-page | every=N | at=N,N").option("--extract <pages>","keep only these pages, e.g. 3-7,12").option("--delete <pages>","drop these pages").option("--rotate <degrees>","90, 180 or 270").option("--separate","with --extract, write one file per page").option("--sharpen","sharpen at the same size; needs the boost extension").option("--boost [2|3|4]","sharpen and enlarge 2x (default), 3x or 4x; needs the boost extension").option("--trim","cut transparent or solid-colour edges; keeps the format").option("--crop <W:H>","cut to a shape, e.g. 1:1, 4:5, 16:9; keeps the subject").option("--resize <percent>","resize to a percent of the size, 1-200, e.g. 50%").option("--width <px>","resize to this width; the height follows").option("--height <px>","resize to this height; the width follows").option("--remove-bg","cut out the subject; needs the remove-background extension").option("--preset <name>","run a preset saved from Done, e.g. --preset blog").option("--pages <ranges>","with --to, which pages to render, e.g. 3-7,12").option("--dpi <n>","rasterisation resolution, 36-600","150").option("--password-stdin","read an encrypted PDF's password from stdin").option("--json","print one JSON document on stdout instead of text").helpOption("-h, --help","show this help").version(v,"-V, --version","show the version").addHelpText("after",`${xe}
61
- ${ye}`).configureOutput({outputError:()=>{}}).exitOverride().allowExcessArguments(!1);try{t.parse(s,{from:"user"})}catch(f){if(f instanceof y&&f.code!=="commander.helpDisplayed"&&f.code!=="commander.version"){let[m="",...b]=f.message.replace(/^error: /,"").split(`
62
- `),_=b.join(" ").trim().replace(/^\((.*)\)\.?$/,"$1");throw p(`${m.charAt(0).toUpperCase()}${m.slice(1).replace(/\.$/,"")}.`,_||"Run forge --help to see what Forge accepts.")}throw f}let n=t.opts(),i=t.args;if(n.formats)return{kind:"formats"};if(n.preset!==void 0){let f=[["to","--to"],["quality","--quality"],["maxSize","--max-size"],["merge","--merge"],["split","--split"],["extract","--extract"],["delete","--delete"],["rotate","--rotate"],["sharpen","--sharpen"],["trim","--trim"],["crop","--crop"],["resize","--resize"],["width","--width"],["height","--height"],["removeBg","--remove-bg"],["pages","--pages"]].filter(([m])=>n[m]!==void 0&&n[m]!==!1).map(([,m])=>m);if(e!==void 0&&f.push("--boost"),f.length>0)throw p(`--preset already says what to do \u2014 leave out ${f.join(" and ")}.`,"Run the preset alone, or change it from Done with \u2192 continue editing.");return{kind:"preset",inputs:i,name:String(n.preset),...n.output===void 0?{}:{output:String(n.output)},force:n.force===!0,recursive:n.recursive===!0,debug:n.debug===!0}}if(n.pages!==void 0&&n.to===void 0)throw p("--pages needs --to: it chooses which pages to render.");let r=["merge","split","extract","delete","rotate"].filter(f=>n[f]!==void 0);if(r.length>1)throw p(`Use one operation at a time \u2014 got ${r.map(f=>`--${f}`).join(" and ")}.`);let o=[...n.sharpen?["--sharpen"]:[],...e!==void 0?["--boost"]:[],...n.removeBg?["--remove-bg"]:[]],l=[...n.resize!==void 0?["--resize"]:[],...n.width!==void 0?["--width"]:[],...n.height!==void 0?["--height"]:[]];if(n.trim||n.crop!==void 0||l.length>0){if(l.length>1)throw p(`Use one of --resize, --width and --height \u2014 got ${l.join(" and ")}.`);let f=n.crop!==void 0?"--crop":l[0]??"--trim",m=[...n.crop!==void 0&&n.trim?["--trim"]:[],...o,...n.maxSize!==void 0?["--max-size"]:[],...n.pages!==void 0?["--pages"]:[],...r.map(he=>`--${he}`)][0];if(m!==void 0)throw p(`${f} cannot be combined with ${m}.`,m!=="--max-size"?"Run them one after the other.":f==="--crop"?"Crop first, then compress the result: forge photo-cropped-1x1.jpg --max-size 500kb":"Resize first, then compress the result: forge photo-1200x900.jpg --max-size 500kb");let b=n.crop!==void 0?{aspect:Q(String(n.crop))}:void 0,_=n.resize!==void 0?{percent:we(n.resize)}:n.width!==void 0?{width:ie("--width",n.width)}:n.height!==void 0?{height:ie("--height",n.height)}:void 0;if(i.length===0)throw p("No files given.","Name an image, for example: forge photo.jpg --resize 50%");let O={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(O.quality=$(String(n.quality)));let w={kind:"edit",inputs:i,trim:!!n.trim,options:O,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return b!==void 0&&(w.crop=b),_!==void 0&&(w.resize=_),n.to&&(w.target=T(String(n.to))),n.output!==void 0&&(w.output=String(n.output)),n.concurrency!==void 0&&(w.concurrency=j(String(n.concurrency))),w}let c=n.sharpen?1:e,h=c!==void 0?"boost":n.removeBg?"remove-background":null;if(h!==null){if(o.length>1)throw p(`Use one operation at a time \u2014 got ${o.join(" and ")}.`);let f=o[0];if(r.length>0)throw p(`${f} cannot be combined with --${r[0]}.`);if(n.maxSize!==void 0||n.pages!==void 0)throw p(`${f} cannot be combined with ${n.maxSize!==void 0?"--max-size":"--pages"}.`);if(i.length===0)throw p("No files given.",`Name an image, for example: forge photo.jpg ${f}`);let m=n.to?T(String(n.to)):"png";if(h==="remove-background"){let O=Z(m);if(O)throw O}let b={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(b.quality=$(String(n.quality)));let _={kind:"extension-op",op:h,inputs:i,target:m,options:b,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return c!==void 0&&(_.scale=c),n.output!==void 0&&(_.output=String(n.output)),n.concurrency!==void 0&&(_.concurrency=j(String(n.concurrency))),_}if(r.length===1){let f=r[0];if(i.length===0)throw p("No files given.",`Name a PDF, for example: forge doc.pdf --${f}`);if(n.separate&&f!=="extract")throw p(`--separate only applies to --extract, not --${f}.`);if(n.output!==void 0)throw p(`--output does not apply to --${f}.`,"Page operations name their own outputs, beside the source. Rename the result afterwards.");let m={kind:"pageop",action:f,inputs:i,force:!!n.force,debug:!!n.debug};if(f==="rotate"){let b=Number(n.rotate);if(!Number.isInteger(b)||b%90!==0||b===0||b>=360)throw p(`--rotate takes a multiple of 90 below 360, not "${n.rotate}".`);m.rotate=b}if((f==="extract"||f==="delete")&&(m.pages=String(n[f]),f==="extract"&&n.separate&&(m.separate=!0)),f==="split"){let b=String(n.split),_=b.match(/^every=(\d+)$/),O=b.match(/^at=([\d,\s]+)$/);if(b==="every-page")m.split={mode:"every-page"};else if(_?.[1]!==void 0){let w=Number(_[1]);if(!Number.isInteger(w)||w<1)throw p(`--split every=N takes a whole number of pages, at least 1, not "${_[1]}".`);m.split={mode:"every-n",n:w}}else if(O?.[1])m.split={mode:"points",after:O[1].split(",").map(w=>Number(w.trim()))};else throw p(`--split takes every-page, every=N or at=N,N \u2014 not "${b}".`)}return m}if(i.length===0&&!n.to&&n.quality===void 0&&n.maxSize===void 0)return{kind:"shell"};if(n.quality!==void 0&&n.maxSize!==void 0)throw p("Use either --quality or --max-size, not both.","They are two ways of asking for the same thing, and Forge will not guess which wins.");if(!n.to&&(n.quality!==void 0||n.maxSize!==void 0)){if(i.length===0)throw p("No files given.","Name a file, for example: forge photo.jpg --max-size 500kb");let f={background:String(n.background),keepMetadata:!!n.keepMetadata},m={kind:"compress",inputs:i,options:f,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};if(n.quality!==void 0&&(m.quality=$(String(n.quality))),n.maxSize!==void 0&&(m.maxBytes=R(n.maxSize)),n.output!==void 0&&(m.output=String(n.output)),t.getOptionValueSource("dpi")==="cli"){let b=Number(n.dpi);if(!Number.isInteger(b)||b<36||b>600)throw H(n.dpi);m.dpi=b}return n.concurrency!==void 0&&(m.concurrency=j(String(n.concurrency))),m}if(!n.to)throw p("No target format given.","Add --to <format>, for example: forge photo.jpg --to webp");if(i.length===0)throw p("No files given.","Name a file, a folder or a glob, for example: forge photo.jpg --to webp");let a={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(a.quality=$(String(n.quality)));let u=Number(n.dpi);if(!Number.isInteger(u)||u<36||u>600)throw H(n.dpi);let d={kind:"convert",inputs:i,target:T(String(n.to)),options:a,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug,dpi:u,passwordStdin:!!n.passwordStdin};return n.output!==void 0&&(d.output=String(n.output)),n.pages!==void 0&&(d.pages=String(n.pages)),n.maxSize!==void 0&&(d.maxBytes=R(n.maxSize)),n.concurrency!==void 0&&(d.concurrency=j(String(n.concurrency))),d}function U(s){return I(s)?s:X(s)}function se(s,e){return N(U(s),{debug:e})}function ae(s,e){process.once("beforeExit",()=>{s()||(e(new Error("Forge stopped before it finished: it was waiting for input that never came.")),process.exitCode=1)})}ue.enableCompileCache?.();function He({completed:s,total:e}){s===0?process.stderr.write(`Converting ${e} files
63
- `):process.stderr.write(` ${s}/${e}
64
- `)}async function Ne(){let s=process.argv.slice(2),e=s.includes("--debug"),t=L(s);try{if(s[0]==="__update-check"){let{checkNow:u}=await import("./chunks/check-INHBJOBB.js");await u();return}if(s[0]==="mcp"){let{runMcpServer:u}=await import("./chunks/server-RM4YA6UL.js");await u(s.slice(1));return}let n=oe(s);if(n.kind==="shell"){if(t)throw p("No files given.","Name a file, for example: forge photo.jpg --to webp --json");if(!process.stdout.isTTY||!process.stdin.isTTY){process.stderr.write(`Forge needs a file and a target format.
4
+ import{b as w,d as C}from"./chunks/chunk-IBPGC4N2.js";import{f as x}from"./chunks/chunk-EHARO6IS.js";import"./chunks/chunk-PSEIJXGT.js";import{c as b,d as S}from"./chunks/chunk-MKVBI37R.js";import"./chunks/chunk-U5TEGDGH.js";import"./chunks/chunk-QVACE4IE.js";import"./chunks/chunk-HZDYZ5RD.js";import"./chunks/chunk-QR6QHTC3.js";import"./chunks/chunk-6L6C3GJU.js";import"./chunks/chunk-EEQSUBBL.js";import"./chunks/chunk-YYB3TTGT.js";import"./chunks/chunk-KAHWYWNT.js";import"./chunks/chunk-SMBK6BTC.js";import"./chunks/chunk-EXLXSKRH.js";import{F as $,d as f,ma as E,na as m}from"./chunks/chunk-3UEQ2OX6.js";import"./chunks/chunk-J7FLFHQJ.js";import"./chunks/chunk-LDKF7KIZ.js";import{a as c}from"./chunks/chunk-EGIKV2GZ.js";import"./chunks/chunk-AAXBN572.js";import"./chunks/chunk-HON4OV7M.js";import"./chunks/chunk-M66BUNYO.js";import"./chunks/chunk-TMUK2DD3.js";import*as F from"node:module";function v(e){return f(e)?e:E(e)}function k(e,n){return m(v(e),{debug:n})}function T(e,n){process.once("beforeExit",()=>{e()||(n(new Error("Forge stopped before it finished: it was waiting for input that never came.")),process.exitCode=1)})}F.enableCompileCache?.();function B({completed:e,total:n}){e===0?process.stderr.write(`Converting ${n} files
5
+ `):process.stderr.write(` ${e}/${n}
6
+ `)}async function I(){let e=process.argv.slice(2),n=e.includes("--debug"),p=b(e);try{if(e[0]==="__update-check"){let{checkNow:r}=await import("./chunks/check-KAR72Y4X.js");await r();return}if(e[0]==="menu"){let{openedFor:r,parseMenuArgs:t}=await import("./chunks/command-I5M275ZV.js"),s=t(e.slice(1));if(s.kind==="open"){let{applyColourPreference:h}=await import("./chunks/theme-WGCMV4T4.js");h();let{bootShell:A}=await import("./chunks/boot-HVIAAJMY.js");await A(void 0,{opened:r(s.action,s.paths)});return}let{runMenuCommand:a}=await import("./chunks/entry-26YSXWT4.js");process.exitCode=await a(s,c);return}if(e[0]==="mcp"){let{runMcpServer:r}=await import("./chunks/server-OAJFUZDM.js");await r(e.slice(1));return}let o=S(e);if(o.kind==="shell"){if(p)throw $("No files given.","Name a file, for example: forge photo.jpg --to webp --json");if(!process.stdout.isTTY||!process.stdin.isTTY){process.stderr.write(`Forge needs a file and a target format.
65
7
  Try: forge photo.jpg --to webp
66
- `),process.exitCode=2;return}let{applyColourPreference:u}=await import("./chunks/theme-LR72ACFF.js");u();let{bootShell:d}=await import("./chunks/boot-IQ4NYHEG.js");await d();return}if(n.kind==="watch"){let{runWatch:u}=await import("./chunks/watch-command-NU7QY6QU.js"),d=new AbortController;process.once("SIGINT",()=>d.abort()),process.exitCode=await u(n,{out:f=>process.stdout.write(`${f}
67
- `),json:t,signal:d.signal});return}let{execute:i}=await import("./chunks/execute-B7UL5RCU.js"),r,o=0,l=(u,d)=>{let f=Date.now();if(u<d&&f-o<100)return;o=f;let m=b=>(b/1e6).toFixed(1);process.stderr.write(`\r downloading ${m(u)} / ${m(d)} MB${u>=d?`
68
- `:""}`)},c=!!process.stderr.isTTY&&!t,h=new AbortController;n.kind==="extension-op"&&process.once("SIGINT",()=>h.abort());let a=await i(n,{json:t,...c?{onInstalling:u=>{r=q(process.stderr,`installing Forge ${u}`)}}:{},signal:h.signal,...c?{onDownload:l}:{},colour:!!process.stdout.isTTY&&!t&&B(),onProgress:c?u=>{u.completed>0&&r?.stop(),He(u)}:void 0,...c?{onSearch:u=>{r??=q(process.stderr,"finding the smallest that fits"),r.update(u)}}:{}});if(r?.stop(),a.stdout.length>0&&process.stdout.write(`${a.stdout.join(`
8
+ `),process.exitCode=2;return}let{applyColourPreference:r}=await import("./chunks/theme-WGCMV4T4.js");r();let{bootShell:t}=await import("./chunks/boot-HVIAAJMY.js");await t(void 0,{menuNote:async()=>(await import("./chunks/entry-26YSXWT4.js")).menuAtStart(c)});return}if(o.kind==="watch"){let{runWatch:r}=await import("./chunks/watch-command-HOG4TM3X.js"),t=new AbortController;process.once("SIGINT",()=>t.abort()),process.exitCode=await r(o,{out:s=>process.stdout.write(`${s}
9
+ `),json:p,signal:t.signal});return}if(o.kind==="uninstall"){let{runUninstall:r}=await import("./chunks/entry-26YSXWT4.js");process.exitCode=await r(c,t=>process.stdout.write(`${t}
10
+ `));return}let{execute:l}=await import("./chunks/execute-GSC2NMDW.js"),i,y=0,P=(r,t)=>{let s=Date.now();if(r<t&&s-y<100)return;y=s;let a=h=>(h/1e6).toFixed(1);process.stderr.write(`\r downloading ${a(r)} / ${a(t)} MB${r>=t?`
11
+ `:""}`)},d=!!process.stderr.isTTY&&!p,g=new AbortController;o.kind==="extension-op"&&process.once("SIGINT",()=>g.abort());let u=await l(o,{json:p,...d?{onInstalling:r=>{i=w(process.stderr,`installing Forge ${r}`)}}:{},signal:g.signal,...d?{onDownload:P}:{},colour:!!process.stdout.isTTY&&!p&&C(),onProgress:d?r=>{r.completed>0&&i?.stop(),B(r)}:void 0,...d?{onSearch:r=>{i??=w(process.stderr,"finding the smallest that fits"),i.update(r)},onEncode:r=>{i??=w(process.stderr,"encoding"),i.update(r)}}:{}});if(i?.stop(),u.stdout.length>0&&process.stdout.write(`${u.stdout.join(`
69
12
  `)}
70
- `),a.stderr.length>0&&process.stderr.write(`${a.stderr.join(`
13
+ `),u.stderr.length>0&&process.stderr.write(`${u.stderr.join(`
71
14
  `)}
72
- `),process.exitCode=h.signal.aborted?130:a.exitCode,c&&process.stdout.isTTY&&n.kind!=="update")try{let{afterCommand:u,spawnRefresh:d}=await import("./chunks/update-note-UH2TQPJ6.js"),{runningScript:f}=await import("./chunks/install-WBAFPZ2Q.js"),m=await u(v,{refresh:()=>d(f(process.argv[1])),colour:B()});m.length>0&&process.stderr.write(`
73
- ${m.join(`
15
+ `),process.exitCode=g.signal.aborted?130:u.exitCode,d&&process.stdout.isTTY&&o.kind!=="update")try{let{afterCommand:r,spawnRefresh:t}=await import("./chunks/update-note-6YGNGYUB.js"),{runningScript:s}=await import("./chunks/install-V62EEK54.js"),a=await r(c,{refresh:()=>t(s(process.argv[1])),colour:C()});a.length>0&&process.stderr.write(`
16
+ ${a.join(`
74
17
  `)}
75
- `)}catch{}}catch(n){if(I(n)){t?process.stdout.write(`${JSON.stringify(G(v,n))}
76
- `):process.stderr.write(`${N(n,{debug:e}).join(`
18
+ `)}catch{}}catch(o){if(f(o)){p?process.stdout.write(`${JSON.stringify(x(c,o))}
19
+ `):process.stderr.write(`${m(o,{debug:n}).join(`
77
20
  `)}
78
- `),process.exitCode=2;return}if(n instanceof Error&&"code"in n&&"exitCode"in n){let i=n.code;process.exitCode=i==="commander.helpDisplayed"||i==="commander.version"?0:2;return}throw n}}function le(s){let e=process.argv.slice(2);if(L(e)){process.stdout.write(`${JSON.stringify(G(v,U(s)))}
79
- `);return}process.stderr.write(`${se(s,e.includes("--debug")).join(`
21
+ `),process.exitCode=2;return}if(o instanceof Error&&"code"in o&&"exitCode"in o){let l=o.code;process.exitCode=l==="commander.helpDisplayed"||l==="commander.version"?0:2;return}throw o}}function j(e){let n=process.argv.slice(2);if(b(n)){process.stdout.write(`${JSON.stringify(x(c,v(e)))}
22
+ `);return}process.stderr.write(`${k(e,n.includes("--debug")).join(`
80
23
  `)}
81
- `)}var ce=!1;ae(()=>ce,le);try{await Ne()}catch(s){le(s),process.exitCode=1}finally{ce=!0}export{v as VERSION};
24
+ `)}var N=!1;T(()=>N,j);try{await I()}catch(e){j(e),process.exitCode=1}finally{N=!0}export{c as VERSION};
package/package.json CHANGED
@@ -1,33 +1,27 @@
1
1
  {
2
2
  "name": "forge-terminal",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "A terminal-native file converter for macOS and Windows",
5
5
  "whatsNew": [
6
- {"title": "Transcribe", "text": "Turn a video, a sound file or a YouTube link into notes and a transcript, on your Mac. Press 6 on home, or run forge transcribe."},
7
- {"title": "/ menu moved", "text": "It now sits above the keys, on the right. Type / to open it, as before."},
8
6
  {
9
- "title": "Watch a folder",
10
- "text": "Drop a folder on Convert. Forge converts what is in it, then each new file that lands there. In a terminal: forge watch."
7
+ "title": "Video and audio",
8
+ "text": "Convert, compress and edit video and audio files. The first time, Forge installs its own ffmpeg for you, in place."
11
9
  },
12
10
  {
13
- "title": "Presets",
14
- "text": "On Done, press p to save what you did. Run it on any file with forge photo.png --preset name."
11
+ "title": "Find a file by name",
12
+ "text": "Type part of a name and Forge finds the file on your Mac, newest first. macOS asks once to allow it."
15
13
  },
16
14
  {
17
- "title": "Continue editing",
18
- "text": "On Done, → adds more steps to the same file without starting over."
15
+ "title": "Supported formats",
16
+ "text": "On home, press Tab to see which files each mode takes."
19
17
  },
20
18
  {
21
- "title": "Paste an image",
22
- "text": "Copy an image anywhere, then press ⌘V on home. The result goes back on the clipboard."
19
+ "title": "Right-click in Finder",
20
+ "text": "Right-click a file in Finder or Explorer to open it in Forge. Switch it off any time with /right-click."
23
21
  },
24
22
  {
25
- "title": "Smaller PNG and GIF",
26
- "text": "Compress can now shrink PNGs and GIFs much further, and never makes a file bigger."
27
- },
28
- {
29
- "title": "Enhance is now Edit",
30
- "text": "Same six tools, a name that fits them all."
23
+ "title": "/ menu, as a popup",
24
+ "text": "Type / for a menu that opens over home: the modes, and the settings, each a keystroke away."
31
25
  }
32
26
  ],
33
27
  "keywords": [
@@ -1,3 +0,0 @@
1
- import { createRequire as __forgeCreateRequire } from 'node:module';
2
- const require = __forgeCreateRequire(import.meta.url);
3
- import{r as l}from"./chunk-MHW4OOQW.js";import{f as a}from"./chunk-5GJK5LP5.js";import"./chunk-HON4OV7M.js";import"./chunk-BXJ2HTKI.js";import"./chunk-TMUK2DD3.js";var i={loadPreferences:a,loadShell:()=>import("./launch-RM5ZVXSU.js")};async function p(e=i){let o=e.loadShell();o.catch(()=>{});let{prefs:t,warning:r}=await e.loadPreferences(),n=l(t.theme),{launchShell:s}=await o;await s({prefs:t,palette:n,...r===void 0?{}:{warning:r}})}export{p as bootShell};
@@ -1,3 +0,0 @@
1
- import { createRequire as __forgeCreateRequire } from 'node:module';
2
- const require = __forgeCreateRequire(import.meta.url);
3
- import{b as t}from"./chunk-4LTI6JHW.js";import{spawnSync as n}from"node:child_process";var r=!1;function c(){r=!0}function p(){return r}function u(){let e=t(process.argv[1]);if(e===void 0)return;let o=n(process.execPath,[...process.execArgv,e],{stdio:"inherit"});process.exitCode=o.status??0}export{c as a,p as b,u as c};
@@ -1,3 +0,0 @@
1
- import { createRequire as __forgeCreateRequire } from 'node:module';
2
- const require = __forgeCreateRequire(import.meta.url);
3
- import{a as M,b as j,e as S,i as P}from"./chunk-XNNTF6FW.js";import{a as E,c as w}from"./chunk-JBSYGB3F.js";import{watch as k}from"node:fs";import{readdir as I,stat as W}from"node:fs/promises";import{join as z,resolve as x}from"node:path";function A(e,o,n){let r=x(e),c=n.settleMs??1e3,d=n.pollMs??500,s=new Set([...o].map(m=>x(m))),l=new Map,t=!1,i=!1,g=!1,p=async()=>{if(!t){if(i){g=!0;return}i=!0;try{let m=await I(r,{withFileTypes:!0}).catch(()=>[]),h=new Set;for(let a of m){if(!a.isFile()||M(a.name))continue;let f=z(r,a.name);if(h.add(f),s.has(f)||n.ignore?.(f))continue;let y=await W(f).catch(()=>{});if(!y||t)continue;let F=Date.now(),b=l.get(f);if(!b||b.size!==y.size||b.mtimeMs!==y.mtimeMs){l.set(f,{size:y.size,mtimeMs:y.mtimeMs,since:F});continue}F-b.since<c||(l.delete(f),s.add(f),n.onFile(f))}for(let a of[...s,...l.keys()])h.has(a)||(s.delete(a),l.delete(a))}finally{i=!1,g&&!t&&(g=!1,p())}}},v=setInterval(()=>{p()},d),u;try{u=k(r,{persistent:!1},()=>{p()}),u.on("error",()=>{})}catch{}return p(),{close(){t=!0,clearInterval(v),u?.close()}}}function K(e,o,n,r){let c=[],d=[];for(let s of e){let l=o[j(s)];if(!l){d.push({path:s.path,reason:R(o)});continue}let t=P(s,l,n,r);"job"in t?c.push(t.job):d.push({path:s.path,reason:t.left})}return{jobs:c,left:d}}async function G(e,o,n={}){let r=new Set,{jobs:c,left:d}=K(e.sources,o,r,n.destination);return{outcome:await w(c,{force:!1,...n.concurrency===void 0?{}:{concurrency:n.concurrency},...n.onEvent?{onEvent:n.onEvent}:{},...n.signal?{signal:n.signal}:{}}),left:d,claimed:r,jobs:c}}var O={images:"an image",pdfs:"a PDF",documents:"a document",videos:"a video",audio:"audio",other:"a file Forge reads"};function R(e){let o=Object.keys(e).filter(r=>e[r]);if(o.length===0)return"not supported";let n=o.map(r=>O[r]);return`not ${n.length===1?n[0]:`${n.slice(0,-1).join(", ")} or ${n.at(-1)}`}`}var J=(e,o)=>e==="other"?o==="text"?"a text file":"not supported":"not yet supported";function H(e){let o=E(e.concurrency),n=[],r=new Set,c=!1,d=async t=>{e.onEvent({type:"arrived",path:t}),e.onEvent({type:"phase",path:t,phase:"reading"});let i=await S(t);if(i.kind==="failed"){e.onEvent({type:"failed",path:t,error:i.failure.error});return}if(i.kind!=="source"){e.onEvent({type:"left",path:t,reason:J(i.kind,i.sniffed)});return}let{jobs:g,left:p}=K([i.source],e.answers,e.claimed,e.destination),[v]=p;if(v){e.onEvent({type:"left",path:t,reason:v.reason});return}let u=await w(g,{force:!1,concurrency:1,onEvent:a=>{a.type==="job:phase"&&"phase"in a.progress&&a.progress.phase!=="page"&&e.onEvent({type:"phase",path:t,phase:a.progress.phase,job:a.job})}}),[m]=u.results,h=[...u.refusals,...u.failures][0];m?e.onEvent({type:"converted",path:t,result:m}):h&&e.onEvent({type:"failed",path:t,error:h.error})},s=()=>{for(;!c&&r.size<o&&n.length>0;){let t=n.shift(),i=d(t).catch(()=>{}).finally(()=>{r.delete(i),s()});r.add(i)}},l=A(e.dir,e.known,{...e.settleMs===void 0?{}:{settleMs:e.settleMs},...e.pollMs===void 0?{}:{pollMs:e.pollMs},ignore:t=>e.claimed.has(t),onFile:t=>{n.push(t),s()}});return{async stop(){c=!0,l.close(),n.length=0,await Promise.all([...r])}}}export{K as a,G as b,H as c};
@@ -1,4 +0,0 @@
1
- import { createRequire as __forgeCreateRequire } from 'node:module';
2
- const require = __forgeCreateRequire(import.meta.url);
3
- import{a as N,b as se,c as ne,d as ae,e as ie,k as ue,l as pe,m as ce,o as de,p as fe}from"./chunk-PGG2OTK6.js";import{e as C}from"./chunk-FWMFN36F.js";import{a as y}from"./chunk-6TERL22R.js";import{c as I}from"./chunk-JBSYGB3F.js";import{a as oe,b as E}from"./chunk-HCN4BH2H.js";import{e as Q}from"./chunk-CBE73ZWA.js";import{a as $,c as U,d as Y,e as F,f as K}from"./chunk-IMC5NRDC.js";import{e as X,f as Z,g as _,h as ee,i as te,j as re}from"./chunk-EHARO6IS.js";import{e as V}from"./chunk-6VOCIMXQ.js";import{n as H,p as L}from"./chunk-D6JPP65L.js";import{a as g}from"./chunk-MHW4OOQW.js";import{F as J,G as q,J as z,b as x,c as w,d as v,la as G,p as D,r as R,t as W,w as O}from"./chunk-DW2EJIUX.js";import{a as h,b as A}from"./chunk-J7FLFHQJ.js";import{a as k}from"./chunk-BXJ2HTKI.js";import{readFile as Be}from"node:fs/promises";import{dirname as ke,resolve as Se}from"node:path";async function le(e){let r=[],t=[...e.resolved.failures];for(let o of e.resolved.sources){let s=$(o);if(!s.includes(e.target)){t.push({path:o.path,error:W(o,e.target,s)});continue}let n=E({sourcePath:o.path,target:e.target,output:e.output,sourceRoot:e.resolved.roots.get(o.path)});r.push({op:"convert",sources:[o],outputs:[n],target:e.target,options:e.options})}return{jobs:r,failures:t}}import{resolve as Re}from"node:path";function $e(e,r=new Set){let t={path:Re(e.path),kind:e.kind,format:e.format,bytes:e.bytes},o=e.kind==="document"&&e.encrypted===!0,s={targets:$(e).filter(n=>!o||F(n)),actions:de([e],r).filter(n=>!o||n.id===C.id).map(n=>n.id)};return e.kind==="image"?{...t,width:e.width,height:e.height,...s}:{...t,pages:e.pages,encrypted:e.encrypted,...s}}async function me(e){let r=await y(e,{recursive:!1}),{installedExtensionIds:t}=await import("./available-HYL2YE56.js"),o=await t();return{probes:r.sources.map(s=>$e(s,o)),failures:r.failures}}import{dirname as Fe}from"node:path";var B=e=>({cwd:e.cwd??process.cwd(),...e.home===void 0?{}:{home:e.home}});function ge(e,r){let t=x(Fe(e),B(r));return t==="."?"":` in ${t.endsWith("/")?t:`${t}/`}`}function he(e,r){let{pct:t,direction:o}=A(e,r);return o==="same"?"same size":`${t}% ${o}`}function ye(e,r={}){let t=e.results[0];if(!t)return[];let o=t.job.sources[0],s=t.job.outputs;if(s.length>1){let a=[`\u2713 ${w(o.path)} \u2192 ${s.length} files${ge(s[0],r)}`,` ${s.map(i=>w(i)).join(", ")}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} total`];for(let i of t.warnings)a.push("",`\u26A0 ${i.message}`);return a}let n=[`\u2713 ${w(o.path)} \u2192 ${x(s[0],B(r))}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} \xB7 ${he(o.bytes,t.outputBytes)}`];for(let a of t.warnings)n.push("",`\u26A0 ${a.message}`);return n}function be(e,r={}){let t=[`\u2713 ${e.results.length} converted`,` ${h(e.inputBytes)} \u2192 ${h(e.outputBytes)} \xB7 ${he(e.inputBytes,e.outputBytes)}`];for(let s of e.results)for(let n of s.job.outputs)t.push(` ${x(n,B(r))}`);let o=e.results.flatMap(s=>s.warnings);if(o.length>0){t.push("");for(let s of o)t.push(`\u26A0 ${s.message}`)}return t}function we(e,r={}){let t=e.results.flatMap(u=>u.job.outputs),o=t.map(u=>w(u)).join(", "),s=t.length===1?"file":"files",n=t[0]===void 0?"":ge(t[0],r),a=[`\u2713 ${t.length} ${s} \xB7 ${o}${n}`],i=e.results.flatMap(u=>u.warnings);for(let u of i)a.push("",`\u26A0 ${u.message}`);return a}function S(e,r){if(e.length===0)return[];let t=[];for(let o of e)t.push(...G(o.error,{debug:r.debug}),"");return t}function Ie(){let e=new Set(U()),r=new Set(Y()),t=["Formats",""];for(let s of e){let n=k[s],a=r.has(s)?"read and write":"read only";t.push(` ${n.label.padEnd(6)} ${n.extensions.join(" ").padEnd(12)} ${a}`)}let o=[...e].filter(s=>!r.has(s)).map(s=>k[s].label);if(o.length>0){let s=o.join(", "),[n,a]=o.length===1?["is","it"]:["are","them"];t.push("",`${s} ${n} read only because Forge cannot yet write ${a}.`)}return t}function Pe(e,r={}){let t=[k[e.format].label,h(e.bytes)];return e.width!==void 0&&e.height!==void 0&&t.push(`${e.width}\xD7${e.height}`),e.pages!==void 0&&t.push(`${e.pages} ${e.pages===1?"page":"pages"}`),e.encrypted&&t.push("password-protected"),[`${x(e.path,B(r))} \xB7 ${t.join(" \xB7 ")}`,` converts to ${e.targets.join(", ")}`,` actions ${e.actions.join(", ")}`]}import{createInterface as xe}from"node:readline";import{PassThrough as Ee}from"node:stream";function Ce(e){return new Promise(r=>{let t=xe({input:e,terminal:!1}),o=!1,s=n=>{if(o)return;o=!0,t.close(),e.pause(),e.unref?.(),r(n.replace(/\r$/,""))};t.once("line",s),t.once("close",()=>s(""))})}async function ve(e){if(e.stdin)return Ce(process.stdin);if(!process.stdin.isTTY)return;let r=new Ee,t=xe({input:process.stdin,output:r,terminal:!0});try{return process.stderr.write("Password: "),await new Promise(o=>t.question("",o))}finally{process.stderr.write(`
4
- `),t.close()}}function T(e){return e.length===0?0:e.some(r=>r.error.code==="invalid-arguments")?2:1}function je(e,r){if(e.action==="merge")return{};if(e.action==="rotate")return{degrees:e.rotate};if(e.action==="extract")return{pages:e.pages,separate:e.separate?"many":"one"};if(e.action==="delete")return{pages:e.pages};let t=r.find(a=>a.kind==="document"),o=t?.pages??0,s=e.split;if(!s)throw J("--split needs a mode: every-page, every=N or at=N,N.");if(s.mode==="every-page")return{cuts:ue(o)};if(s.mode==="every-n")return{cuts:pe(o,s.n)};let n=Math.max(o-1,0);for(let a of s.after)if(!Number.isInteger(a)||a<1||a>n)throw q(String(a),`"${a}" is outside 1 and ${n} \u2014 ${t?w(t.path):"the document"} has ${o} pages.`,o);return{cuts:s.after.map(a=>a-1)}}function Oe(e,r){let t;return()=>r?(t??=ve({stdin:e}).then(o=>e&&o===""?void 0:o),t):Promise.resolve(void 0)}async function Je(e,r,t,o){let s;if(e.encrypted){if(s=r.password??await t(),s===void 0)return{failure:{path:e.path,error:O(e.path)}};let i;try{i=await V(await Be(e.path),s)}catch{return{failure:{path:e.path,error:O(e.path,{attempted:!0})}}}i.destroy()}let n;try{n=C.plan([e],{target:r.target,background:r.options.background,keepMetadata:r.options.keepMetadata,dpi:String(r.dpi??150),...r.options.quality===void 0?{}:{quality:r.options.quality},...r.pages===void 0?{}:{pages:r.pages},...r.output===void 0?{}:{destination:r.output},...o===void 0?{}:{sourceRoot:o}})}catch(i){if(!v(i))throw i;return{failure:{path:e.path,error:i}}}let a=n[0];if(a?.op!=="convert")throw new Error(`convertAction.plan() did not return a convert job for ${e.path}`);return s!==void 0&&(a.options.password=s),{job:a}}function j(e,r){return t=>{if(t.type==="search:attempt"){r||e.onSearch?.(t.rung.dpi===void 0?`attempt ${t.attempt} of ${t.of}`:`${t.rung.dpi} dpi \xB7 attempt ${t.attempt} of ${t.of}`);return}if(t.type==="search:settled"){r&&e.onSearch?.(`${t.completed} of ${t.total} searched`);return}r&&(t.type==="job:done"||t.type==="job:error")&&e.onProgress?.({completed:t.completed,total:t.total})}}var b=(e,r)=>({kind:e,results:[],failures:r,inputBytes:0,outputBytes:0});async function Ne(e){let r=await y(e.inputs,{recursive:!1});if(r.sources.length===0)return b("pageop",r.failures);let t=ce.find(a=>a.id===e.action);if(!t)throw new Error(`no action registered for "${e.action}"`);let o=r.sources[0]?.path??"";if(!t.appliesTo(r.sources)){let a=fe(t,r.sources)??"not available for these files";return b("pageop",[...r.failures,{path:o,error:R(e.action,a)}])}let s;try{s=t.plan(r.sources,je(e,r.sources))}catch(a){if(!v(a))throw a;return b("pageop",[...r.failures,{path:o,error:a}])}let n=await I(s,{force:e.force});return{kind:"pageop",results:n.results,failures:[...r.failures,...n.refusals,...n.failures],inputBytes:n.inputBytes,outputBytes:n.outputBytes}}async function Te(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let i of t.sources){if(!N.appliesTo([i])){s.push({path:i.path,error:D(i)});continue}let u=e.output!==void 0&&!oe(e.output)?Se(e.output):void 0,c=e.output===void 0||u!==void 0?ke(i.path):ke(E({sourcePath:i.path,target:i.format,output:e.output,sourceRoot:t.roots.get(i.path)})),[p]=N.plan([i],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},destination:c});p?.op==="convert"&&(u!==void 0&&(p.outputs=[u]),e.dpi!==void 0&&(p.options.dpi=e.dpi),o.push(p))}let n=o.length>1;n&&r.onProgress?.({completed:0,total:o.length});let a=await I(o,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:j(r,n)});return{kind:"compress",results:a.results,failures:[...t.failures,...s,...a.refusals,...a.unreachable.map(i=>({path:i.job.sources[0].path,error:i.error})),...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function Me(e,r){let t=e.kind,o=e.op==="remove-background"?H(e.target):void 0;if(o)return b(t,[{path:"",error:o}]);let{installed:s}=await import("./paths-KTXPDCDD.js"),n=await s(e.op);if(!n)return b(t,[{path:"",error:z(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:l,catalogEntry:f}=await import("./catalog-U7IF2BH2.js"),d=f("boost"),P=d&&l(d)?.version,M=L(e.scale,n.version,P);if(M)return b(t,[{path:"",error:M}])}let a=await y(e.inputs,{recursive:e.recursive}),i=e.op==="boost"?ne:ae,u=[],c=[];for(let l of a.sources){if(!i.appliesTo([l])){c.push({path:l.path,error:R(e.op,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});continue}let f=se(l,e.target);if(f){c.push({path:l.path,error:f});continue}u.push(...i.plan([l],{target:e.target,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.scale===void 0?{}:{scale:e.scale},...e.options.quality===void 0?{}:{quality:e.options.quality},...e.output===void 0?{}:{output:e.output},roots:a.roots}))}let p=u.length>1;p&&r.onProgress?.({completed:0,total:u.length});let m=await I(u,{force:e.force,concurrency:1,...r.signal===void 0?{}:{signal:r.signal},onEvent:j(r,p)});return{kind:t,results:m.results,failures:[...a.failures,...c,...m.refusals,...m.failures],inputBytes:m.inputBytes,outputBytes:m.outputBytes}}async function Ae(e,r){let t=e.crop!==void 0?"crop":e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:Q(e.target,t);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),n=[],a=[];for(let p of s.sources)p.kind==="image"?n.push(p):a.push({path:p.path,error:R(t,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});let i=ie(n,{trim:e.trim,...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.options.quality===void 0?{}:{quality:e.options.quality}}),u=i.length>1;u&&r.onProgress?.({completed:0,total:i.length});let c=await I(i,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:j(r,u)});return{kind:e.kind,results:c.results,failures:[...s.failures,...a,...c.refusals,...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function De(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=d=>d.kind==="document"&&d.format==="pdf",s=F(e.target),n=s?t.sources.filter(o):[],a=s?t.sources.filter(d=>!o(d)):t.sources,i=[],u=[],c=Oe(e.passwordStdin??!1,r.interactive??!0);for(let d of n){let P=await Je(d,e,c,t.roots.get(d.path));"failure"in P?u.push(P.failure):i.push(P.job)}let p=await le({resolved:{sources:a,failures:[],roots:t.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),m=[...p.jobs,...i],l=m.length>1;l&&r.onProgress?.({completed:0,total:m.length});let f=await I(m,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:j(r,l)});return{kind:"convert",results:f.results,failures:[...t.failures,...u,...p.failures,...f.refusals,...f.unreachable.map(d=>({path:d.job.sources[0].path,error:d.error})),...f.failures],inputBytes:f.inputBytes,outputBytes:f.outputBytes}}async function We(e,r={}){try{if(e.kind==="pageop")return await Ne(e);if(e.kind==="extension-op")return await Me(e,r);if(e.kind==="edit")return await Ae(e,r);if(e.kind==="preset"){let{runPresetCommand:t}=await import("./preset-command-AXYFLVYA.js");return await t(e)}return e.kind==="compress"?await Te(e,r):await De(e,r)}catch(t){if(!v(t))throw t;return b(e.kind,[{path:"",error:t}])}}function qe(e,r){let t=T(e.failures);if(r.json)return{exitCode:t,stdout:[JSON.stringify(X(g,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?we(e):e.results.length===1?ye(e):be(e);return{exitCode:t,stdout:o,stderr:S(e.failures,{debug:r.debug})}}function ze(e,r){let t=[{path:"",error:e}],o=T(t);return r.json?{exitCode:o,stdout:[JSON.stringify(Z(g,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:S(t,{debug:r.debug})}}async function Ge(e,r){let{runConfig:t}=await import("./config-command-R7QOBYF4.js"),o=await t(e);return r?{exitCode:0,stdout:[JSON.stringify(te(g,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function Bt(e,r={}){let t=r.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Ge(e,t);if(e.kind==="clip"){let{runClipCommand:s}=await import("./clip-command-Q6SLD4U4.js");return await s(e,{...r,json:t,debug:o})}if(e.kind==="update"){let{runUpdate:s}=await import("./update-command-2SHKIIQD.js"),n=await s(g,{...r.onInstalling?{onInstalling:r.onInstalling}:{}});return{exitCode:0,stdout:t?[JSON.stringify({forge:g,ok:!0,...n.data})]:n.stdout,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:s}=await import("./extensions-command-AITZYSMM.js"),n=await s(e,{onDownload:r.onDownload});return{exitCode:0,stdout:t?[JSON.stringify(re(g,n.data))]:n.stdout,stderr:[]}}if(e.kind==="formats")return t?{exitCode:0,stdout:[JSON.stringify(_(g,K()))],stderr:[]}:{exitCode:0,stdout:Ie(),stderr:[]};if(e.kind==="probe"){let{probes:s,failures:n}=await me(e.inputs),a=T(n);return t?{exitCode:a,stdout:[JSON.stringify(ee(g,{probes:s,failures:n}))],stderr:[]}:{exitCode:a,stdout:s.flatMap((i,u)=>[...u>0?[""]:[],...Pe(i)]),stderr:S(n,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"){let{runPalette:s,runScale:n}=await import("./colour-JPG24QYI.js"),a={json:t,colour:r.colour??!1};return e.kind==="palette"?await s(e,a):await n(e,a)}if(e.kind==="transcribe"){let{runTranscribeCommand:s}=await import("./transcribe-command-6YTLVSMW.js"),n=[],a=[];return{exitCode:await s(e,{out:u=>n.push(u),err:u=>a.push(u)}),stdout:n,stderr:a}}if(e.kind==="shell")return{exitCode:0,stdout:[],stderr:[]};if(e.kind==="watch")throw J("forge watch runs in a terminal until ctrl-c.","Try: forge watch ./images --to webp");return qe(await We(e,r),{json:t,debug:o})}catch(s){if(!v(s))throw s;return ze(s,{json:t,debug:o})}}export{me as a,he as b,T as c,We as d,qe as e,Bt as f};