vidup 1.0.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/bin/cli.js +113 -0
- package/dist/.DS_Store +0 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/strip.d.ts +14 -0
- package/dist/sync.d.ts +22 -0
- package/dist/utilities/log.d.ts +13 -0
- package/dist/utilities/video.d.ts +3 -0
- package/license.txt +21 -0
- package/package.json +78 -0
- package/readme.md +225 -0
package/bin/cli.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var Me=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')});var vn=(i=0)=>e=>`\x1B[${e+i}m`,$n=(i=0)=>e=>`\x1B[${38+i};5;${e}m`,Nn=(i=0)=>(e,t,n)=>`\x1B[${38+i};2;${e};${t};${n}m`,Q={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},Nr=Object.keys(Q.modifier),ts=Object.keys(Q.color),ns=Object.keys(Q.bgColor),Fr=[...ts,...ns];function is(){let i=new Map;for(let[e,t]of Object.entries(Q)){for(let[n,s]of Object.entries(t))Q[n]={open:`\x1B[${s[0]}m`,close:`\x1B[${s[1]}m`},t[n]=Q[n],i.set(s[0],s[1]);Object.defineProperty(Q,e,{value:t,enumerable:!1})}return Object.defineProperty(Q,"codes",{value:i,enumerable:!1}),Q.color.close="\x1B[39m",Q.bgColor.close="\x1B[49m",Q.color.ansi=vn(),Q.color.ansi256=$n(),Q.color.ansi16m=Nn(),Q.bgColor.ansi=vn(10),Q.bgColor.ansi256=$n(10),Q.bgColor.ansi16m=Nn(10),Object.defineProperties(Q,{rgbToAnsi256:{value(e,t,n){return e===t&&t===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5)},enumerable:!1},hexToRgb:{value(e){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[n]=t;n.length===3&&(n=[...n].map(r=>r+r).join(""));let s=Number.parseInt(n,16);return[s>>16&255,s>>8&255,s&255]},enumerable:!1},hexToAnsi256:{value:e=>Q.rgbToAnsi256(...Q.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,n,s;if(e>=232)t=((e-232)*10+8)/255,n=t,s=t;else{e-=16;let c=e%36;t=Math.floor(e/36)/5,n=Math.floor(c/6)/5,s=c%6/5}let r=Math.max(t,n,s)*2;if(r===0)return 30;let a=30+(Math.round(s)<<2|Math.round(n)<<1|Math.round(t));return r===2&&(a+=60),a},enumerable:!1},rgbToAnsi:{value:(e,t,n)=>Q.ansi256ToAnsi(Q.rgbToAnsi256(e,t,n)),enumerable:!1},hexToAnsi:{value:e=>Q.ansi256ToAnsi(Q.hexToAnsi256(e)),enumerable:!1}}),Q}var ss=is(),Se=ss;import qt from"node:process";import rs from"node:os";import Fn from"node:tty";function ye(i,e=globalThis.Deno?globalThis.Deno.args:qt.argv){let t=i.startsWith("-")?"":i.length===1?"-":"--",n=e.indexOf(t+i),s=e.indexOf("--");return n!==-1&&(s===-1||n<s)}var{env:X}=qt,Ot;ye("no-color")||ye("no-colors")||ye("color=false")||ye("color=never")?Ot=0:(ye("color")||ye("colors")||ye("color=true")||ye("color=always"))&&(Ot=1);function os(){if("FORCE_COLOR"in X)return X.FORCE_COLOR==="true"?1:X.FORCE_COLOR==="false"?0:X.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(X.FORCE_COLOR,10),3)}function as(i){return i===0?!1:{level:i,hasBasic:!0,has256:i>=2,has16m:i>=3}}function ls(i,{streamIsTTY:e,sniffFlags:t=!0}={}){let n=os();n!==void 0&&(Ot=n);let s=t?Ot:n;if(s===0)return 0;if(t){if(ye("color=16m")||ye("color=full")||ye("color=truecolor"))return 3;if(ye("color=256"))return 2}if("TF_BUILD"in X&&"AGENT_NAME"in X)return 1;if(i&&!e&&s===void 0)return 0;let r=s||0;if(X.TERM==="dumb")return r;if(qt.platform==="win32"){let a=rs.release().split(".");return Number(a[0])>=10&&Number(a[2])>=10586?Number(a[2])>=14931?3:2:1}if("CI"in X)return"GITHUB_ACTIONS"in X||"GITEA_ACTIONS"in X?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(a=>a in X)||X.CI_NAME==="codeship"?1:r;if("TEAMCITY_VERSION"in X)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(X.TEAMCITY_VERSION)?1:0;if(X.COLORTERM==="truecolor"||X.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in X){let a=Number.parseInt((X.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(X.TERM_PROGRAM){case"iTerm.app":return a>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(X.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(X.TERM)||"COLORTERM"in X?1:r}function Rn(i,e={}){let t=ls(i,{streamIsTTY:i&&i.isTTY,...e});return as(t)}var cs={stdout:Rn({isTTY:Fn.isatty(1)}),stderr:Rn({isTTY:Fn.isatty(2)})},Dn=cs;function Tn(i,e,t){let n=i.indexOf(e);if(n===-1)return i;let s=e.length,r=0,a="";do a+=i.slice(r,n)+e+t,r=n+s,n=i.indexOf(e,r);while(n!==-1);return a+=i.slice(r),a}function Ln(i,e,t,n){let s=0,r="";do{let a=i[n-1]==="\r";r+=i.slice(s,a?n-1:n)+e+(a?`\r
|
|
3
|
+
`:`
|
|
4
|
+
`)+t,s=n+1,n=i.indexOf(`
|
|
5
|
+
`,s)}while(n!==-1);return r+=i.slice(s),r}var{stdout:Wn,stderr:Un}=Dn,Kt=Symbol("GENERATOR"),nt=Symbol("STYLER"),ft=Symbol("IS_EMPTY"),Bn=["ansi","ansi","ansi256","ansi16m"],it=Object.create(null),fs=(i,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=Wn?Wn.level:0;i.level=e.level===void 0?t:e.level};var us=i=>{let e=(...t)=>t.join(" ");return fs(e,i),Object.setPrototypeOf(e,ut.prototype),e};function ut(i){return us(i)}Object.setPrototypeOf(ut.prototype,Function.prototype);for(let[i,e]of Object.entries(Se))it[i]={get(){let t=_t(this,Qt(e.open,e.close,this[nt]),this[ft]);return Object.defineProperty(this,i,{value:t}),t}};it.visible={get(){let i=_t(this,this[nt],!0);return Object.defineProperty(this,"visible",{value:i}),i}};var Jt=(i,e,t,...n)=>i==="rgb"?e==="ansi16m"?Se[t].ansi16m(...n):e==="ansi256"?Se[t].ansi256(Se.rgbToAnsi256(...n)):Se[t].ansi(Se.rgbToAnsi(...n)):i==="hex"?Jt("rgb",e,t,...Se.hexToRgb(...n)):Se[t][i](...n),hs=["rgb","hex","ansi256"];for(let i of hs){it[i]={get(){let{level:t}=this;return function(...n){let s=Qt(Jt(i,Bn[t],"color",...n),Se.color.close,this[nt]);return _t(this,s,this[ft])}}};let e="bg"+i[0].toUpperCase()+i.slice(1);it[e]={get(){let{level:t}=this;return function(...n){let s=Qt(Jt(i,Bn[t],"bgColor",...n),Se.bgColor.close,this[nt]);return _t(this,s,this[ft])}}}}var ds=Object.defineProperties(()=>{},{...it,level:{enumerable:!0,get(){return this[Kt].level},set(i){this[Kt].level=i}}}),Qt=(i,e,t)=>{let n,s;return t===void 0?(n=i,s=e):(n=t.openAll+i,s=e+t.closeAll),{open:i,close:e,openAll:n,closeAll:s,parent:t}},_t=(i,e,t)=>{let n=(...s)=>ps(n,s.length===1?""+s[0]:s.join(" "));return Object.setPrototypeOf(n,ds),n[Kt]=i,n[nt]=e,n[ft]=t,n},ps=(i,e)=>{if(i.level<=0||!e)return i[ft]?"":e;let t=i[nt];if(t===void 0)return e;let{openAll:n,closeAll:s}=t;if(e.includes("\x1B"))for(;t!==void 0;)e=Tn(e,t.close,t.open),t=t.parent;let r=e.indexOf(`
|
|
6
|
+
`);return r!==-1&&(e=Ln(e,s,n,r)),n+e+s};Object.defineProperties(ut.prototype,it);var ms=ut(),Hr=ut({level:Un?Un.level:0});var Pe=ms;import{oraPromise as gs}from"ora";var zn,Vn=((zn=process==null?void 0:process.versions)==null?void 0:zn.node)!==void 0,bs={verbose:!1,log(...i){if(!this.verbose)return;let e=Pe.gray("[Log]");Vn?console.warn(e,...i):console.log(e,...i)},logPrefixed(i,...e){this.info(Pe.blue(`[${i}]`),...e)},info(...i){if(!this.verbose)return;let e=Pe.green("[Info]");Vn?console.warn(e,...i):console.info(e,...i)},infoPrefixed(i,...e){this.info(Pe.blue(`[${i}]`),...e)},async infoSpin(i,e){return gs(i,{prefixText:Pe.green("[Info]"),stream:process.stderr,text:e})},warn(...i){console.warn(Pe.yellow("[Warning]"),...i)},warnPrefixed(i,...e){this.warn(Pe.blue(`[${i}]`),...e)},error(...i){console.error(Pe.red("[Error]"),...i)},errorPrefixed(i,...e){this.error(Pe.blue(`[${i}]`),...e)}},G=bs;import{execa as Yn}from"execa";import Ct from"ffmpeg-static";import Gn from"node:fs/promises";import Zt from"node:path";import ys from"node:os";var Hn=ys.homedir();function st(i){if(typeof i!="string")throw new TypeError(`Expected a string, got ${typeof i}`);return Hn?i.replace(/^~(?=$|\/|\\)/,Hn):i}async function Xt(i){let e=st(i);return(await Gn.readdir(e)).filter(s=>{let r=Zt.extname(s);return[".mp4",".mov",".avi",".mkv"].includes(r)}).map(s=>Zt.join(e,s))}async function qn(i){if(Ct===null)throw new Error("ffmpeg-static failed to locate ffmpeg binary");try{let{stderr:e,stdout:t}=await Yn(Ct,["-i",i,"-f","ffmetadata","-"]);return t.includes("creation_time")||e.includes("creation_time")}catch(e){throw new Error(`Failed to check metadata for: ${i}:
|
|
7
|
+
${String(e)}`)}}async function Kn(i){if(Ct===null)throw new Error("ffmpeg-static failed to locate ffmpeg binary");try{let e=Zt.extname(i).slice(1),t=`${i.slice(0,Math.max(0,i.lastIndexOf(".")))}.temp.${e}`;await Yn(Ct,["-i",i,"-map_metadata","-1","-c:v","copy","-c:a","copy",t]),await Gn.rename(t,i)}catch(e){throw new Error(`Failed to strip metadata from: ${i}:
|
|
8
|
+
${String(e)}`)}}async function Jn(i,e={}){let{dryRun:t=!1,verbose:n=!1}=e,s=G.verbose;G.verbose=n;let r=[];for(let a of i)await qn(a)&&r.push(a);if(!t){G.info(`Found ${r.length} videos with metadata to strip`);for(let a of r)console.log(`Stripping metadata from: ${a}`),await Kn(a)}return G.verbose=s,r}import{BunnyCdnStream as Ps}from"bunnycdn-stream";import{hash as Is}from"hasha";import{readFile as js}from"node:fs/promises";import{rename as ws,writeFile as Os}from"node:fs/promises";import{basename as _s,dirname as Cs,join as xs}from"node:path";import{fileURLToPath as Es}from"node:url";function As(i){let e=i instanceof URL?Es(i):i.toString();return xs(Cs(e),`.${_s(e)}.tmp`)}async function Ss(i,e,t){for(let n=0;n<e;n++)try{return await i()}catch(s){if(n<e-1)await new Promise(r=>setTimeout(r,t));else throw s}}var xt=class{#e;#t;#n=!1;#s=null;#r=null;#o=null;#i=null;#a(e){return this.#i=e,this.#o||=new Promise((t,n)=>{this.#r=[t,n]}),new Promise((t,n)=>{var s;(s=this.#o)==null||s.then(t).catch(n)})}async#l(e){var t,n;this.#n=!0;try{await Os(this.#t,e,"utf-8"),await Ss(async()=>{await ws(this.#t,this.#e)},10,100),(t=this.#s)==null||t[0]()}catch(s){throw s instanceof Error&&((n=this.#s)==null||n[1](s)),s}finally{if(this.#n=!1,this.#s=this.#r,this.#r=this.#o=null,this.#i!==null){let s=this.#i;this.#i=null,await this.write(s)}}}constructor(e){this.#e=e,this.#t=As(e)}async write(e){return this.#n?this.#a(e):this.#l(e)}};var Et=class{#e;#t;constructor(e){this.#e=e,this.#t=new xt(e)}async read(){let e;try{e=await js(this.#e,"utf-8")}catch(t){if(t.code==="ENOENT")return null;throw t}return e}write(e){return this.#t.write(e)}};var At=class{#e;#t;#n;constructor(e,{parse:t,stringify:n}){this.#e=new Et(e),this.#t=t,this.#n=n}async read(){let e=await this.#e.read();return e===null?null:this.#t(e)}write(e){return this.#e.write(this.#n(e))}};var St=class extends At{constructor(e){super(e,{parse:JSON.parse,stringify:t=>JSON.stringify(t,null,2)})}};var jt=class{#e=null;read(){return Promise.resolve(this.#e)}write(e){return this.#e=e,Promise.resolve()}};function Ms(i,e){if(i===void 0)throw new Error("lowdb: missing adapter");if(e===void 0)throw new Error("lowdb: missing default data")}var Mt=class{adapter;data;constructor(e,t){Ms(e,t),this.adapter=e,this.data=t}async read(){let e=await this.adapter.read();e&&(this.data=e)}async write(){this.data&&await this.adapter.write(this.data)}async update(e){e(this.data),await this.write()}};async function Qn(i,e){let t=process.env.NODE_ENV==="test"?new jt:new St(i),n=new Mt(t,e);return await n.read(),n}import{createReadStream as Zn}from"node:fs";import ht from"node:path";async function kt(i,e){let t=st(i),{credentials:n,dryRun:s=!1,service:r,stripMetadata:a=!0,verbose:c=!1}=e,g=G.verbose;G.verbose=c;let b=[],m=await Xt(t);G.info(`Found ${m.length} video files in directory "${i}"`);let h=a?await Jn(m,{dryRun:s,verbose:c}):[],d=await Qn(ht.join(t,".vidup-state.json"),{syncState:[]});d.data.syncState=d.data.syncState.filter(S=>m.includes(ht.join(t,S.filename)));for(let S of m){let A=ht.basename(S),T=await Is(S,{algorithm:"sha1"}),ce=d.data.syncState.find(oe=>oe.filename===A);ce?ce.localHash=T:d.data.syncState.push({filename:A,localHash:T,remoteHash:{}})}if(s||await d.write(),r!=="bunny")throw new Error(`Streaming service not yet implemented: ${r}`);let w=new Ps({apiKey:n.key,videoLibrary:n.library}),C=await w.listAllVideos();G.info(`Found ${C.length} video files on ${r} remote streaming service`);let _=C.filter(S=>{let A=d.data.syncState.find(T=>T.filename===S.title);return A!==void 0&&A.localHash===A.remoteHash[r]});for(let S of _)b.push({action:"Unchanged",localFile:S.title,remoteId:S.guid,stripMetadata:h.includes(S.title)});let p=d.data.syncState.filter(S=>!C.some(A=>A.title===S.filename));for(let S of p)b.push({action:"Created",localFile:S.filename,remoteId:"Not yet uploaded (Dry run)",stripMetadata:h.includes(S.filename)});let W=C.filter(S=>{let A=d.data.syncState.find(T=>T.filename===S.title);return A!==void 0&&A.localHash!==A.remoteHash[r]});for(let S of W)b.push({action:"Updated",localFile:S.title,remoteId:"Not yet uploaded (Dry run)",stripMetadata:h.includes(S.title)});let B=C.filter(S=>!d.data.syncState.some(A=>A.filename===S.title));for(let S of B)b.push({action:"Deleted",localFile:S.title,remoteId:S.guid,stripMetadata:h.includes(S.title)});if(!s){d.data.lastRun=new Date,await d.write(),G.info("Synchronizing...");for(let[S,A]of B.entries()){if(S===0&&G.info(`Deleting ${B.length} remote videos...`),!(await G.infoSpin(w.deleteVideo(A.guid),`Deleting remote video ${S+1}/${B.length}: ${A.title}`)).success)throw new Error(`Failed to delete remote video: ${A.title}`);d.data.lastUpdate=new Date,await d.write()}for(let[S,A]of p.entries()){S===0&&G.info(`Uploading ${p.length} new local videos...`);let T=Zn(ht.join(t,A.filename)),ce=await G.infoSpin(w.createAndUploadVideo(T,{title:A.filename}),`Uploading new video ${S+1}/${p.length}: ${A.filename}`);G.info(`Remote video ${S+1}/${p.length} created with GUID: ${ce.guid}`);let oe=d.data.syncState.find(he=>he.filename===A.filename);if(oe===void 0)throw new Error(`Failed to find state entry for: ${A.filename}`);oe.remoteHash[r]=A.localHash,d.data.lastUpdate=new Date,await d.write();let be=b.find(he=>he.localFile===A.filename);if(be===void 0)throw new Error(`Failed to find report entry for: ${A.filename}`);be.remoteId=ce.guid}for(let[S,A]of W.entries()){S===0&&(G.info(`Updating ${W.length} remote videos...`),G.warn("Bunny does not currently support updating videos in-place, so vidup will delete and re-uploading instead... this will change the video's GUID!"));let T=d.data.syncState.find(H=>H.filename===A.title);if(T===void 0)throw new Error(`Failed to find state entry for: ${A.title}`);if(!(await w.deleteVideo(A.guid)).success)throw new Error(`Failed to delete remote video before updating: ${A.title}`);let oe=Zn(ht.join(t,T.filename)),be=await G.infoSpin(w.createAndUploadVideo(oe,{title:T.filename}),`Updating remote video ${S+1}/${W.length}: ${A.title}`);G.info(`Updated remote video ${S+1}/${W.length} created with GUID: ${be.guid}`),T.remoteHash[r]=T.localHash,d.data.lastUpdate=new Date,await d.write();let he=b.find(H=>H.localFile===T.filename);if(he===void 0)throw new Error(`Failed to find report entry for: ${T.filename}`);he.remoteId=be.guid}G.info(`All ${m.length} videos are now in sync!`)}return G.verbose=g,b}var Xn=i=>Number.isFinite(i)?i:0;function vs(i){return{days:Math.trunc(i/864e5),hours:Math.trunc(i/36e5%24),minutes:Math.trunc(i/6e4%60),seconds:Math.trunc(i/1e3%60),milliseconds:Math.trunc(i%1e3),microseconds:Math.trunc(Xn(i*1e3)%1e3),nanoseconds:Math.trunc(Xn(i*1e6)%1e3)}}function $s(i){return{days:i/86400000n,hours:i/3600000n%24n,minutes:i/60000n%60n,seconds:i/1000n%60n,milliseconds:i%1000n,microseconds:0n,nanoseconds:0n}}function en(i){switch(typeof i){case"number":{if(Number.isFinite(i))return vs(i);break}case"bigint":return $s(i)}throw new TypeError("Expected a finite number or bigint")}var Ns=i=>i===0||i===0n,Fs=(i,e)=>e===1||e===1n?i:`${i}s`,Rs=1e-7,Ds=24n*60n*60n*1000n;function tn(i,e){let t=typeof i=="bigint";if(!t&&!Number.isFinite(i))throw new TypeError("Expected a finite number or bigint");e={...e},e.colonNotation&&(e.compact=!1,e.formatSubMilliseconds=!1,e.separateMilliseconds=!1,e.verbose=!1),e.compact&&(e.unitCount=1,e.secondsDecimalDigits=0,e.millisecondsDecimalDigits=0);let n=[],s=(b,m)=>{let h=Math.floor(b*10**m+Rs);return(Math.round(h)/10**m).toFixed(m)},r=(b,m,h,d)=>{if(!((n.length===0||!e.colonNotation)&&Ns(b)&&!(e.colonNotation&&h==="m"))){if(d=d??String(b),e.colonNotation){let w=d.includes(".")?d.split(".")[0].length:d.length,C=n.length>0?2:1;d="0".repeat(Math.max(0,C-w))+d}else d+=e.verbose?" "+Fs(m,b):h;n.push(d)}},a=en(i),c=BigInt(a.days);if(r(c/365n,"year","y"),r(c%365n,"day","d"),r(Number(a.hours),"hour","h"),r(Number(a.minutes),"minute","m"),e.separateMilliseconds||e.formatSubMilliseconds||!e.colonNotation&&i<1e3){let b=Number(a.seconds),m=Number(a.milliseconds),h=Number(a.microseconds),d=Number(a.nanoseconds);if(r(b,"second","s"),e.formatSubMilliseconds)r(m,"millisecond","ms"),r(h,"microsecond","\xB5s"),r(d,"nanosecond","ns");else{let w=m+h/1e3+d/1e6,C=typeof e.millisecondsDecimalDigits=="number"?e.millisecondsDecimalDigits:0,_=w>=1?Math.round(w):Math.ceil(w),p=C?w.toFixed(C):_;r(Number.parseFloat(p),"millisecond","ms",p)}}else{let b=(t?Number(i%Ds):i)/1e3%60,m=typeof e.secondsDecimalDigits=="number"?e.secondsDecimalDigits:1,h=s(b,m),d=e.keepDecimalsOnWholeSeconds?h:h.replace(/\.0+$/,"");r(Number.parseFloat(d),"second","s",d)}if(n.length===0)return"0"+(e.verbose?" milliseconds":"ms");let g=e.colonNotation?":":" ";return typeof e.unitCount=="number"&&(n=n.slice(0,Math.max(e.unitCount,1))),n.join(g)}import{notStrictEqual as ar,strictEqual as lr}from"assert";var Ts={right:Vs,center:zs},Ls=0,Pt=1,Ws=2,It=3,nn=class{constructor(e){var t;this.width=e.width,this.wrap=(t=e.wrap)!==null&&t!==void 0?t:!0,this.rows=[]}span(...e){let t=this.div(...e);t.span=!0}resetOutput(){this.rows=[]}div(...e){if(e.length===0&&this.div(""),this.wrap&&this.shouldApplyLayoutDSL(...e)&&typeof e[0]=="string")return this.applyLayoutDSL(e[0]);let t=e.map(n=>typeof n=="string"?this.colFromString(n):n);return this.rows.push(t),t}shouldApplyLayoutDSL(...e){return e.length===1&&typeof e[0]=="string"&&/[\t\n]/.test(e[0])}applyLayoutDSL(e){let t=e.split(`
|
|
9
|
+
`).map(s=>s.split(" ")),n=0;return t.forEach(s=>{s.length>1&&de.stringWidth(s[0])>n&&(n=Math.min(Math.floor(this.width*.5),de.stringWidth(s[0])))}),t.forEach(s=>{this.div(...s.map((r,a)=>({text:r.trim(),padding:this.measurePadding(r),width:a===0&&s.length>1?n:void 0})))}),this.rows[this.rows.length-1]}colFromString(e){return{text:e,padding:this.measurePadding(e)}}measurePadding(e){let t=de.stripAnsi(e);return[0,t.match(/\s*$/)[0].length,0,t.match(/^\s*/)[0].length]}toString(){let e=[];return this.rows.forEach(t=>{this.rowToString(t,e)}),e.filter(t=>!t.hidden).map(t=>t.text).join(`
|
|
10
|
+
`)}rowToString(e,t){return this.rasterize(e).forEach((n,s)=>{let r="";n.forEach((a,c)=>{let{width:g}=e[c],b=this.negatePadding(e[c]),m=a;if(b>de.stringWidth(a)&&(m+=" ".repeat(b-de.stringWidth(a))),e[c].align&&e[c].align!=="left"&&this.wrap){let d=Ts[e[c].align];m=d(m,b),de.stringWidth(m)<b&&(m+=" ".repeat((g||0)-de.stringWidth(m)-1))}let h=e[c].padding||[0,0,0,0];h[It]&&(r+=" ".repeat(h[It])),r+=kn(e[c],m,"| "),r+=m,r+=kn(e[c],m," |"),h[Pt]&&(r+=" ".repeat(h[Pt])),s===0&&t.length>0&&(r=this.renderInline(r,t[t.length-1]))}),t.push({text:r.replace(/ +$/,""),span:e.span})}),t}renderInline(e,t){let n=e.match(/^ */),s=n?n[0].length:0,r=t.text,a=de.stringWidth(r.trimRight());return t.span?this.wrap?s<a?e:(t.hidden=!0,r.trimRight()+" ".repeat(s-a)+e.trimLeft()):(t.hidden=!0,r+e):e}rasterize(e){let t=[],n=this.columnWidths(e),s;return e.forEach((r,a)=>{r.width=n[a],this.wrap?s=de.wrap(r.text,this.negatePadding(r),{hard:!0}).split(`
|
|
11
|
+
`):s=r.text.split(`
|
|
12
|
+
`),r.border&&(s.unshift("."+"-".repeat(this.negatePadding(r)+2)+"."),s.push("'"+"-".repeat(this.negatePadding(r)+2)+"'")),r.padding&&(s.unshift(...new Array(r.padding[Ls]||0).fill("")),s.push(...new Array(r.padding[Ws]||0).fill(""))),s.forEach((c,g)=>{t[g]||t.push([]);let b=t[g];for(let m=0;m<a;m++)b[m]===void 0&&b.push("");b.push(c)})}),t}negatePadding(e){let t=e.width||0;return e.padding&&(t-=(e.padding[It]||0)+(e.padding[Pt]||0)),e.border&&(t-=4),t}columnWidths(e){if(!this.wrap)return e.map(a=>a.width||de.stringWidth(a.text));let t=e.length,n=this.width,s=e.map(a=>{if(a.width)return t--,n-=a.width,a.width}),r=t?Math.floor(n/t):0;return s.map((a,c)=>a===void 0?Math.max(r,Us(e[c])):a)}};function kn(i,e,t){return i.border?/[.']-+[.']/.test(e)?"":e.trim().length!==0?t:" ":""}function Us(i){let e=i.padding||[],t=1+(e[It]||0)+(e[Pt]||0);return i.border?t+4:t}function Bs(){return typeof process=="object"&&process.stdout&&process.stdout.columns?process.stdout.columns:80}function Vs(i,e){i=i.trim();let t=de.stringWidth(i);return t<e?" ".repeat(e-t)+i:i}function zs(i,e){i=i.trim();let t=de.stringWidth(i);return t>=e?i:" ".repeat(e-t>>1)+i}var de;function ei(i,e){return de=e,new nn({width:(i==null?void 0:i.width)||Bs(),wrap:i==null?void 0:i.wrap})}var ti=new RegExp("\x1B(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)","g");function sn(i){return i.replace(ti,"")}function ni(i,e){let[t,n]=i.match(ti)||["",""];i=sn(i);let s="";for(let r=0;r<i.length;r++)r!==0&&r%e===0&&(s+=`
|
|
13
|
+
`),s+=i.charAt(r);return t&&n&&(s=`${t}${s}${n}`),s}function rn(i){return ei(i,{stringWidth:e=>[...e].length,stripAnsi:sn,wrap:ni})}import{dirname as ii,resolve as si}from"path";import{readdirSync as Hs,statSync as Ys}from"fs";function ri(i,e){let t=si(".",i),n;for(Ys(t).isDirectory()||(t=ii(t));;){if(n=e(t,Hs(t)),n)return si(t,n);if(t=ii(n=t),n===t)break}}import{inspect as cr}from"util";import{readFileSync as fr}from"fs";import{fileURLToPath as ur}from"url";import{format as Ks}from"util";import{normalize as Js,resolve as Qs}from"path";function ze(i){if(i!==i.toLowerCase()&&i!==i.toUpperCase()||(i=i.toLowerCase()),i.indexOf("-")===-1&&i.indexOf("_")===-1)return i;{let t="",n=!1,s=i.match(/^-+/);for(let r=s?s[0].length:0;r<i.length;r++){let a=i.charAt(r);n&&(n=!1,a=a.toUpperCase()),r!==0&&(a==="-"||a==="_")?n=!0:a!=="-"&&a!=="_"&&(t+=a)}return t}}function vt(i,e){let t=i.toLowerCase();e=e||"-";let n="";for(let s=0;s<i.length;s++){let r=t.charAt(s),a=i.charAt(s);r!==a&&s>0?n+=`${e}${t.charAt(s)}`:n+=a}return n}function $t(i){return i==null?!1:typeof i=="number"||/^0x[0-9a-f]+$/i.test(i)?!0:/^0[^.]/.test(i)?!1:/^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(i)}function oi(i){if(Array.isArray(i))return i.map(a=>typeof a!="string"?a+"":a);i=i.trim();let e=0,t=null,n=null,s=null,r=[];for(let a=0;a<i.length;a++){if(t=n,n=i.charAt(a),n===" "&&!s){t!==" "&&e++;continue}n===s?s=null:(n==="'"||n==='"')&&!s&&(s=n),r[e]||(r[e]=""),r[e]+=n}return r}var we;(function(i){i.BOOLEAN="boolean",i.STRING="string",i.NUMBER="number",i.ARRAY="array"})(we||(we={}));var Fe,Nt=class{constructor(e){Fe=e}parse(e,t){let n=Object.assign({alias:void 0,array:void 0,boolean:void 0,config:void 0,configObjects:void 0,configuration:void 0,coerce:void 0,count:void 0,default:void 0,envPrefix:void 0,narg:void 0,normalize:void 0,string:void 0,number:void 0,__:void 0,key:void 0},t),s=oi(e),r=typeof e=="string",a=Gs(Object.assign(Object.create(null),n.alias)),c=Object.assign({"boolean-negation":!0,"camel-case-expansion":!0,"combine-arrays":!1,"dot-notation":!0,"duplicate-arguments-array":!0,"flatten-duplicate-arrays":!0,"greedy-arrays":!0,"halt-at-non-option":!1,"nargs-eats-options":!1,"negation-prefix":"no-","parse-numbers":!0,"parse-positional-numbers":!0,"populate--":!1,"set-placeholder-key":!1,"short-option-groups":!0,"strip-aliased":!1,"strip-dashed":!1,"unknown-options-as-args":!1},n.configuration),g=Object.assign(Object.create(null),n.default),b=n.configObjects||[],m=n.envPrefix,h=c["populate--"],d=h?"--":"_",w=Object.create(null),C=Object.create(null),_=n.__||Fe.format,p={aliases:Object.create(null),arrays:Object.create(null),bools:Object.create(null),strings:Object.create(null),numbers:Object.create(null),counts:Object.create(null),normalize:Object.create(null),configs:Object.create(null),nargs:Object.create(null),coercions:Object.create(null),keys:[]},W=/^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/,B=new RegExp("^--"+c["negation-prefix"]+"(.+)");[].concat(n.array||[]).filter(Boolean).forEach(function(l){let u=typeof l=="object"?l.key:l,O=Object.keys(l).map(function(y){return{boolean:"bools",string:"strings",number:"numbers"}[y]}).filter(Boolean).pop();O&&(p[O][u]=!0),p.arrays[u]=!0,p.keys.push(u)}),[].concat(n.boolean||[]).filter(Boolean).forEach(function(l){p.bools[l]=!0,p.keys.push(l)}),[].concat(n.string||[]).filter(Boolean).forEach(function(l){p.strings[l]=!0,p.keys.push(l)}),[].concat(n.number||[]).filter(Boolean).forEach(function(l){p.numbers[l]=!0,p.keys.push(l)}),[].concat(n.count||[]).filter(Boolean).forEach(function(l){p.counts[l]=!0,p.keys.push(l)}),[].concat(n.normalize||[]).filter(Boolean).forEach(function(l){p.normalize[l]=!0,p.keys.push(l)}),typeof n.narg=="object"&&Object.entries(n.narg).forEach(([l,u])=>{typeof u=="number"&&(p.nargs[l]=u,p.keys.push(l))}),typeof n.coerce=="object"&&Object.entries(n.coerce).forEach(([l,u])=>{typeof u=="function"&&(p.coercions[l]=u,p.keys.push(l))}),typeof n.config<"u"&&(Array.isArray(n.config)||typeof n.config=="string"?[].concat(n.config).filter(Boolean).forEach(function(l){p.configs[l]=!0}):typeof n.config=="object"&&Object.entries(n.config).forEach(([l,u])=>{(typeof u=="boolean"||typeof u=="function")&&(p.configs[l]=u)})),Ve(n.key,a,n.default,p.arrays),Object.keys(g).forEach(function(l){(p.aliases[l]||[]).forEach(function(u){g[u]=g[l]})});let S=null;wt();let A=[],T=Object.assign(Object.create(null),{_:[]}),ce={};for(let l=0;l<s.length;l++){let u=s[l],O=u.replace(/^-{3,}/,"---"),y,f,I,E,N,ae;if(u!=="--"&&/^-/.test(u)&&k(u))oe(u);else if(O.match(/^---+(=|$)/)){oe(u);continue}else if(u.match(/^--.+=/)||!c["short-option-groups"]&&u.match(/^-.+=/))E=u.match(/^--?([^=]+)=([\s\S]*)$/),E!==null&&Array.isArray(E)&&E.length>=3&&(R(E[1],p.arrays)?l=he(l,E[1],s,E[2]):R(E[1],p.nargs)!==!1?l=be(l,E[1],s,E[2]):H(E[1],E[2],!0));else if(u.match(B)&&c["boolean-negation"])E=u.match(B),E!==null&&Array.isArray(E)&&E.length>=2&&(f=E[1],H(f,R(f,p.arrays)?[!1]:!1));else if(u.match(/^--.+/)||!c["short-option-groups"]&&u.match(/^-[^-]+/))E=u.match(/^--?(.+)/),E!==null&&Array.isArray(E)&&E.length>=2&&(f=E[1],R(f,p.arrays)?l=he(l,f,s):R(f,p.nargs)!==!1?l=be(l,f,s):(N=s[l+1],N!==void 0&&(!N.match(/^-/)||N.match(W))&&!R(f,p.bools)&&!R(f,p.counts)||/^(true|false)$/.test(N)?(H(f,N),l++):H(f,ee(f))));else if(u.match(/^-.\..+=/))E=u.match(/^-([^=]+)=([\s\S]*)$/),E!==null&&Array.isArray(E)&&E.length>=3&&H(E[1],E[2]);else if(u.match(/^-.\..+/)&&!u.match(W))N=s[l+1],E=u.match(/^-(.\..+)/),E!==null&&Array.isArray(E)&&E.length>=2&&(f=E[1],N!==void 0&&!N.match(/^-/)&&!R(f,p.bools)&&!R(f,p.counts)?(H(f,N),l++):H(f,ee(f)));else if(u.match(/^-[^-]+/)&&!u.match(W)){I=u.slice(1,-1).split(""),y=!1;for(let fe=0;fe<I.length;fe++){if(N=u.slice(fe+2),I[fe+1]&&I[fe+1]==="="){ae=u.slice(fe+3),f=I[fe],R(f,p.arrays)?l=he(l,f,s,ae):R(f,p.nargs)!==!1?l=be(l,f,s,ae):H(f,ae),y=!0;break}if(N==="-"){H(I[fe],N);continue}if(/[A-Za-z]/.test(I[fe])&&/^-?\d+(\.\d*)?(e-?\d+)?$/.test(N)&&R(N,p.bools)===!1){H(I[fe],N),y=!0;break}if(I[fe+1]&&I[fe+1].match(/\W/)){H(I[fe],N),y=!0;break}else H(I[fe],ee(I[fe]))}f=u.slice(-1)[0],!y&&f!=="-"&&(R(f,p.arrays)?l=he(l,f,s):R(f,p.nargs)!==!1?l=be(l,f,s):(N=s[l+1],N!==void 0&&(!/^(-|--)[^-]/.test(N)||N.match(W))&&!R(f,p.bools)&&!R(f,p.counts)||/^(true|false)$/.test(N)?(H(f,N),l++):H(f,ee(f))))}else if(u.match(/^-[0-9]$/)&&u.match(W)&&R(u.slice(1),p.bools))f=u.slice(1),H(f,ee(f));else if(u==="--"){A=s.slice(l+1);break}else if(c["halt-at-non-option"]){A=s.slice(l);break}else oe(u)}z(T,!0),z(T,!1),U(T),se(),Z(T,p.aliases,g,!0),re(T),c["set-placeholder-key"]&&Be(T),Object.keys(p.counts).forEach(function(l){$e(T,l.split("."))||H(l,0)}),h&&A.length&&(T[d]=[]),A.forEach(function(l){T[d].push(l)}),c["camel-case-expansion"]&&c["strip-dashed"]&&Object.keys(T).filter(l=>l!=="--"&&l.includes("-")).forEach(l=>{delete T[l]}),c["strip-aliased"]&&[].concat(...Object.keys(a).map(l=>a[l])).forEach(l=>{c["camel-case-expansion"]&&l.includes("-")&&delete T[l.split(".").map(u=>ze(u)).join(".")],delete T[l]});function oe(l){let u=P("_",l);(typeof u=="string"||typeof u=="number")&&T._.push(u)}function be(l,u,O,y){let f,I=R(u,p.nargs);if(I=typeof I!="number"||isNaN(I)?1:I,I===0)return Ae(y)||(S=Error(_("Argument unexpected for: %s",u))),H(u,ee(u)),l;let E=Ae(y)?0:1;if(c["nargs-eats-options"])O.length-(l+1)+E<I&&(S=Error(_("Not enough arguments following: %s",u))),E=I;else{for(f=l+1;f<O.length&&(!O[f].match(/^-[^0-9]/)||O[f].match(W)||k(O[f]));f++)E++;E<I&&(S=Error(_("Not enough arguments following: %s",u)))}let N=Math.min(E,I);for(!Ae(y)&&N>0&&(H(u,y),N--),f=l+1;f<N+l+1;f++)H(u,O[f]);return l+N}function he(l,u,O,y){let f=[],I=y||O[l+1],E=R(u,p.nargs);if(R(u,p.bools)&&!/^(true|false)$/.test(I))f.push(!0);else if(Ae(I)||Ae(y)&&/^-/.test(I)&&!W.test(I)&&!k(I)){if(g[u]!==void 0){let N=g[u];f=Array.isArray(N)?N:[N]}}else{Ae(y)||f.push(x(u,y,!0));for(let N=l+1;N<O.length&&!(!c["greedy-arrays"]&&f.length>0||E&&typeof E=="number"&&f.length>=E||(I=O[N],/^-/.test(I)&&!W.test(I)&&!k(I)));N++)l=N,f.push(x(u,I,r))}return typeof E=="number"&&(E&&f.length<E||isNaN(E)&&f.length===0)&&(S=Error(_("Not enough arguments following: %s",u))),H(u,f),l}function H(l,u,O=r){if(/-/.test(l)&&c["camel-case-expansion"]){let I=l.split(".").map(function(E){return ze(E)}).join(".");v(l,I)}let y=x(l,u,O),f=l.split(".");Ne(T,f,y),p.aliases[l]&&p.aliases[l].forEach(function(I){let E=I.split(".");Ne(T,E,y)}),f.length>1&&c["dot-notation"]&&(p.aliases[f[0]]||[]).forEach(function(I){let E=I.split("."),N=[].concat(f);N.shift(),E=E.concat(N),(p.aliases[l]||[]).includes(E.join("."))||Ne(T,E,y)}),R(l,p.normalize)&&!R(l,p.arrays)&&[l].concat(p.aliases[l]||[]).forEach(function(E){Object.defineProperty(ce,E,{enumerable:!0,get(){return u},set(N){u=typeof N=="string"?Fe.normalize(N):N}})})}function v(l,u){p.aliases[l]&&p.aliases[l].length||(p.aliases[l]=[u],w[u]=!0),p.aliases[u]&&p.aliases[u].length||v(u,l)}function x(l,u,O){O&&(u=qs(u)),(R(l,p.bools)||R(l,p.counts))&&typeof u=="string"&&(u=u==="true");let y=Array.isArray(u)?u.map(function(f){return P(l,f)}):P(l,u);return R(l,p.counts)&&(Ae(y)||typeof y=="boolean")&&(y=on()),R(l,p.normalize)&&R(l,p.arrays)&&(Array.isArray(u)?y=u.map(f=>Fe.normalize(f)):y=Fe.normalize(u)),y}function P(l,u){return!c["parse-positional-numbers"]&&l==="_"||!R(l,p.strings)&&!R(l,p.bools)&&!Array.isArray(u)&&($t(u)&&c["parse-numbers"]&&Number.isSafeInteger(Math.floor(parseFloat(`${u}`)))||!Ae(u)&&R(l,p.numbers))&&(u=Number(u)),u}function U(l){let u=Object.create(null);Z(u,p.aliases,g),Object.keys(p.configs).forEach(function(O){let y=l[O]||u[O];if(y)try{let f=null,I=Fe.resolve(Fe.cwd(),y),E=p.configs[O];if(typeof E=="function"){try{f=E(I)}catch(N){f=N}if(f instanceof Error){S=f;return}}else f=Fe.require(I);Y(f)}catch(f){f.name==="PermissionDenied"?S=f:l[O]&&(S=Error(_("Invalid JSON config file: %s",y)))}})}function Y(l,u){Object.keys(l).forEach(function(O){let y=l[O],f=u?u+"."+O:O;typeof y=="object"&&y!==null&&!Array.isArray(y)&&c["dot-notation"]?Y(y,f):(!$e(T,f.split("."))||R(f,p.arrays)&&c["combine-arrays"])&&H(f,y)})}function se(){typeof b<"u"&&b.forEach(function(l){Y(l)})}function z(l,u){if(typeof m>"u")return;let O=typeof m=="string"?m:"",y=Fe.env();Object.keys(y).forEach(function(f){if(O===""||f.lastIndexOf(O,0)===0){let I=f.split("__").map(function(E,N){return N===0&&(E=E.substring(O.length)),ze(E)});(u&&p.configs[I.join(".")]||!u)&&!$e(l,I)&&H(I.join("."),y[f])}})}function re(l){let u,O=new Set;Object.keys(l).forEach(function(y){if(!O.has(y)&&(u=R(y,p.coercions),typeof u=="function"))try{let f=P(y,u(l[y]));[].concat(p.aliases[y]||[],y).forEach(I=>{O.add(I),l[I]=f})}catch(f){S=f}})}function Be(l){return p.keys.forEach(u=>{~u.indexOf(".")||typeof l[u]>"u"&&(l[u]=void 0)}),l}function Z(l,u,O,y=!1){Object.keys(O).forEach(function(f){$e(l,f.split("."))||(Ne(l,f.split("."),O[f]),y&&(C[f]=!0),(u[f]||[]).forEach(function(I){$e(l,I.split("."))||Ne(l,I.split("."),O[f])}))})}function $e(l,u){let O=l;c["dot-notation"]||(u=[u.join(".")]),u.slice(0,-1).forEach(function(f){O=O[f]||{}});let y=u[u.length-1];return typeof O!="object"?!1:y in O}function Ne(l,u,O){let y=l;c["dot-notation"]||(u=[u.join(".")]),u.slice(0,-1).forEach(function(ae){ae=ai(ae),typeof y=="object"&&y[ae]===void 0&&(y[ae]={}),typeof y[ae]!="object"||Array.isArray(y[ae])?(Array.isArray(y[ae])?y[ae].push({}):y[ae]=[y[ae],{}],y=y[ae][y[ae].length-1]):y=y[ae]});let f=ai(u[u.length-1]),I=R(u.join("."),p.arrays),E=Array.isArray(O),N=c["duplicate-arguments-array"];!N&&R(f,p.nargs)&&(N=!0,(!Ae(y[f])&&p.nargs[f]===1||Array.isArray(y[f])&&y[f].length===p.nargs[f])&&(y[f]=void 0)),O===on()?y[f]=on(y[f]):Array.isArray(y[f])?N&&I&&E?y[f]=c["flatten-duplicate-arrays"]?y[f].concat(O):(Array.isArray(y[f][0])?y[f]:[y[f]]).concat([O]):!N&&!!I==!!E?y[f]=O:y[f]=y[f].concat([O]):y[f]===void 0&&I?y[f]=E?O:[O]:N&&!(y[f]===void 0||R(f,p.counts)||R(f,p.bools))?y[f]=[y[f],O]:y[f]=O}function Ve(...l){l.forEach(function(u){Object.keys(u||{}).forEach(function(O){p.aliases[O]||(p.aliases[O]=[].concat(a[O]||[]),p.aliases[O].concat(O).forEach(function(y){if(/-/.test(y)&&c["camel-case-expansion"]){let f=ze(y);f!==O&&p.aliases[O].indexOf(f)===-1&&(p.aliases[O].push(f),w[f]=!0)}}),p.aliases[O].concat(O).forEach(function(y){if(y.length>1&&/[A-Z]/.test(y)&&c["camel-case-expansion"]){let f=vt(y,"-");f!==O&&p.aliases[O].indexOf(f)===-1&&(p.aliases[O].push(f),w[f]=!0)}}),p.aliases[O].forEach(function(y){p.aliases[y]=[O].concat(p.aliases[O].filter(function(f){return y!==f}))}))})})}function R(l,u){let O=[].concat(p.aliases[l]||[],l),y=Object.keys(u),f=O.find(I=>y.includes(I));return f?u[f]:!1}function Gt(l){let u=Object.keys(p);return[].concat(u.map(y=>p[y])).some(function(y){return Array.isArray(y)?y.includes(l):y[l]})}function F(l,...u){return[].concat(...u).some(function(y){let f=l.match(y);return f&&Gt(f[1])})}function J(l){if(l.match(W)||!l.match(/^-[^-]+/))return!1;let u=!0,O,y=l.slice(1).split("");for(let f=0;f<y.length;f++){if(O=l.slice(f+2),!Gt(y[f])){u=!1;break}if(y[f+1]&&y[f+1]==="="||O==="-"||/[A-Za-z]/.test(y[f])&&/^-?\d+(\.\d*)?(e-?\d+)?$/.test(O)||y[f+1]&&y[f+1].match(/\W/))break}return u}function k(l){return c["unknown-options-as-args"]&&V(l)}function V(l){return l=l.replace(/^-{3,}/,"--"),l.match(W)||J(l)?!1:!F(l,/^-+([^=]+?)=[\s\S]*$/,B,/^-+([^=]+?)$/,/^-+([^=]+?)-$/,/^-+([^=]+?\d+)$/,/^-+([^=]+?)\W+.*$/)}function ee(l){return!R(l,p.bools)&&!R(l,p.counts)&&`${l}`in g?g[l]:ne(Ee(l))}function ne(l){return{[we.BOOLEAN]:!0,[we.STRING]:"",[we.NUMBER]:void 0,[we.ARRAY]:[]}[l]}function Ee(l){let u=we.BOOLEAN;return R(l,p.strings)?u=we.STRING:R(l,p.numbers)?u=we.NUMBER:R(l,p.bools)?u=we.BOOLEAN:R(l,p.arrays)&&(u=we.ARRAY),u}function Ae(l){return l===void 0}function wt(){Object.keys(p.counts).find(l=>R(l,p.arrays)?(S=Error(_("Invalid configuration: %s, opts.count excludes opts.array.",l)),!0):R(l,p.nargs)?(S=Error(_("Invalid configuration: %s, opts.count excludes opts.narg.",l)),!0):!1)}return{aliases:Object.assign({},p.aliases),argv:Object.assign(ce,T),configuration:c,defaulted:Object.assign({},C),error:S,newAliases:Object.assign({},w)}}};function Gs(i){let e=[],t=Object.create(null),n=!0;for(Object.keys(i).forEach(function(s){e.push([].concat(i[s],s))});n;){n=!1;for(let s=0;s<e.length;s++)for(let r=s+1;r<e.length;r++)if(e[s].filter(function(c){return e[r].indexOf(c)!==-1}).length){e[s]=e[s].concat(e[r]),e.splice(r,1),n=!0;break}}return e.forEach(function(s){s=s.filter(function(a,c,g){return g.indexOf(a)===c});let r=s.pop();r!==void 0&&typeof r=="string"&&(t[r]=s)}),t}function on(i){return i!==void 0?i+1:1}function ai(i){return i==="__proto__"?"___proto___":i}function qs(i){return typeof i=="string"&&(i[0]==="'"||i[0]==='"')&&i[i.length-1]===i[0]?i.substring(1,i.length-1):i}import{readFileSync as Zs}from"fs";var an,ln,cn,li=process&&process.env&&process.env.YARGS_MIN_NODE_VERSION?Number(process.env.YARGS_MIN_NODE_VERSION):12,ci=(ln=(an=process==null?void 0:process.versions)===null||an===void 0?void 0:an.node)!==null&&ln!==void 0?ln:(cn=process==null?void 0:process.version)===null||cn===void 0?void 0:cn.slice(1);if(ci&&Number(ci.match(/^([^.]+)/)[1])<li)throw Error(`yargs parser supports a minimum Node.js version of ${li}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`);var Xs=process?process.env:{},fi=new Nt({cwd:process.cwd,env:()=>Xs,format:Ks,normalize:Js,resolve:Qs,require:i=>{if(typeof Me<"u")return Me(i);if(i.match(/\.json$/))return JSON.parse(Zs(i,"utf8"));throw Error("only .json config files are supported in ESM")}}),dt=function(e,t){return fi.parse(e.slice(),t).argv};dt.detailed=function(i,e){return fi.parse(i.slice(),e)};dt.camelCase=ze;dt.decamelize=vt;dt.looksLikeNumber=$t;var fn=dt;import{basename as hr,dirname as dr,extname as pr,relative as mr,resolve as gi}from"path";function ui(){return ks()?0:1}function ks(){return er()&&!process.defaultApp}function er(){return!!process.versions.electron}function un(i){return i.slice(ui()+1)}function hi(){return process.argv[ui()]}var q=class i extends Error{constructor(e){super(e||"yargs error"),this.name="YError",Error.captureStackTrace&&Error.captureStackTrace(this,i)}};import{readFileSync as tr,statSync as nr,writeFile as ir}from"fs";import{format as sr}from"util";import{resolve as rr}from"path";var di={fs:{readFileSync:tr,writeFile:ir},format:sr,resolve:rr,exists:i=>{try{return nr(i).isFile()}catch{return!1}}};var je,hn=class{constructor(e){e=e||{},this.directory=e.directory||"./locales",this.updateFiles=typeof e.updateFiles=="boolean"?e.updateFiles:!0,this.locale=e.locale||"en",this.fallbackToLanguage=typeof e.fallbackToLanguage=="boolean"?e.fallbackToLanguage:!0,this.cache=Object.create(null),this.writeQueue=[]}__(...e){if(typeof arguments[0]!="string")return this._taggedLiteral(arguments[0],...arguments);let t=e.shift(),n=function(){};return typeof e[e.length-1]=="function"&&(n=e.pop()),n=n||function(){},this.cache[this.locale]||this._readLocaleFile(),!this.cache[this.locale][t]&&this.updateFiles?(this.cache[this.locale][t]=t,this._enqueueWrite({directory:this.directory,locale:this.locale,cb:n})):n(),je.format.apply(je.format,[this.cache[this.locale][t]||t].concat(e))}__n(){let e=Array.prototype.slice.call(arguments),t=e.shift(),n=e.shift(),s=e.shift(),r=function(){};typeof e[e.length-1]=="function"&&(r=e.pop()),this.cache[this.locale]||this._readLocaleFile();let a=s===1?t:n;this.cache[this.locale][t]&&(a=this.cache[this.locale][t][s===1?"one":"other"]),!this.cache[this.locale][t]&&this.updateFiles?(this.cache[this.locale][t]={one:t,other:n},this._enqueueWrite({directory:this.directory,locale:this.locale,cb:r})):r();let c=[a];return~a.indexOf("%d")&&c.push(s),je.format.apply(je.format,c.concat(e))}setLocale(e){this.locale=e}getLocale(){return this.locale}updateLocale(e){this.cache[this.locale]||this._readLocaleFile();for(let t in e)Object.prototype.hasOwnProperty.call(e,t)&&(this.cache[this.locale][t]=e[t])}_taggedLiteral(e,...t){let n="";return e.forEach(function(s,r){let a=t[r+1];n+=s,typeof a<"u"&&(n+="%s")}),this.__.apply(this,[n].concat([].slice.call(t,1)))}_enqueueWrite(e){this.writeQueue.push(e),this.writeQueue.length===1&&this._processWriteQueue()}_processWriteQueue(){let e=this,t=this.writeQueue[0],n=t.directory,s=t.locale,r=t.cb,a=this._resolveLocaleFile(n,s),c=JSON.stringify(this.cache[s],null,2);je.fs.writeFile(a,c,"utf-8",function(g){e.writeQueue.shift(),e.writeQueue.length>0&&e._processWriteQueue(),r(g)})}_readLocaleFile(){let e={},t=this._resolveLocaleFile(this.directory,this.locale);try{je.fs.readFileSync&&(e=JSON.parse(je.fs.readFileSync(t,"utf-8")))}catch(n){if(n instanceof SyntaxError&&(n.message="syntax error in "+t),n.code==="ENOENT")e={};else throw n}this.cache[this.locale]=e}_resolveLocaleFile(e,t){let n=je.resolve(e,"./",t+".json");if(this.fallbackToLanguage&&!this._fileExistsSync(n)&&~t.lastIndexOf("_")){let s=je.resolve(e,"./",t.split("_")[0]+".json");this._fileExistsSync(s)&&(n=s)}return n}_fileExistsSync(e){return je.exists(e)}};function pi(i,e){je=e;let t=new hn(i);return{__:t.__.bind(t),__n:t.__n.bind(t),setLocale:t.setLocale.bind(t),getLocale:t.getLocale.bind(t),updateLocale:t.updateLocale.bind(t),locale:t.locale}}var or=i=>pi(i,di),mi=or;var gr="require is not supported by ESM",bi="loading a directory of commands is not supported yet for ESM",pt;try{pt=ur(import.meta.url)}catch{pt=process.cwd()}var br=pt.substring(0,pt.lastIndexOf("node_modules")),dn={assert:{notStrictEqual:ar,strictEqual:lr},cliui:rn,findUp:ri,getEnv:i=>process.env[i],inspect:cr,getCallerFile:()=>{throw new q(bi)},getProcessArgvBin:hi,mainFilename:br||process.cwd(),Parser:fn,path:{basename:hr,dirname:dr,extname:pr,relative:mr,resolve:gi},process:{argv:()=>process.argv,cwd:process.cwd,emitWarning:(i,e)=>process.emitWarning(i,e),execPath:()=>process.execPath,exit:process.exit,nextTick:process.nextTick,stdColumns:typeof process.stdout.columns<"u"?process.stdout.columns:null},readFileSync:fr,require:()=>{throw new q(gr)},requireDirectory:()=>{throw new q(bi)},stringWidth:i=>[...i].length,y18n:mi({directory:gi(pt,"../../../locales"),updateFiles:!1})};function ue(i,e,t,n){t.assert.notStrictEqual(i,e,n)}function pn(i,e){e.assert.strictEqual(typeof i,"string")}function rt(i){return Object.keys(i)}function K(i){return!!i&&!!i.then&&typeof i.then=="function"}function Re(i){let t=i.replace(/\s{2,}/g," ").split(/\s+(?![^[]*]|[^<]*>)/),n=/\.*[\][<>]/g,s=t.shift();if(!s)throw new Error(`No command found in: ${i}`);let r={cmd:s.replace(n,""),demanded:[],optional:[]};return t.forEach((a,c)=>{let g=!1;a=a.replace(/\s/g,""),/\.+[\]>]/.test(a)&&c===t.length-1&&(g=!0),/^\[/.test(a)?r.optional.push({cmd:a.replace(n,"").split("|"),variadic:g}):r.demanded.push({cmd:a.replace(n,"").split("|"),variadic:g})}),r}var yr=["first","second","third","fourth","fifth","sixth"];function j(i,e,t){function n(){return typeof i=="object"?[{demanded:[],optional:[]},i,e]:[Re(`cmd ${i}`),e,t]}try{let s=0,[r,a,c]=n(),g=[].slice.call(a);for(;g.length&&g[g.length-1]===void 0;)g.pop();let b=c||g.length;if(b<r.demanded.length)throw new q(`Not enough arguments provided. Expected ${r.demanded.length} but received ${g.length}.`);let m=r.demanded.length+r.optional.length;if(b>m)throw new q(`Too many arguments provided. Expected max ${m} but received ${b}.`);r.demanded.forEach(h=>{let d=g.shift(),w=yi(d);h.cmd.filter(_=>_===w||_==="*").length===0&&wi(w,h.cmd,s),s+=1}),r.optional.forEach(h=>{if(g.length===0)return;let d=g.shift(),w=yi(d);h.cmd.filter(_=>_===w||_==="*").length===0&&wi(w,h.cmd,s),s+=1})}catch(s){console.warn(s.stack)}}function yi(i){return Array.isArray(i)?"array":i===null?"null":typeof i}function wi(i,e,t){throw new q(`Invalid ${yr[t]||"manyith"} argument. Expected ${e.join(" or ")} but received ${i}.`)}var Ft=class{constructor(e){this.globalMiddleware=[],this.frozens=[],this.yargs=e}addMiddleware(e,t,n=!0,s=!1){if(j("<array|function> [boolean] [boolean] [boolean]",[e,t,n],arguments.length),Array.isArray(e)){for(let r=0;r<e.length;r++){if(typeof e[r]!="function")throw Error("middleware must be a function");let a=e[r];a.applyBeforeValidation=t,a.global=n}Array.prototype.push.apply(this.globalMiddleware,e)}else if(typeof e=="function"){let r=e;r.applyBeforeValidation=t,r.global=n,r.mutates=s,this.globalMiddleware.push(e)}return this.yargs}addCoerceMiddleware(e,t){let n=this.yargs.getAliases();return this.globalMiddleware=this.globalMiddleware.filter(s=>{let r=[...n[t]||[],t];return s.option?!r.includes(s.option):!0}),e.option=t,this.addMiddleware(e,!0,!0,!0)}getMiddleware(){return this.globalMiddleware}freeze(){this.frozens.push([...this.globalMiddleware])}unfreeze(){let e=this.frozens.pop();e!==void 0&&(this.globalMiddleware=e)}reset(){this.globalMiddleware=this.globalMiddleware.filter(e=>e.global)}};function Oi(i){return i?i.map(e=>(e.applyBeforeValidation=!1,e)):[]}function He(i,e,t,n){return t.reduce((s,r)=>{if(r.applyBeforeValidation!==n)return s;if(r.mutates){if(r.applied)return s;r.applied=!0}if(K(s))return s.then(a=>Promise.all([a,r(a,e)])).then(([a,c])=>Object.assign(a,c));{let a=r(s,e);return K(a)?a.then(c=>Object.assign(s,c)):Object.assign(s,a)}},i)}function Ye(i,e,t=n=>{throw n}){try{let n=wr(i)?i():i;return K(n)?n.then(s=>e(s)):e(n)}catch(n){return t(n)}}function wr(i){return typeof i=="function"}function mn(i){if(typeof Me>"u")return null;for(let e=0,t=Object.keys(Me.cache),n;e<t.length;e++)if(n=Me.cache[t[e]],n.exports===i)return n;return null}var ot=/(^\*)|(^\$0)/,gn=class{constructor(e,t,n,s){this.requireCache=new Set,this.handlers={},this.aliasMap={},this.frozens=[],this.shim=s,this.usage=e,this.globalMiddleware=n,this.validation=t}addDirectory(e,t,n,s){s=s||{},typeof s.recurse!="boolean"&&(s.recurse=!1),Array.isArray(s.extensions)||(s.extensions=["js"]);let r=typeof s.visit=="function"?s.visit:a=>a;s.visit=(a,c,g)=>{let b=r(a,c,g);if(b){if(this.requireCache.has(c))return b;this.requireCache.add(c),this.addHandler(b)}return b},this.shim.requireDirectory({require:t,filename:n},e,s)}addHandler(e,t,n,s,r,a){let c=[],g=Oi(r);if(s=s||(()=>{}),Array.isArray(e))if(Or(e))[e,...c]=e;else for(let b of e)this.addHandler(b);else if(Cr(e)){let b=Array.isArray(e.command)||typeof e.command=="string"?e.command:this.moduleName(e);e.aliases&&(b=[].concat(b).concat(e.aliases)),this.addHandler(b,this.extractDesc(e),e.builder,e.handler,e.middlewares,e.deprecated);return}else if(_i(n)){this.addHandler([e].concat(c),t,n.builder,n.handler,n.middlewares,n.deprecated);return}if(typeof e=="string"){let b=Re(e);c=c.map(d=>Re(d).cmd);let m=!1,h=[b.cmd].concat(c).filter(d=>ot.test(d)?(m=!0,!1):!0);h.length===0&&m&&h.push("$0"),m&&(b.cmd=h[0],c=h.slice(1),e=e.replace(ot,b.cmd)),c.forEach(d=>{this.aliasMap[d]=b.cmd}),t!==!1&&this.usage.command(e,t,m,c,a),this.handlers[b.cmd]={original:e,description:t,handler:s,builder:n||{},middlewares:g,deprecated:a,demanded:b.demanded,optional:b.optional},m&&(this.defaultCommand=this.handlers[b.cmd])}}getCommandHandlers(){return this.handlers}getCommands(){return Object.keys(this.handlers).concat(Object.keys(this.aliasMap))}hasDefaultCommand(){return!!this.defaultCommand}runCommand(e,t,n,s,r,a){let c=this.handlers[e]||this.handlers[this.aliasMap[e]]||this.defaultCommand,g=t.getInternalMethods().getContext(),b=g.commands.slice(),m=!e;e&&(g.commands.push(e),g.fullCommands.push(c.original));let h=this.applyBuilderUpdateUsageAndParse(m,c,t,n.aliases,b,s,r,a);return K(h)?h.then(d=>this.applyMiddlewareAndGetResult(m,c,d.innerArgv,g,r,d.aliases,t)):this.applyMiddlewareAndGetResult(m,c,h.innerArgv,g,r,h.aliases,t)}applyBuilderUpdateUsageAndParse(e,t,n,s,r,a,c,g){let b=t.builder,m=n;if(Rt(b)){n.getInternalMethods().getUsageInstance().freeze();let h=b(n.getInternalMethods().reset(s),g);if(K(h))return h.then(d=>(m=xi(d)?d:n,this.parseAndUpdateUsage(e,t,m,r,a,c)))}else _r(b)&&(n.getInternalMethods().getUsageInstance().freeze(),m=n.getInternalMethods().reset(s),Object.keys(t.builder).forEach(h=>{m.option(h,b[h])}));return this.parseAndUpdateUsage(e,t,m,r,a,c)}parseAndUpdateUsage(e,t,n,s,r,a){e&&n.getInternalMethods().getUsageInstance().unfreeze(!0),this.shouldUpdateUsage(n)&&n.getInternalMethods().getUsageInstance().usage(this.usageFromParentCommandsCommandHandler(s,t),t.description);let c=n.getInternalMethods().runYargsParserAndExecuteCommands(null,void 0,!0,r,a);return K(c)?c.then(g=>({aliases:n.parsed.aliases,innerArgv:g})):{aliases:n.parsed.aliases,innerArgv:c}}shouldUpdateUsage(e){return!e.getInternalMethods().getUsageInstance().getUsageDisabled()&&e.getInternalMethods().getUsageInstance().getUsage().length===0}usageFromParentCommandsCommandHandler(e,t){let n=ot.test(t.original)?t.original.replace(ot,"").trim():t.original,s=e.filter(r=>!ot.test(r));return s.push(n),`$0 ${s.join(" ")}`}handleValidationAndGetResult(e,t,n,s,r,a,c,g){if(!a.getInternalMethods().getHasOutput()){let b=a.getInternalMethods().runValidation(r,g,a.parsed.error,e);n=Ye(n,m=>(b(m),m))}if(t.handler&&!a.getInternalMethods().getHasOutput()){a.getInternalMethods().setHasOutput();let b=!!a.getOptions().configuration["populate--"];a.getInternalMethods().postProcess(n,b,!1,!1),n=He(n,a,c,!1),n=Ye(n,m=>{let h=t.handler(m);return K(h)?h.then(()=>m):m}),e||a.getInternalMethods().getUsageInstance().cacheHelpMessage(),K(n)&&!a.getInternalMethods().hasParseCallback()&&n.catch(m=>{try{a.getInternalMethods().getUsageInstance().fail(null,m)}catch{}})}return e||(s.commands.pop(),s.fullCommands.pop()),n}applyMiddlewareAndGetResult(e,t,n,s,r,a,c){let g={};if(r)return n;c.getInternalMethods().getHasOutput()||(g=this.populatePositionals(t,n,s,c));let b=this.globalMiddleware.getMiddleware().slice(0).concat(t.middlewares),m=He(n,c,b,!0);return K(m)?m.then(h=>this.handleValidationAndGetResult(e,t,h,s,a,c,b,g)):this.handleValidationAndGetResult(e,t,m,s,a,c,b,g)}populatePositionals(e,t,n,s){t._=t._.slice(n.commands.length);let r=e.demanded.slice(0),a=e.optional.slice(0),c={};for(this.validation.positionalCount(r.length,t._.length);r.length;){let g=r.shift();this.populatePositional(g,t,c)}for(;a.length;){let g=a.shift();this.populatePositional(g,t,c)}return t._=n.commands.concat(t._.map(g=>""+g)),this.postProcessPositionals(t,c,this.cmdToParseOptions(e.original),s),c}populatePositional(e,t,n){let s=e.cmd[0];e.variadic?n[s]=t._.splice(0).map(String):t._.length&&(n[s]=[String(t._.shift())])}cmdToParseOptions(e){let t={array:[],default:{},alias:{},demand:{}},n=Re(e);return n.demanded.forEach(s=>{let[r,...a]=s.cmd;s.variadic&&(t.array.push(r),t.default[r]=[]),t.alias[r]=a,t.demand[r]=!0}),n.optional.forEach(s=>{let[r,...a]=s.cmd;s.variadic&&(t.array.push(r),t.default[r]=[]),t.alias[r]=a}),t}postProcessPositionals(e,t,n,s){let r=Object.assign({},s.getOptions());r.default=Object.assign(n.default,r.default);for(let b of Object.keys(n.alias))r.alias[b]=(r.alias[b]||[]).concat(n.alias[b]);r.array=r.array.concat(n.array),r.config={};let a=[];if(Object.keys(t).forEach(b=>{t[b].map(m=>{r.configuration["unknown-options-as-args"]&&(r.key[b]=!0),a.push(`--${b}`),a.push(m)})}),!a.length)return;let c=Object.assign({},r.configuration,{"populate--":!1}),g=this.shim.Parser.detailed(a,Object.assign({},r,{configuration:c}));if(g.error)s.getInternalMethods().getUsageInstance().fail(g.error.message,g.error);else{let b=Object.keys(t);Object.keys(t).forEach(m=>{b.push(...g.aliases[m])}),Object.keys(g.argv).forEach(m=>{b.includes(m)&&(t[m]||(t[m]=g.argv[m]),!this.isInConfigs(s,m)&&!this.isDefaulted(s,m)&&Object.prototype.hasOwnProperty.call(e,m)&&Object.prototype.hasOwnProperty.call(g.argv,m)&&(Array.isArray(e[m])||Array.isArray(g.argv[m]))?e[m]=[].concat(e[m],g.argv[m]):e[m]=g.argv[m])})}}isDefaulted(e,t){let{default:n}=e.getOptions();return Object.prototype.hasOwnProperty.call(n,t)||Object.prototype.hasOwnProperty.call(n,this.shim.Parser.camelCase(t))}isInConfigs(e,t){let{configObjects:n}=e.getOptions();return n.some(s=>Object.prototype.hasOwnProperty.call(s,t))||n.some(s=>Object.prototype.hasOwnProperty.call(s,this.shim.Parser.camelCase(t)))}runDefaultBuilderOn(e){if(!this.defaultCommand)return;if(this.shouldUpdateUsage(e)){let n=ot.test(this.defaultCommand.original)?this.defaultCommand.original:this.defaultCommand.original.replace(/^[^[\]<>]*/,"$0 ");e.getInternalMethods().getUsageInstance().usage(n,this.defaultCommand.description)}let t=this.defaultCommand.builder;if(Rt(t))return t(e,!0);_i(t)||Object.keys(t).forEach(n=>{e.option(n,t[n])})}moduleName(e){let t=mn(e);if(!t)throw new Error(`No command name given for module: ${this.shim.inspect(e)}`);return this.commandFromFilename(t.filename)}commandFromFilename(e){return this.shim.path.basename(e,this.shim.path.extname(e))}extractDesc({describe:e,description:t,desc:n}){for(let s of[e,t,n]){if(typeof s=="string"||s===!1)return s;ue(s,!0,this.shim)}return!1}freeze(){this.frozens.push({handlers:this.handlers,aliasMap:this.aliasMap,defaultCommand:this.defaultCommand})}unfreeze(){let e=this.frozens.pop();ue(e,void 0,this.shim),{handlers:this.handlers,aliasMap:this.aliasMap,defaultCommand:this.defaultCommand}=e}reset(){return this.handlers={},this.aliasMap={},this.defaultCommand=void 0,this.requireCache=new Set,this}};function Ci(i,e,t,n){return new gn(i,e,t,n)}function _i(i){return typeof i=="object"&&!!i.builder&&typeof i.handler=="function"}function Or(i){return i.every(e=>typeof e=="string")}function Rt(i){return typeof i=="function"}function _r(i){return typeof i=="object"}function Cr(i){return typeof i=="object"&&!Array.isArray(i)}function De(i={},e=()=>!0){let t={};return rt(i).forEach(n=>{e(n,i[n])&&(t[n]=i[n])}),t}function Te(i){typeof process>"u"||[process.stdout,process.stderr].forEach(e=>{let t=e;t._handle&&t.isTTY&&typeof t._handle.setBlocking=="function"&&t._handle.setBlocking(i)})}function xr(i){return typeof i=="boolean"}function Ai(i,e){let t=e.y18n.__,n={},s=[];n.failFn=function(x){s.push(x)};let r=null,a=null,c=!0;n.showHelpOnFail=function(x=!0,P){let[U,Y]=typeof x=="string"?[!0,x]:[x,P];return i.getInternalMethods().isGlobalContext()&&(a=Y),r=Y,c=U,n};let g=!1;n.fail=function(x,P){let U=i.getInternalMethods().getLoggerInstance();if(s.length)for(let Y=s.length-1;Y>=0;--Y){let se=s[Y];if(xr(se)){if(P)throw P;if(x)throw Error(x)}else se(x,P,n)}else{if(i.getExitProcess()&&Te(!0),!g){g=!0,c&&(i.showHelp("error"),U.error()),(x||P)&&U.error(x||P);let Y=r||a;Y&&((x||P)&&U.error(""),U.error(Y))}if(P=P||new q(x),i.getExitProcess())return i.exit(1);if(i.getInternalMethods().hasParseCallback())return i.exit(1,P);throw P}};let b=[],m=!1;n.usage=(v,x)=>v===null?(m=!0,b=[],n):(m=!1,b.push([v,x||""]),n),n.getUsage=()=>b,n.getUsageDisabled=()=>m,n.getPositionalGroupName=()=>t("Positionals:");let h=[];n.example=(v,x)=>{h.push([v,x||""])};let d=[];n.command=function(x,P,U,Y,se=!1){U&&(d=d.map(z=>(z[2]=!1,z))),d.push([x,P||"",U,Y,se])},n.getCommands=()=>d;let w={};n.describe=function(x,P){Array.isArray(x)?x.forEach(U=>{n.describe(U,P)}):typeof x=="object"?Object.keys(x).forEach(U=>{n.describe(U,x[U])}):w[x]=P},n.getDescriptions=()=>w;let C=[];n.epilog=v=>{C.push(v)};let _=!1,p;n.wrap=v=>{_=!0,p=v},n.getWrap=()=>e.getEnv("YARGS_DISABLE_WRAP")?null:(_||(p=be(),_=!0),p);let W="__yargsString__:";n.deferY18nLookup=v=>W+v,n.help=function(){if(A)return A;S();let x=i.customScriptName?i.$0:e.path.basename(i.$0),P=i.getDemandedOptions(),U=i.getDemandedCommands(),Y=i.getDeprecatedOptions(),se=i.getGroups(),z=i.getOptions(),re=[];re=re.concat(Object.keys(w)),re=re.concat(Object.keys(P)),re=re.concat(Object.keys(U)),re=re.concat(Object.keys(z.default)),re=re.filter(ce),re=Object.keys(re.reduce((F,J)=>(J!=="_"&&(F[J]=!0),F),{}));let Be=n.getWrap(),Z=e.cliui({width:Be,wrap:!!Be});if(!m){if(b.length)b.forEach(F=>{Z.div({text:`${F[0].replace(/\$0/g,x)}`}),F[1]&&Z.div({text:`${F[1]}`,padding:[1,0,0,0]})}),Z.div();else if(d.length){let F=null;U._?F=`${x} <${t("command")}>
|
|
14
|
+
`:F=`${x} [${t("command")}]
|
|
15
|
+
`,Z.div(`${F}`)}}if(d.length>1||d.length===1&&!d[0][2]){Z.div(t("Commands:"));let F=i.getInternalMethods().getContext(),J=F.commands.length?`${F.commands.join(" ")} `:"";i.getInternalMethods().getParserConfiguration()["sort-commands"]===!0&&(d=d.sort((V,ee)=>V[0].localeCompare(ee[0])));let k=x?`${x} `:"";d.forEach(V=>{let ee=`${k}${J}${V[0].replace(/^\$0 ?/,"")}`;Z.span({text:ee,padding:[0,2,0,2],width:B(d,Be,`${x}${J}`)+4},{text:V[1]});let ne=[];V[2]&&ne.push(`[${t("default")}]`),V[3]&&V[3].length&&ne.push(`[${t("aliases:")} ${V[3].join(", ")}]`),V[4]&&(typeof V[4]=="string"?ne.push(`[${t("deprecated: %s",V[4])}]`):ne.push(`[${t("deprecated")}]`)),ne.length?Z.div({text:ne.join(" "),padding:[0,0,0,2],align:"right"}):Z.div()}),Z.div()}let $e=(Object.keys(z.alias)||[]).concat(Object.keys(i.parsed.newAliases)||[]);re=re.filter(F=>!i.parsed.newAliases[F]&&$e.every(J=>(z.alias[J]||[]).indexOf(F)===-1));let Ne=t("Options:");se[Ne]||(se[Ne]=[]),T(re,z.alias,se,Ne);let Ve=F=>/^--/.test(Dt(F)),R=Object.keys(se).filter(F=>se[F].length>0).map(F=>{let J=se[F].filter(ce).map(k=>{if($e.includes(k))return k;for(let V=0,ee;(ee=$e[V])!==void 0;V++)if((z.alias[ee]||[]).includes(k))return ee;return k});return{groupName:F,normalizedKeys:J}}).filter(({normalizedKeys:F})=>F.length>0).map(({groupName:F,normalizedKeys:J})=>{let k=J.reduce((V,ee)=>(V[ee]=[ee].concat(z.alias[ee]||[]).map(ne=>F===n.getPositionalGroupName()?ne:(/^[0-9]$/.test(ne)?z.boolean.includes(ee)?"-":"--":ne.length>1?"--":"-")+ne).sort((ne,Ee)=>Ve(ne)===Ve(Ee)?0:Ve(ne)?1:-1).join(", "),V),{});return{groupName:F,normalizedKeys:J,switches:k}});if(R.filter(({groupName:F})=>F!==n.getPositionalGroupName()).some(({normalizedKeys:F,switches:J})=>!F.every(k=>Ve(J[k])))&&R.filter(({groupName:F})=>F!==n.getPositionalGroupName()).forEach(({normalizedKeys:F,switches:J})=>{F.forEach(k=>{Ve(J[k])&&(J[k]=Er(J[k],4))})}),R.forEach(({groupName:F,normalizedKeys:J,switches:k})=>{Z.div(F),J.forEach(V=>{let ee=k[V],ne=w[V]||"",Ee=null;ne.includes(W)&&(ne=t(ne.substring(W.length))),z.boolean.includes(V)&&(Ee=`[${t("boolean")}]`),z.count.includes(V)&&(Ee=`[${t("count")}]`),z.string.includes(V)&&(Ee=`[${t("string")}]`),z.normalize.includes(V)&&(Ee=`[${t("string")}]`),z.array.includes(V)&&(Ee=`[${t("array")}]`),z.number.includes(V)&&(Ee=`[${t("number")}]`);let Ae=u=>typeof u=="string"?`[${t("deprecated: %s",u)}]`:`[${t("deprecated")}]`,wt=[V in Y?Ae(Y[V]):null,Ee,V in P?`[${t("required")}]`:null,z.choices&&z.choices[V]?`[${t("choices:")} ${n.stringifiedValues(z.choices[V])}]`:null,oe(z.default[V],z.defaultDescription[V])].filter(Boolean).join(" ");Z.span({text:Dt(ee),padding:[0,2,0,2+Ei(ee)],width:B(k,Be)+4},ne);let l=i.getInternalMethods().getUsageConfiguration()["hide-types"]===!0;wt&&!l?Z.div({text:wt,padding:[0,0,0,2],align:"right"}):Z.div()}),Z.div()}),h.length&&(Z.div(t("Examples:")),h.forEach(F=>{F[0]=F[0].replace(/\$0/g,x)}),h.forEach(F=>{F[1]===""?Z.div({text:F[0],padding:[0,2,0,2]}):Z.div({text:F[0],padding:[0,2,0,2],width:B(h,Be)+4},{text:F[1]})}),Z.div()),C.length>0){let F=C.map(J=>J.replace(/\$0/g,x)).join(`
|
|
16
|
+
`);Z.div(`${F}
|
|
17
|
+
`)}return Z.toString().replace(/\s*$/,"")};function B(v,x,P){let U=0;return Array.isArray(v)||(v=Object.values(v).map(Y=>[Y])),v.forEach(Y=>{U=Math.max(e.stringWidth(P?`${P} ${Dt(Y[0])}`:Dt(Y[0]))+Ei(Y[0]),U)}),x&&(U=Math.min(U,parseInt((x*.5).toString(),10))),U}function S(){let v=i.getDemandedOptions(),x=i.getOptions();(Object.keys(x.alias)||[]).forEach(P=>{x.alias[P].forEach(U=>{w[U]&&n.describe(P,w[U]),U in v&&i.demandOption(P,v[U]),x.boolean.includes(U)&&i.boolean(P),x.count.includes(U)&&i.count(P),x.string.includes(U)&&i.string(P),x.normalize.includes(U)&&i.normalize(P),x.array.includes(U)&&i.array(P),x.number.includes(U)&&i.number(P)})})}let A;n.cacheHelpMessage=function(){A=this.help()},n.clearCachedHelpMessage=function(){A=void 0},n.hasCachedHelpMessage=function(){return!!A};function T(v,x,P,U){let Y=[],se=null;return Object.keys(P).forEach(z=>{Y=Y.concat(P[z])}),v.forEach(z=>{se=[z].concat(x[z]),se.some(re=>Y.indexOf(re)!==-1)||P[U].push(z)}),Y}function ce(v){return i.getOptions().hiddenOptions.indexOf(v)<0||i.parsed.argv[i.getOptions().showHiddenOpt]}n.showHelp=v=>{let x=i.getInternalMethods().getLoggerInstance();v||(v="error"),(typeof v=="function"?v:x[v])(n.help())},n.functionDescription=v=>["(",v.name?e.Parser.decamelize(v.name,"-"):t("generated-value"),")"].join(""),n.stringifiedValues=function(x,P){let U="",Y=P||", ",se=[].concat(x);return!x||!se.length||se.forEach(z=>{U.length&&(U+=Y),U+=JSON.stringify(z)}),U};function oe(v,x){let P=`[${t("default:")} `;if(v===void 0&&!x)return null;if(x)P+=x;else switch(typeof v){case"string":P+=`"${v}"`;break;case"object":P+=JSON.stringify(v);break;default:P+=v}return`${P}]`}function be(){return e.process.stdColumns?Math.min(80,e.process.stdColumns):80}let he=null;n.version=v=>{he=v},n.showVersion=v=>{let x=i.getInternalMethods().getLoggerInstance();v||(v="error"),(typeof v=="function"?v:x[v])(he)},n.reset=function(x){return r=null,g=!1,b=[],m=!1,C=[],h=[],d=[],w=De(w,P=>!x[P]),n};let H=[];return n.freeze=function(){H.push({failMessage:r,failureOutput:g,usages:b,usageDisabled:m,epilogs:C,examples:h,commands:d,descriptions:w})},n.unfreeze=function(x=!1){let P=H.pop();P&&(x?(w={...P.descriptions,...w},d=[...P.commands,...d],b=[...P.usages,...b],h=[...P.examples,...h],C=[...P.epilogs,...C]):{failMessage:r,failureOutput:g,usages:b,usageDisabled:m,epilogs:C,examples:h,commands:d,descriptions:w}=P)},n}function bn(i){return typeof i=="object"}function Er(i,e){return bn(i)?{text:i.text,indentation:i.indentation+e}:{text:i,indentation:e}}function Ei(i){return bn(i)?i.indentation:0}function Dt(i){return bn(i)?i.text:i}var Si=`###-begin-{{app_name}}-completions-###
|
|
18
|
+
#
|
|
19
|
+
# yargs command completion script
|
|
20
|
+
#
|
|
21
|
+
# Installation: {{app_path}} {{completion_command}} >> ~/.bashrc
|
|
22
|
+
# or {{app_path}} {{completion_command}} >> ~/.bash_profile on OSX.
|
|
23
|
+
#
|
|
24
|
+
_{{app_name}}_yargs_completions()
|
|
25
|
+
{
|
|
26
|
+
local cur_word args type_list
|
|
27
|
+
|
|
28
|
+
cur_word="\${COMP_WORDS[COMP_CWORD]}"
|
|
29
|
+
args=("\${COMP_WORDS[@]}")
|
|
30
|
+
|
|
31
|
+
# ask yargs to generate completions.
|
|
32
|
+
type_list=$({{app_path}} --get-yargs-completions "\${args[@]}")
|
|
33
|
+
|
|
34
|
+
COMPREPLY=( $(compgen -W "\${type_list}" -- \${cur_word}) )
|
|
35
|
+
|
|
36
|
+
# if no match was found, fall back to filename completion
|
|
37
|
+
if [ \${#COMPREPLY[@]} -eq 0 ]; then
|
|
38
|
+
COMPREPLY=()
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
return 0
|
|
42
|
+
}
|
|
43
|
+
complete -o bashdefault -o default -F _{{app_name}}_yargs_completions {{app_name}}
|
|
44
|
+
###-end-{{app_name}}-completions-###
|
|
45
|
+
`,ji=`#compdef {{app_name}}
|
|
46
|
+
###-begin-{{app_name}}-completions-###
|
|
47
|
+
#
|
|
48
|
+
# yargs command completion script
|
|
49
|
+
#
|
|
50
|
+
# Installation: {{app_path}} {{completion_command}} >> ~/.zshrc
|
|
51
|
+
# or {{app_path}} {{completion_command}} >> ~/.zprofile on OSX.
|
|
52
|
+
#
|
|
53
|
+
_{{app_name}}_yargs_completions()
|
|
54
|
+
{
|
|
55
|
+
local reply
|
|
56
|
+
local si=$IFS
|
|
57
|
+
IFS=$'
|
|
58
|
+
' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" {{app_path}} --get-yargs-completions "\${words[@]}"))
|
|
59
|
+
IFS=$si
|
|
60
|
+
_describe 'values' reply
|
|
61
|
+
}
|
|
62
|
+
compdef _{{app_name}}_yargs_completions {{app_name}}
|
|
63
|
+
###-end-{{app_name}}-completions-###
|
|
64
|
+
`;var yn=class{constructor(e,t,n,s){var r,a,c;this.yargs=e,this.usage=t,this.command=n,this.shim=s,this.completionKey="get-yargs-completions",this.aliases=null,this.customCompletionFunction=null,this.indexAfterLastReset=0,this.zshShell=(c=((r=this.shim.getEnv("SHELL"))===null||r===void 0?void 0:r.includes("zsh"))||((a=this.shim.getEnv("ZSH_NAME"))===null||a===void 0?void 0:a.includes("zsh")))!==null&&c!==void 0?c:!1}defaultCompletion(e,t,n,s){let r=this.command.getCommandHandlers();for(let c=0,g=e.length;c<g;++c)if(r[e[c]]&&r[e[c]].builder){let b=r[e[c]].builder;if(Rt(b)){this.indexAfterLastReset=c+1;let m=this.yargs.getInternalMethods().reset();return b(m,!0),m.argv}}let a=[];this.commandCompletions(a,e,n),this.optionCompletions(a,e,t,n),this.choicesFromOptionsCompletions(a,e,t,n),this.choicesFromPositionalsCompletions(a,e,t,n),s(null,a)}commandCompletions(e,t,n){let s=this.yargs.getInternalMethods().getContext().commands;!n.match(/^-/)&&s[s.length-1]!==n&&!this.previousArgHasChoices(t)&&this.usage.getCommands().forEach(r=>{let a=Re(r[0]).cmd;if(t.indexOf(a)===-1)if(!this.zshShell)e.push(a);else{let c=r[1]||"";e.push(a.replace(/:/g,"\\:")+":"+c)}})}optionCompletions(e,t,n,s){if((s.match(/^-/)||s===""&&e.length===0)&&!this.previousArgHasChoices(t)){let r=this.yargs.getOptions(),a=this.yargs.getGroups()[this.usage.getPositionalGroupName()]||[];Object.keys(r.key).forEach(c=>{let g=!!r.configuration["boolean-negation"]&&r.boolean.includes(c);!a.includes(c)&&!r.hiddenOptions.includes(c)&&!this.argsContainKey(t,c,g)&&this.completeOptionKey(c,e,s,g&&!!r.default[c])})}}choicesFromOptionsCompletions(e,t,n,s){if(this.previousArgHasChoices(t)){let r=this.getPreviousArgChoices(t);r&&r.length>0&&e.push(...r.map(a=>a.replace(/:/g,"\\:")))}}choicesFromPositionalsCompletions(e,t,n,s){if(s===""&&e.length>0&&this.previousArgHasChoices(t))return;let r=this.yargs.getGroups()[this.usage.getPositionalGroupName()]||[],a=Math.max(this.indexAfterLastReset,this.yargs.getInternalMethods().getContext().commands.length+1),c=r[n._.length-a-1];if(!c)return;let g=this.yargs.getOptions().choices[c]||[];for(let b of g)b.startsWith(s)&&e.push(b.replace(/:/g,"\\:"))}getPreviousArgChoices(e){if(e.length<1)return;let t=e[e.length-1],n="";if(!t.startsWith("-")&&e.length>1&&(n=t,t=e[e.length-2]),!t.startsWith("-"))return;let s=t.replace(/^-+/,""),r=this.yargs.getOptions(),a=[s,...this.yargs.getAliases()[s]||[]],c;for(let g of a)if(Object.prototype.hasOwnProperty.call(r.key,g)&&Array.isArray(r.choices[g])){c=r.choices[g];break}if(c)return c.filter(g=>!n||g.startsWith(n))}previousArgHasChoices(e){let t=this.getPreviousArgChoices(e);return t!==void 0&&t.length>0}argsContainKey(e,t,n){let s=r=>e.indexOf((/^[^0-9]$/.test(r)?"-":"--")+r)!==-1;if(s(t)||n&&s(`no-${t}`))return!0;if(this.aliases){for(let r of this.aliases[t])if(s(r))return!0}return!1}completeOptionKey(e,t,n,s){var r,a,c,g;let b=e;if(this.zshShell){let w=this.usage.getDescriptions(),C=(a=(r=this===null||this===void 0?void 0:this.aliases)===null||r===void 0?void 0:r[e])===null||a===void 0?void 0:a.find(W=>{let B=w[W];return typeof B=="string"&&B.length>0}),_=C?w[C]:void 0,p=(g=(c=w[e])!==null&&c!==void 0?c:_)!==null&&g!==void 0?g:"";b=`${e.replace(/:/g,"\\:")}:${p.replace("__yargsString__:","").replace(/(\r\n|\n|\r)/gm," ")}`}let m=w=>/^--/.test(w),h=w=>/^[^0-9]$/.test(w),d=!m(n)&&h(e)?"-":"--";t.push(d+b),s&&t.push(d+"no-"+b)}customCompletion(e,t,n,s){if(ue(this.customCompletionFunction,null,this.shim),Sr(this.customCompletionFunction)){let r=this.customCompletionFunction(n,t);return K(r)?r.then(a=>{this.shim.process.nextTick(()=>{s(null,a)})}).catch(a=>{this.shim.process.nextTick(()=>{s(a,void 0)})}):s(null,r)}else return jr(this.customCompletionFunction)?this.customCompletionFunction(n,t,(r=s)=>this.defaultCompletion(e,t,n,r),r=>{s(null,r)}):this.customCompletionFunction(n,t,r=>{s(null,r)})}getCompletion(e,t){let n=e.length?e[e.length-1]:"",s=this.yargs.parse(e,!0),r=this.customCompletionFunction?a=>this.customCompletion(e,a,n,t):a=>this.defaultCompletion(e,a,n,t);return K(s)?s.then(r):r(s)}generateCompletionScript(e,t){let n=this.zshShell?ji:Si,s=this.shim.path.basename(e);return e.match(/\.js$/)&&(e=`./${e}`),n=n.replace(/{{app_name}}/g,s),n=n.replace(/{{completion_command}}/g,t),n.replace(/{{app_path}}/g,e)}registerFunction(e){this.customCompletionFunction=e}setParsed(e){this.aliases=e.aliases}};function Mi(i,e,t,n){return new yn(i,e,t,n)}function Sr(i){return i.length<3}function jr(i){return i.length>3}function Pi(i,e){if(i.length===0)return e.length;if(e.length===0)return i.length;let t=[],n;for(n=0;n<=e.length;n++)t[n]=[n];let s;for(s=0;s<=i.length;s++)t[0][s]=s;for(n=1;n<=e.length;n++)for(s=1;s<=i.length;s++)e.charAt(n-1)===i.charAt(s-1)?t[n][s]=t[n-1][s-1]:n>1&&s>1&&e.charAt(n-2)===i.charAt(s-1)&&e.charAt(n-1)===i.charAt(s-2)?t[n][s]=t[n-2][s-2]+1:t[n][s]=Math.min(t[n-1][s-1]+1,Math.min(t[n][s-1]+1,t[n-1][s]+1));return t[e.length][i.length]}var Ii=["$0","--","_"];function vi(i,e,t){let n=t.y18n.__,s=t.y18n.__n,r={};r.nonOptionCount=function(h){let d=i.getDemandedCommands(),C=h._.length+(h["--"]?h["--"].length:0)-i.getInternalMethods().getContext().commands.length;d._&&(C<d._.min||C>d._.max)&&(C<d._.min?d._.minMsg!==void 0?e.fail(d._.minMsg?d._.minMsg.replace(/\$0/g,C.toString()).replace(/\$1/,d._.min.toString()):null):e.fail(s("Not enough non-option arguments: got %s, need at least %s","Not enough non-option arguments: got %s, need at least %s",C,C.toString(),d._.min.toString())):C>d._.max&&(d._.maxMsg!==void 0?e.fail(d._.maxMsg?d._.maxMsg.replace(/\$0/g,C.toString()).replace(/\$1/,d._.max.toString()):null):e.fail(s("Too many non-option arguments: got %s, maximum of %s","Too many non-option arguments: got %s, maximum of %s",C,C.toString(),d._.max.toString()))))},r.positionalCount=function(h,d){d<h&&e.fail(s("Not enough non-option arguments: got %s, need at least %s","Not enough non-option arguments: got %s, need at least %s",d,d+"",h+""))},r.requiredArguments=function(h,d){let w=null;for(let C of Object.keys(d))(!Object.prototype.hasOwnProperty.call(h,C)||typeof h[C]>"u")&&(w=w||{},w[C]=d[C]);if(w){let C=[];for(let p of Object.keys(w)){let W=w[p];W&&C.indexOf(W)<0&&C.push(W)}let _=C.length?`
|
|
65
|
+
${C.join(`
|
|
66
|
+
`)}`:"";e.fail(s("Missing required argument: %s","Missing required arguments: %s",Object.keys(w).length,Object.keys(w).join(", ")+_))}},r.unknownArguments=function(h,d,w,C,_=!0){var p;let W=i.getInternalMethods().getCommandInstance().getCommands(),B=[],S=i.getInternalMethods().getContext();if(Object.keys(h).forEach(A=>{!Ii.includes(A)&&!Object.prototype.hasOwnProperty.call(w,A)&&!Object.prototype.hasOwnProperty.call(i.getInternalMethods().getParseContext(),A)&&!r.isValidAndSomeAliasIsNotNew(A,d)&&B.push(A)}),_&&(S.commands.length>0||W.length>0||C)&&h._.slice(S.commands.length).forEach(A=>{W.includes(""+A)||B.push(""+A)}),_){let T=((p=i.getDemandedCommands()._)===null||p===void 0?void 0:p.max)||0,ce=S.commands.length+T;ce<h._.length&&h._.slice(ce).forEach(oe=>{oe=String(oe),!S.commands.includes(oe)&&!B.includes(oe)&&B.push(oe)})}B.length&&e.fail(s("Unknown argument: %s","Unknown arguments: %s",B.length,B.map(A=>A.trim()?A:`"${A}"`).join(", ")))},r.unknownCommands=function(h){let d=i.getInternalMethods().getCommandInstance().getCommands(),w=[],C=i.getInternalMethods().getContext();return(C.commands.length>0||d.length>0)&&h._.slice(C.commands.length).forEach(_=>{d.includes(""+_)||w.push(""+_)}),w.length>0?(e.fail(s("Unknown command: %s","Unknown commands: %s",w.length,w.join(", "))),!0):!1},r.isValidAndSomeAliasIsNotNew=function(h,d){if(!Object.prototype.hasOwnProperty.call(d,h))return!1;let w=i.parsed.newAliases;return[h,...d[h]].some(C=>!Object.prototype.hasOwnProperty.call(w,C)||!w[h])},r.limitedChoices=function(h){let d=i.getOptions(),w={};if(!Object.keys(d.choices).length)return;Object.keys(h).forEach(p=>{Ii.indexOf(p)===-1&&Object.prototype.hasOwnProperty.call(d.choices,p)&&[].concat(h[p]).forEach(W=>{d.choices[p].indexOf(W)===-1&&W!==void 0&&(w[p]=(w[p]||[]).concat(W))})});let C=Object.keys(w);if(!C.length)return;let _=n("Invalid values:");C.forEach(p=>{_+=`
|
|
67
|
+
${n("Argument: %s, Given: %s, Choices: %s",p,e.stringifiedValues(w[p]),e.stringifiedValues(d.choices[p]))}`}),e.fail(_)};let a={};r.implies=function(h,d){j("<string|object> [array|number|string]",[h,d],arguments.length),typeof h=="object"?Object.keys(h).forEach(w=>{r.implies(w,h[w])}):(i.global(h),a[h]||(a[h]=[]),Array.isArray(d)?d.forEach(w=>r.implies(h,w)):(ue(d,void 0,t),a[h].push(d)))},r.getImplied=function(){return a};function c(m,h){let d=Number(h);return h=isNaN(d)?h:d,typeof h=="number"?h=m._.length>=h:h.match(/^--no-.+/)?(h=h.match(/^--no-(.+)/)[1],h=!Object.prototype.hasOwnProperty.call(m,h)):h=Object.prototype.hasOwnProperty.call(m,h),h}r.implications=function(h){let d=[];if(Object.keys(a).forEach(w=>{let C=w;(a[w]||[]).forEach(_=>{let p=C,W=_;p=c(h,p),_=c(h,_),p&&!_&&d.push(` ${C} -> ${W}`)})}),d.length){let w=`${n("Implications failed:")}
|
|
68
|
+
`;d.forEach(C=>{w+=C}),e.fail(w)}};let g={};r.conflicts=function(h,d){j("<string|object> [array|string]",[h,d],arguments.length),typeof h=="object"?Object.keys(h).forEach(w=>{r.conflicts(w,h[w])}):(i.global(h),g[h]||(g[h]=[]),Array.isArray(d)?d.forEach(w=>r.conflicts(h,w)):g[h].push(d))},r.getConflicting=()=>g,r.conflicting=function(h){Object.keys(h).forEach(d=>{g[d]&&g[d].forEach(w=>{w&&h[d]!==void 0&&h[w]!==void 0&&e.fail(n("Arguments %s and %s are mutually exclusive",d,w))})}),i.getInternalMethods().getParserConfiguration()["strip-dashed"]&&Object.keys(g).forEach(d=>{g[d].forEach(w=>{w&&h[t.Parser.camelCase(d)]!==void 0&&h[t.Parser.camelCase(w)]!==void 0&&e.fail(n("Arguments %s and %s are mutually exclusive",d,w))})})},r.recommendCommands=function(h,d){d=d.sort((p,W)=>W.length-p.length);let C=null,_=1/0;for(let p=0,W;(W=d[p])!==void 0;p++){let B=Pi(h,W);B<=3&&B<_&&(_=B,C=W)}C&&e.fail(n("Did you mean %s?",C))},r.reset=function(h){return a=De(a,d=>!h[d]),g=De(g,d=>!h[d]),r};let b=[];return r.freeze=function(){b.push({implied:a,conflicting:g})},r.unfreeze=function(){let h=b.pop();ue(h,void 0,t),{implied:a,conflicting:g}=h},r}var wn=[],mt;function gt(i,e,t,n){mt=n;let s={};if(Object.prototype.hasOwnProperty.call(i,"extends")){if(typeof i.extends!="string")return s;let r=/\.json|\..*rc$/.test(i.extends),a=null;if(r)a=Pr(e,i.extends);else try{a=Me.resolve(i.extends)}catch{return i}Mr(a),wn.push(a),s=r?JSON.parse(mt.readFileSync(a,"utf8")):Me(i.extends),delete i.extends,s=gt(s,mt.path.dirname(a),t,mt)}return wn=[],t?$i(s,i):Object.assign({},s,i)}function Mr(i){if(wn.indexOf(i)>-1)throw new q(`Circular extended configurations: '${i}'.`)}function Pr(i,e){return mt.path.resolve(i,e)}function $i(i,e){let t={};function n(s){return s&&typeof s=="object"&&!Array.isArray(s)}Object.assign(t,i);for(let s of Object.keys(e))n(e[s])&&n(t[s])?t[s]=$i(i[s],e[s]):t[s]=e[s];return t}var M=function(i,e,t,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?i!==e||!s:!e.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(i,t):s?s.value=t:e.set(i,t),t},o=function(i,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?i!==e||!n:!e.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(i):n?n.value:e.get(i)},ie,Ge,bt,Oe,pe,Tt,Le,qe,Lt,_e,Wt,Ce,Ie,me,xe,Ut,at,le,$,Bt,Vt,ge,Ke,lt,Je,We,zt,D,Qe,Ze,Xe,L,Ht,ve,te;function Xi(i){return(e=[],t=i.process.cwd(),n)=>{let s=new In(e,t,n,i);return Object.defineProperty(s,"argv",{get:()=>s.parse(),enumerable:!0}),s.help(),s.version(),s}}var Ni=Symbol("copyDoubleDash"),Fi=Symbol("copyDoubleDash"),On=Symbol("deleteFromParserHintObject"),Ri=Symbol("emitWarning"),Di=Symbol("freeze"),Ti=Symbol("getDollarZero"),ke=Symbol("getParserConfiguration"),Li=Symbol("getUsageConfiguration"),_n=Symbol("guessLocale"),Wi=Symbol("guessVersion"),Ui=Symbol("parsePositionalNumbers"),Cn=Symbol("pkgUp"),Ue=Symbol("populateParserHintArray"),ct=Symbol("populateParserHintSingleValueDictionary"),xn=Symbol("populateParserHintArrayDictionary"),En=Symbol("populateParserHintDictionary"),An=Symbol("sanitizeKey"),Sn=Symbol("setKey"),jn=Symbol("unfreeze"),Bi=Symbol("validateAsync"),Vi=Symbol("getCommandInstance"),zi=Symbol("getContext"),Hi=Symbol("getHasOutput"),Yi=Symbol("getLoggerInstance"),Gi=Symbol("getParseContext"),qi=Symbol("getUsageInstance"),Ki=Symbol("getValidationInstance"),Yt=Symbol("hasParseCallback"),Ji=Symbol("isGlobalContext"),et=Symbol("postProcess"),Qi=Symbol("rebase"),Mn=Symbol("reset"),yt=Symbol("runYargsParserAndExecuteCommands"),Pn=Symbol("runValidation"),Zi=Symbol("setHasOutput"),tt=Symbol("kTrackManuallySetKeys"),In=class{constructor(e=[],t,n,s){this.customScriptName=!1,this.parsed=!1,ie.set(this,void 0),Ge.set(this,void 0),bt.set(this,{commands:[],fullCommands:[]}),Oe.set(this,null),pe.set(this,null),Tt.set(this,"show-hidden"),Le.set(this,null),qe.set(this,!0),Lt.set(this,{}),_e.set(this,!0),Wt.set(this,[]),Ce.set(this,void 0),Ie.set(this,{}),me.set(this,!1),xe.set(this,null),Ut.set(this,!0),at.set(this,void 0),le.set(this,""),$.set(this,void 0),Bt.set(this,void 0),Vt.set(this,{}),ge.set(this,null),Ke.set(this,null),lt.set(this,{}),Je.set(this,{}),We.set(this,void 0),zt.set(this,!1),D.set(this,void 0),Qe.set(this,!1),Ze.set(this,!1),Xe.set(this,!1),L.set(this,void 0),Ht.set(this,{}),ve.set(this,null),te.set(this,void 0),M(this,D,s,"f"),M(this,We,e,"f"),M(this,Ge,t,"f"),M(this,Bt,n,"f"),M(this,Ce,new Ft(this),"f"),this.$0=this[Ti](),this[Mn](),M(this,ie,o(this,ie,"f"),"f"),M(this,L,o(this,L,"f"),"f"),M(this,te,o(this,te,"f"),"f"),M(this,$,o(this,$,"f"),"f"),o(this,$,"f").showHiddenOpt=o(this,Tt,"f"),M(this,at,this[Fi](),"f")}addHelpOpt(e,t){let n="help";return j("[string|boolean] [string]",[e,t],arguments.length),o(this,xe,"f")&&(this[On](o(this,xe,"f")),M(this,xe,null,"f")),e===!1&&t===void 0?this:(M(this,xe,typeof e=="string"?e:n,"f"),this.boolean(o(this,xe,"f")),this.describe(o(this,xe,"f"),t||o(this,L,"f").deferY18nLookup("Show help")),this)}help(e,t){return this.addHelpOpt(e,t)}addShowHiddenOpt(e,t){if(j("[string|boolean] [string]",[e,t],arguments.length),e===!1&&t===void 0)return this;let n=typeof e=="string"?e:o(this,Tt,"f");return this.boolean(n),this.describe(n,t||o(this,L,"f").deferY18nLookup("Show hidden options")),o(this,$,"f").showHiddenOpt=n,this}showHidden(e,t){return this.addShowHiddenOpt(e,t)}alias(e,t){return j("<object|string|array> [string|array]",[e,t],arguments.length),this[xn](this.alias.bind(this),"alias",e,t),this}array(e){return j("<array|string>",[e],arguments.length),this[Ue]("array",e),this[tt](e),this}boolean(e){return j("<array|string>",[e],arguments.length),this[Ue]("boolean",e),this[tt](e),this}check(e,t){return j("<function> [boolean]",[e,t],arguments.length),this.middleware((n,s)=>Ye(()=>e(n,s.getOptions()),r=>(r?(typeof r=="string"||r instanceof Error)&&o(this,L,"f").fail(r.toString(),r):o(this,L,"f").fail(o(this,D,"f").y18n.__("Argument check failed: %s",e.toString())),n),r=>(o(this,L,"f").fail(r.message?r.message:r.toString(),r),n)),!1,t),this}choices(e,t){return j("<object|string|array> [string|array]",[e,t],arguments.length),this[xn](this.choices.bind(this),"choices",e,t),this}coerce(e,t){if(j("<object|string|array> [function]",[e,t],arguments.length),Array.isArray(e)){if(!t)throw new q("coerce callback must be provided");for(let n of e)this.coerce(n,t);return this}else if(typeof e=="object"){for(let n of Object.keys(e))this.coerce(n,e[n]);return this}if(!t)throw new q("coerce callback must be provided");return o(this,$,"f").key[e]=!0,o(this,Ce,"f").addCoerceMiddleware((n,s)=>{let r;return Object.prototype.hasOwnProperty.call(n,e)?Ye(()=>(r=s.getAliases(),t(n[e])),c=>{n[e]=c;let g=s.getInternalMethods().getParserConfiguration()["strip-aliased"];if(r[e]&&g!==!0)for(let b of r[e])n[b]=c;return n},c=>{throw new q(c.message)}):n},e),this}conflicts(e,t){return j("<string|object> [string|array]",[e,t],arguments.length),o(this,te,"f").conflicts(e,t),this}config(e="config",t,n){return j("[object|string] [string|function] [function]",[e,t,n],arguments.length),typeof e=="object"&&!Array.isArray(e)?(e=gt(e,o(this,Ge,"f"),this[ke]()["deep-merge-config"]||!1,o(this,D,"f")),o(this,$,"f").configObjects=(o(this,$,"f").configObjects||[]).concat(e),this):(typeof t=="function"&&(n=t,t=void 0),this.describe(e,t||o(this,L,"f").deferY18nLookup("Path to JSON config file")),(Array.isArray(e)?e:[e]).forEach(s=>{o(this,$,"f").config[s]=n||!0}),this)}completion(e,t,n){return j("[string] [string|boolean|function] [function]",[e,t,n],arguments.length),typeof t=="function"&&(n=t,t=void 0),M(this,pe,e||o(this,pe,"f")||"completion","f"),!t&&t!==!1&&(t="generate completion script"),this.command(o(this,pe,"f"),t),n&&o(this,Oe,"f").registerFunction(n),this}command(e,t,n,s,r,a){return j("<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]",[e,t,n,s,r,a],arguments.length),o(this,ie,"f").addHandler(e,t,n,s,r,a),this}commands(e,t,n,s,r,a){return this.command(e,t,n,s,r,a)}commandDir(e,t){j("<string> [object]",[e,t],arguments.length);let n=o(this,Bt,"f")||o(this,D,"f").require;return o(this,ie,"f").addDirectory(e,n,o(this,D,"f").getCallerFile(),t),this}count(e){return j("<array|string>",[e],arguments.length),this[Ue]("count",e),this[tt](e),this}default(e,t,n){return j("<object|string|array> [*] [string]",[e,t,n],arguments.length),n&&(pn(e,o(this,D,"f")),o(this,$,"f").defaultDescription[e]=n),typeof t=="function"&&(pn(e,o(this,D,"f")),o(this,$,"f").defaultDescription[e]||(o(this,$,"f").defaultDescription[e]=o(this,L,"f").functionDescription(t)),t=t.call()),this[ct](this.default.bind(this),"default",e,t),this}defaults(e,t,n){return this.default(e,t,n)}demandCommand(e=1,t,n,s){return j("[number] [number|string] [string|null|undefined] [string|null|undefined]",[e,t,n,s],arguments.length),typeof t!="number"&&(n=t,t=1/0),this.global("_",!1),o(this,$,"f").demandedCommands._={min:e,max:t,minMsg:n,maxMsg:s},this}demand(e,t,n){return Array.isArray(t)?(t.forEach(s=>{ue(n,!0,o(this,D,"f")),this.demandOption(s,n)}),t=1/0):typeof t!="number"&&(n=t,t=1/0),typeof e=="number"?(ue(n,!0,o(this,D,"f")),this.demandCommand(e,t,n,n)):Array.isArray(e)?e.forEach(s=>{ue(n,!0,o(this,D,"f")),this.demandOption(s,n)}):typeof n=="string"?this.demandOption(e,n):(n===!0||typeof n>"u")&&this.demandOption(e),this}demandOption(e,t){return j("<object|string|array> [string]",[e,t],arguments.length),this[ct](this.demandOption.bind(this),"demandedOptions",e,t),this}deprecateOption(e,t){return j("<string> [string|boolean]",[e,t],arguments.length),o(this,$,"f").deprecatedOptions[e]=t,this}describe(e,t){return j("<object|string|array> [string]",[e,t],arguments.length),this[Sn](e,!0),o(this,L,"f").describe(e,t),this}detectLocale(e){return j("<boolean>",[e],arguments.length),M(this,qe,e,"f"),this}env(e){return j("[string|boolean]",[e],arguments.length),e===!1?delete o(this,$,"f").envPrefix:o(this,$,"f").envPrefix=e||"",this}epilogue(e){return j("<string>",[e],arguments.length),o(this,L,"f").epilog(e),this}epilog(e){return this.epilogue(e)}example(e,t){return j("<string|array> [string]",[e,t],arguments.length),Array.isArray(e)?e.forEach(n=>this.example(...n)):o(this,L,"f").example(e,t),this}exit(e,t){M(this,me,!0,"f"),M(this,Le,t,"f"),o(this,_e,"f")&&o(this,D,"f").process.exit(e)}exitProcess(e=!0){return j("[boolean]",[e],arguments.length),M(this,_e,e,"f"),this}fail(e){if(j("<function|boolean>",[e],arguments.length),typeof e=="boolean"&&e!==!1)throw new q("Invalid first argument. Expected function or boolean 'false'");return o(this,L,"f").failFn(e),this}getAliases(){return this.parsed?this.parsed.aliases:{}}async getCompletion(e,t){return j("<array> [function]",[e,t],arguments.length),t?o(this,Oe,"f").getCompletion(e,t):new Promise((n,s)=>{o(this,Oe,"f").getCompletion(e,(r,a)=>{r?s(r):n(a)})})}getDemandedOptions(){return j([],0),o(this,$,"f").demandedOptions}getDemandedCommands(){return j([],0),o(this,$,"f").demandedCommands}getDeprecatedOptions(){return j([],0),o(this,$,"f").deprecatedOptions}getDetectLocale(){return o(this,qe,"f")}getExitProcess(){return o(this,_e,"f")}getGroups(){return Object.assign({},o(this,Ie,"f"),o(this,Je,"f"))}getHelp(){if(M(this,me,!0,"f"),!o(this,L,"f").hasCachedHelpMessage()){if(!this.parsed){let t=this[yt](o(this,We,"f"),void 0,void 0,0,!0);if(K(t))return t.then(()=>o(this,L,"f").help())}let e=o(this,ie,"f").runDefaultBuilderOn(this);if(K(e))return e.then(()=>o(this,L,"f").help())}return Promise.resolve(o(this,L,"f").help())}getOptions(){return o(this,$,"f")}getStrict(){return o(this,Qe,"f")}getStrictCommands(){return o(this,Ze,"f")}getStrictOptions(){return o(this,Xe,"f")}global(e,t){return j("<string|array> [boolean]",[e,t],arguments.length),e=[].concat(e),t!==!1?o(this,$,"f").local=o(this,$,"f").local.filter(n=>e.indexOf(n)===-1):e.forEach(n=>{o(this,$,"f").local.includes(n)||o(this,$,"f").local.push(n)}),this}group(e,t){j("<string|array> <string>",[e,t],arguments.length);let n=o(this,Je,"f")[t]||o(this,Ie,"f")[t];o(this,Je,"f")[t]&&delete o(this,Je,"f")[t];let s={};return o(this,Ie,"f")[t]=(n||[]).concat(e).filter(r=>s[r]?!1:s[r]=!0),this}hide(e){return j("<string>",[e],arguments.length),o(this,$,"f").hiddenOptions.push(e),this}implies(e,t){return j("<string|object> [number|string|array]",[e,t],arguments.length),o(this,te,"f").implies(e,t),this}locale(e){return j("[string]",[e],arguments.length),e===void 0?(this[_n](),o(this,D,"f").y18n.getLocale()):(M(this,qe,!1,"f"),o(this,D,"f").y18n.setLocale(e),this)}middleware(e,t,n){return o(this,Ce,"f").addMiddleware(e,!!t,n)}nargs(e,t){return j("<string|object|array> [number]",[e,t],arguments.length),this[ct](this.nargs.bind(this),"narg",e,t),this}normalize(e){return j("<array|string>",[e],arguments.length),this[Ue]("normalize",e),this}number(e){return j("<array|string>",[e],arguments.length),this[Ue]("number",e),this[tt](e),this}option(e,t){if(j("<string|object> [object]",[e,t],arguments.length),typeof e=="object")Object.keys(e).forEach(n=>{this.options(n,e[n])});else{typeof t!="object"&&(t={}),this[tt](e),o(this,ve,"f")&&(e==="version"||(t==null?void 0:t.alias)==="version")&&this[Ri](['"version" is a reserved word.',"Please do one of the following:",'- Disable version with `yargs.version(false)` if using "version" as an option',"- Use the built-in `yargs.version` method instead (if applicable)","- Use a different option key","https://yargs.js.org/docs/#api-reference-version"].join(`
|
|
69
|
+
`),void 0,"versionWarning"),o(this,$,"f").key[e]=!0,t.alias&&this.alias(e,t.alias);let n=t.deprecate||t.deprecated;n&&this.deprecateOption(e,n);let s=t.demand||t.required||t.require;s&&this.demand(e,s),t.demandOption&&this.demandOption(e,typeof t.demandOption=="string"?t.demandOption:void 0),t.conflicts&&this.conflicts(e,t.conflicts),"default"in t&&this.default(e,t.default),t.implies!==void 0&&this.implies(e,t.implies),t.nargs!==void 0&&this.nargs(e,t.nargs),t.config&&this.config(e,t.configParser),t.normalize&&this.normalize(e),t.choices&&this.choices(e,t.choices),t.coerce&&this.coerce(e,t.coerce),t.group&&this.group(e,t.group),(t.boolean||t.type==="boolean")&&(this.boolean(e),t.alias&&this.boolean(t.alias)),(t.array||t.type==="array")&&(this.array(e),t.alias&&this.array(t.alias)),(t.number||t.type==="number")&&(this.number(e),t.alias&&this.number(t.alias)),(t.string||t.type==="string")&&(this.string(e),t.alias&&this.string(t.alias)),(t.count||t.type==="count")&&this.count(e),typeof t.global=="boolean"&&this.global(e,t.global),t.defaultDescription&&(o(this,$,"f").defaultDescription[e]=t.defaultDescription),t.skipValidation&&this.skipValidation(e);let r=t.describe||t.description||t.desc,a=o(this,L,"f").getDescriptions();(!Object.prototype.hasOwnProperty.call(a,e)||typeof r=="string")&&this.describe(e,r),t.hidden&&this.hide(e),t.requiresArg&&this.requiresArg(e)}return this}options(e,t){return this.option(e,t)}parse(e,t,n){j("[string|array] [function|boolean|object] [function]",[e,t,n],arguments.length),this[Di](),typeof e>"u"&&(e=o(this,We,"f")),typeof t=="object"&&(M(this,Ke,t,"f"),t=n),typeof t=="function"&&(M(this,ge,t,"f"),t=!1),t||M(this,We,e,"f"),o(this,ge,"f")&&M(this,_e,!1,"f");let s=this[yt](e,!!t),r=this.parsed;return o(this,Oe,"f").setParsed(this.parsed),K(s)?s.then(a=>(o(this,ge,"f")&&o(this,ge,"f").call(this,o(this,Le,"f"),a,o(this,le,"f")),a)).catch(a=>{throw o(this,ge,"f")&&o(this,ge,"f")(a,this.parsed.argv,o(this,le,"f")),a}).finally(()=>{this[jn](),this.parsed=r}):(o(this,ge,"f")&&o(this,ge,"f").call(this,o(this,Le,"f"),s,o(this,le,"f")),this[jn](),this.parsed=r,s)}parseAsync(e,t,n){let s=this.parse(e,t,n);return K(s)?s:Promise.resolve(s)}parseSync(e,t,n){let s=this.parse(e,t,n);if(K(s))throw new q(".parseSync() must not be used with asynchronous builders, handlers, or middleware");return s}parserConfiguration(e){return j("<object>",[e],arguments.length),M(this,Vt,e,"f"),this}pkgConf(e,t){j("<string> [string]",[e,t],arguments.length);let n=null,s=this[Cn](t||o(this,Ge,"f"));return s[e]&&typeof s[e]=="object"&&(n=gt(s[e],t||o(this,Ge,"f"),this[ke]()["deep-merge-config"]||!1,o(this,D,"f")),o(this,$,"f").configObjects=(o(this,$,"f").configObjects||[]).concat(n)),this}positional(e,t){j("<string> <object>",[e,t],arguments.length);let n=["default","defaultDescription","implies","normalize","choices","conflicts","coerce","type","describe","desc","description","alias"];t=De(t,(a,c)=>a==="type"&&!["string","number","boolean"].includes(c)?!1:n.includes(a));let s=o(this,bt,"f").fullCommands[o(this,bt,"f").fullCommands.length-1],r=s?o(this,ie,"f").cmdToParseOptions(s):{array:[],alias:{},default:{},demand:{}};return rt(r).forEach(a=>{let c=r[a];Array.isArray(c)?c.indexOf(e)!==-1&&(t[a]=!0):c[e]&&!(a in t)&&(t[a]=c[e])}),this.group(e,o(this,L,"f").getPositionalGroupName()),this.option(e,t)}recommendCommands(e=!0){return j("[boolean]",[e],arguments.length),M(this,zt,e,"f"),this}required(e,t,n){return this.demand(e,t,n)}require(e,t,n){return this.demand(e,t,n)}requiresArg(e){return j("<array|string|object> [number]",[e],arguments.length),typeof e=="string"&&o(this,$,"f").narg[e]?this:(this[ct](this.requiresArg.bind(this),"narg",e,NaN),this)}showCompletionScript(e,t){return j("[string] [string]",[e,t],arguments.length),e=e||this.$0,o(this,at,"f").log(o(this,Oe,"f").generateCompletionScript(e,t||o(this,pe,"f")||"completion")),this}showHelp(e){if(j("[string|function]",[e],arguments.length),M(this,me,!0,"f"),!o(this,L,"f").hasCachedHelpMessage()){if(!this.parsed){let n=this[yt](o(this,We,"f"),void 0,void 0,0,!0);if(K(n))return n.then(()=>{o(this,L,"f").showHelp(e)}),this}let t=o(this,ie,"f").runDefaultBuilderOn(this);if(K(t))return t.then(()=>{o(this,L,"f").showHelp(e)}),this}return o(this,L,"f").showHelp(e),this}scriptName(e){return this.customScriptName=!0,this.$0=e,this}showHelpOnFail(e,t){return j("[boolean|string] [string]",[e,t],arguments.length),o(this,L,"f").showHelpOnFail(e,t),this}showVersion(e){return j("[string|function]",[e],arguments.length),o(this,L,"f").showVersion(e),this}skipValidation(e){return j("<array|string>",[e],arguments.length),this[Ue]("skipValidation",e),this}strict(e){return j("[boolean]",[e],arguments.length),M(this,Qe,e!==!1,"f"),this}strictCommands(e){return j("[boolean]",[e],arguments.length),M(this,Ze,e!==!1,"f"),this}strictOptions(e){return j("[boolean]",[e],arguments.length),M(this,Xe,e!==!1,"f"),this}string(e){return j("<array|string>",[e],arguments.length),this[Ue]("string",e),this[tt](e),this}terminalWidth(){return j([],0),o(this,D,"f").process.stdColumns}updateLocale(e){return this.updateStrings(e)}updateStrings(e){return j("<object>",[e],arguments.length),M(this,qe,!1,"f"),o(this,D,"f").y18n.updateLocale(e),this}usage(e,t,n,s){if(j("<string|null|undefined> [string|boolean] [function|object] [function]",[e,t,n,s],arguments.length),t!==void 0){if(ue(e,null,o(this,D,"f")),(e||"").match(/^\$0( |$)/))return this.command(e,t,n,s);throw new q(".usage() description must start with $0 if being used as alias for .command()")}else return o(this,L,"f").usage(e),this}usageConfiguration(e){return j("<object>",[e],arguments.length),M(this,Ht,e,"f"),this}version(e,t,n){let s="version";if(j("[boolean|string] [string] [string]",[e,t,n],arguments.length),o(this,ve,"f")&&(this[On](o(this,ve,"f")),o(this,L,"f").version(void 0),M(this,ve,null,"f")),arguments.length===0)n=this[Wi](),e=s;else if(arguments.length===1){if(e===!1)return this;n=e,e=s}else arguments.length===2&&(n=t,t=void 0);return M(this,ve,typeof e=="string"?e:s,"f"),t=t||o(this,L,"f").deferY18nLookup("Show version number"),o(this,L,"f").version(n||void 0),this.boolean(o(this,ve,"f")),this.describe(o(this,ve,"f"),t),this}wrap(e){return j("<number|null|undefined>",[e],arguments.length),o(this,L,"f").wrap(e),this}[(ie=new WeakMap,Ge=new WeakMap,bt=new WeakMap,Oe=new WeakMap,pe=new WeakMap,Tt=new WeakMap,Le=new WeakMap,qe=new WeakMap,Lt=new WeakMap,_e=new WeakMap,Wt=new WeakMap,Ce=new WeakMap,Ie=new WeakMap,me=new WeakMap,xe=new WeakMap,Ut=new WeakMap,at=new WeakMap,le=new WeakMap,$=new WeakMap,Bt=new WeakMap,Vt=new WeakMap,ge=new WeakMap,Ke=new WeakMap,lt=new WeakMap,Je=new WeakMap,We=new WeakMap,zt=new WeakMap,D=new WeakMap,Qe=new WeakMap,Ze=new WeakMap,Xe=new WeakMap,L=new WeakMap,Ht=new WeakMap,ve=new WeakMap,te=new WeakMap,Ni)](e){if(!e._||!e["--"])return e;e._.push.apply(e._,e["--"]);try{delete e["--"]}catch{}return e}[Fi](){return{log:(...e)=>{this[Yt]()||console.log(...e),M(this,me,!0,"f"),o(this,le,"f").length&&M(this,le,o(this,le,"f")+`
|
|
70
|
+
`,"f"),M(this,le,o(this,le,"f")+e.join(" "),"f")},error:(...e)=>{this[Yt]()||console.error(...e),M(this,me,!0,"f"),o(this,le,"f").length&&M(this,le,o(this,le,"f")+`
|
|
71
|
+
`,"f"),M(this,le,o(this,le,"f")+e.join(" "),"f")}}}[On](e){rt(o(this,$,"f")).forEach(t=>{if((s=>s==="configObjects")(t))return;let n=o(this,$,"f")[t];Array.isArray(n)?n.includes(e)&&n.splice(n.indexOf(e),1):typeof n=="object"&&delete n[e]}),delete o(this,L,"f").getDescriptions()[e]}[Ri](e,t,n){o(this,Lt,"f")[n]||(o(this,D,"f").process.emitWarning(e,t),o(this,Lt,"f")[n]=!0)}[Di](){o(this,Wt,"f").push({options:o(this,$,"f"),configObjects:o(this,$,"f").configObjects.slice(0),exitProcess:o(this,_e,"f"),groups:o(this,Ie,"f"),strict:o(this,Qe,"f"),strictCommands:o(this,Ze,"f"),strictOptions:o(this,Xe,"f"),completionCommand:o(this,pe,"f"),output:o(this,le,"f"),exitError:o(this,Le,"f"),hasOutput:o(this,me,"f"),parsed:this.parsed,parseFn:o(this,ge,"f"),parseContext:o(this,Ke,"f")}),o(this,L,"f").freeze(),o(this,te,"f").freeze(),o(this,ie,"f").freeze(),o(this,Ce,"f").freeze()}[Ti](){let e="",t;return/\b(node|iojs|electron)(\.exe)?$/.test(o(this,D,"f").process.argv()[0])?t=o(this,D,"f").process.argv().slice(1,2):t=o(this,D,"f").process.argv().slice(0,1),e=t.map(n=>{let s=this[Qi](o(this,Ge,"f"),n);return n.match(/^(\/|([a-zA-Z]:)?\\)/)&&s.length<n.length?s:n}).join(" ").trim(),o(this,D,"f").getEnv("_")&&o(this,D,"f").getProcessArgvBin()===o(this,D,"f").getEnv("_")&&(e=o(this,D,"f").getEnv("_").replace(`${o(this,D,"f").path.dirname(o(this,D,"f").process.execPath())}/`,"")),e}[ke](){return o(this,Vt,"f")}[Li](){return o(this,Ht,"f")}[_n](){if(!o(this,qe,"f"))return;let e=o(this,D,"f").getEnv("LC_ALL")||o(this,D,"f").getEnv("LC_MESSAGES")||o(this,D,"f").getEnv("LANG")||o(this,D,"f").getEnv("LANGUAGE")||"en_US";this.locale(e.replace(/[.:].*/,""))}[Wi](){return this[Cn]().version||"unknown"}[Ui](e){let t=e["--"]?e["--"]:e._;for(let n=0,s;(s=t[n])!==void 0;n++)o(this,D,"f").Parser.looksLikeNumber(s)&&Number.isSafeInteger(Math.floor(parseFloat(`${s}`)))&&(t[n]=Number(s));return e}[Cn](e){let t=e||"*";if(o(this,lt,"f")[t])return o(this,lt,"f")[t];let n={};try{let s=e||o(this,D,"f").mainFilename;!e&&o(this,D,"f").path.extname(s)&&(s=o(this,D,"f").path.dirname(s));let r=o(this,D,"f").findUp(s,(a,c)=>{if(c.includes("package.json"))return"package.json"});ue(r,void 0,o(this,D,"f")),n=JSON.parse(o(this,D,"f").readFileSync(r,"utf8"))}catch{}return o(this,lt,"f")[t]=n||{},o(this,lt,"f")[t]}[Ue](e,t){t=[].concat(t),t.forEach(n=>{n=this[An](n),o(this,$,"f")[e].push(n)})}[ct](e,t,n,s){this[En](e,t,n,s,(r,a,c)=>{o(this,$,"f")[r][a]=c})}[xn](e,t,n,s){this[En](e,t,n,s,(r,a,c)=>{o(this,$,"f")[r][a]=(o(this,$,"f")[r][a]||[]).concat(c)})}[En](e,t,n,s,r){if(Array.isArray(n))n.forEach(a=>{e(a,s)});else if((a=>typeof a=="object")(n))for(let a of rt(n))e(a,n[a]);else r(t,this[An](n),s)}[An](e){return e==="__proto__"?"___proto___":e}[Sn](e,t){return this[ct](this[Sn].bind(this),"key",e,t),this}[jn](){var e,t,n,s,r,a,c,g,b,m,h,d;let w=o(this,Wt,"f").pop();ue(w,void 0,o(this,D,"f"));let C;e=this,t=this,n=this,s=this,r=this,a=this,c=this,g=this,b=this,m=this,h=this,d=this,{options:{set value(_){M(e,$,_,"f")}}.value,configObjects:C,exitProcess:{set value(_){M(t,_e,_,"f")}}.value,groups:{set value(_){M(n,Ie,_,"f")}}.value,output:{set value(_){M(s,le,_,"f")}}.value,exitError:{set value(_){M(r,Le,_,"f")}}.value,hasOutput:{set value(_){M(a,me,_,"f")}}.value,parsed:this.parsed,strict:{set value(_){M(c,Qe,_,"f")}}.value,strictCommands:{set value(_){M(g,Ze,_,"f")}}.value,strictOptions:{set value(_){M(b,Xe,_,"f")}}.value,completionCommand:{set value(_){M(m,pe,_,"f")}}.value,parseFn:{set value(_){M(h,ge,_,"f")}}.value,parseContext:{set value(_){M(d,Ke,_,"f")}}.value}=w,o(this,$,"f").configObjects=C,o(this,L,"f").unfreeze(),o(this,te,"f").unfreeze(),o(this,ie,"f").unfreeze(),o(this,Ce,"f").unfreeze()}[Bi](e,t){return Ye(t,n=>(e(n),n))}getInternalMethods(){return{getCommandInstance:this[Vi].bind(this),getContext:this[zi].bind(this),getHasOutput:this[Hi].bind(this),getLoggerInstance:this[Yi].bind(this),getParseContext:this[Gi].bind(this),getParserConfiguration:this[ke].bind(this),getUsageConfiguration:this[Li].bind(this),getUsageInstance:this[qi].bind(this),getValidationInstance:this[Ki].bind(this),hasParseCallback:this[Yt].bind(this),isGlobalContext:this[Ji].bind(this),postProcess:this[et].bind(this),reset:this[Mn].bind(this),runValidation:this[Pn].bind(this),runYargsParserAndExecuteCommands:this[yt].bind(this),setHasOutput:this[Zi].bind(this)}}[Vi](){return o(this,ie,"f")}[zi](){return o(this,bt,"f")}[Hi](){return o(this,me,"f")}[Yi](){return o(this,at,"f")}[Gi](){return o(this,Ke,"f")||{}}[qi](){return o(this,L,"f")}[Ki](){return o(this,te,"f")}[Yt](){return!!o(this,ge,"f")}[Ji](){return o(this,Ut,"f")}[et](e,t,n,s){return n||K(e)||(t||(e=this[Ni](e)),(this[ke]()["parse-positional-numbers"]||this[ke]()["parse-positional-numbers"]===void 0)&&(e=this[Ui](e)),s&&(e=He(e,this,o(this,Ce,"f").getMiddleware(),!1))),e}[Mn](e={}){M(this,$,o(this,$,"f")||{},"f");let t={};t.local=o(this,$,"f").local||[],t.configObjects=o(this,$,"f").configObjects||[];let n={};t.local.forEach(a=>{n[a]=!0,(e[a]||[]).forEach(c=>{n[c]=!0})}),Object.assign(o(this,Je,"f"),Object.keys(o(this,Ie,"f")).reduce((a,c)=>{let g=o(this,Ie,"f")[c].filter(b=>!(b in n));return g.length>0&&(a[c]=g),a},{})),M(this,Ie,{},"f");let s=["array","boolean","string","skipValidation","count","normalize","number","hiddenOptions"],r=["narg","key","alias","default","defaultDescription","config","choices","demandedOptions","demandedCommands","deprecatedOptions"];return s.forEach(a=>{t[a]=(o(this,$,"f")[a]||[]).filter(c=>!n[c])}),r.forEach(a=>{t[a]=De(o(this,$,"f")[a],c=>!n[c])}),t.envPrefix=o(this,$,"f").envPrefix,M(this,$,t,"f"),M(this,L,o(this,L,"f")?o(this,L,"f").reset(n):Ai(this,o(this,D,"f")),"f"),M(this,te,o(this,te,"f")?o(this,te,"f").reset(n):vi(this,o(this,L,"f"),o(this,D,"f")),"f"),M(this,ie,o(this,ie,"f")?o(this,ie,"f").reset():Ci(o(this,L,"f"),o(this,te,"f"),o(this,Ce,"f"),o(this,D,"f")),"f"),o(this,Oe,"f")||M(this,Oe,Mi(this,o(this,L,"f"),o(this,ie,"f"),o(this,D,"f")),"f"),o(this,Ce,"f").reset(),M(this,pe,null,"f"),M(this,le,"","f"),M(this,Le,null,"f"),M(this,me,!1,"f"),this.parsed=!1,this}[Qi](e,t){return o(this,D,"f").path.relative(e,t)}[yt](e,t,n,s=0,r=!1){let a=!!n||r;e=e||o(this,We,"f"),o(this,$,"f").__=o(this,D,"f").y18n.__,o(this,$,"f").configuration=this[ke]();let c=!!o(this,$,"f").configuration["populate--"],g=Object.assign({},o(this,$,"f").configuration,{"populate--":!0}),b=o(this,D,"f").Parser.detailed(e,Object.assign({},o(this,$,"f"),{configuration:{"parse-positional-numbers":!1,...g}})),m=Object.assign(b.argv,o(this,Ke,"f")),h,d=b.aliases,w=!1,C=!1;Object.keys(m).forEach(_=>{_===o(this,xe,"f")&&m[_]?w=!0:_===o(this,ve,"f")&&m[_]&&(C=!0)}),m.$0=this.$0,this.parsed=b,s===0&&o(this,L,"f").clearCachedHelpMessage();try{if(this[_n](),t)return this[et](m,c,!!n,!1);o(this,xe,"f")&&[o(this,xe,"f")].concat(d[o(this,xe,"f")]||[]).filter(S=>S.length>1).includes(""+m._[m._.length-1])&&(m._.pop(),w=!0),M(this,Ut,!1,"f");let _=o(this,ie,"f").getCommands(),p=o(this,Oe,"f").completionKey in m,W=w||p||r;if(m._.length){if(_.length){let B;for(let S=s||0,A;m._[S]!==void 0;S++)if(A=String(m._[S]),_.includes(A)&&A!==o(this,pe,"f")){let T=o(this,ie,"f").runCommand(A,this,b,S+1,r,w||C||r);return this[et](T,c,!!n,!1)}else if(!B&&A!==o(this,pe,"f")){B=A;break}!o(this,ie,"f").hasDefaultCommand()&&o(this,zt,"f")&&B&&!W&&o(this,te,"f").recommendCommands(B,_)}o(this,pe,"f")&&m._.includes(o(this,pe,"f"))&&!p&&(o(this,_e,"f")&&Te(!0),this.showCompletionScript(),this.exit(0))}if(o(this,ie,"f").hasDefaultCommand()&&!W){let B=o(this,ie,"f").runCommand(null,this,b,0,r,w||C||r);return this[et](B,c,!!n,!1)}if(p){o(this,_e,"f")&&Te(!0),e=[].concat(e);let B=e.slice(e.indexOf(`--${o(this,Oe,"f").completionKey}`)+1);return o(this,Oe,"f").getCompletion(B,(S,A)=>{if(S)throw new q(S.message);(A||[]).forEach(T=>{o(this,at,"f").log(T)}),this.exit(0)}),this[et](m,!c,!!n,!1)}if(o(this,me,"f")||(w?(o(this,_e,"f")&&Te(!0),a=!0,this.showHelp("log"),this.exit(0)):C&&(o(this,_e,"f")&&Te(!0),a=!0,o(this,L,"f").showVersion("log"),this.exit(0))),!a&&o(this,$,"f").skipValidation.length>0&&(a=Object.keys(m).some(B=>o(this,$,"f").skipValidation.indexOf(B)>=0&&m[B]===!0)),!a){if(b.error)throw new q(b.error.message);if(!p){let B=this[Pn](d,{},b.error);n||(h=He(m,this,o(this,Ce,"f").getMiddleware(),!0)),h=this[Bi](B,h??m),K(h)&&!n&&(h=h.then(()=>He(m,this,o(this,Ce,"f").getMiddleware(),!1)))}}}catch(_){if(_ instanceof q)o(this,L,"f").fail(_.message,_);else throw _}return this[et](h??m,c,!!n,!0)}[Pn](e,t,n,s){let r={...this.getDemandedOptions()};return a=>{if(n)throw new q(n.message);o(this,te,"f").nonOptionCount(a),o(this,te,"f").requiredArguments(a,r);let c=!1;o(this,Ze,"f")&&(c=o(this,te,"f").unknownCommands(a)),o(this,Qe,"f")&&!c?o(this,te,"f").unknownArguments(a,e,t,!!s):o(this,Xe,"f")&&o(this,te,"f").unknownArguments(a,e,{},!1,!1),o(this,te,"f").limitedChoices(a),o(this,te,"f").implications(a),o(this,te,"f").conflicting(a)}}[Zi](){M(this,me,!0,"f")}[tt](e){if(typeof e=="string")o(this,$,"f").key[e]=!0;else for(let t of e)o(this,$,"f").key[t]=!0}};function xi(i){return!!i&&typeof i.getInternalMethods=="function"}var Ir=Xi(dn),ki=Ir;var vr=performance.now(),es=ki(un(process.argv));await es.scriptName("vidup").usage("$0 [command]","Run a vidup command.").command(["$0 <directory> [options]","sync <directory> [options]"],"Synchronize a remote video streaming service to mirror the contents of a local directory.",i=>i.positional("directory",{default:void 0,demandOption:!0,describe:"The path to the local directory of video files to sync.",type:"string"}).option("service",{alias:"s",choices:["bunny","mux","cloudflare"],demandOption:!0,describe:"Streaming service to sync to. Only the Bunny.net streaming CDN is supported at this time.",type:"string"}).option("key",{default:void 0,demandOption:!0,describe:"Streaming service API access key",type:"string"}).option("library",{default:void 0,demandOption:!0,describe:"Streaming service library ID",type:"string"}).option("strip-metadata",{default:!0,describe:"Remove all metadata from the video files before uploading them to the streaming service.",type:"boolean"}).option("dry-run",{alias:"d",default:!1,describe:"Perform a dry run without making any changes. Useful for testing and debugging.",type:"boolean"}).option("json",{default:!1,describe:"Output the sync report as JSON",type:"boolean"}).option("verbose",{default:!1,describe:"Enable verbose logging. All verbose logs and prefixed with their log level and are printed to `stderr` for ease of redirection.",type:"boolean"}).check(e=>{if(e.service==="bunny")return e;throw new Error(`Sorry, vidup doesn't yet implement synchronization support the ${e.service} streaming service. Only Bunny.net is supported at the moment. If you'd like to see support for another service, please open an issue or send a PR on GitHub: https://github.com/kitschpatrol/vidup/issues`)}),async({directory:i,dryRun:e,json:t,key:n,library:s,service:r,stripMetadata:a,verbose:c})=>{G.verbose=c,G.info("Starting video synchronization..."),e&&G.warn("Dry run enabled, not making any changes");let g=await kt(i,{credentials:{key:n,library:s},dryRun:e,service:r,stripMetadata:a,verbose:c});if(t)process.stdout.write(JSON.stringify(g,void 0,2)),process.stdout.write(`
|
|
72
|
+
`);else for(let b of g)process.stdout.write(`${b.action}: ${b.localFile}
|
|
73
|
+
`);G.info(`Synchronized video in ${tn(performance.now()-vr)}`),process.exitCode=0}).demandCommand(1).alias("h","help").version("version").alias("v","version").help().wrap(process.stdout.isTTY?Math.min(120,es.terminalWidth()):0).parse();
|
|
74
|
+
/*! Bundled license information:
|
|
75
|
+
|
|
76
|
+
yargs-parser/build/lib/string-utils.js:
|
|
77
|
+
(**
|
|
78
|
+
* @license
|
|
79
|
+
* Copyright (c) 2016, Contributors
|
|
80
|
+
* SPDX-License-Identifier: ISC
|
|
81
|
+
*)
|
|
82
|
+
|
|
83
|
+
yargs-parser/build/lib/tokenize-arg-string.js:
|
|
84
|
+
(**
|
|
85
|
+
* @license
|
|
86
|
+
* Copyright (c) 2016, Contributors
|
|
87
|
+
* SPDX-License-Identifier: ISC
|
|
88
|
+
*)
|
|
89
|
+
|
|
90
|
+
yargs-parser/build/lib/yargs-parser-types.js:
|
|
91
|
+
(**
|
|
92
|
+
* @license
|
|
93
|
+
* Copyright (c) 2016, Contributors
|
|
94
|
+
* SPDX-License-Identifier: ISC
|
|
95
|
+
*)
|
|
96
|
+
|
|
97
|
+
yargs-parser/build/lib/yargs-parser.js:
|
|
98
|
+
(**
|
|
99
|
+
* @license
|
|
100
|
+
* Copyright (c) 2016, Contributors
|
|
101
|
+
* SPDX-License-Identifier: ISC
|
|
102
|
+
*)
|
|
103
|
+
|
|
104
|
+
yargs-parser/build/lib/index.js:
|
|
105
|
+
(**
|
|
106
|
+
* @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
|
|
107
|
+
* CJS and ESM environments.
|
|
108
|
+
*
|
|
109
|
+
* @license
|
|
110
|
+
* Copyright (c) 2016, Contributors
|
|
111
|
+
* SPDX-License-Identifier: ISC
|
|
112
|
+
*)
|
|
113
|
+
*/
|
package/dist/.DS_Store
ADDED
|
Binary file
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var X=(t=0)=>e=>`\x1B[${e+t}m`,Z=(t=0)=>e=>`\x1B[${38+t};5;${e}m`,ee=(t=0)=>(e,r,o)=>`\x1B[${38+t};2;${e};${r};${o}m`,c={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},Xe=Object.keys(c.modifier),xe=Object.keys(c.color),Se=Object.keys(c.bgColor),Ze=[...xe,...Se];function Oe(){let t=new Map;for(let[e,r]of Object.entries(c)){for(let[o,i]of Object.entries(r))c[o]={open:`\x1B[${i[0]}m`,close:`\x1B[${i[1]}m`},r[o]=c[o],t.set(i[0],i[1]);Object.defineProperty(c,e,{value:r,enumerable:!1})}return Object.defineProperty(c,"codes",{value:t,enumerable:!1}),c.color.close="\x1B[39m",c.bgColor.close="\x1B[49m",c.color.ansi=X(),c.color.ansi256=Z(),c.color.ansi16m=ee(),c.bgColor.ansi=X(10),c.bgColor.ansi256=Z(10),c.bgColor.ansi16m=ee(10),Object.defineProperties(c,{rgbToAnsi256:{value(e,r,o){return e===r&&r===o?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(r/255*5)+Math.round(o/255*5)},enumerable:!1},hexToRgb:{value(e){let r=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!r)return[0,0,0];let[o]=r;o.length===3&&(o=[...o].map(n=>n+n).join(""));let i=Number.parseInt(o,16);return[i>>16&255,i>>8&255,i&255]},enumerable:!1},hexToAnsi256:{value:e=>c.rgbToAnsi256(...c.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let r,o,i;if(e>=232)r=((e-232)*10+8)/255,o=r,i=r;else{e-=16;let R=e%36;r=Math.floor(e/36)/5,o=Math.floor(R/6)/5,i=R%6/5}let n=Math.max(r,o,i)*2;if(n===0)return 30;let l=30+(Math.round(i)<<2|Math.round(o)<<1|Math.round(r));return n===2&&(l+=60),l},enumerable:!1},rgbToAnsi:{value:(e,r,o)=>c.ansi256ToAnsi(c.rgbToAnsi256(e,r,o)),enumerable:!1},hexToAnsi:{value:e=>c.ansi256ToAnsi(c.hexToAnsi256(e)),enumerable:!1}}),c}var Re=Oe(),h=Re;import J from"node:process";import Ee from"node:os";import te from"node:tty";function m(t,e=globalThis.Deno?globalThis.Deno.args:J.argv){let r=t.startsWith("-")?"":t.length===1?"-":"--",o=e.indexOf(r+t),i=e.indexOf("--");return o!==-1&&(i===-1||o<i)}var{env:d}=J,V;m("no-color")||m("no-colors")||m("color=false")||m("color=never")?V=0:(m("color")||m("colors")||m("color=true")||m("color=always"))&&(V=1);function Te(){if("FORCE_COLOR"in d)return d.FORCE_COLOR==="true"?1:d.FORCE_COLOR==="false"?0:d.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(d.FORCE_COLOR,10),3)}function Fe(t){return t===0?!1:{level:t,hasBasic:!0,has256:t>=2,has16m:t>=3}}function Ce(t,{streamIsTTY:e,sniffFlags:r=!0}={}){let o=Te();o!==void 0&&(V=o);let i=r?V:o;if(i===0)return 0;if(r){if(m("color=16m")||m("color=full")||m("color=truecolor"))return 3;if(m("color=256"))return 2}if("TF_BUILD"in d&&"AGENT_NAME"in d)return 1;if(t&&!e&&i===void 0)return 0;let n=i||0;if(d.TERM==="dumb")return n;if(J.platform==="win32"){let l=Ee.release().split(".");return Number(l[0])>=10&&Number(l[2])>=10586?Number(l[2])>=14931?3:2:1}if("CI"in d)return"GITHUB_ACTIONS"in d||"GITEA_ACTIONS"in d?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(l=>l in d)||d.CI_NAME==="codeship"?1:n;if("TEAMCITY_VERSION"in d)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(d.TEAMCITY_VERSION)?1:0;if(d.COLORTERM==="truecolor"||d.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in d){let l=Number.parseInt((d.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(d.TERM_PROGRAM){case"iTerm.app":return l>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(d.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(d.TERM)||"COLORTERM"in d?1:n}function re(t,e={}){let r=Ce(t,{streamIsTTY:t&&t.isTTY,...e});return Fe(r)}var Ne={stdout:re({isTTY:te.isatty(1)}),stderr:re({isTTY:te.isatty(2)})},oe=Ne;function ie(t,e,r){let o=t.indexOf(e);if(o===-1)return t;let i=e.length,n=0,l="";do l+=t.slice(n,o)+e+r,n=o+i,o=t.indexOf(e,n);while(o!==-1);return l+=t.slice(n),l}function ne(t,e,r,o){let i=0,n="";do{let l=t[o-1]==="\r";n+=t.slice(i,l?o-1:o)+e+(l?`\r
|
|
2
|
+
`:`
|
|
3
|
+
`)+r,i=o+1,o=t.indexOf(`
|
|
4
|
+
`,i)}while(o!==-1);return n+=t.slice(i),n}var{stdout:se,stderr:ae}=oe,K=Symbol("GENERATOR"),x=Symbol("STYLER"),I=Symbol("IS_EMPTY"),le=["ansi","ansi","ansi256","ansi16m"],S=Object.create(null),Ae=(t,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let r=se?se.level:0;t.level=e.level===void 0?r:e.level};var Ie=t=>{let e=(...r)=>r.join(" ");return Ae(e,t),Object.setPrototypeOf(e,$.prototype),e};function $(t){return Ie(t)}Object.setPrototypeOf($.prototype,Function.prototype);for(let[t,e]of Object.entries(h))S[t]={get(){let r=D(this,z(e.open,e.close,this[x]),this[I]);return Object.defineProperty(this,t,{value:r}),r}};S.visible={get(){let t=D(this,this[x],!0);return Object.defineProperty(this,"visible",{value:t}),t}};var W=(t,e,r,...o)=>t==="rgb"?e==="ansi16m"?h[r].ansi16m(...o):e==="ansi256"?h[r].ansi256(h.rgbToAnsi256(...o)):h[r].ansi(h.rgbToAnsi(...o)):t==="hex"?W("rgb",e,r,...h.hexToRgb(...o)):h[r][t](...o),$e=["rgb","hex","ansi256"];for(let t of $e){S[t]={get(){let{level:r}=this;return function(...o){let i=z(W(t,le[r],"color",...o),h.color.close,this[x]);return D(this,i,this[I])}}};let e="bg"+t[0].toUpperCase()+t.slice(1);S[e]={get(){let{level:r}=this;return function(...o){let i=z(W(t,le[r],"bgColor",...o),h.bgColor.close,this[x]);return D(this,i,this[I])}}}}var Me=Object.defineProperties(()=>{},{...S,level:{enumerable:!0,get(){return this[K].level},set(t){this[K].level=t}}}),z=(t,e,r)=>{let o,i;return r===void 0?(o=t,i=e):(o=r.openAll+t,i=e+r.closeAll),{open:t,close:e,openAll:o,closeAll:i,parent:r}},D=(t,e,r)=>{let o=(...i)=>Pe(o,i.length===1?""+i[0]:i.join(" "));return Object.setPrototypeOf(o,Me),o[K]=t,o[x]=e,o[I]=r,o},Pe=(t,e)=>{if(t.level<=0||!e)return t[I]?"":e;let r=t[x];if(r===void 0)return e;let{openAll:o,closeAll:i}=r;if(e.includes("\x1B"))for(;r!==void 0;)e=ie(e,r.close,r.open),r=r.parent;let n=e.indexOf(`
|
|
5
|
+
`);return n!==-1&&(e=ne(e,i,o,n)),o+e+i};Object.defineProperties($.prototype,S);var Be=$(),ct=$({level:ae?ae.level:0});var y=Be;import{oraPromise as Ve}from"ora";var de,ce=((de=process==null?void 0:process.versions)==null?void 0:de.node)!==void 0,De={verbose:!1,log(...t){if(!this.verbose)return;let e=y.gray("[Log]");ce?console.warn(e,...t):console.log(e,...t)},logPrefixed(t,...e){this.info(y.blue(`[${t}]`),...e)},info(...t){if(!this.verbose)return;let e=y.green("[Info]");ce?console.warn(e,...t):console.info(e,...t)},infoPrefixed(t,...e){this.info(y.blue(`[${t}]`),...e)},async infoSpin(t,e){return Ve(t,{prefixText:y.green("[Info]"),stream:process.stderr,text:e})},warn(...t){console.warn(y.yellow("[Warning]"),...t)},warnPrefixed(t,...e){this.warn(y.blue(`[${t}]`),...e)},error(...t){console.error(y.red("[Error]"),...t)},errorPrefixed(t,...e){this.error(y.blue(`[${t}]`),...e)}},f=De;import{execa as ue}from"execa";import k from"ffmpeg-static";import pe from"node:fs/promises";import q from"node:path";import ke from"node:os";var fe=ke.homedir();function O(t){if(typeof t!="string")throw new TypeError(`Expected a string, got ${typeof t}`);return fe?t.replace(/^~(?=$|\/|\\)/,fe):t}async function Q(t){let e=O(t);return(await pe.readdir(e)).filter(i=>{let n=q.extname(i);return[".mp4",".mov",".avi",".mkv"].includes(n)}).map(i=>q.join(e,i))}async function me(t){if(k===null)throw new Error("ffmpeg-static failed to locate ffmpeg binary");try{let{stderr:e,stdout:r}=await ue(k,["-i",t,"-f","ffmetadata","-"]);return r.includes("creation_time")||e.includes("creation_time")}catch(e){throw new Error(`Failed to check metadata for: ${t}:
|
|
6
|
+
${String(e)}`)}}async function he(t){if(k===null)throw new Error("ffmpeg-static failed to locate ffmpeg binary");try{let e=q.extname(t).slice(1),r=`${t.slice(0,Math.max(0,t.lastIndexOf(".")))}.temp.${e}`;await ue(k,["-i",t,"-map_metadata","-1","-c:v","copy","-c:a","copy",r]),await pe.rename(r,t)}catch(e){throw new Error(`Failed to strip metadata from: ${t}:
|
|
7
|
+
${String(e)}`)}}async function ye(t,e={}){let{dryRun:r=!1,verbose:o=!1}=e,i=f.verbose;f.verbose=o;let n=[];for(let l of t)await me(l)&&n.push(l);if(!r){f.info(`Found ${n.length} videos with metadata to strip`);for(let l of n)console.log(`Stripping metadata from: ${l}`),await he(l)}return f.verbose=i,n}import{BunnyCdnStream as ze}from"bunnycdn-stream";import{hash as qe}from"hasha";import{readFile as Ke}from"node:fs/promises";import{rename as _e,writeFile as Ue}from"node:fs/promises";import{basename as je,dirname as Le,join as Ge}from"node:path";import{fileURLToPath as He}from"node:url";function Ye(t){let e=t instanceof URL?He(t):t.toString();return Ge(Le(e),`.${je(e)}.tmp`)}async function Je(t,e,r){for(let o=0;o<e;o++)try{return await t()}catch(i){if(o<e-1)await new Promise(n=>setTimeout(n,r));else throw i}}var _=class{#e;#t;#r=!1;#i=null;#n=null;#s=null;#o=null;#a(e){return this.#o=e,this.#s||=new Promise((r,o)=>{this.#n=[r,o]}),new Promise((r,o)=>{var i;(i=this.#s)==null||i.then(r).catch(o)})}async#l(e){var r,o;this.#r=!0;try{await Ue(this.#t,e,"utf-8"),await Je(async()=>{await _e(this.#t,this.#e)},10,100),(r=this.#i)==null||r[0]()}catch(i){throw i instanceof Error&&((o=this.#i)==null||o[1](i)),i}finally{if(this.#r=!1,this.#i=this.#n,this.#n=this.#s=null,this.#o!==null){let i=this.#o;this.#o=null,await this.write(i)}}}constructor(e){this.#e=e,this.#t=Ye(e)}async write(e){return this.#r?this.#a(e):this.#l(e)}};var U=class{#e;#t;constructor(e){this.#e=e,this.#t=new _(e)}async read(){let e;try{e=await Ke(this.#e,"utf-8")}catch(r){if(r.code==="ENOENT")return null;throw r}return e}write(e){return this.#t.write(e)}};var j=class{#e;#t;#r;constructor(e,{parse:r,stringify:o}){this.#e=new U(e),this.#t=r,this.#r=o}async read(){let e=await this.#e.read();return e===null?null:this.#t(e)}write(e){return this.#e.write(this.#r(e))}};var L=class extends j{constructor(e){super(e,{parse:JSON.parse,stringify:r=>JSON.stringify(r,null,2)})}};var G=class{#e=null;read(){return Promise.resolve(this.#e)}write(e){return this.#e=e,Promise.resolve()}};function We(t,e){if(t===void 0)throw new Error("lowdb: missing adapter");if(e===void 0)throw new Error("lowdb: missing default data")}var H=class{adapter;data;constructor(e,r){We(e,r),this.adapter=e,this.data=r}async read(){let e=await this.adapter.read();e&&(this.data=e)}async write(){this.data&&await this.adapter.write(this.data)}async update(e){e(this.data),await this.write()}};async function ge(t,e){let r=process.env.NODE_ENV==="test"?new G:new L(t),o=new H(r,e);return await o.read(),o}import{createReadStream as we}from"node:fs";import M from"node:path";async function Qe(t,e){let r=O(t),{credentials:o,dryRun:i=!1,service:n,stripMetadata:l=!0,verbose:R=!1}=e,be=f.verbose;f.verbose=R;let g=[],E=await Q(r);f.info(`Found ${E.length} video files in directory "${t}"`);let P=l?await ye(E,{dryRun:i,verbose:R}):[],u=await ge(M.join(r,".vidup-state.json"),{syncState:[]});u.data.syncState=u.data.syncState.filter(s=>E.includes(M.join(r,s.filename)));for(let s of E){let a=M.basename(s),p=await qe(s,{algorithm:"sha1"}),w=u.data.syncState.find(b=>b.filename===a);w?w.localHash=p:u.data.syncState.push({filename:a,localHash:p,remoteHash:{}})}if(i||await u.write(),n!=="bunny")throw new Error(`Streaming service not yet implemented: ${n}`);let T=new ze({apiKey:o.key,videoLibrary:o.library}),F=await T.listAllVideos();f.info(`Found ${F.length} video files on ${n} remote streaming service`);let ve=F.filter(s=>{let a=u.data.syncState.find(p=>p.filename===s.title);return a!==void 0&&a.localHash===a.remoteHash[n]});for(let s of ve)g.push({action:"Unchanged",localFile:s.title,remoteId:s.guid,stripMetadata:P.includes(s.title)});let C=u.data.syncState.filter(s=>!F.some(a=>a.title===s.filename));for(let s of C)g.push({action:"Created",localFile:s.filename,remoteId:"Not yet uploaded (Dry run)",stripMetadata:P.includes(s.filename)});let N=F.filter(s=>{let a=u.data.syncState.find(p=>p.filename===s.title);return a!==void 0&&a.localHash!==a.remoteHash[n]});for(let s of N)g.push({action:"Updated",localFile:s.title,remoteId:"Not yet uploaded (Dry run)",stripMetadata:P.includes(s.title)});let B=F.filter(s=>!u.data.syncState.some(a=>a.filename===s.title));for(let s of B)g.push({action:"Deleted",localFile:s.title,remoteId:s.guid,stripMetadata:P.includes(s.title)});if(!i){u.data.lastRun=new Date,await u.write(),f.info("Synchronizing...");for(let[s,a]of B.entries()){if(s===0&&f.info(`Deleting ${B.length} remote videos...`),!(await f.infoSpin(T.deleteVideo(a.guid),`Deleting remote video ${s+1}/${B.length}: ${a.title}`)).success)throw new Error(`Failed to delete remote video: ${a.title}`);u.data.lastUpdate=new Date,await u.write()}for(let[s,a]of C.entries()){s===0&&f.info(`Uploading ${C.length} new local videos...`);let p=we(M.join(r,a.filename)),w=await f.infoSpin(T.createAndUploadVideo(p,{title:a.filename}),`Uploading new video ${s+1}/${C.length}: ${a.filename}`);f.info(`Remote video ${s+1}/${C.length} created with GUID: ${w.guid}`);let b=u.data.syncState.find(v=>v.filename===a.filename);if(b===void 0)throw new Error(`Failed to find state entry for: ${a.filename}`);b.remoteHash[n]=a.localHash,u.data.lastUpdate=new Date,await u.write();let A=g.find(v=>v.localFile===a.filename);if(A===void 0)throw new Error(`Failed to find report entry for: ${a.filename}`);A.remoteId=w.guid}for(let[s,a]of N.entries()){s===0&&(f.info(`Updating ${N.length} remote videos...`),f.warn("Bunny does not currently support updating videos in-place, so vidup will delete and re-uploading instead... this will change the video's GUID!"));let p=u.data.syncState.find(Y=>Y.filename===a.title);if(p===void 0)throw new Error(`Failed to find state entry for: ${a.title}`);if(!(await T.deleteVideo(a.guid)).success)throw new Error(`Failed to delete remote video before updating: ${a.title}`);let b=we(M.join(r,p.filename)),A=await f.infoSpin(T.createAndUploadVideo(b,{title:p.filename}),`Updating remote video ${s+1}/${N.length}: ${a.title}`);f.info(`Updated remote video ${s+1}/${N.length} created with GUID: ${A.guid}`),p.remoteHash[n]=p.localHash,u.data.lastUpdate=new Date,await u.write();let v=g.find(Y=>Y.localFile===p.filename);if(v===void 0)throw new Error(`Failed to find report entry for: ${p.filename}`);v.remoteId=A.guid}f.info(`All ${E.length} videos are now in sync!`)}return f.verbose=be,g}export{f as log,Qe as syncVideoInDirectory};
|
package/dist/strip.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type StripOptions = {
|
|
2
|
+
dryRun?: boolean;
|
|
3
|
+
verbose?: boolean;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Strip metadata from video files in a directory
|
|
7
|
+
* @returns List of file paths with metadata that were stripped
|
|
8
|
+
*/
|
|
9
|
+
export declare function stripVideoMetadataInDirectory(directory: string, options?: StripOptions): Promise<string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Strip metadata from multiple video files
|
|
12
|
+
* @returns List of file paths with metadata that were stripped
|
|
13
|
+
*/
|
|
14
|
+
export declare function stripVideoMetadataInFiles(files: string[], options?: StripOptions): Promise<string[]>;
|
package/dist/sync.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type Service = 'bunny' | 'cloudflare' | 'mux';
|
|
2
|
+
export type SyncReport = Array<{
|
|
3
|
+
action: 'Created' | 'Deleted' | 'Unchanged' | 'Updated';
|
|
4
|
+
localFile?: string;
|
|
5
|
+
remoteId: string;
|
|
6
|
+
stripMetadata: boolean;
|
|
7
|
+
}>;
|
|
8
|
+
export type SyncOptions = {
|
|
9
|
+
credentials: {
|
|
10
|
+
key: string;
|
|
11
|
+
library: string;
|
|
12
|
+
};
|
|
13
|
+
dryRun?: boolean;
|
|
14
|
+
service: Service;
|
|
15
|
+
stripMetadata?: boolean;
|
|
16
|
+
verbose?: boolean;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Synchronize a remote streaming service to mirror the contents of a local directory
|
|
20
|
+
* @returns Array of sync report entries describing what was changed (or will change if a dry run)
|
|
21
|
+
*/
|
|
22
|
+
export declare function syncVideoInDirectory(directory: string, options: SyncOptions): Promise<SyncReport>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const log: {
|
|
2
|
+
verbose: boolean;
|
|
3
|
+
log(...data: unknown[]): void;
|
|
4
|
+
logPrefixed(prefix: string, ...data: unknown[]): void;
|
|
5
|
+
info(...data: unknown[]): void;
|
|
6
|
+
infoPrefixed(prefix: string, ...data: unknown[]): void;
|
|
7
|
+
infoSpin<T>(promise: Promise<T>, message: string): Promise<T>;
|
|
8
|
+
warn(...data: unknown[]): void;
|
|
9
|
+
warnPrefixed(prefix: string, ...data: unknown[]): void;
|
|
10
|
+
error(...data: unknown[]): void;
|
|
11
|
+
errorPrefixed(prefix: string, ...data: unknown[]): void;
|
|
12
|
+
};
|
|
13
|
+
export default log;
|
package/license.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Eric Mika
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vidup",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Synchronize a local directory of video files to remote streaming services.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/kitschpatrol/vidup.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/kitschpatrol/vidup",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/kitschpatrol/vidup/issues",
|
|
13
|
+
"email": "eric@ericmika.com"
|
|
14
|
+
},
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Eric Mika",
|
|
17
|
+
"email": "eric@ericmika.com",
|
|
18
|
+
"url": "https://ericmika.com"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"packageManager": "pnpm@8.15.6+sha256.01c01eeb990e379b31ef19c03e9d06a14afa5250b82e81303f88721c99ff2e6f",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18.0.0",
|
|
24
|
+
"pnpm": ">=8.0.0"
|
|
25
|
+
},
|
|
26
|
+
"bin": {
|
|
27
|
+
"vidup": "bin/cli.js"
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/lib/index.js",
|
|
30
|
+
"module": "./dist/lib/index.js",
|
|
31
|
+
"types": "./dist/lib/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"bin/*",
|
|
34
|
+
"dist/*"
|
|
35
|
+
],
|
|
36
|
+
"keywords": [
|
|
37
|
+
"bunnycdn-stream",
|
|
38
|
+
"bunnycdn",
|
|
39
|
+
"cli",
|
|
40
|
+
"npm-package",
|
|
41
|
+
"sync",
|
|
42
|
+
"upload",
|
|
43
|
+
"video"
|
|
44
|
+
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"bunnycdn-stream": "^2.2.3",
|
|
47
|
+
"execa": "^8.0.1",
|
|
48
|
+
"ffmpeg-static": "^5.2.0",
|
|
49
|
+
"fs-extra": "^11.2.0",
|
|
50
|
+
"hasha": "^6.0.0",
|
|
51
|
+
"ora": "^8.0.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@kitschpatrol/shared-config": "^4.6.1",
|
|
55
|
+
"@types/fs-extra": "^11.0.4",
|
|
56
|
+
"@types/node": "^20.12.5",
|
|
57
|
+
"@types/yargs": "^17.0.32",
|
|
58
|
+
"bumpp": "^9.4.0",
|
|
59
|
+
"chalk": "^5.3.0",
|
|
60
|
+
"lowdb": "^7.0.1",
|
|
61
|
+
"pretty-ms": "^9.0.0",
|
|
62
|
+
"tsup": "^8.0.2",
|
|
63
|
+
"typescript": "^5.4.4",
|
|
64
|
+
"untildify": "^5.0.0",
|
|
65
|
+
"yargs": "^17.7.2"
|
|
66
|
+
},
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public"
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "tsup && tsc -p tsconfig.build.json",
|
|
72
|
+
"clean": "git clean -fdX",
|
|
73
|
+
"fix": "pnpm shared-config --fix",
|
|
74
|
+
"lint": "pnpm shared-config --lint",
|
|
75
|
+
"release": "pnpm bumpp -r --commit 'Release: %s' --tag 'v%s' && pnpm -r publish --otp $(op read 'op://Personal/Npmjs/one-time password?attribute=otp')",
|
|
76
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
77
|
+
}
|
|
78
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
<!--+ Warning: Content inside HTML comment blocks was generated by mdat and may be overwritten. +-->
|
|
2
|
+
|
|
3
|
+
<!-- title -->
|
|
4
|
+
|
|
5
|
+
# vidup
|
|
6
|
+
|
|
7
|
+
<!-- /title -->
|
|
8
|
+
|
|
9
|
+
<!-- badges -->
|
|
10
|
+
|
|
11
|
+
[](https://npmjs.com/package/vidup)
|
|
12
|
+
[](https://opensource.org/licenses/MIT)
|
|
13
|
+
|
|
14
|
+
<!-- /badges -->
|
|
15
|
+
|
|
16
|
+
<!-- short-description -->
|
|
17
|
+
|
|
18
|
+
**Synchronize a local directory of video files to remote streaming services.**
|
|
19
|
+
|
|
20
|
+
<!-- /short-description -->
|
|
21
|
+
|
|
22
|
+
> \[!WARNING]\
|
|
23
|
+
> This tool was built in haste and has been tested only against a relatively narrow use-case. If you use it, please review the docs, invoke with care, and make sure you have local copies of your remote videos and metadata.
|
|
24
|
+
|
|
25
|
+
## Overview
|
|
26
|
+
|
|
27
|
+
Vidup is a CLI tool and Node library to automate one-way synchronization of local video files to remote video streaming CDN services.
|
|
28
|
+
|
|
29
|
+
It checks for differences between your local and remote videos, and automatically creates, updates, or deletes videos on the remote service so that it exactly mirrors the contents of a local directory.
|
|
30
|
+
|
|
31
|
+
Currently, only Bunny.net's [Bunny Stream](https://bunny.net/stream/) service is supported as a sync target. Adding support additional platforms like [Mux](https://www.mux.com) and [Cloudflare Stream](https://www.cloudflare.com/products/cloudflare-stream/) wouldn't be too tricky.
|
|
32
|
+
|
|
33
|
+
## Getting started
|
|
34
|
+
|
|
35
|
+
### Dependencies
|
|
36
|
+
|
|
37
|
+
The vidup CLI tool requires Node 18+. The exported APIs for are ESM-only and share the Node 18+ requirement. Vidup is implemented in TypeScript and bundles type definitions.
|
|
38
|
+
|
|
39
|
+
A [Bunny Stream](https://bunny.net/stream/) account, API key, and library ID are required.
|
|
40
|
+
|
|
41
|
+
### Installation
|
|
42
|
+
|
|
43
|
+
Invoke directly:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npx vidup
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or, install locally to access the CLI commands in a single project or to import the provided APIs:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
npm install vidup
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or, install globally for access across your system:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
npm install --global vidup
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
Vidup treats local videos' file names as keys, and will look for a file with the same name / title on the remote streaming service.
|
|
64
|
+
|
|
65
|
+
Any video files present in the local folder that aren't matched to a video on the remote service will be uploaded.
|
|
66
|
+
|
|
67
|
+
If you change the name of a local video file, the remote video with the previous name will be deleted, and a new remote video (with a ne GUID) will be created.
|
|
68
|
+
|
|
69
|
+
Vidup tracks the content hash of each local video. If you replace a local video file with another of the same name, the change in content will be detected and the remote video will be updated.
|
|
70
|
+
(_Note that this is currently equivalent to deleting / creating a new remote video since Bunny.net doesn't support in-place video updates. The GUID will change, so you'll need to update any embeds accordingly._)
|
|
71
|
+
|
|
72
|
+
Any videos present on the remote service that aren't matched to a video file in the local folder **will be deleted from the remote service**.
|
|
73
|
+
|
|
74
|
+
### CLI
|
|
75
|
+
|
|
76
|
+
<!-- cli-help -->
|
|
77
|
+
|
|
78
|
+
#### Command: `vidup`
|
|
79
|
+
|
|
80
|
+
Run a vidup command.
|
|
81
|
+
|
|
82
|
+
This section lists top-level commands for `vidup`.
|
|
83
|
+
|
|
84
|
+
If no command is provided, `vidup sync` is run by default.
|
|
85
|
+
|
|
86
|
+
Usage:
|
|
87
|
+
|
|
88
|
+
```txt
|
|
89
|
+
vidup [command]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
| Command | Argument | Description |
|
|
93
|
+
| ------- | ------------------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
94
|
+
| `sync` | `<directory>` `[options]` | Synchronize a remote video streaming service to mirror the contents of a local directory. _(Default command.)_ |
|
|
95
|
+
|
|
96
|
+
_See the sections below for more information on each subcommand._
|
|
97
|
+
|
|
98
|
+
#### Subcommand: `vidup sync`
|
|
99
|
+
|
|
100
|
+
Synchronize a remote video streaming service to mirror the contents of a local directory.
|
|
101
|
+
|
|
102
|
+
Usage:
|
|
103
|
+
|
|
104
|
+
```txt
|
|
105
|
+
vidup sync <directory> [options]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
| Positional Argument | Description | Type |
|
|
109
|
+
| ------------------- | --------------------------------------------------------------------- | -------- |
|
|
110
|
+
| `directory` | The path to the local directory of video files to sync. _(Required.)_ | `string` |
|
|
111
|
+
|
|
112
|
+
| Option | Alias | Description | Type | Default |
|
|
113
|
+
| ------------------ | ----- | ------------------------------------------------------------------------------------------------------------------------------- | --------- | ------- |
|
|
114
|
+
| `--service` | `-s` | Streaming service to sync to. Only the Bunny.net streaming CDN is supported at this time. | `string` | |
|
|
115
|
+
| `--key` | | Streaming service API access key | `string` | |
|
|
116
|
+
| `--library` | | Streaming service library ID | `string` | |
|
|
117
|
+
| `--strip-metadata` | | Remove all metadata from the video files before uploading them to the streaming service. | `boolean` | `true` |
|
|
118
|
+
| `--dry-run` | `-d` | Perform a dry run without making any changes. Useful for testing and debugging. | `boolean` | `false` |
|
|
119
|
+
| `--json` | | Output the sync report as JSON | `boolean` | `false` |
|
|
120
|
+
| `--verbose` | | Enable verbose logging. All verbose logs and prefixed with their log level and are printed to `stderr` for ease of redirection. | `boolean` | `false` |
|
|
121
|
+
| `--help` | `-h` | Show help | `boolean` | |
|
|
122
|
+
| `--version` | `-v` | Show version number | `boolean` | |
|
|
123
|
+
|
|
124
|
+
<!-- /cli-help -->
|
|
125
|
+
|
|
126
|
+
#### Examples
|
|
127
|
+
|
|
128
|
+
**Synchronize video files in the current folder to Bunny Stream:**
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
vidup . --service bunny --key <BUNNY_API_KEY> --library <BUNNY_LIBRARY_ID>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Large uploads can take some time. Upon completion, a report summarizing the actions taken is printed to stdout:
|
|
135
|
+
|
|
136
|
+
```sh
|
|
137
|
+
Unchanged: an-already-uploaded-video.mov
|
|
138
|
+
Created: a-new-video.mov
|
|
139
|
+
Updated: a-changed-video.mp4
|
|
140
|
+
Deleted: a-remote-only-video.mp4
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Perform a non-executive dry-run and get the snynchronization plan report as JSON:**
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
vidup . --service bunny --key --json < BUNNY_API_KEY > --library < BUNNY_LIBRARY_ID > --dry-run
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The JSON version of the output provides some extra info.
|
|
150
|
+
|
|
151
|
+
### Library
|
|
152
|
+
|
|
153
|
+
#### API
|
|
154
|
+
|
|
155
|
+
Vidup's functionality is also provided in module form for use in TypeScript or JavaScript Node projects.
|
|
156
|
+
|
|
157
|
+
The library exports a single async function, `syncVideoInDirectory`, which takes an options argument mirroring the arguments available via the command line. The same default values apply:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
async function syncVideoInDirectory(
|
|
161
|
+
directory: string,
|
|
162
|
+
options: {
|
|
163
|
+
service: Service
|
|
164
|
+
credentials: {
|
|
165
|
+
key: string
|
|
166
|
+
library: string
|
|
167
|
+
}
|
|
168
|
+
dryRun?: boolean // defaults to false
|
|
169
|
+
stripMetadata?: boolean // defaults to true
|
|
170
|
+
verbose?: boolean // defaults to false
|
|
171
|
+
},
|
|
172
|
+
): Promise<SyncReport>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### Examples
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { syncVideoInDirectory } from 'vidup'
|
|
179
|
+
|
|
180
|
+
const syncReport = await syncVideoInDirectory(process.cwd(), {
|
|
181
|
+
service: 'bunny',
|
|
182
|
+
credentials: {
|
|
183
|
+
key: BUNNY_API_KEY,
|
|
184
|
+
library: BUNNY_LIBRARY_ID,
|
|
185
|
+
},
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
console.log(JSON.stringify(syncReport, undefined, 2))
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Background
|
|
192
|
+
|
|
193
|
+
### Motivation
|
|
194
|
+
|
|
195
|
+
Video streaming providers have slow and clunky web UIs. I'd rather not maintain the remote collection by hand. The web these days makes Finder.app feel like a CRUD tour-de-force.
|
|
196
|
+
|
|
197
|
+
## The future
|
|
198
|
+
|
|
199
|
+
- [ ] Tests
|
|
200
|
+
- [ ] Add [Cosmiconfig](https://github.com/cosmiconfig/cosmiconfig)
|
|
201
|
+
- [ ] Synchronize thumbnails and other metadata
|
|
202
|
+
- [ ] Remote collection / folder support
|
|
203
|
+
- [ ] Mux support
|
|
204
|
+
- [ ] Cloudflare Stream support
|
|
205
|
+
- [ ] Support for additional streaming services
|
|
206
|
+
|
|
207
|
+
## Maintainers
|
|
208
|
+
|
|
209
|
+
[@kitschpatrol](https://github.com/kitschpatrol)
|
|
210
|
+
|
|
211
|
+
## Acknowledgements
|
|
212
|
+
|
|
213
|
+
Thanks to [@dan-online](https://github.com/dan-online) for his super-helpful [bunnycdn-stream](https://github.com/dan-online/bunnycdn-stream) library.
|
|
214
|
+
|
|
215
|
+
<!-- footer -->
|
|
216
|
+
|
|
217
|
+
## Contributing
|
|
218
|
+
|
|
219
|
+
[Issues](https://github.com/kitschpatrol/vidup/issues) and pull requests are welcome.
|
|
220
|
+
|
|
221
|
+
## License
|
|
222
|
+
|
|
223
|
+
[MIT](license.txt) © Eric Mika
|
|
224
|
+
|
|
225
|
+
<!-- /footer -->
|