@shotstack/cli 0.1.0 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/shotstack.js +13 -13
- package/package.json +2 -2
package/dist/shotstack.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as
|
|
2
|
+
import{createRequire as CE}from"node:module";var WE=Object.create;var{getPrototypeOf:DE,defineProperty:m,getOwnPropertyNames:FE}=Object;var kE=Object.prototype.hasOwnProperty;function VE(E){return this[E]}var AE,xE,bE=(E,f,R)=>{var $=E!=null&&typeof E==="object";if($){var S=f?AE??=new WeakMap:xE??=new WeakMap,T=S.get(E);if(T)return T}R=E!=null?WE(DE(E)):{};let L=f||!E||!E.__esModule?m(R,"default",{value:E,enumerable:!0}):R;for(let _ of FE(E))if(!kE.call(L,_))m(L,_,{get:VE.bind(E,_),enumerable:!0});if($)S.set(E,L);return L};var X=(E,f)=>()=>(f||E((f={exports:{}}).exports,f),f.exports);var Q=CE(import.meta.url);var K=X((uE)=>{class u extends Error{constructor(E,f,R){super(R);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=f,this.exitCode=E,this.nestedError=void 0}}class d extends u{constructor(E){super(1,"commander.invalidArgument",E);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}uE.CommanderError=u;uE.InvalidArgumentError=d});var N=X((sE)=>{var{InvalidArgumentError:vE}=K();class p{constructor(E,f){switch(this.description=f||"",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}if(this._name.length>3&&this._name.slice(-3)==="...")this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_concatValue(E,f){if(f===this.defaultValue||!Array.isArray(f))return[E];return f.concat(E)}default(E,f){return this.defaultValue=E,this.defaultValueDescription=f,this}argParser(E){return this.parseArg=E,this}choices(E){return this.argChoices=E.slice(),this.parseArg=(f,R)=>{if(!this.argChoices.includes(f))throw new vE(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._concatValue(f,R);return f},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function rE(E){let f=E.name()+(E.variadic===!0?"...":"");return E.required?"<"+f+">":"["+f+"]"}sE.Argument=p;sE.humanReadableArgName=rE});var h=X((nE)=>{var{humanReadableArgName:gE}=N();class o{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(E){let f=E.commands.filter(($)=>!$._hidden),R=E._getHelpCommand();if(R&&!R._hidden)f.push(R);if(this.sortSubcommands)f.sort(($,S)=>{return $.name().localeCompare(S.name())});return f}compareOptions(E,f){let R=($)=>{return $.short?$.short.replace(/^-/,""):$.long.replace(/^--/,"")};return R(E).localeCompare(R(f))}visibleOptions(E){let f=E.options.filter(($)=>!$.hidden),R=E._getHelpOption();if(R&&!R.hidden){let $=R.short&&E._findOption(R.short),S=R.long&&E._findOption(R.long);if(!$&&!S)f.push(R);else if(R.long&&!S)f.push(E.createOption(R.long,R.description));else if(R.short&&!$)f.push(E.createOption(R.short,R.description))}if(this.sortOptions)f.sort(this.compareOptions);return f}visibleGlobalOptions(E){if(!this.showGlobalOptions)return[];let f=[];for(let R=E.parent;R;R=R.parent){let $=R.options.filter((S)=>!S.hidden);f.push(...$)}if(this.sortOptions)f.sort(this.compareOptions);return f}visibleArguments(E){if(E._argsDescription)E.registeredArguments.forEach((f)=>{f.description=f.description||E._argsDescription[f.name()]||""});if(E.registeredArguments.find((f)=>f.description))return E.registeredArguments;return[]}subcommandTerm(E){let f=E.registeredArguments.map((R)=>gE(R)).join(" ");return E._name+(E._aliases[0]?"|"+E._aliases[0]:"")+(E.options.length?" [options]":"")+(f?" "+f:"")}optionTerm(E){return E.flags}argumentTerm(E){return E.name()}longestSubcommandTermLength(E,f){return f.visibleCommands(E).reduce((R,$)=>{return Math.max(R,f.subcommandTerm($).length)},0)}longestOptionTermLength(E,f){return f.visibleOptions(E).reduce((R,$)=>{return Math.max(R,f.optionTerm($).length)},0)}longestGlobalOptionTermLength(E,f){return f.visibleGlobalOptions(E).reduce((R,$)=>{return Math.max(R,f.optionTerm($).length)},0)}longestArgumentTermLength(E,f){return f.visibleArguments(E).reduce((R,$)=>{return Math.max(R,f.argumentTerm($).length)},0)}commandUsage(E){let f=E._name;if(E._aliases[0])f=f+"|"+E._aliases[0];let R="";for(let $=E.parent;$;$=$.parent)R=$.name()+" "+R;return R+f+" "+E.usage()}commandDescription(E){return E.description()}subcommandDescription(E){return E.summary()||E.description()}optionDescription(E){let f=[];if(E.argChoices)f.push(`choices: ${E.argChoices.map((R)=>JSON.stringify(R)).join(", ")}`);if(E.defaultValue!==void 0){if(E.required||E.optional||E.isBoolean()&&typeof E.defaultValue==="boolean")f.push(`default: ${E.defaultValueDescription||JSON.stringify(E.defaultValue)}`)}if(E.presetArg!==void 0&&E.optional)f.push(`preset: ${JSON.stringify(E.presetArg)}`);if(E.envVar!==void 0)f.push(`env: ${E.envVar}`);if(f.length>0)return`${E.description} (${f.join(", ")})`;return E.description}argumentDescription(E){let f=[];if(E.argChoices)f.push(`choices: ${E.argChoices.map((R)=>JSON.stringify(R)).join(", ")}`);if(E.defaultValue!==void 0)f.push(`default: ${E.defaultValueDescription||JSON.stringify(E.defaultValue)}`);if(f.length>0){let R=`(${f.join(", ")})`;if(E.description)return`${E.description} ${R}`;return R}return E.description}formatHelp(E,f){let R=f.padWidth(E,f),$=f.helpWidth||80,S=2,T=2;function L(U,P){if(P){let C=`${U.padEnd(R+2)}${P}`;return f.wrap(C,$-2,R+2)}return U}function _(U){return U.join(`
|
|
3
3
|
`).replace(/^/gm," ".repeat(2))}let I=[`Usage: ${f.commandUsage(E)}`,""],w=f.commandDescription(E);if(w.length>0)I=I.concat([f.wrap(w,$,0),""]);let y=f.visibleArguments(E).map((U)=>{return L(f.argumentTerm(U),f.argumentDescription(U))});if(y.length>0)I=I.concat(["Arguments:",_(y),""]);let q=f.visibleOptions(E).map((U)=>{return L(f.optionTerm(U),f.optionDescription(U))});if(q.length>0)I=I.concat(["Options:",_(q),""]);if(this.showGlobalOptions){let U=f.visibleGlobalOptions(E).map((P)=>{return L(f.optionTerm(P),f.optionDescription(P))});if(U.length>0)I=I.concat(["Global Options:",_(U),""])}let Y=f.visibleCommands(E).map((U)=>{return L(f.subcommandTerm(U),f.subcommandDescription(U))});if(Y.length>0)I=I.concat(["Commands:",_(Y),""]);return I.join(`
|
|
4
4
|
`)}padWidth(E,f){return Math.max(f.longestOptionTermLength(E,f),f.longestGlobalOptionTermLength(E,f),f.longestSubcommandTermLength(E,f),f.longestArgumentTermLength(E,f))}wrap(E,f,R,$=40){let T=new RegExp(`[\\n][${" \\f\\t\\v - \uFEFF"}]+`);if(E.match(T))return E;let L=f-R;if(L<$)return E;let _=E.slice(0,R),I=E.slice(R).replace(`\r
|
|
5
5
|
`,`
|
|
6
6
|
`),w=" ".repeat(R),q=`\\s${""}`,Y=new RegExp(`
|
|
7
7
|
|.{1,${L-1}}([${q}]|$)|[^${q}]+?([${q}]|$)`,"g"),U=I.match(Y)||[];return _+U.map((P,C)=>{if(P===`
|
|
8
8
|
`)return"";return(C>0?w:"")+P.trimEnd()}).join(`
|
|
9
|
-
`)}}
|
|
9
|
+
`)}}nE.Help=o});var O=X((pE)=>{var{InvalidArgumentError:lE}=K();class e{constructor(E,f){this.flags=E,this.description=f||"",this.required=E.includes("<"),this.optional=E.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(E),this.mandatory=!1;let R=dE(E);if(this.short=R.shortFlag,this.long=R.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}default(E,f){return this.defaultValue=E,this.defaultValueDescription=f,this}preset(E){return this.presetArg=E,this}conflicts(E){return this.conflictsWith=this.conflictsWith.concat(E),this}implies(E){let f=E;if(typeof E==="string")f={[E]:!0};return this.implied=Object.assign(this.implied||{},f),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}_concatValue(E,f){if(f===this.defaultValue||!Array.isArray(f))return[E];return f.concat(E)}choices(E){return this.argChoices=E.slice(),this.parseArg=(f,R)=>{if(!this.argChoices.includes(f))throw new lE(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._concatValue(f,R);return f},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){return mE(this.name().replace(/^no-/,""))}is(E){return this.short===E||this.long===E}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class a{constructor(E){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,E.forEach((f)=>{if(f.negate)this.negativeOptions.set(f.attributeName(),f);else this.positiveOptions.set(f.attributeName(),f)}),this.negativeOptions.forEach((f,R)=>{if(this.positiveOptions.has(R))this.dualOptions.add(R)})}valueFromOption(E,f){let R=f.attributeName();if(!this.dualOptions.has(R))return!0;let $=this.negativeOptions.get(R).presetArg,S=$!==void 0?$:!1;return f.negate===(S===E)}}function mE(E){return E.split("-").reduce((f,R)=>{return f+R[0].toUpperCase()+R.slice(1)})}function dE(E){let f,R,$=E.split(/[ |,]+/);if($.length>1&&!/^[[<]/.test($[1]))f=$.shift();if(R=$.shift(),!f&&/^-[^-]$/.test(R))f=R,R=void 0;return{shortFlag:f,longFlag:R}}pE.Option=e;pE.DualOptions=a});var EE=X((ff)=>{function aE(E,f){if(Math.abs(E.length-f.length)>3)return Math.max(E.length,f.length);let R=[];for(let $=0;$<=E.length;$++)R[$]=[$];for(let $=0;$<=f.length;$++)R[0][$]=$;for(let $=1;$<=f.length;$++)for(let S=1;S<=E.length;S++){let T=1;if(E[S-1]===f[$-1])T=0;else T=1;if(R[S][$]=Math.min(R[S-1][$]+1,R[S][$-1]+1,R[S-1][$-1]+T),S>1&&$>1&&E[S-1]===f[$-2]&&E[S-2]===f[$-1])R[S][$]=Math.min(R[S][$],R[S-2][$-2]+1)}return R[E.length][f.length]}function Ef(E,f){if(!f||f.length===0)return"";f=Array.from(new Set(f));let R=E.startsWith("--");if(R)E=E.slice(2),f=f.map((L)=>L.slice(2));let $=[],S=3,T=0.4;if(f.forEach((L)=>{if(L.length<=1)return;let _=aE(E,L),I=Math.max(E.length,L.length);if((I-_)/I>T){if(_<S)S=_,$=[L];else if(_===S)$.push(L)}}),$.sort((L,_)=>L.localeCompare(_)),R)$=$.map((L)=>`--${L}`);if($.length>1)return`
|
|
10
10
|
(Did you mean one of ${$.join(", ")}?)`;if($.length===1)return`
|
|
11
|
-
(Did you mean ${$[0]}?)`;return""}
|
|
12
|
-
- specify the name in Command constructor or using .name()`);if(f=f||{},f.isDefault)this._defaultCommandName=E._name;if(f.noHelp||f.hidden)E._hidden=!0;return this._registerCommand(E),E.parent=this,E._checkForBrokenPassThrough(),this}createArgument(E,f){return new
|
|
13
|
-
Expecting one of '${R.join("', '")}'`);if(this._lifeCycleHooks[E])this._lifeCycleHooks[E].push(f);else this._lifeCycleHooks[E]=[f];return this}exitOverride(E){if(E)this._exitCallback=E;else this._exitCallback=(f)=>{if(f.code!=="commander.executeSubCommandAsync")throw f};return this}_exit(E,f,R){if(this._exitCallback)this._exitCallback(new s(E,f,R));J.exit(E)}action(E){let f=(R)=>{let $=this.registeredArguments.length,S=R.slice(0,$);if(this._storeOptionsAsProperties)S[$]=this;else S[$]=this.opts();return S.push(this),E.apply(this,S)};return this._actionHandler=f,this}createOption(E,f){return new fE(E,f)}_callParseArg(E,f,R,$){try{return E.parseArg(f,R)}catch(S){if(S.code==="commander.invalidArgument"){let T=`${$} ${S.message}`;this.error(T,{exitCode:S.exitCode,code:S.code})}throw S}}_registerOption(E){let f=E.short&&this._findOption(E.short)||E.long&&this._findOption(E.long);if(f){let R=E.long&&this._findOption(E.long)?E.long:E.short;throw
|
|
14
|
-
- already used by option '${f.flags}'`)}this.options.push(E)}_registerCommand(E){let f=($)=>{return[$.name()].concat($.aliases())},R=f(E).find(($)=>this._findCommand($));if(R){let $=f(this._findCommand(R)).join("|"),S=f(E).join("|");throw
|
|
11
|
+
(Did you mean ${$[0]}?)`;return""}ff.suggestSimilar=Ef});var SE=X((If)=>{var $f=Q("node:events").EventEmitter,v=Q("node:child_process"),M=Q("node:path"),r=Q("node:fs"),J=Q("node:process"),{Argument:Sf,humanReadableArgName:Tf}=N(),{CommanderError:s}=K(),{Help:_f}=h(),{Option:fE,DualOptions:Lf}=O(),{suggestSimilar:RE}=EE();class t extends $f{constructor(E){super();this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!0,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._outputConfiguration={writeOut:(f)=>J.stdout.write(f),writeErr:(f)=>J.stderr.write(f),getOutHelpWidth:()=>J.stdout.isTTY?J.stdout.columns:void 0,getErrHelpWidth:()=>J.stderr.isTTY?J.stderr.columns:void 0,outputError:(f,R)=>R(f)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={}}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 f=this;f;f=f.parent)E.push(f);return E}command(E,f,R){let $=f,S=R;if(typeof $==="object"&&$!==null)S=$,$=null;S=S||{};let[,T,L]=E.match(/([^ ]+) *(.*)/),_=this.createCommand(T);if($)_.description($),_._executableHandler=!0;if(S.isDefault)this._defaultCommandName=_._name;if(_._hidden=!!(S.noHelp||S.hidden),_._executableFile=S.executableFile||null,L)_.arguments(L);if(this._registerCommand(_),_.parent=this,_.copyInheritedSettings(this),$)return this;return _}createCommand(E){return new t(E)}createHelp(){return Object.assign(new _f,this.configureHelp())}configureHelp(E){if(E===void 0)return this._helpConfiguration;return this._helpConfiguration=E,this}configureOutput(E){if(E===void 0)return this._outputConfiguration;return Object.assign(this._outputConfiguration,E),this}showHelpAfterError(E=!0){if(typeof E!=="string")E=!!E;return this._showHelpAfterError=E,this}showSuggestionAfterError(E=!0){return this._showSuggestionAfterError=!!E,this}addCommand(E,f){if(!E._name)throw Error(`Command passed to .addCommand() must have a name
|
|
12
|
+
- specify the name in Command constructor or using .name()`);if(f=f||{},f.isDefault)this._defaultCommandName=E._name;if(f.noHelp||f.hidden)E._hidden=!0;return this._registerCommand(E),E.parent=this,E._checkForBrokenPassThrough(),this}createArgument(E,f){return new Sf(E,f)}argument(E,f,R,$){let S=this.createArgument(E,f);if(typeof R==="function")S.default($).argParser(R);else S.default(R);return this.addArgument(S),this}arguments(E){return E.trim().split(/ +/).forEach((f)=>{this.argument(f)}),this}addArgument(E){let f=this.registeredArguments.slice(-1)[0];if(f&&f.variadic)throw Error(`only the last argument can be variadic '${f.name()}'`);if(E.required&&E.defaultValue!==void 0&&E.parseArg===void 0)throw Error(`a default value for a required argument is never used: '${E.name()}'`);return this.registeredArguments.push(E),this}helpCommand(E,f){if(typeof E==="boolean")return this._addImplicitHelpCommand=E,this;E=E??"help [command]";let[,R,$]=E.match(/([^ ]+) *(.*)/),S=f??"display help for command",T=this.createCommand(R);if(T.helpOption(!1),$)T.arguments($);if(S)T.description(S);return this._addImplicitHelpCommand=!0,this._helpCommand=T,this}addHelpCommand(E,f){if(typeof E!=="object")return this.helpCommand(E,f),this;return this._addImplicitHelpCommand=!0,this._helpCommand=E,this}_getHelpCommand(){if(this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))){if(this._helpCommand===void 0)this.helpCommand(void 0,void 0);return this._helpCommand}return null}hook(E,f){let R=["preSubcommand","preAction","postAction"];if(!R.includes(E))throw Error(`Unexpected value for event passed to hook : '${E}'.
|
|
13
|
+
Expecting one of '${R.join("', '")}'`);if(this._lifeCycleHooks[E])this._lifeCycleHooks[E].push(f);else this._lifeCycleHooks[E]=[f];return this}exitOverride(E){if(E)this._exitCallback=E;else this._exitCallback=(f)=>{if(f.code!=="commander.executeSubCommandAsync")throw f};return this}_exit(E,f,R){if(this._exitCallback)this._exitCallback(new s(E,f,R));J.exit(E)}action(E){let f=(R)=>{let $=this.registeredArguments.length,S=R.slice(0,$);if(this._storeOptionsAsProperties)S[$]=this;else S[$]=this.opts();return S.push(this),E.apply(this,S)};return this._actionHandler=f,this}createOption(E,f){return new fE(E,f)}_callParseArg(E,f,R,$){try{return E.parseArg(f,R)}catch(S){if(S.code==="commander.invalidArgument"){let T=`${$} ${S.message}`;this.error(T,{exitCode:S.exitCode,code:S.code})}throw S}}_registerOption(E){let f=E.short&&this._findOption(E.short)||E.long&&this._findOption(E.long);if(f){let R=E.long&&this._findOption(E.long)?E.long:E.short;throw Error(`Cannot add option '${E.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${R}'
|
|
14
|
+
- already used by option '${f.flags}'`)}this.options.push(E)}_registerCommand(E){let f=($)=>{return[$.name()].concat($.aliases())},R=f(E).find(($)=>this._findCommand($));if(R){let $=f(this._findCommand(R)).join("|"),S=f(E).join("|");throw Error(`cannot add command '${S}' as already have command '${$}'`)}this.commands.push(E)}addOption(E){this._registerOption(E);let f=E.name(),R=E.attributeName();if(E.negate){let S=E.long.replace(/^--no-/,"--");if(!this._findOption(S))this.setOptionValueWithSource(R,E.defaultValue===void 0?!0:E.defaultValue,"default")}else if(E.defaultValue!==void 0)this.setOptionValueWithSource(R,E.defaultValue,"default");let $=(S,T,L)=>{if(S==null&&E.presetArg!==void 0)S=E.presetArg;let _=this.getOptionValue(R);if(S!==null&&E.parseArg)S=this._callParseArg(E,S,_,T);else if(S!==null&&E.variadic)S=E._concatValue(S,_);if(S==null)if(E.negate)S=!1;else if(E.isBoolean()||E.optional)S=!0;else S="";this.setOptionValueWithSource(R,S,L)};if(this.on("option:"+f,(S)=>{let T=`error: option '${E.flags}' argument '${S}' is invalid.`;$(S,T,"cli")}),E.envVar)this.on("optionEnv:"+f,(S)=>{let T=`error: option '${E.flags}' value '${S}' from env '${E.envVar}' is invalid.`;$(S,T,"env")});return this}_optionEx(E,f,R,$,S){if(typeof f==="object"&&f instanceof fE)throw Error("To add an Option object use addOption() instead of option() or requiredOption()");let T=this.createOption(f,R);if(T.makeOptionMandatory(!!E.mandatory),typeof $==="function")T.default(S).argParser($);else if($ instanceof RegExp){let L=$;$=(_,I)=>{let w=L.exec(_);return w?w[0]:I},T.default(S).argParser($)}else T.default($);return this.addOption(T)}option(E,f,R,$){return this._optionEx({},E,f,R,$)}requiredOption(E,f,R,$){return this._optionEx({mandatory:!0},E,f,R,$)}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 Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(E=!0){if(this.options.length)throw Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!E,this}getOptionValue(E){if(this._storeOptionsAsProperties)return this[E];return this._optionValues[E]}setOptionValue(E,f){return this.setOptionValueWithSource(E,f,void 0)}setOptionValueWithSource(E,f,R){if(this._storeOptionsAsProperties)this[E]=f;else this._optionValues[E]=f;return this._optionValueSources[E]=R,this}getOptionValueSource(E){return this._optionValueSources[E]}getOptionValueSourceWithGlobals(E){let f;return this._getCommandAndAncestors().forEach((R)=>{if(R.getOptionValueSource(E)!==void 0)f=R.getOptionValueSource(E)}),f}_prepareUserArgs(E,f){if(E!==void 0&&!Array.isArray(E))throw Error("first parameter to parse must be array or undefined");if(f=f||{},E===void 0&&f.from===void 0){if(J.versions?.electron)f.from="electron";let $=J.execArgv??[];if($.includes("-e")||$.includes("--eval")||$.includes("-p")||$.includes("--print"))f.from="eval"}if(E===void 0)E=J.argv;this.rawArgs=E.slice();let R;switch(f.from){case void 0:case"node":this._scriptPath=E[1],R=E.slice(2);break;case"electron":if(J.defaultApp)this._scriptPath=E[1],R=E.slice(2);else R=E.slice(1);break;case"user":R=E.slice(0);break;case"eval":R=E.slice(1);break;default:throw Error(`unexpected parse option { from: '${f.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);return this._name=this._name||"program",R}parse(E,f){let R=this._prepareUserArgs(E,f);return this._parseCommand([],R),this}async parseAsync(E,f){let R=this._prepareUserArgs(E,f);return await this._parseCommand([],R),this}_executeSubCommand(E,f){f=f.slice();let R=!1,$=[".js",".ts",".tsx",".mjs",".cjs"];function S(w,y){let q=M.resolve(w,y);if(r.existsSync(q))return q;if($.includes(M.extname(y)))return;let Y=$.find((U)=>r.existsSync(`${q}${U}`));if(Y)return`${q}${Y}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let T=E._executableFile||`${this._name}-${E._name}`,L=this._executableDir||"";if(this._scriptPath){let w;try{w=r.realpathSync(this._scriptPath)}catch(y){w=this._scriptPath}L=M.resolve(M.dirname(w),L)}if(L){let w=S(L,T);if(!w&&!E._executableFile&&this._scriptPath){let y=M.basename(this._scriptPath,M.extname(this._scriptPath));if(y!==this._name)w=S(L,`${y}-${E._name}`)}T=w||T}R=$.includes(M.extname(T));let _;if(J.platform!=="win32")if(R)f.unshift(T),f=$E(J.execArgv).concat(f),_=v.spawn(J.argv[0],f,{stdio:"inherit"});else _=v.spawn(T,f,{stdio:"inherit"});else f.unshift(T),f=$E(J.execArgv).concat(f),_=v.spawn(J.execPath,f,{stdio:"inherit"});if(!_.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((y)=>{J.on(y,()=>{if(_.killed===!1&&_.exitCode===null)_.kill(y)})});let I=this._exitCallback;_.on("close",(w)=>{if(w=w??1,!I)J.exit(w);else I(new s(w,"commander.executeSubCommandAsync","(close)"))}),_.on("error",(w)=>{if(w.code==="ENOENT"){let y=L?`searched for local subcommand relative to directory '${L}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",q=`'${T}' does not exist
|
|
15
15
|
- if '${E._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
16
16
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
17
|
-
- ${y}`;throw
|
|
17
|
+
- ${y}`;throw Error(q)}else if(w.code==="EACCES")throw Error(`'${T}' not executable`);if(!I)J.exit(1);else{let y=new s(1,"commander.executeSubCommandAsync","(error)");y.nestedError=w,I(y)}}),this.runningCommand=_}_dispatchSubcommand(E,f,R){let $=this._findCommand(E);if(!$)this.help({error:!0});let S;return S=this._chainOrCallSubCommandHook(S,$,"preSubcommand"),S=this._chainOrCall(S,()=>{if($._executableHandler)this._executeSubCommand($,f.concat(R));else return $._parseCommand(f,R)}),S}_dispatchHelpCommand(E){if(!E)this.help();let f=this._findCommand(E);if(f&&!f._executableHandler)f.help();return this._dispatchSubcommand(E,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach((E,f)=>{if(E.required&&this.args[f]==null)this.missingArgument(E.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)return;if(this.args.length>this.registeredArguments.length)this._excessArguments(this.args)}_processArguments(){let E=(R,$,S)=>{let T=$;if($!==null&&R.parseArg){let L=`error: command-argument value '${$}' is invalid for argument '${R.name()}'.`;T=this._callParseArg(R,$,S,L)}return T};this._checkNumberOfArguments();let f=[];this.registeredArguments.forEach((R,$)=>{let S=R.defaultValue;if(R.variadic){if($<this.args.length){if(S=this.args.slice($),R.parseArg)S=S.reduce((T,L)=>{return E(R,L,T)},R.defaultValue)}else if(S===void 0)S=[]}else if($<this.args.length){if(S=this.args[$],R.parseArg)S=E(R,S,R.defaultValue)}f[$]=S}),this.processedArgs=f}_chainOrCall(E,f){if(E&&E.then&&typeof E.then==="function")return E.then(()=>f());return f()}_chainOrCallHooks(E,f){let R=E,$=[];if(this._getCommandAndAncestors().reverse().filter((S)=>S._lifeCycleHooks[f]!==void 0).forEach((S)=>{S._lifeCycleHooks[f].forEach((T)=>{$.push({hookedCommand:S,callback:T})})}),f==="postAction")$.reverse();return $.forEach((S)=>{R=this._chainOrCall(R,()=>{return S.callback(S.hookedCommand,this)})}),R}_chainOrCallSubCommandHook(E,f,R){let $=E;if(this._lifeCycleHooks[R]!==void 0)this._lifeCycleHooks[R].forEach((S)=>{$=this._chainOrCall($,()=>{return S(this,f)})});return $}_parseCommand(E,f){let R=this.parseOptions(f);if(this._parseOptionsEnv(),this._parseOptionsImplied(),E=E.concat(R.operands),f=R.unknown,this.args=E.concat(f),E&&this._findCommand(E[0]))return this._dispatchSubcommand(E[0],E.slice(1),f);if(this._getHelpCommand()&&E[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(E[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(f),this._dispatchSubcommand(this._defaultCommandName,E,f);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(R.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let $=()=>{if(R.unknown.length>0)this.unknownOption(R.unknown[0])},S=`command:${this.name()}`;if(this._actionHandler){$(),this._processArguments();let T;if(T=this._chainOrCallHooks(T,"preAction"),T=this._chainOrCall(T,()=>this._actionHandler(this.processedArgs)),this.parent)T=this._chainOrCall(T,()=>{this.parent.emit(S,E,f)});return T=this._chainOrCallHooks(T,"postAction"),T}if(this.parent&&this.parent.listenerCount(S))$(),this._processArguments(),this.parent.emit(S,E,f);else if(E.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",E,f);if(this.listenerCount("command:*"))this.emit("command:*",E,f);else if(this.commands.length)this.unknownCommand();else $(),this._processArguments()}else if(this.commands.length)$(),this.help({error:!0});else $(),this._processArguments()}_findCommand(E){if(!E)return;return this.commands.find((f)=>f._name===E||f._aliases.includes(E))}_findOption(E){return this.options.find((f)=>f.is(E))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach((E)=>{E.options.forEach((f)=>{if(f.mandatory&&E.getOptionValue(f.attributeName())===void 0)E.missingMandatoryOptionValue(f)})})}_checkForConflictingLocalOptions(){let E=this.options.filter((R)=>{let $=R.attributeName();if(this.getOptionValue($)===void 0)return!1;return this.getOptionValueSource($)!=="default"});E.filter((R)=>R.conflictsWith.length>0).forEach((R)=>{let $=E.find((S)=>R.conflictsWith.includes(S.attributeName()));if($)this._conflictingOption(R,$)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach((E)=>{E._checkForConflictingLocalOptions()})}parseOptions(E){let f=[],R=[],$=f,S=E.slice();function T(_){return _.length>1&&_[0]==="-"}let L=null;while(S.length){let _=S.shift();if(_==="--"){if($===R)$.push(_);$.push(...S);break}if(L&&!T(_)){this.emit(`option:${L.name()}`,_);continue}if(L=null,T(_)){let I=this._findOption(_);if(I){if(I.required){let w=S.shift();if(w===void 0)this.optionMissingArgument(I);this.emit(`option:${I.name()}`,w)}else if(I.optional){let w=null;if(S.length>0&&!T(S[0]))w=S.shift();this.emit(`option:${I.name()}`,w)}else this.emit(`option:${I.name()}`);L=I.variadic?I:null;continue}}if(_.length>2&&_[0]==="-"&&_[1]!=="-"){let I=this._findOption(`-${_[1]}`);if(I){if(I.required||I.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${I.name()}`,_.slice(2));else this.emit(`option:${I.name()}`),S.unshift(`-${_.slice(2)}`);continue}}if(/^--[^=]+=/.test(_)){let I=_.indexOf("="),w=this._findOption(_.slice(0,I));if(w&&(w.required||w.optional)){this.emit(`option:${w.name()}`,_.slice(I+1));continue}}if(T(_))$=R;if((this._enablePositionalOptions||this._passThroughOptions)&&f.length===0&&R.length===0){if(this._findCommand(_)){if(f.push(_),S.length>0)R.push(...S);break}else if(this._getHelpCommand()&&_===this._getHelpCommand().name()){if(f.push(_),S.length>0)f.push(...S);break}else if(this._defaultCommandName){if(R.push(_),S.length>0)R.push(...S);break}}if(this._passThroughOptions){if($.push(_),S.length>0)$.push(...S);break}$.push(_)}return{operands:f,unknown:R}}opts(){if(this._storeOptionsAsProperties){let E={},f=this.options.length;for(let R=0;R<f;R++){let $=this.options[R].attributeName();E[$]=$===this._versionOptionName?this._version:this[$]}return E}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((E,f)=>Object.assign(E,f.opts()),{})}error(E,f){if(this._outputConfiguration.outputError(`${E}
|
|
18
18
|
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==="string")this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
19
19
|
`);else if(this._showHelpAfterError)this._outputConfiguration.writeErr(`
|
|
20
|
-
`),this.outputHelp({error:!0});let R=f||{},$=R.exitCode||1,S=R.code||"commander.error";this._exit($,S,E)}_parseOptionsEnv(){this.options.forEach((E)=>{if(E.envVar&&E.envVar in J.env){let f=E.attributeName();if(this.getOptionValue(f)===void 0||["default","config","env"].includes(this.getOptionValueSource(f)))if(E.required||E.optional)this.emit(`optionEnv:${E.name()}`,J.env[E.envVar]);else this.emit(`optionEnv:${E.name()}`)}})}_parseOptionsImplied(){let E=new
|
|
21
|
-
`),this._exit(0,"commander.version",E)}),this}description(E,f){if(E===void 0&&f===void 0)return this._description;if(this._description=E,f)this._argsDescription=f;return this}summary(E){if(E===void 0)return this._summary;return this._summary=E,this}alias(E){if(E===void 0)return this._aliases[0];let f=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)f=this.commands[this.commands.length-1];if(E===f._name)throw
|
|
20
|
+
`),this.outputHelp({error:!0});let R=f||{},$=R.exitCode||1,S=R.code||"commander.error";this._exit($,S,E)}_parseOptionsEnv(){this.options.forEach((E)=>{if(E.envVar&&E.envVar in J.env){let f=E.attributeName();if(this.getOptionValue(f)===void 0||["default","config","env"].includes(this.getOptionValueSource(f)))if(E.required||E.optional)this.emit(`optionEnv:${E.name()}`,J.env[E.envVar]);else this.emit(`optionEnv:${E.name()}`)}})}_parseOptionsImplied(){let E=new Lf(this.options),f=(R)=>{return this.getOptionValue(R)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(R))};this.options.filter((R)=>R.implied!==void 0&&f(R.attributeName())&&E.valueFromOption(this.getOptionValue(R.attributeName()),R)).forEach((R)=>{Object.keys(R.implied).filter(($)=>!f($)).forEach(($)=>{this.setOptionValueWithSource($,R.implied[$],"implied")})})}missingArgument(E){let f=`error: missing required argument '${E}'`;this.error(f,{code:"commander.missingArgument"})}optionMissingArgument(E){let f=`error: option '${E.flags}' argument missing`;this.error(f,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(E){let f=`error: required option '${E.flags}' not specified`;this.error(f,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(E,f){let R=(T)=>{let L=T.attributeName(),_=this.getOptionValue(L),I=this.options.find((y)=>y.negate&&L===y.attributeName()),w=this.options.find((y)=>!y.negate&&L===y.attributeName());if(I&&(I.presetArg===void 0&&_===!1||I.presetArg!==void 0&&_===I.presetArg))return I;return w||T},$=(T)=>{let L=R(T),_=L.attributeName();if(this.getOptionValueSource(_)==="env")return`environment variable '${L.envVar}'`;return`option '${L.flags}'`},S=`error: ${$(E)} cannot be used with ${$(f)}`;this.error(S,{code:"commander.conflictingOption"})}unknownOption(E){if(this._allowUnknownOption)return;let f="";if(E.startsWith("--")&&this._showSuggestionAfterError){let $=[],S=this;do{let T=S.createHelp().visibleOptions(S).filter((L)=>L.long).map((L)=>L.long);$=$.concat(T),S=S.parent}while(S&&!S._enablePositionalOptions);f=RE(E,$)}let R=`error: unknown option '${E}'${f}`;this.error(R,{code:"commander.unknownOption"})}_excessArguments(E){if(this._allowExcessArguments)return;let f=this.registeredArguments.length,R=f===1?"":"s",S=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${f} argument${R} but got ${E.length}.`;this.error(S,{code:"commander.excessArguments"})}unknownCommand(){let E=this.args[0],f="";if(this._showSuggestionAfterError){let $=[];this.createHelp().visibleCommands(this).forEach((S)=>{if($.push(S.name()),S.alias())$.push(S.alias())}),f=RE(E,$)}let R=`error: unknown command '${E}'${f}`;this.error(R,{code:"commander.unknownCommand"})}version(E,f,R){if(E===void 0)return this._version;this._version=E,f=f||"-V, --version",R=R||"output the version number";let $=this.createOption(f,R);return this._versionOptionName=$.attributeName(),this._registerOption($),this.on("option:"+$.name(),()=>{this._outputConfiguration.writeOut(`${E}
|
|
21
|
+
`),this._exit(0,"commander.version",E)}),this}description(E,f){if(E===void 0&&f===void 0)return this._description;if(this._description=E,f)this._argsDescription=f;return this}summary(E){if(E===void 0)return this._summary;return this._summary=E,this}alias(E){if(E===void 0)return this._aliases[0];let f=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)f=this.commands[this.commands.length-1];if(E===f._name)throw Error("Command alias can't be the same as its name");let R=this.parent?._findCommand(E);if(R){let $=[R.name()].concat(R.aliases()).join("|");throw Error(`cannot add alias '${E}' to command '${this.name()}' as already have command '${$}'`)}return f._aliases.push(E),this}aliases(E){if(E===void 0)return this._aliases;return E.forEach((f)=>this.alias(f)),this}usage(E){if(E===void 0){if(this._usage)return this._usage;let f=this.registeredArguments.map((R)=>{return Tf(R)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?f:[]).join(" ")}return this._usage=E,this}name(E){if(E===void 0)return this._name;return this._name=E,this}nameFromFilename(E){return this._name=M.basename(E,M.extname(E)),this}executableDir(E){if(E===void 0)return this._executableDir;return this._executableDir=E,this}helpInformation(E){let f=this.createHelp();if(f.helpWidth===void 0)f.helpWidth=E&&E.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth();return f.formatHelp(this,f)}_getHelpContext(E){E=E||{};let f={error:!!E.error},R;if(f.error)R=($)=>this._outputConfiguration.writeErr($);else R=($)=>this._outputConfiguration.writeOut($);return f.write=E.write||R,f.command=this,f}outputHelp(E){let f;if(typeof E==="function")f=E,E=void 0;let R=this._getHelpContext(E);this._getCommandAndAncestors().reverse().forEach((S)=>S.emit("beforeAllHelp",R)),this.emit("beforeHelp",R);let $=this.helpInformation(R);if(f){if($=f($),typeof $!=="string"&&!Buffer.isBuffer($))throw Error("outputHelp callback must return a string or a Buffer")}if(R.write($),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",R),this._getCommandAndAncestors().forEach((S)=>S.emit("afterAllHelp",R))}helpOption(E,f){if(typeof E==="boolean"){if(E)this._helpOption=this._helpOption??void 0;else this._helpOption=null;return this}return E=E??"-h, --help",f=f??"display help for command",this._helpOption=this.createOption(E,f),this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption(E){return this._helpOption=E,this}help(E){this.outputHelp(E);let f=J.exitCode||0;if(f===0&&E&&typeof E!=="function"&&E.error)f=1;this._exit(f,"commander.help","(outputHelp)")}addHelpText(E,f){let R=["beforeAll","before","after","afterAll"];if(!R.includes(E))throw Error(`Unexpected value for position to addHelpText.
|
|
22
22
|
Expecting one of '${R.join("', '")}'`);let $=`${E}Help`;return this.on($,(S)=>{let T;if(typeof f==="function")T=f({error:S.error,command:S.command});else T=f;if(T)S.write(`${T}
|
|
23
|
-
`)}),this}_outputHelpIfRequested(E){let f=this._getHelpOption();if(f&&E.find(($)=>f.is($)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function $E(E){return E.map((f)=>{if(!f.startsWith("--inspect"))return f;let R,$="127.0.0.1",S="9229",T;if((T=f.match(/^(--inspect(-brk)?)$/))!==null)R=T[1];else if((T=f.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(R=T[1],/^\d+$/.test(T[3]))S=T[3];else $=T[3];else if((T=f.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)R=T[1],$=T[3],S=T[4];if(R&&S!=="0")return`${R}=${$}:${parseInt(S)+1}`;return f})}
|
|
24
|
-
`;if(await
|
|
25
|
-
`).filter((L)=>L.trim().length>0).slice(-E).reverse(),T=[];for(let L of S)try{T.push(JSON.parse(L))}catch{}return T}function
|
|
26
|
-
`)}var BE=80,
|
|
23
|
+
`)}),this}_outputHelpIfRequested(E){let f=this._getHelpOption();if(f&&E.find(($)=>f.is($)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function $E(E){return E.map((f)=>{if(!f.startsWith("--inspect"))return f;let R,$="127.0.0.1",S="9229",T;if((T=f.match(/^(--inspect(-brk)?)$/))!==null)R=T[1];else if((T=f.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(R=T[1],/^\d+$/.test(T[3]))S=T[3];else $=T[3];else if((T=f.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)R=T[1],$=T[3],S=T[4];if(R&&S!=="0")return`${R}=${$}:${parseInt(S)+1}`;return f})}If.Command=t});var IE=X((Uf)=>{var{Argument:TE}=N(),{Command:c}=SE(),{CommanderError:yf,InvalidArgumentError:_E}=K(),{Help:Jf}=h(),{Option:LE}=O();Uf.program=new c;Uf.createCommand=(E)=>new c(E);Uf.createOption=(E,f)=>new LE(E,f);Uf.createArgument=(E,f)=>new TE(E,f);Uf.Command=c;Uf.Option=LE;Uf.Argument=TE;Uf.Help=Jf;Uf.CommanderError=yf;Uf.InvalidArgumentError=_E;Uf.InvalidOptionArgumentError=_E});var wE=bE(IE(),1),{program:X0,createCommand:z0,createArgument:Z0,createOption:j0,CommanderError:B0,InvalidArgumentError:Q0,InvalidOptionArgumentError:K0,Command:G,Argument:H0,Option:N0,Help:W0}=wE.default;import{readFile as gf}from"node:fs/promises";import{resolve as nf}from"node:path";var yE={name:"@shotstack/cli",version:"0.1.3",description:"Command-line interface for the Shotstack video rendering API.",license:"Apache-2.0",homepage:"https://github.com/shotstack/shotstack-cli",repository:{type:"git",url:"git+https://github.com/shotstack/shotstack-cli.git"},bugs:{url:"https://github.com/shotstack/shotstack-cli/issues"},type:"module",bin:{shotstack:"dist/shotstack.js"},files:["dist/shotstack.js","SKILL.md","references"],scripts:{start:"bun run src/index.ts",build:"bun build src/index.ts --target=node --minify --outfile=dist/shotstack.js --banner='#!/usr/bin/env node' && chmod +x dist/shotstack.js",prepack:"bun run build",typecheck:"tsc --noEmit",test:"bun test"},dependencies:{commander:"^12.1.0"},devDependencies:{"@types/bun":"latest",typescript:"^5.6.0"}};var H=yE.version,JE=`shotstack-cli/${H} (${process.platform}-${process.arch})`;class z extends Error{status;body;constructor(E,f,R){super(R);this.status=E;this.body=f;this.name="ApiError"}get isTransient(){return this.status>=500||this.status===429}}function W(E){let f=E.env.baseUrl.replace(/\/$/,"");async function R($,S,T){let L=await fetch(`${f}${S}`,{method:$,headers:{"x-api-key":E.apiKey,"x-shotstack-origin":"cli","x-shotstack-environment":E.env.name,"user-agent":JE,...T!==void 0?{"content-type":"application/json"}:{}},body:T!==void 0?JSON.stringify(T):void 0}),_=await L.text(),I=_?Hf(_):void 0;if(!L.ok)throw new z(L.status,I??_,`${$} ${S} → ${L.status} ${L.statusText}`);return I}return{post:($,S)=>R("POST",$,S),get:($)=>R("GET",$)}}function Hf(E){try{return JSON.parse(E)}catch{return E}}class Z extends Error{constructor(){super("SHOTSTACK_API_KEY is not set. Get a key at https://shotstack.io.");this.name="MissingApiKeyError"}}function D(){let E=process.env.SHOTSTACK_API_KEY?.trim();if(!E)throw new Z;return E}var UE={dev:"https://api.shotstack.io/edit/dev",stage:"https://api.shotstack.io/edit/stage",v1:"https://api.shotstack.io/edit/v1"},j=Object.keys(UE);class B extends Error{constructor(E){super(`Invalid environment "${E}". Use one of: ${j.join(", ")}.`);this.name="InvalidEnvError"}}function F(E){let f=process.env.SHOTSTACK_API_BASE_URL?.trim();if(f)return{name:"custom",baseUrl:f};let R=E??process.env.SHOTSTACK_ENV?.trim()??"v1";if(!Nf(R))throw new B(R);return{name:R,baseUrl:UE[R]}}function Nf(E){return j.includes(E)}function k(E){if(E==="json")return"json";return"text"}function V(E,f,R){if(E==="json")console.log(JSON.stringify(f));else console.log(R)}import{mkdir as Wf,appendFile as Df,stat as GE,readFile as Ff,writeFile as YE}from"node:fs/promises";import{join as g,dirname as kf}from"node:path";import{homedir as qE}from"node:os";var Vf=1e6,Af=500000,ME=2000;function A(){if(process.platform==="win32"){let E=process.env.APPDATA??g(qE(),"AppData","Roaming");return g(E,"shotstack","log.jsonl")}return g(qE(),".shotstack","log.jsonl")}function xf(E,f=new Date){let R={ts:f.toISOString(),cmd:E.cmd,args:E.args.map(rf),exit:E.exit,durationMs:E.durationMs};if(E.renderId)R.renderId=E.renderId;if(E.response!==void 0)R.response=tf(n(E.response));if(E.error)R.error=bf(E.error);return R}function bf(E){return{name:E.name,message:typeof E.message==="string"?i(E.message):String(E.message)}}function Cf(E){if(E instanceof Error)return{name:E.name,message:E.message};if(E===void 0||E===null)return;return{name:"Unknown",message:String(E)}}async function PE(E,f=A()){let R=xf(E),$=JSON.stringify(R)+`
|
|
24
|
+
`;if(await Wf(kf(f),{recursive:!0,mode:448}),!await uf(f))await YE(f,"",{mode:384});await Df(f,$),await hf(f)}async function uf(E){try{return await GE(E),!0}catch{return!1}}async function hf(E){let f=await GE(E).catch(()=>null);if(!f||f.size<=Vf)return;let R=await Ff(E),$=R.subarray(Math.max(0,R.length-Af)),S=$.indexOf(10),T=S>=0?$.subarray(S+1):$;await YE(E,T,{mode:384})}var Of=/^https?:\/\//i,vf=/(https?:\/\/[^\s'"<>]+?)\?[^\s'"<>]*?(?:Signature|X-Amz-[A-Za-z0-9-]*)=[^\s'"<>]*/gi;function i(E){return E.replace(vf,"$1?[redacted-signed]")}function rf(E){if(typeof E!=="string")return E;if(E.startsWith("-"))return E;if(Of.test(E))return i(E);if(/[\/\\]/.test(E))return sf(E);return E}function sf(E){let f=E.split(/[\/\\]/);return f[f.length-1]||E}function n(E){if(typeof E==="string")return i(E);if(Array.isArray(E))return E.map(n);if(E&&typeof E==="object"){let f={};for(let[R,$]of Object.entries(E))f[R]=n($);return f}return E}function tf(E){let f=JSON.stringify(E);if(f===void 0||f.length<=ME)return E;return f.slice(0,ME)+"...[truncated]"}async function x(E,f,R){let $=Date.now();try{let S=await R(),T=S.exitCode??0;if(await PE({cmd:E,args:f,exit:T,durationMs:Date.now()-$,renderId:S.renderId,response:S.response}).catch(()=>{}),T!==0)process.exit(T)}catch(S){let T=cf(S),L=S instanceof z?S.body:void 0;throw await PE({cmd:E,args:f,exit:T,durationMs:Date.now()-$,response:L,error:Cf(S)}).catch(()=>{}),S}}function cf(E){if(E instanceof z)return E.isTransient?2:1;if(E instanceof Z||E instanceof B)return 1;if(E instanceof Error&&E.code==="ENOENT")return 1;return 2}function b(E){let f=process.argv.slice(2),R=f.indexOf(E);return R>=0?f.slice(R+1):f}var XE=new G("render").description("Submit a Shotstack timeline JSON to the render API").argument("<file>","Path to a Shotstack timeline JSON file").option("--env <name>",`Environment: ${j.join(" | ")}`).option("--output <format>","Output format: text | json","text").action(async(E,f)=>{await x("render",b("render"),async()=>{let R=k(f.output),$=D(),S=F(f.env),T=nf(process.cwd(),E),L=await gf(T,"utf8"),_=JSON.parse(L),w=await W({apiKey:$,env:S}).post("/render",_),y=w.response.id;return V(R,{id:y},y),{renderId:y,response:w.response}})});var lf=new Set(["done","failed"]),mf=3000,zE=new G("status").description("Poll the status of a Shotstack render").argument("<id>","Render ID returned by `shotstack render`").option("--watch","Poll continuously until the render reaches a terminal state").option("--env <name>",`Environment: ${j.join(" | ")}`).option("--output <format>","Output format: text | json","text").action(async(E,f)=>{await x("status",b("status"),async()=>{let R=k(f.output),$=D(),S=F(f.env),T=W({apiKey:$,env:S});while(!0){let _=(await T.get(`/render/${encodeURIComponent(E)}`)).response;if(V(R,_,df(_)),!f.watch||lf.has(_.status)){let I=_.status==="failed"?1:0;return{renderId:_.id,response:_,exitCode:I}}await pf(mf)}})});function df(E){let f=[E.status];if(E.url)f.push(E.url);if(E.error)f.push(`error: ${E.error}`);return f.join(" ")}function pf(E){return new Promise((f)=>setTimeout(f,E))}import{readFile as of,writeFile as ef,mkdtemp as af}from"node:fs/promises";import{tmpdir as E0}from"node:os";import{join as ZE}from"node:path";import{spawn as f0}from"node:child_process";var jE="https://github.com/shotstack/shotstack-cli/issues/new?template=bug.yml",R0=6000,HE=5,NE=new G("feedback").description("Open a pre-filled GitHub issue with a flight-recorder dossier from your last 5 invocations").action(async()=>{let E=await $0(HE),f=S0(E),R=_0(E),$=`&title=${encodeURIComponent(R)}`,S=`${jE}${$}&body=${encodeURIComponent(f)}`;if(S.length<=R0){KE(S),console.log("Opened browser with pre-filled issue. Review before submitting.");return}let T=await af(ZE(E0(),"shotstack-feedback-")),L=ZE(T,"dossier.md");await ef(L,f),KE(`${jE}${$}`),console.log(`Dossier too large to inline. Saved to: ${L}`),console.log("Drag the file into the issue body, or paste its contents.")});async function $0(E){let f=A(),R;try{R=await of(f,"utf8")}catch{return[]}let S=R.split(`
|
|
25
|
+
`).filter((L)=>L.trim().length>0).slice(-E).reverse(),T=[];for(let L of S)try{T.push(JSON.parse(L))}catch{}return T}function S0(E){let f=[];if(f.push("## Environment"),f.push(`- Shotstack CLI: ${H}`),f.push(`- OS: ${process.platform}-${process.arch}`),f.push(""),f.push(`## Last ${HE} invocations (most recent first)`),f.push(""),E.length===0)f.push("_No recorded invocations._");else for(let R of E){let $=(R.args??[]).join(" "),S=`### ${R.ts} — shotstack ${R.cmd}${$?" "+$:""}`;if(f.push(S),f.push(`- Exit: ${R.exit} Duration: ${R.durationMs}ms`),R.renderId)f.push(`- Render ID: ${R.renderId}`);if(R.response!==void 0){let T=typeof R.response==="string"?R.response:JSON.stringify(R.response);f.push(`- Response: ${T}`)}if(R.error)f.push(`- Error: ${R.error.name}: ${R.error.message}`);f.push("")}return f.push(`[full log at ${A()}]`),f.push(""),f.push("## What I expected vs what happened"),f.push("<!-- Describe the issue, request, or question here. -->"),f.join(`
|
|
26
|
+
`)}var BE=80,T0="Feedback from shotstack CLI";function _0(E){let f=E.find((S)=>S.error);if(f&&f.error)return l(`${f.cmd}: ${f.error.name} — ${f.error.message}`);let R=E.find((S)=>QE(S.response)!==null);if(R){let S=QE(R.response);return l(`Render failed: ${S}`)}let $=E.find((S)=>S.exit!==0);if($)return l(`${$.cmd} exited ${$.exit}`);return T0}function QE(E){if(!E||typeof E!=="object"||Array.isArray(E))return null;let f=E;if(f.state!=="failed")return null;return typeof f.error==="string"&&f.error.length>0?f.error:"unknown error"}function l(E){return E.length<=BE?E:E.slice(0,BE-1)+"…"}function KE(E){let f=process.platform==="win32",R=process.platform==="darwin"?"open":f?"cmd":"xdg-open",S=f0(R,f?["/c","start","",E]:[E],{stdio:"ignore",detached:!0});S.on("error",()=>{console.error(`Could not open browser. Visit: ${E}`)}),S.unref()}var L0=new G().name("shotstack").description("Command-line interface for the Shotstack video rendering API").version(H).addCommand(XE).addCommand(zE).addCommand(NE);try{await L0.parseAsync(process.argv)}catch(E){process.exit(I0(E))}function I0(E){if(E instanceof Z||E instanceof B)return console.error(E.message),1;if(E instanceof z){if(console.error(E.message),E.body)console.error(typeof E.body==="string"?E.body:JSON.stringify(E.body));return E.isTransient?2:1}if(E instanceof Error){if("code"in E&&E.code==="ENOENT")return console.error(E.message),1;return console.error(E.message),2}return console.error(String(E)),2}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shotstack/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Command-line interface for the Shotstack video rendering API.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/shotstack/shotstack-cli",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"type": "module",
|
|
15
15
|
"bin": {
|
|
16
|
-
"shotstack": "
|
|
16
|
+
"shotstack": "dist/shotstack.js"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/shotstack.js",
|