forge-terminal 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -10
- package/dist/chunks/available-QN6QAGCU.js +3 -0
- package/dist/chunks/boot-ISMRSTLL.js +3 -0
- package/dist/chunks/catalog-O3V24DK7.js +3 -0
- package/dist/chunks/check-DN7SEN44.js +3 -0
- package/dist/chunks/chunk-4L6HNYSN.js +4 -0
- package/dist/chunks/{chunk-XFEHJ4C7.js → chunk-6ZEGAH36.js} +1 -1
- package/dist/chunks/chunk-775ILWZI.js +3 -0
- package/dist/chunks/chunk-CKWYIU2N.js +4 -0
- package/dist/chunks/{chunk-G2D6BKOS.js → chunk-CXVYIBCA.js} +2 -2
- package/dist/chunks/chunk-E5QDHFKQ.js +3 -0
- package/dist/chunks/{chunk-VH5RWPGZ.js → chunk-GDQQDHXJ.js} +2 -2
- package/dist/chunks/chunk-HON4OV7M.js +3 -0
- package/dist/chunks/chunk-IBPGC4N2.js +3 -0
- package/dist/chunks/chunk-LI2JPLF7.js +3 -0
- package/dist/chunks/{chunk-5B7WODWH.js → chunk-M6LD6DHO.js} +1 -1
- package/dist/chunks/chunk-NY6BX7QS.js +5 -0
- package/dist/chunks/chunk-OIZCRBLT.js +3 -0
- package/dist/chunks/chunk-Q45MSMTN.js +3 -0
- package/dist/chunks/chunk-RE7E6NA7.js +3 -0
- package/dist/chunks/{chunk-PN73WK2S.js → chunk-VNAIHACR.js} +1 -1
- package/dist/chunks/chunk-W42HVOBD.js +3 -0
- package/dist/chunks/chunk-XSOCV3F2.js +3 -0
- package/dist/chunks/chunk-YILLB45O.js +3 -0
- package/dist/chunks/chunk-YZG5A3GA.js +4 -0
- package/dist/chunks/chunk-ZRP5CWIK.js +3 -0
- package/dist/chunks/{catalog-NTACQH5V.js → clipboard-CPHPA4FH.js} +1 -1
- package/dist/chunks/colour-LZ7EJ6H4.js +3 -0
- package/dist/chunks/config-command-UW6BYQ2K.js +3 -0
- package/dist/chunks/execute-JRS6RQZA.js +3 -0
- package/dist/chunks/extensions-command-5QO6YX6O.js +3 -0
- package/dist/chunks/image-ESDL7GZU.js +3 -0
- package/dist/chunks/install-HCF5BIA6.js +3 -0
- package/dist/chunks/launch-BWYE27OQ.js +65 -0
- package/dist/chunks/lock-RZ6NVZFD.js +3 -0
- package/dist/chunks/manager-7HNOLCYH.js +4 -0
- package/dist/chunks/paths-H2WS22BA.js +3 -0
- package/dist/chunks/preferences-AKDCPHJ5.js +3 -0
- package/dist/chunks/restart-6ONEYN6T.js +3 -0
- package/dist/chunks/run-C475RRUL.js +4 -0
- package/dist/chunks/{server-DU7QWDAH.js → server-A327QWB6.js} +6 -6
- package/dist/chunks/theme-YG3CRJBG.js +3 -0
- package/dist/chunks/update-command-HT2RBFLR.js +3 -0
- package/dist/chunks/update-note-6GBF5AE4.js +3 -0
- package/dist/index.js +33 -29
- package/package.json +7 -4
- package/skills/forge/SKILL.md +3 -0
- package/dist/chunks/available-HEUREG6L.js +0 -3
- package/dist/chunks/boot-BUGERSEB.js +0 -3
- package/dist/chunks/chunk-2WYHI73Y.js +0 -3
- package/dist/chunks/chunk-4YCO7S4K.js +0 -3
- package/dist/chunks/chunk-C2WYXNRM.js +0 -4
- package/dist/chunks/chunk-C7OOWUMU.js +0 -3
- package/dist/chunks/chunk-EOYBXOCV.js +0 -4
- package/dist/chunks/chunk-HUAEVW2A.js +0 -3
- package/dist/chunks/chunk-L76Q54MB.js +0 -3
- package/dist/chunks/chunk-PD5DFBCU.js +0 -3
- package/dist/chunks/chunk-TEGB7JRM.js +0 -3
- package/dist/chunks/chunk-YXDEOLNA.js +0 -3
- package/dist/chunks/colour-DE6N6AZO.js +0 -3
- package/dist/chunks/config-command-SQXRTBRO.js +0 -3
- package/dist/chunks/execute-M3C3TTWB.js +0 -3
- package/dist/chunks/extensions-command-HJDBUBYO.js +0 -3
- package/dist/chunks/image-GYUUMS6H.js +0 -3
- package/dist/chunks/launch-WBUFRVQ7.js +0 -65
- package/dist/chunks/lock-XD4L3WFM.js +0 -3
- package/dist/chunks/manager-KBJTXZ27.js +0 -4
- package/dist/chunks/paths-JUM6GKQU.js +0 -3
- package/dist/chunks/run-RXVQD4DZ.js +0 -4
- package/dist/chunks/theme-DESCJOCE.js +0 -3
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
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}from"./chunk-CXVYIBCA.js";import"./chunk-TMUK2DD3.js";export{s as BAR,c as DARK,d as LIGHT,g as MODE_KEYS,i as MODE_MARKERS,f as MODE_ORDER,e as NEUTRAL,b as SYMBOLS,a as VERSION,u as applyColourPreference,t as colourEnabled,r as colourProp,n as commandsPalette,m as dotGradient,j as modeColours,h as modeForKey,k as modeGradient,o as modePalette,l as modeWash,p as paintsCanvas,q as paletteFor};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{U as a}from"./chunk-E5QDHFKQ.js";import"./chunk-J7FLFHQJ.js";import"./chunk-TMUK2DD3.js";async function d(i,n={}){let e=n.check??(async()=>(await import("./check-DN7SEN44.js")).checkNow()),s=n.install??(async r=>(await import("./install-HCF5BIA6.js")).installUpdate(r)),t=await e();if(t===void 0)throw a();let{isNewer:o}=await import("./check-DN7SEN44.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};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{b as m,c as w,d as h,f as l,g as p,h as b}from"./chunk-YZG5A3GA.js";import{c as u,d as $}from"./chunk-CXVYIBCA.js";import{e as g}from"./chunk-4L6HNYSN.js";import"./chunk-HON4OV7M.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};
|
package/dist/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
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{d as
|
|
5
|
-
`)}displayWidth(e){return he(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
|
|
6
|
-
`+" ".repeat(t+h)),
|
|
7
|
-
${
|
|
8
|
-
`)}};var
|
|
4
|
+
import{b as W,d as B}from"./chunks/chunk-IBPGC4N2.js";import{a as U}from"./chunks/chunk-QVACE4IE.js";import{h as j}from"./chunks/chunk-M6LD6DHO.js";import{d as G}from"./chunks/chunk-VNAIHACR.js";import"./chunks/chunk-LI2JPLF7.js";import{a as X}from"./chunks/chunk-775ILWZI.js";import"./chunks/chunk-OIZCRBLT.js";import{a as y}from"./chunks/chunk-CXVYIBCA.js";import{a as D}from"./chunks/chunk-Q45MSMTN.js";import{I as d,L as P,ca as K,da as T,e as J,g as E}from"./chunks/chunk-E5QDHFKQ.js";import{d as Y}from"./chunks/chunk-J7FLFHQJ.js";import"./chunks/chunk-4L6HNYSN.js";import"./chunks/chunk-HON4OV7M.js";import"./chunks/chunk-TMUK2DD3.js";import*as ae from"node:module";var w=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 w{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};var $=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 H(s){let e=s.name()+(s.variadic===!0?"...":"");return s.required?"<"+e+">":"["+e+"]"}import{EventEmitter as de}from"node:events";import q from"node:child_process";import O from"node:path";import V from"node:fs";import g from"node:process";import{stripVTControlCharacters as fe}from"node:util";import{stripVTControlCharacters as he}from"node:util";var S=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=>H(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(a,p){return t.formatItem(a,n,p,t)}let o=[`${t.styleTitle("Usage:")} ${t.styleUsage(t.commandUsage(e))}`,""],u=t.commandDescription(e);u.length>0&&(o=o.concat([t.boxWrap(t.styleCommandDescription(u),i),""]));let h=t.visibleArguments(e).map(a=>r(t.styleArgumentTerm(t.argumentTerm(a)),t.styleArgumentDescription(t.argumentDescription(a))));if(o=o.concat(this.formatItemList("Arguments:",h,t)),this.groupItems(e.options,t.visibleOptions(e),a=>a.helpGroupHeading??"Options:").forEach((a,p)=>{let f=a.map(m=>r(t.styleOptionTerm(t.optionTerm(m)),t.styleOptionDescription(t.optionDescription(m))));o=o.concat(this.formatItemList(p,f,t))}),t.showGlobalOptions){let a=t.visibleGlobalOptions(e).map(p=>r(t.styleOptionTerm(t.optionTerm(p)),t.styleOptionDescription(t.optionDescription(p))));o=o.concat(this.formatItemList("Global Options:",a,t))}return this.groupItems(e.commands,t.visibleCommands(e),a=>a.helpGroup()||"Commands:").forEach((a,p)=>{let f=a.map(m=>r(t.styleSubcommandTerm(t.subcommandTerm(m)),t.styleSubcommandDescription(t.subcommandDescription(m))));o=o.concat(this.formatItemList(p,f,t))}),o.join(`
|
|
5
|
+
`)}displayWidth(e){return he(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 u=e.padEnd(t+e.length-i.displayWidth(e)),h=2,l=(this.helpWidth??80)-t-h-2,a;return l<this.minWidthToWrap||i.preformatted(n)?a=n:a=i.boxWrap(n,l).replace(/\n/g,`
|
|
6
|
+
`+" ".repeat(t+h)),o+u+" ".repeat(h)+a.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 u=o.match(i);if(u===null){r.push("");return}let h=[u.shift()],c=this.displayWidth(h[0]);u.forEach(l=>{let a=this.displayWidth(l);if(c+a<=t){h.push(l),c+=a;return}r.push(h.join(""));let p=l.trimStart();h=[p],c=this.displayWidth(p)}),r.push(h.join(""))}),r.join(`
|
|
8
|
+
`)}};var v=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=ce(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?Q(this.name().replace(/^no-/,"")):Q(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}},I=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 Q(s){return s.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function ce(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],u=`option creation failed due to '${o}' in option flags '${s}'`;throw/^-[^-][^-]/.test(o)?new Error(`${u}
|
|
9
9
|
- a short flag is a single dash and a single character
|
|
10
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(
|
|
12
|
-
- too many short flags`):i.test(
|
|
13
|
-
- too many long flags`):new Error(`${
|
|
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 pe(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
|
|
11
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`):n.test(o)?new Error(`${u}
|
|
12
|
+
- too many short flags`):i.test(o)?new Error(`${u}
|
|
13
|
+
- too many long flags`):new Error(`${u}
|
|
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 pe(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 u=pe(s,o),h=Math.max(s.length,o.length);(h-u)/h>r&&(u<i?(i=u,n=[o]):u===i&&n.push(o))}),n.sort((o,u)=>o.localeCompare(u)),t&&(n=n.map(o=>`--${o}`)),n.length>1?`
|
|
15
15
|
(Did you mean one of ${n.join(", ")}?)`:n.length===1?`
|
|
16
|
-
(Did you mean ${n[0]}?)`:""}var
|
|
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
|
|
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 w(e,t,n)),g.exit(e)}action(e){let t=n=>{let i=this.registeredArguments.length,
|
|
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("|"),
|
|
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(
|
|
16
|
+
(Did you mean ${n[0]}?)`:""}var A=class s extends de{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:()=>ee()??(g.stdout.isTTY&&g.stdout.hasColors?.()),getErrHasColors:()=>ee()??(g.stderr.isTTY&&g.stderr.hasColors?.()),stripColor:t=>fe(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,u]=e.match(/([^ ]+) *(.*)/),h=this.createCommand(o);return i&&(h.description(i),h._executableHandler=!0),r.isDefault&&(this._defaultCommandName=h._name),h._hidden=!!(r.noHelp||r.hidden),h._executableFile=r.executableFile||null,u&&h.arguments(u),this._registerCommand(h),h.parent=this,h.copyInheritedSettings(this),i?this:h}createCommand(e){return new s(e)}createHelp(){return Object.assign(new S,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 $(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",u=this.createCommand(i);return u.helpOption(!1),r&&u.arguments(r),o&&u.description(o),this._addImplicitHelpCommand=!0,this._helpCommand=u,(e||t)&&this._initCommandGroup(u),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 w(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 v(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,u)=>{r==null&&e.presetArg!==void 0&&(r=e.presetArg);let h=this.getOptionValue(n);r!==null&&e.parseArg?r=this._callParseArg(e,r,h,o):r!==null&&e.variadic&&(r=e._collectValue(r,h)),r==null&&(e.negate?r=!1:e.isBoolean()||e.optional?r=!0:r=""),this.setOptionValueWithSource(n,r,u)};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 v)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 u=i;i=(h,c)=>{let l=u.exec(h);return l?l[0]:c},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(V.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
21
|
- if '${n}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
22
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(
|
|
23
|
+
- ${i}`;throw new Error(r)}_executeSubCommand(e,t){t=t.slice();let n=[".js",".ts",".tsx",".mjs",".cjs"];function i(l,a){let p=O.resolve(l,a);if(V.existsSync(p))return p;if(n.includes(O.extname(a)))return;let f=n.find(m=>V.existsSync(`${p}${m}`));if(f)return`${p}${f}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=e._executableFile||`${this._name}-${e._name}`,o=this._executableDir||"";if(this._scriptPath){let l;try{l=V.realpathSync(this._scriptPath)}catch{l=this._scriptPath}o=O.resolve(O.dirname(l),o)}if(o){let l=i(o,r);if(!l&&!e._executableFile&&this._scriptPath){let a=O.basename(this._scriptPath,O.extname(this._scriptPath));a!==this._name&&(l=i(o,`${a}-${e._name}`))}r=l||r}let u=n.includes(O.extname(r)),h;g.platform!=="win32"?u?(t.unshift(r),t=Z(g.execArgv).concat(t),h=q.spawn(g.argv[0],t,{stdio:"inherit"})):h=q.spawn(r,t,{stdio:"inherit"}):(this._checkForMissingExecutable(r,o,e._name),t.unshift(r),t=Z(g.execArgv).concat(t),h=q.spawn(g.execPath,t,{stdio:"inherit"})),h.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(a=>{g.on(a,()=>{h.killed===!1&&h.exitCode===null&&h.kill(a)})});let c=this._exitCallback;h.on("close",l=>{l=l??1,c?c(new w(l,"commander.executeSubCommandAsync","(close)")):g.exit(l)}),h.on("error",l=>{if(l.code==="ENOENT")this._checkForMissingExecutable(r,o,e._name);else if(l.code==="EACCES")throw new Error(`'${r}' not executable`);if(!c)g.exit(1);else{let a=new w(1,"commander.executeSubCommandAsync","(error)");a.nestedError=l,c(a)}}),this.runningCommand=h}_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 u=`error: command-argument value '${i}' is invalid for argument '${n.name()}'.`;o=this._callParseArg(n,i,r,u)}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,u)=>e(n,u,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(l){return l.length>1&&l[0]==="-"}let o=l=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(l)?!this._getCommandAndAncestors().some(a=>a.options.map(p=>p.short).some(p=>/^-\d$/.test(p))):!1,u=null,h=null,c=0;for(;c<e.length||h;){let l=h??e[c++];if(h=null,l==="--"){i===n&&i.push(l),i.push(...e.slice(c));break}if(u&&(!r(l)||o(l))){this.emit(`option:${u.name()}`,l);continue}if(u=null,r(l)){let a=this._findOption(l);if(a){if(a.required){let p=e[c++];p===void 0&&this.optionMissingArgument(a),this.emit(`option:${a.name()}`,p)}else if(a.optional){let p=null;c<e.length&&(!r(e[c])||o(e[c]))&&(p=e[c++]),this.emit(`option:${a.name()}`,p)}else this.emit(`option:${a.name()}`);u=a.variadic?a:null;continue}}if(l.length>2&&l[0]==="-"&&l[1]!=="-"){let a=this._findOption(`-${l[1]}`);if(a){a.required||a.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${a.name()}`,l.slice(2)):(this.emit(`option:${a.name()}`),h=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){let a=l.indexOf("="),p=this._findOption(l.slice(0,a));if(p&&(p.required||p.optional)){this.emit(`option:${p.name()}`,l.slice(a+1));continue}}if(i===t&&r(l)&&!(this.commands.length===0&&o(l))&&(i=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(l)){t.push(l),n.push(...e.slice(c));break}else if(this._getHelpCommand()&&l===this._getHelpCommand().name()){t.push(l,...e.slice(c));break}else if(this._defaultCommandName){n.push(l,...e.slice(c));break}}if(this._passThroughOptions){i.push(l,...e.slice(c));break}i.push(l)}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
24
|
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
25
25
|
`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
|
|
26
|
-
`),this.outputHelp({error:!0}));let n=t||{},i=n.exitCode||1,
|
|
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=>H(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=O.basename(e,O.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,
|
|
28
|
-
Expecting one of '${n.join("', '")}'`);let i=`${e}Help`;return this.on(i,
|
|
29
|
-
`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(i=>t.is(i))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}};function Z(s){return s.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",i="9229",
|
|
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 I(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 u=o.attributeName(),h=this.getOptionValue(u),c=this.options.find(a=>a.negate&&u===a.attributeName()),l=this.options.find(a=>!a.negate&&u===a.attributeName());return c&&(c.presetArg===void 0&&h===!1||c.presetArg!==void 0&&h===c.presetArg)?c:l||o},i=o=>{let u=n(o),h=u.attributeName();return this.getOptionValueSource(h)==="env"?`environment variable '${u.envVar}'`:`option '${u.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(u=>u.long).map(u=>u.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(", "),u=`error: too many arguments${r}. Expected ${t} argument${n} but got ${i}: ${o}.`;this.error(u,{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=>H(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=O.basename(e,O.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=u=>this._outputConfiguration.writeErr(u),i=this._outputConfiguration.getErrHasColors(),r=this._outputConfiguration.getErrHelpWidth()):(n=u=>this._outputConfiguration.writeOut(u),i=this._outputConfiguration.getOutHasColors(),r=this._outputConfiguration.getOutHelpWidth()),{error:t,write:u=>(i||(u=this._outputConfiguration.stripColor(u)),n(u)),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 Z(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 ee(){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 tt=new A;function me(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 d(`Unknown config setting ${t??"(none)"}.`,`Try one of: ${D.join(", ")}.`);let i=n.join(" ");if(i.length===0)throw d(`forge config set ${t} needs a value.`);return{kind:"config",action:"set",key:t,value:i}}throw d(`Unknown config action ${e}.`,"Try: forge config list, forge config set <setting> <value>, or forge config path.")}var ge={jpg:"jpeg",tif:"tiff",heif:"heic"};function z(s){let e=s.toLowerCase().replace(/^\./,""),t=J(ge[e]??e);if(!t)throw d(`${s} is not a format Forge knows.`,"Run forge --formats to see what is available.");return t.id}function N(s){let e=Number(s);if(!Number.isInteger(e)||e<1||e>100)throw d(`Quality must be a whole number between 1 and 100, not ${s}.`);return e}function te(s,e){let t=/^\d+$/.test(String(e))?Number(e):Number.NaN;if(!Number.isInteger(t)||t<1)throw d(`${s} takes a whole number of pixels, at least 1, not ${e}.`);return t}function _e(s){let e=String(s),t=/^\d+(\.\d+)?%?$/.test(e)?Number.parseFloat(e):Number.NaN;if(!(t>=1&&t<=j))throw d(`--resize takes a percent from 1 to ${j}, not ${s}.`,"Try --resize 50% to halve, or --width 1200 for an exact width.");return t}function F(s){let e=Number(s);if(!Number.isInteger(e)||e<1)throw d(`Concurrency must be a positive whole number, not ${s}.`);return e}var be=`
|
|
30
30
|
Exit codes:
|
|
31
31
|
0 every input succeeded
|
|
32
32
|
1 the command was understood, and at least one input failed or was refused
|
|
@@ -37,7 +37,8 @@ Other commands:
|
|
|
37
37
|
forge scale <colour> 50\u2013950 from one colour, with it at 500 (--json, --svg)
|
|
38
38
|
forge config [list | path | set <setting> <value>]
|
|
39
39
|
forge extensions [add | remove <id>] optional extras, such as boost and remove-background
|
|
40
|
-
forge
|
|
40
|
+
forge update install a newer Forge, if there is one
|
|
41
|
+
forge mcp run as a local MCP server over stdio, for AI agents`;function ne(s){let e=Y(String(s));if(e===void 0)throw d(`${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 d(`forge probe takes files, not ${t}.`,"Try: forge probe photo.jpg --json");if(e.length===0)throw d("No files given.","Name a file, for example: forge probe scan.pdf --json");return{kind:"probe",inputs:e}}function xe(s){let e=s.slice(1).filter(o=>o!=="--json"),t=e.find(o=>o.startsWith("-"));if(t!==void 0)throw d(`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 d(`Unknown extensions action ${n}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");if(i===void 0||r.length>0)throw d(`forge extensions ${n} takes exactly one extension.`,`Try: forge extensions ${n} boost`);return{kind:"extensions",action:n,id:i}}function ie(s){if(s===void 0)throw d("No colour given.","Try: forge scale 6579FD \u2014 or quote it, '#6579FD', because an unquoted # starts a comment in the shell.");let e=U(s);if(!e)throw d(`${s} is not a colour.`,"Try a hex code, for example 6579FD or #6579FD.");return e}var Ce={palette:`Usage: forge palette <image> [--json] [--svg] [--inside <hex>]
|
|
41
42
|
|
|
42
43
|
An image's main colours, most of the image first.
|
|
43
44
|
--json one JSON document: palette.colours[] with hex, rgb, oklch, share
|
|
@@ -48,21 +49,24 @@ An image's main colours, most of the image first.
|
|
|
48
49
|
50\u2013950 built in OKLCH, with <colour> at 500. Pass the hex without #, or quote it.
|
|
49
50
|
--json one JSON document: scale.steps[] with hex, oklch, white, black
|
|
50
51
|
--svg a card of swatches; pipe to pbcopy and paste into Figma
|
|
51
|
-
`};function ye(s){let[e,...t]=s;if(t.includes("--help")||t.includes("-h"))throw process.stdout.write(Ce[e==="scale"?"scale":"palette"]),new w(0,"commander.helpDisplayed","(outputHelp)");let n=t.filter(h=>h!=="--json"&&h!=="--svg"),i=t.includes("--svg"),
|
|
52
|
+
`};function ye(s){let[e,...t]=s;if(t.includes("--help")||t.includes("-h"))throw process.stdout.write(Ce[e==="scale"?"scale":"palette"]),new w(0,"commander.helpDisplayed","(outputHelp)");let n=t.filter(h=>h!=="--json"&&h!=="--svg"),i=t.includes("--svg"),r=n.indexOf("--inside"),o=r===-1?void 0:n[r+1];r!==-1&&n.splice(r,2);let u=n.find(h=>h.startsWith("-"));if(u!==void 0)throw d(`forge ${e} does not take ${u}.`,`Try: forge ${e} --help`);if(e==="scale"){if(r!==-1)throw d("--inside is for forge palette.","Try: forge palette photo.jpg --inside F26E69");if(n.length>1)throw d("forge scale takes one colour.","Try: forge scale 6579FD");return{kind:"scale",colour:ie(n[0]),svg:i}}if(n.length!==1)throw d(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:ie(o)}}}function R(s){let e=s.indexOf("--");return(e===-1?s:s.slice(0,e)).includes("--json")}function ve(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 u=t[o],h=u.startsWith("--boost=")?u.slice(8):void 0;if(u!=="--boost"&&h===void 0){i.push(u);continue}let c=h;if(c===void 0&&/^\d+$/.test(t[o+1]??"")&&(c=t[++o]),c!==void 0&&c!=="2"&&c!=="3"&&c!=="4")throw d(`--boost takes 2, 3 or 4, not ${c}.`,"Try --boost, --boost 2, --boost 3 or --boost 4.");r=c==="4"?4:c==="3"?3:2}return{rest:[...i,...n],...r===void 0?{}:{scale:r}}}function re(s){let e=s;if(e[0]==="config"||e[0]==="probe"||e[0]==="extensions"||e[0]==="palette"||e[0]==="scale"||e[0]==="update")return Ae(e);let t=ve(e);return ke(t.rest,t.scale)}function Ae(s){if(s[0]==="update"){let e=s.slice(1).filter(t=>t!=="--json");if(e.length>0)throw d(`forge update takes nothing else, got: ${e.join(" ")}.`,"Try: forge update");return{kind:"update"}}return s[0]==="config"?me(s.filter(e=>e!=="--json")):s[0]==="probe"?Oe(s):s[0]==="palette"||s[0]==="scale"?ye(s):xe(s)}function ke(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("--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("--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(y,"-V, --version","show the version").addHelpText("after",`${we}
|
|
52
53
|
${be}`).configureOutput({outputError:()=>{}}).exitOverride().allowExcessArguments(!1);try{t.parse(s,{from:"user"})}catch(f){if(f instanceof w&&f.code!=="commander.helpDisplayed"&&f.code!=="commander.version"){let[m="",..._]=f.message.replace(/^error: /,"").split(`
|
|
53
|
-
`),b=_.join(" ").trim().replace(/^\((.*)\)\.?$/,"$1");throw d(`${m.charAt(0).toUpperCase()}${m.slice(1).replace(/\.$/,"")}.`,b||"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.pages!==void 0&&n.to===void 0)throw d("--pages needs --to: it chooses which pages to render.");let
|
|
54
|
+
`),b=_.join(" ").trim().replace(/^\((.*)\)\.?$/,"$1");throw d(`${m.charAt(0).toUpperCase()}${m.slice(1).replace(/\.$/,"")}.`,b||"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.pages!==void 0&&n.to===void 0)throw d("--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 d(`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"]:[]],u=[...n.resize!==void 0?["--resize"]:[],...n.width!==void 0?["--width"]:[],...n.height!==void 0?["--height"]:[]];if(n.trim||u.length>0){if(u.length>1)throw d(`Use one of --resize, --width and --height \u2014 got ${u.join(" and ")}.`);let f=[...o,...n.maxSize!==void 0?["--max-size"]:[],...n.pages!==void 0?["--pages"]:[],...r.map(x=>`--${x}`)][0];if(f!==void 0)throw d(`${u[0]??"--trim"} cannot be combined with ${f}.`,f==="--max-size"?"Resize first, then compress the result: forge photo-1200x900.jpg --max-size 500kb":"Run them one after the other.");let m=n.resize!==void 0?{percent:_e(n.resize)}:n.width!==void 0?{width:te("--width",n.width)}:n.height!==void 0?{height:te("--height",n.height)}:void 0;if(i.length===0)throw d("No files given.","Name an image, for example: forge photo.jpg --resize 50%");let _={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(_.quality=N(String(n.quality)));let b={kind:"edit",inputs:i,trim:!!n.trim,options:_,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return m!==void 0&&(b.resize=m),n.to&&(b.target=z(String(n.to))),n.output!==void 0&&(b.output=String(n.output)),n.concurrency!==void 0&&(b.concurrency=F(String(n.concurrency))),b}let h=n.sharpen?1:e,c=h!==void 0?"boost":n.removeBg?"remove-background":null;if(c!==null){if(o.length>1)throw d(`Use one operation at a time \u2014 got ${o.join(" and ")}.`);let f=o[0];if(r.length>0)throw d(`${f} cannot be combined with --${r[0]}.`);if(n.maxSize!==void 0||n.pages!==void 0)throw d(`${f} cannot be combined with ${n.maxSize!==void 0?"--max-size":"--pages"}.`);if(i.length===0)throw d("No files given.",`Name an image, for example: forge photo.jpg ${f}`);let m=n.to?z(String(n.to)):"png";if(c==="remove-background"){let x=X(m);if(x)throw x}let _={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(_.quality=N(String(n.quality)));let b={kind:"extension-op",op:c,inputs:i,target:m,options:_,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return h!==void 0&&(b.scale=h),n.output!==void 0&&(b.output=String(n.output)),n.concurrency!==void 0&&(b.concurrency=F(String(n.concurrency))),b}if(r.length===1){let f=r[0];if(i.length===0)throw d("No files given.",`Name a PDF, for example: forge doc.pdf --${f}`);if(n.separate&&f!=="extract")throw d(`--separate only applies to --extract, not --${f}.`);if(n.output!==void 0)throw d(`--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 _=Number(n.rotate);if(!Number.isInteger(_)||_%90!==0||_===0||_>=360)throw d(`--rotate takes a multiple of 90 below 360, not "${n.rotate}".`);m.rotate=_}if((f==="extract"||f==="delete")&&(m.pages=String(n[f]),f==="extract"&&n.separate&&(m.separate=!0)),f==="split"){let _=String(n.split),b=_.match(/^every=(\d+)$/),x=_.match(/^at=([\d,\s]+)$/);if(_==="every-page")m.split={mode:"every-page"};else if(b?.[1]!==void 0){let k=Number(b[1]);if(!Number.isInteger(k)||k<1)throw d(`--split every=N takes a whole number of pages, at least 1, not "${b[1]}".`);m.split={mode:"every-n",n:k}}else if(x?.[1])m.split={mode:"points",after:x[1].split(",").map(k=>Number(k.trim()))};else throw d(`--split takes every-page, every=N or at=N,N \u2014 not "${_}".`)}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 d("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 d("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=N(String(n.quality))),n.maxSize!==void 0&&(m.maxBytes=ne(n.maxSize)),n.output!==void 0&&(m.output=String(n.output)),t.getOptionValueSource("dpi")==="cli"){let _=Number(n.dpi);if(!Number.isInteger(_)||_<36||_>600)throw P(n.dpi);m.dpi=_}return n.concurrency!==void 0&&(m.concurrency=F(String(n.concurrency))),m}if(!n.to)throw d("No target format given.","Add --to <format>, for example: forge photo.jpg --to webp");if(i.length===0)throw d("No files given.","Name a file, a folder or a glob, for example: forge photo.jpg --to webp");let l={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(l.quality=N(String(n.quality)));let a=Number(n.dpi);if(!Number.isInteger(a)||a<36||a>600)throw P(n.dpi);let p={kind:"convert",inputs:i,target:z(String(n.to)),options:l,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug,dpi:a,passwordStdin:!!n.passwordStdin};return n.output!==void 0&&(p.output=String(n.output)),n.pages!==void 0&&(p.pages=String(n.pages)),n.maxSize!==void 0&&(p.maxBytes=ne(n.maxSize)),n.concurrency!==void 0&&(p.concurrency=F(String(n.concurrency))),p}function L(s){return E(s)?s:K(s)}function oe(s,e){return T(L(s),{debug:e})}function se(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)})}ae.enableCompileCache?.();function $e({completed:s,total:e}){s===0?process.stderr.write(`Converting ${e} files
|
|
54
55
|
`):process.stderr.write(` ${s}/${e}
|
|
55
|
-
`)}async function Se(){let s=process.argv.slice(2),e=s.includes("--debug"),t=
|
|
56
|
+
`)}async function Se(){let s=process.argv.slice(2),e=s.includes("--debug"),t=R(s);try{if(s[0]==="__update-check"){let{checkNow:a}=await import("./chunks/check-DN7SEN44.js");await a();return}if(s[0]==="mcp"){let{runMcpServer:a}=await import("./chunks/server-A327QWB6.js");await a(s.slice(1));return}let n=re(s);if(n.kind==="shell"){if(t)throw d("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.
|
|
56
57
|
Try: forge photo.jpg --to webp
|
|
57
|
-
`),process.exitCode=2;return}let{applyColourPreference:
|
|
58
|
-
`:""}`)},h=!!process.stderr.isTTY&&!t,c=new AbortController;n.kind==="extension-op"&&process.once("SIGINT",()=>c.abort());let l=await i(n,{json:t,signal:c.signal,...h?{onDownload:
|
|
58
|
+
`),process.exitCode=2;return}let{applyColourPreference:a}=await import("./chunks/theme-YG3CRJBG.js");a();let{bootShell:p}=await import("./chunks/boot-ISMRSTLL.js");await p();return}let{execute:i}=await import("./chunks/execute-JRS6RQZA.js"),r,o=0,u=(a,p)=>{let f=Date.now();if(a<p&&f-o<100)return;o=f;let m=_=>(_/1e6).toFixed(1);process.stderr.write(`\r downloading ${m(a)} / ${m(p)} MB${a>=p?`
|
|
59
|
+
`:""}`)},h=!!process.stderr.isTTY&&!t,c=new AbortController;n.kind==="extension-op"&&process.once("SIGINT",()=>c.abort());let l=await i(n,{json:t,...h?{onInstalling:a=>{r=W(process.stderr,`installing Forge ${a}`)}}:{},signal:c.signal,...h?{onDownload:u}:{},colour:!!process.stdout.isTTY&&!t&&B(),onProgress:h?a=>{a.completed>0&&r?.stop(),$e(a)}:void 0,...h?{onSearch:a=>{r??=W(process.stderr,"finding the smallest that fits"),r.update(a)}}:{}});if(r?.stop(),l.stdout.length>0&&process.stdout.write(`${l.stdout.join(`
|
|
59
60
|
`)}
|
|
60
61
|
`),l.stderr.length>0&&process.stderr.write(`${l.stderr.join(`
|
|
61
62
|
`)}
|
|
62
|
-
`),process.exitCode=c.signal.aborted?130:l.exitCode
|
|
63
|
+
`),process.exitCode=c.signal.aborted?130:l.exitCode,h&&process.stdout.isTTY&&n.kind!=="update")try{let{afterCommand:a,spawnRefresh:p}=await import("./chunks/update-note-6GBF5AE4.js"),{runningScript:f}=await import("./chunks/install-HCF5BIA6.js"),m=await a(y,{refresh:()=>p(f(process.argv[1])),colour:B()});m.length>0&&process.stderr.write(`
|
|
64
|
+
${m.join(`
|
|
65
|
+
`)}
|
|
66
|
+
`)}catch{}}catch(n){if(E(n)){t?process.stdout.write(`${JSON.stringify(G(y,n))}
|
|
63
67
|
`):process.stderr.write(`${T(n,{debug:e}).join(`
|
|
64
68
|
`)}
|
|
65
|
-
`),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 ue(s){let e=process.argv.slice(2);if(
|
|
66
|
-
`);return}process.stderr.write(`${
|
|
69
|
+
`),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 ue(s){let e=process.argv.slice(2);if(R(e)){process.stdout.write(`${JSON.stringify(G(y,L(s)))}
|
|
70
|
+
`);return}process.stderr.write(`${oe(s,e.includes("--debug")).join(`
|
|
67
71
|
`)}
|
|
68
|
-
`)}var le=!1;se(()=>le,ue);try{await Se()}catch(s){ue(s),process.exitCode=1}finally{le=!0}export{
|
|
72
|
+
`)}var le=!1;se(()=>le,ue);try{await Se()}catch(s){ue(s),process.exitCode=1}finally{le=!0}export{y as VERSION};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "forge-terminal",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A terminal-native file converter for macOS",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "A terminal-native file converter for macOS and Windows",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"convert",
|
|
7
7
|
"converter",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"cli",
|
|
15
15
|
"terminal",
|
|
16
16
|
"tui",
|
|
17
|
-
"macos"
|
|
17
|
+
"macos",
|
|
18
|
+
"windows"
|
|
18
19
|
],
|
|
19
20
|
"homepage": "https://github.com/AtharvaN16/forge-terminal#readme",
|
|
20
21
|
"repository": {
|
|
@@ -37,7 +38,8 @@
|
|
|
37
38
|
"node": ">=20"
|
|
38
39
|
},
|
|
39
40
|
"os": [
|
|
40
|
-
"darwin"
|
|
41
|
+
"darwin",
|
|
42
|
+
"win32"
|
|
41
43
|
],
|
|
42
44
|
"license": "MIT",
|
|
43
45
|
"scripts": {
|
|
@@ -70,6 +72,7 @@
|
|
|
70
72
|
"esbuild": "^0.28.2",
|
|
71
73
|
"ink": "^7.1.1",
|
|
72
74
|
"ink-testing-library": "^4.0.0",
|
|
75
|
+
"libheif-js": "^1.23.5",
|
|
73
76
|
"mammoth": "^1.13.0",
|
|
74
77
|
"onnxruntime-node": "1.23.2",
|
|
75
78
|
"pdf-lib": "^1.17.1",
|
package/skills/forge/SKILL.md
CHANGED
|
@@ -60,6 +60,9 @@ forge scale 6579FD --json # 50–950, the colou
|
|
|
60
60
|
For a colour, pass the hex without `#`, or quote it: an unquoted `#` starts
|
|
61
61
|
a shell comment, and `forge scale` then exits 2 with "No colour given".
|
|
62
62
|
|
|
63
|
+
`forge update` installs a newer Forge globally with npm. Run it only when the
|
|
64
|
+
user asks for an update.
|
|
65
|
+
|
|
63
66
|
Outputs go beside the source unless `-o` names a folder (or, for one file, a
|
|
64
67
|
filename). Page operations always write beside the source, take no `-o`, and
|
|
65
68
|
never edit the original.
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{c as t}from"./chunk-4YCO7S4K.js";import{a as i}from"./chunk-TEGB7JRM.js";import"./chunk-TMUK2DD3.js";async function l(){let e=await Promise.all(i.map(async n=>await t(n.id)?n.id:null));return new Set(e.filter(n=>n!==null))}export{l as installedExtensionIds};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{p as l}from"./chunk-G2D6BKOS.js";import{d as a}from"./chunk-EOYBXOCV.js";import"./chunk-TMUK2DD3.js";var i={loadPreferences:a,loadShell:()=>import("./launch-WBUFRVQ7.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
|
-
var u=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function a(t,f){if(t.isTTY!==!0)return{update:()=>{},tick:()=>{},stop:()=>{}};let r=0,n="",e=!1,i=60,o=()=>{e||t.write(`\r${" ".repeat(i)}\r${u[r%u.length]} ${f}${n}`)};return{update(s){n=s===""?"":` \xB7 ${s}`,r++,o()},tick(){r++,o()},stop(){e||(e=!0,t.write(`\r${" ".repeat(i)}\r`))}}}var R=new Set(["iTerm.app","WezTerm","ghostty","vscode"]),O=new Set(["xterm-kitty","xterm-ghostty"]);function E(t=process.env){return t.FORGE_POWERLINE==="1"?!0:t.FORGE_POWERLINE==="0"||t.NO_COLOR!==void 0&&t.NO_COLOR!==""?!1:R.has(t.TERM_PROGRAM??"")||O.has(t.TERM??"")}function c(t=process.env){return t.FORGE_TRUECOLOR==="1"?!0:t.FORGE_TRUECOLOR==="0"||t.NO_COLOR!==void 0&&t.NO_COLOR!==""?!1:t.COLORTERM==="truecolor"||t.COLORTERM==="24bit"?!0:R.has(t.TERM_PROGRAM??"")||O.has(t.TERM??"")}export{u as a,a as b,E as c,c as d};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{b as c}from"./chunk-TEGB7JRM.js";import{access as l,readFile as a}from"node:fs/promises";import{homedir as x}from"node:os";import{join as e}from"node:path";function g(){let n=process.env.XDG_CONFIG_HOME,t=n!==void 0&&n.length>0?n:e(x(),".config");return e(t,"forge","extensions")}var y=/^[A-Za-z0-9][A-Za-z0-9._-]*$/;async function w(n){if(c(n)!==void 0)try{let t=e(g(),n),r=(await a(e(t,"current"),"utf8")).trim();if(!y.test(r))return;let i=e(t,r),o=JSON.parse(await a(e(i,"manifest.json"),"utf8"));if(typeof o!="object"||o===null)return;let{id:m,version:p,entry:s,kind:d,files:f}=o;if(m!==n||p!==r||d!=="node"&&d!=="exec"||typeof s!="string"||typeof f!="object"||f===null||!(s in f))return;let u=e(i,s);return u.startsWith(`${i}/`)?(await l(u),{id:n,version:r,dir:i,entry:u,kind:d}):void 0}catch{return}}export{g as a,y as b,w as c};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{b as J,c as re,d as E,f as F,g as oe,h as se,i as ne,j as ae,o as ue,p as ie,q as pe,s as ce,t as de,v as I,x as h}from"./chunk-C7OOWUMU.js";import{c as U,d as X,e as Z,f as _,g as ee,h as te}from"./chunk-PN73WK2S.js";import{a as k,c as V,d as Y,e as $,f as K,k as Q}from"./chunk-5B7WODWH.js";import{e as L}from"./chunk-L76Q54MB.js";import{a as w}from"./chunk-G2D6BKOS.js";import{a as G,c as H}from"./chunk-YXDEOLNA.js";import{I as W,J as D,M as q,_ as z,b as P,c as b,d as x,g as v,s as M,u as R,w as A,z as C}from"./chunk-PD5DFBCU.js";import{a as g,b as T}from"./chunk-J7FLFHQJ.js";import{readFile as Be}from"node:fs/promises";import{dirname as xe,resolve as Se}from"node:path";async function fe(e){let r=[],t=[...e.resolved.failures];for(let o of e.resolved.sources){let s=k(o);if(!s.includes(e.target)){t.push({path:o.path,error:A(o,e.target,s)});continue}let a=E({sourcePath:o.path,target:e.target,output:e.output,sourceRoot:e.resolved.roots.get(o.path)});r.push({op:"convert",sources:[o],outputs:[a],target:e.target,options:e.options})}return{jobs:r,failures:t}}import{resolve as Re}from"node:path";function ke(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:k(e).filter(a=>!o||$(a)),actions:ce([e],r).filter(a=>!o||a.id===F.id).map(a=>a.id)};return e.kind==="image"?{...t,width:e.width,height:e.height,...s}:{...t,pages:e.pages,encrypted:e.encrypted,...s}}async function le(e){let r=await h(e,{recursive:!1}),{installedExtensionIds:t}=await import("./available-HEUREG6L.js"),o=await t();return{probes:r.sources.map(s=>ke(s,o)),failures:r.failures}}import{dirname as $e}from"node:path";var B=e=>({cwd:e.cwd??process.cwd(),...e.home===void 0?{}:{home:e.home}});function me(e,r){let t=P($e(e),B(r));return t==="."?"":` in ${t.endsWith("/")?t:`${t}/`}`}function ge(e,r){let{pct:t,direction:o}=T(e,r);return o==="same"?"same size":`${t}% ${o}`}function he(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 n=[`\u2713 ${b(o.path)} \u2192 ${s.length} files${me(s[0],r)}`,` ${s.map(u=>b(u)).join(", ")}`,` ${g(o.bytes)} \u2192 ${g(t.outputBytes)} total`];for(let u of t.warnings)n.push("",`\u26A0 ${u.message}`);return n}let a=[`\u2713 ${b(o.path)} \u2192 ${P(s[0],B(r))}`,` ${g(o.bytes)} \u2192 ${g(t.outputBytes)} \xB7 ${ge(o.bytes,t.outputBytes)}`];for(let n of t.warnings)a.push("",`\u26A0 ${n.message}`);return a}function ye(e,r={}){let t=[`\u2713 ${e.results.length} converted`,` ${g(e.inputBytes)} \u2192 ${g(e.outputBytes)} \xB7 ${ge(e.inputBytes,e.outputBytes)}`];for(let s of e.results)for(let a of s.job.outputs)t.push(` ${P(a,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 be(e,r={}){let t=e.results.flatMap(i=>i.job.outputs),o=t.map(i=>b(i)).join(", "),s=t.length===1?"file":"files",a=t[0]===void 0?"":me(t[0],r),n=[`\u2713 ${t.length} ${s} \xB7 ${o}${a}`],u=e.results.flatMap(i=>i.warnings);for(let i of u)n.push("",`\u26A0 ${i.message}`);return n}function S(e,r){if(e.length===0)return[];let t=[];for(let o of e)t.push(...z(o.error,{debug:r.debug}),"");return t}function we(){let e=new Set(V()),r=new Set(Y()),t=["Formats",""];for(let s of e){let a=x[s],n=r.has(s)?"read and write":"read only";t.push(` ${a.label.padEnd(6)} ${a.extensions.join(" ").padEnd(12)} ${n}`)}let o=[...e].filter(s=>!r.has(s)).map(s=>x[s].label);if(o.length>0){let s=o.join(", "),[a,n]=o.length===1?["is","it"]:["are","them"];t.push("",`${s} ${a} read only because Forge cannot yet write ${n}.`)}return t}function Ie(e,r={}){let t=[x[e.format].label,g(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"),[`${P(e.path,B(r))} \xB7 ${t.join(" \xB7 ")}`,` converts to ${e.targets.join(", ")}`,` actions ${e.actions.join(", ")}`]}import{createInterface as Pe}from"node:readline";import{PassThrough as Ee}from"node:stream";function Fe(e){return new Promise(r=>{let t=Pe({input:e,terminal:!1}),o=!1,s=a=>{if(o)return;o=!0,t.close(),e.pause(),e.unref?.(),r(a.replace(/\r$/,""))};t.once("line",s),t.once("close",()=>s(""))})}async function ve(e){if(e.stdin)return Fe(process.stdin);if(!process.stdin.isTTY)return;let r=new Ee,t=Pe({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 N(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(n=>n.kind==="document"),o=t?.pages??0,s=e.split;if(!s)throw W("--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:ie(o,s.n)};let a=Math.max(o-1,0);for(let n of s.after)if(!Number.isInteger(n)||n<1||n>a)throw D(String(n),`"${n}" is outside 1 and ${a} \u2014 ${t?b(t.path):"the document"} has ${o} pages.`,o);return{cuts:s.after.map(n=>n-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 Ce(e,r,t,o){let s;if(e.encrypted){if(s=r.password??await t(),s===void 0)return{failure:{path:e.path,error:C(e.path)}};let u;try{u=await L(await Be(e.path),s)}catch{return{failure:{path:e.path,error:C(e.path,{attempted:!0})}}}u.destroy()}let a;try{a=F.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(u){if(!v(u))throw u;return{failure:{path:e.path,error:u}}}let n=a[0];if(n?.op!=="convert")throw new Error(`convertAction.plan() did not return a convert job for ${e.path}`);return s!==void 0&&(n.options.password=s),{job:n}}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 y=(e,r)=>({kind:e,results:[],failures:r,inputBytes:0,outputBytes:0});async function Je(e){let r=await h(e.inputs,{recursive:!1});if(r.sources.length===0)return y("pageop",r.failures);let t=pe.find(n=>n.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 n=de(t,r.sources)??"not available for these files";return y("pageop",[...r.failures,{path:o,error:R(e.action,n)}])}let s;try{s=t.plan(r.sources,je(e,r.sources))}catch(n){if(!v(n))throw n;return y("pageop",[...r.failures,{path:o,error:n}])}let a=await I(s,{force:e.force});return{kind:"pageop",results:a.results,failures:[...r.failures,...a.refusals,...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function Ne(e,r){let t=await h(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let u of t.sources){if(!J.appliesTo([u])){s.push({path:u.path,error:M(u)});continue}let i=e.output!==void 0&&!re(e.output)?Se(e.output):void 0,c=e.output===void 0||i!==void 0?xe(u.path):xe(E({sourcePath:u.path,target:u.format,output:e.output,sourceRoot:t.roots.get(u.path)})),[p]=J.plan([u],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},destination:c});p?.op==="convert"&&(i!==void 0&&(p.outputs=[i]),e.dpi!==void 0&&(p.options.dpi=e.dpi),o.push(p))}let a=o.length>1;a&&r.onProgress?.({completed:0,total:o.length});let n=await I(o,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:j(r,a)});return{kind:"compress",results:n.results,failures:[...t.failures,...s,...n.refusals,...n.unreachable.map(u=>({path:u.job.sources[0].path,error:u.error})),...n.failures],inputBytes:n.inputBytes,outputBytes:n.outputBytes}}async function Te(e,r){let t=e.kind,o=e.op==="remove-background"?G(e.target):void 0;if(o)return y(t,[{path:"",error:o}]);let{installed:s}=await import("./paths-JUM6GKQU.js"),a=await s(e.op);if(!a)return y(t,[{path:"",error:q(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{catalogEntry:f}=await import("./catalog-NTACQH5V.js"),d=H(e.scale,a.version,f("boost")?.version);if(d)return y(t,[{path:"",error:d}])}let n=await h(e.inputs,{recursive:e.recursive}),u=e.op==="boost"?se:ne,i=[],c=[];for(let f of n.sources){if(!u.appliesTo([f])){c.push({path:f.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 d=oe(f,e.target);if(d){c.push({path:f.path,error:d});continue}i.push(...u.plan([f],{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:n.roots}))}let p=i.length>1;p&&r.onProgress?.({completed:0,total:i.length});let m=await I(i,{force:e.force,concurrency:1,...r.signal===void 0?{}:{signal:r.signal},onEvent:j(r,p)});return{kind:t,results:m.results,failures:[...n.failures,...c,...m.refusals,...m.failures],inputBytes:m.inputBytes,outputBytes:m.outputBytes}}async function Me(e,r){let t=e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:Q(e.target,t);if(o)return y(e.kind,[{path:"",error:o}]);let s=await h(e.inputs,{recursive:e.recursive}),a=[],n=[];for(let p of s.sources)p.kind==="image"?a.push(p):n.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 u=ae(a,{trim:e.trim,...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}}),i=u.length>1;i&&r.onProgress?.({completed:0,total:u.length});let c=await I(u,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:j(r,i)});return{kind:e.kind,results:c.results,failures:[...s.failures,...n,...c.refusals,...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function Ae(e,r){let t=await h(e.inputs,{recursive:e.recursive}),o=l=>l.kind==="document"&&l.format==="pdf",s=$(e.target),a=s?t.sources.filter(o):[],n=s?t.sources.filter(l=>!o(l)):t.sources,u=[],i=[],c=Oe(e.passwordStdin??!1,r.interactive??!0);for(let l of a){let O=await Ce(l,e,c,t.roots.get(l.path));"failure"in O?i.push(O.failure):u.push(O.job)}let p=await fe({resolved:{sources:n,failures:[],roots:t.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),m=[...p.jobs,...u],f=m.length>1;f&&r.onProgress?.({completed:0,total:m.length});let d=await I(m,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:j(r,f)});return{kind:"convert",results:d.results,failures:[...t.failures,...i,...p.failures,...d.refusals,...d.unreachable.map(l=>({path:l.job.sources[0].path,error:l.error})),...d.failures],inputBytes:d.inputBytes,outputBytes:d.outputBytes}}async function We(e,r={}){try{return e.kind==="pageop"?await Je(e):e.kind==="extension-op"?await Te(e,r):e.kind==="edit"?await Me(e,r):e.kind==="compress"?await Ne(e,r):await Ae(e,r)}catch(t){if(!v(t))throw t;return y(e.kind,[{path:"",error:t}])}}function De(e,r){let t=N(e.failures);if(r.json)return{exitCode:t,stdout:[JSON.stringify(U(w,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?be(e):e.results.length===1?he(e):ye(e);return{exitCode:t,stdout:o,stderr:S(e.failures,{debug:r.debug})}}function qe(e,r){let t=[{path:"",error:e}],o=N(t);return r.json?{exitCode:o,stdout:[JSON.stringify(X(w,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:S(t,{debug:r.debug})}}async function ze(e,r){let{runConfig:t}=await import("./config-command-SQXRTBRO.js"),o=await t(e);return r?{exitCode:0,stdout:[JSON.stringify(ee(w,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 ze(e,t);if(e.kind==="extensions"){let{runExtensions:s}=await import("./extensions-command-HJDBUBYO.js"),a=await s(e,{onDownload:r.onDownload});return{exitCode:0,stdout:t?[JSON.stringify(te(w,a.data))]:a.stdout,stderr:[]}}if(e.kind==="formats")return t?{exitCode:0,stdout:[JSON.stringify(Z(w,K()))],stderr:[]}:{exitCode:0,stdout:we(),stderr:[]};if(e.kind==="probe"){let{probes:s,failures:a}=await le(e.inputs),n=N(a);return t?{exitCode:n,stdout:[JSON.stringify(_(w,{probes:s,failures:a}))],stderr:[]}:{exitCode:n,stdout:s.flatMap((u,i)=>[...i>0?[""]:[],...Ie(u)]),stderr:S(a,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"){let{runPalette:s,runScale:a}=await import("./colour-DE6N6AZO.js"),n={json:t,colour:r.colour??!1};return e.kind==="palette"?await s(e,n):await a(e,n)}return e.kind==="shell"?{exitCode:0,stdout:[],stderr:[]}:De(await We(e,r),{json:t,debug:o})}catch(s){if(!v(s))throw s;return qe(s,{json:t,debug:o})}}export{le as a,N as b,We as c,De as d,Bt as e};
|