gitpick 4.15.0-canary.1 → 4.15.0-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +20 -20
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import e from"node:fs";import t from"node:path";import{parseArgs as n,stripVTControlCharacters as r}from"node:util";import i from"node:os";import a from"node:process";import{fileURLToPath as o}from"node:url";import{pipeline as s}from"node:stream/promises";import{on as c,once as l}from"node:events";import{spawn as u}from"node:child_process";import{stat as d}from"node:fs/promises";import f from"
|
|
3
|
-
for await (const line of spawn(...)) { ... }`);t.isIterating=!0;try{let{[n]:t}=await e.nodeChildProcess;if(!t)return;let r=``;for await(let e of t.iterator({destroyOnReturn:!1})){let t=`${r}${e}`.split(/\r?\n/);r=t.pop(),yield*t}r&&(yield r)}finally{await e}},re=async function*(...e){try{let t=[];for(;e.length>0;){t=e.map((e,n)=>t[n]??ie(e));let[{value:n,done:r},i]=await Promise.race(t.map((e,t)=>Promise.all([e,t]))),[a]=e.splice(i,1);t.splice(i,1),r||(e.push(a),yield n)}}finally{await Promise.all(e.map(e=>e.return()))}},ie=async e=>{try{return await e.next()}catch(t){await e.throw(t)}},ae=({stdin:e,stdout:n,stderr:r,stdio:i=[e,n,r],env:s,preferLocal:c,cwd:l=`.`,...u})=>{let d=l instanceof URL?o(l):t.resolve(l),f=s?{...a.env,...s}:void 0,p=i[0]?.string;return{...u,input:p,stdio:p===void 0?i:[`pipe`,...i.slice(1)],env:c?oe(f??a.env,d):f,cwd:d}},oe=({Path:e=``,PATH:n=e,...r},i)=>{let a=n.split(t.delimiter),o=
|
|
4
|
-
`?e.slice(0,e.at(-2)===`\r`?-2:-1):e,
|
|
2
|
+
import e from"node:fs";import t from"node:path";import{parseArgs as n,stripVTControlCharacters as r}from"node:util";import i from"node:os";import a from"node:process";import{fileURLToPath as o}from"node:url";import{pipeline as s}from"node:stream/promises";import{on as c,once as l}from"node:events";import{spawn as u}from"node:child_process";import{stat as d}from"node:fs/promises";import f from"node:tty";import p from"process";var m=Object.defineProperty,ee=(e,t)=>{let n={};for(var r in e)m(n,r,{get:e[r],enumerable:!0});return t||m(n,Symbol.toStringTag,{value:`Module`}),n};const h=async(n,r)=>{let i=await e.promises.readdir(n,{withFileTypes:!0});await e.promises.mkdir(r,{recursive:!0});for(let a of i){if(a.name===`.git`)continue;let i=t.join(n,a.name),o=t.join(r,a.name);if(a.isDirectory())await h(i,o);else if(a.isSymbolicLink()){let t=await e.promises.readlink(i);await e.promises.symlink(t,o)}else await e.promises.copyFile(i,o)}},te=e=>({start:a.hrtime.bigint(),command:e.map(e=>ne(r(e))).join(` `),state:{stdout:``,stderr:``,output:``}}),ne=e=>/[^\w./-]/.test(e)?`'${e.replaceAll(`'`,`'\\''`)}'`:e,g=async function*(e,{state:t},n){if(t.isIterating===!1)throw Error(`The subprocess must be iterated right away, for example:
|
|
3
|
+
for await (const line of spawn(...)) { ... }`);t.isIterating=!0;try{let{[n]:t}=await e.nodeChildProcess;if(!t)return;let r=``;for await(let e of t.iterator({destroyOnReturn:!1})){let t=`${r}${e}`.split(/\r?\n/);r=t.pop(),yield*t}r&&(yield r)}finally{await e}},re=async function*(...e){try{let t=[];for(;e.length>0;){t=e.map((e,n)=>t[n]??ie(e));let[{value:n,done:r},i]=await Promise.race(t.map((e,t)=>Promise.all([e,t]))),[a]=e.splice(i,1);t.splice(i,1),r||(e.push(a),yield n)}}finally{await Promise.all(e.map(e=>e.return()))}},ie=async e=>{try{return await e.next()}catch(t){await e.throw(t)}},ae=({stdin:e,stdout:n,stderr:r,stdio:i=[e,n,r],env:s,preferLocal:c,cwd:l=`.`,...u})=>{let d=l instanceof URL?o(l):t.resolve(l),f=s?{...a.env,...s}:void 0,p=i[0]?.string;return{...u,input:p,stdio:p===void 0?i:[`pipe`,...i.slice(1)],env:c?oe(f??a.env,d):f,cwd:d}},oe=({Path:e=``,PATH:n=e,...r},i)=>{let a=n.split(t.delimiter),o=_([],t.resolve(i)).map(e=>t.join(e,`node_modules/.bin`)).filter(e=>!a.includes(e));return{...r,PATH:[...o,n].filter(Boolean).join(t.delimiter)}},_=(e,n)=>e.at(-1)===n?e:_([...e,n],t.resolve(n,`..`)),se=async e=>{let[[t,n]]=await Promise.all([Promise.allSettled(e),ce(e)]);if(n.reason)throw n.reason.pipedFrom=t.reason??t.value,n.reason;if(t.reason)throw t.reason;return{...n.value,pipedFrom:t.value}},ce=async e=>{try{let[{stdout:t},{stdin:n}]=await Promise.all(e.map(({nodeChildProcess:e})=>e));if(n===null)throw Error(`The "stdin" option must be set on the first "spawn()" call in the pipeline.`);if(t===null)throw Error(`The "stdout" option must be set on the last "spawn()" call in the pipeline.`);s(t,n).catch(()=>{})}catch(t){throw await Promise.allSettled(e.map(({nodeChildProcess:e})=>le(e))),t}},le=async e=>{let{stdin:t}=await e;t.end()},v=async(e,{input:t},n)=>{let r=await e;t!==void 0&&r.stdin.end(t);let i=l(r,`close`);try{return await Promise.race([i,...r.stdio.filter(Boolean).map(e=>ue(e))]),de(n,x(r)),S(n)}catch(e){throw await Promise.allSettled([i]),y(e,r,n)}},ue=async e=>{for await(let[t]of c(e,`error`))if(![`ERR_STREAM_PREMATURE_CLOSE`,`EPIPE`].includes(t?.code))throw t},de=({command:e},{exitCode:t,signalName:n})=>{if(n!==void 0)throw new b(`Command was terminated with ${n}: ${e}`);if(t!==void 0)throw new b(`Command failed with exit code ${t}: ${e}`)},y=(e,t,n)=>Object.assign(fe(e,n),x(t),S(n)),fe=(e,{command:t})=>e instanceof b?e:new b(`Command failed: ${t}`,{cause:e});var b=class extends Error{name=`SubprocessError`};const x=({exitCode:e,signalCode:t})=>({...e<1?{}:{exitCode:e},...t===null?{}:{signalName:t}}),S=({state:{stdout:e,stderr:t,output:n},command:r,start:i})=>({stdout:C(e),stderr:C(t),output:C(n),command:r,durationMs:Number(a.hrtime.bigint()-i)/1e6}),C=e=>e.at(-1)===`
|
|
4
|
+
`?e.slice(0,e.at(-2)===`\r`?-2:-1):e,pe=async(e,t,n)=>await me(e,n)?[T(e),t.map(e=>ve(e)),{...n,shell:!0}]:[e,t,n],me=async(e,{shell:t,cwd:n,env:r=a.env})=>a.platform===`win32`&&!t&&!await he(e,n,r),he=async(e,t,{Path:n=``,PATH:r=n})=>w.some(t=>e.toLowerCase().endsWith(t))||(ge[`${e}\0${t}\0${r}`]??=await _e(e,t,r)),ge={},_e=async(e,n,r)=>{let i=r.split(t.delimiter).filter(Boolean).map(e=>e.replace(/^"(.*)"$/,`$1`));try{await Promise.all(w.flatMap(r=>[n,...i].map(n=>`${t.resolve(n,e)}${r}`)).map(async e=>{try{await d(e)}catch{return}throw 0}))}catch{return!0}return!1},w=[`.exe`,`.com`],ve=e=>T(T(`"${e.replaceAll(/(\\*)"/g,`$1$1\\"`).replace(/(\\*)$/,`$1$1`)}"`)),T=e=>e.replaceAll(/([()\][%!^"`<>&|;, *?])/g,`^$1`),ye=async(e,t,n,r)=>{try{[e,t]=[`node`,`node.exe`].includes(e.toLowerCase())?[a.execPath,[...a.execArgv.filter(e=>!e.startsWith(`--inspect`)),...t]]:[e,t];let i=u(...await pe(e,t,n));return E(i.stdout,r,`stdout`),E(i.stderr,r,`stderr`),i.once(`error`,()=>{}),await l(i,`spawn`),i}catch(e){throw y(e,{},r)}},E=(e,{state:t},n)=>{e&&(e.setEncoding(`utf8`),t.isIterating||(t.isIterating=!1,e.on(`data`,e=>{t[n]+=e,t.output+=e})))};function D(e,t,n,r){let[i=[],a={}]=Array.isArray(t)?[t,n]:[[],t],o=te([e,...i]),s=ae(a),c=ye(e,i,s,o),l=v(c,s,o);Object.assign(l,{nodeChildProcess:c}),l=r?se([r,l]):l;let u=g(l,o,`stdout`),d=g(l,o,`stderr`);return Object.assign(l,{nodeChildProcess:c,stdout:u,stderr:d,[Symbol.asyncIterator]:()=>re(u,d),pipe:(e,t,n)=>D(e,t,n,l)})}var be=ee({bgBlack:()=>Me,bgBlue:()=>Ie,bgBlueBright:()=>Ze,bgCyan:()=>Re,bgCyanBright:()=>$e,bgGray:()=>Be,bgGreen:()=>Pe,bgGreenBright:()=>Ye,bgMagenta:()=>Le,bgMagentaBright:()=>Qe,bgRed:()=>Ne,bgRedBright:()=>Je,bgWhite:()=>ze,bgWhiteBright:()=>et,bgYellow:()=>Fe,bgYellowBright:()=>Xe,black:()=>Oe,blue:()=>F,blueBright:()=>We,bold:()=>k,cyan:()=>I,cyanBright:()=>Ke,dim:()=>A,gray:()=>je,green:()=>N,greenBright:()=>He,hidden:()=>Ee,inverse:()=>Te,italic:()=>j,magenta:()=>ke,magentaBright:()=>Ge,overline:()=>we,red:()=>M,redBright:()=>Ve,reset:()=>Se,strikethrough:()=>De,underline:()=>Ce,white:()=>Ae,whiteBright:()=>qe,yellow:()=>P,yellowBright:()=>Ue});const xe=f?.WriteStream?.prototype?.hasColors?.()??!1,O=(e,t)=>{if(!xe)return e=>e;let n=`\u001B[${e}m`,r=`\u001B[${t}m`;return e=>{let t=e+``,i=t.indexOf(r);if(i===-1)return n+t+r;let a=n,o=0;for(;i!==-1;)a+=t.slice(o,i)+n,o=i+r.length,i=t.indexOf(r,o);return a+=t.slice(o)+r,a}},Se=O(0,0),k=O(1,22),A=O(2,22),j=O(3,23),Ce=O(4,24),we=O(53,55),Te=O(7,27),Ee=O(8,28),De=O(9,29),Oe=O(30,39),M=O(31,39),N=O(32,39),P=O(33,39),F=O(34,39),ke=O(35,39),I=O(36,39),Ae=O(37,39),je=O(90,39),Me=O(40,49),Ne=O(41,49),Pe=O(42,49),Fe=O(43,49),Ie=O(44,49),Le=O(45,49),Re=O(46,49),ze=O(47,49),Be=O(100,49),Ve=O(91,39),He=O(92,39),Ue=O(93,39),We=O(94,39),Ge=O(95,39),Ke=O(96,39),qe=O(97,39),Je=O(101,49),Ye=O(102,49),Xe=O(103,49),Ze=O(104,49),Qe=O(105,49),$e=O(106,49),et=O(107,49),L=a.platform!==`win32`||!!a.env.WT_SESSION,tt=e=>!!(e.isTTY&&a.env.TERM!==`dumb`&&!(`CI`in a.env)),nt=F(L?`ℹ`:`i`),rt=N(L?`✔`:`√`),it=P(L?`⚠`:`‼`),at=M(L?`✖️`:`×`),ot={frames:L?[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`]:[`-`,`\\`,`|`,`/`],interval:80};var st=class{#e;#t;#n=-1;#r;#i;#a;#o;#s=0;#c;#l;#u=0;constructor(e={}){let t=e.spinner??ot;this.#e=t.frames,this.#t=t.interval,this.#i=e.text??``,this.#a=e.stream??a.stderr,this.#o=e.color??`cyan`,this.#l=tt(this.#a),this.#c=this.#y.bind(this)}start(e){return e&&(this.#i=e),this.isSpinning?this:(this.#h(),this.#f(),this.#_(),this.#r=setInterval(()=>{this.#f()},this.#t),this)}stop(e){return this.isSpinning?(clearInterval(this.#r),this.#r=void 0,this.#g(),this.clear(),this.#v(),e&&this.#a.write(`${e}\n`),this):this}#d(e,t){return this.stop(`${e} ${t??this.#i}`)}success(e){return this.#d(rt,e)}error(e){return this.#d(at,e)}warning(e){return this.#d(it,e)}info(e){return this.#d(nt,e)}get isSpinning(){return this.#r!==void 0}get text(){return this.#i}set text(e){this.#i=e??``,this.#f()}get color(){return this.#o}set color(e){this.#o=e,this.#f()}clear(){if(!this.#l)return this;this.#a.cursorTo(0);for(let e=0;e<this.#s;e++)e>0&&this.#a.moveCursor(0,-1),this.#a.clearLine(1);return this.#s=0,this}#f(){let e=Date.now();(this.#n===-1||e-this.#u>=this.#t)&&(this.#n=++this.#n%this.#e.length,this.#u=e);let t=be[this.#o]??I,n=this.#e[this.#n],r=`${t(n)} ${this.#i}`;this.#l||(r+=`
|
|
5
5
|
`),this.clear(),this.#p(r),this.#l&&(this.#s=this.#m(r))}#p(e){this.#a.write(e)}#m(e){let t=this.#a.columns??80,n=r(e).split(`
|
|
6
|
-
`),i=0;for(let e of n)i+=Math.max(1,Math.ceil(e.length/t));return i}#h(){this.#l&&this.#p(`\x1B[?25l`)}#g(){this.#l&&this.#p(`\x1B[?25h`)}#_(){a.once(`SIGINT`,this.#c),a.once(`SIGTERM`,this.#c)}#v(){a.off(`SIGINT`,this.#c),a.off(`SIGTERM`,this.#c)}#y(e){this.isSpinning&&this.stop();let t=e===`SIGINT`?130:e===`SIGTERM`?143:1;a.exit(t)}};function
|
|
6
|
+
`),i=0;for(let e of n)i+=Math.max(1,Math.ceil(e.length/t));return i}#h(){this.#l&&this.#p(`\x1B[?25l`)}#g(){this.#l&&this.#p(`\x1B[?25h`)}#_(){a.once(`SIGINT`,this.#c),a.once(`SIGTERM`,this.#c)}#v(){a.off(`SIGINT`,this.#c),a.off(`SIGTERM`,this.#c)}#y(e){this.isSpinning&&this.stop();let t=e===`SIGINT`?130:e===`SIGTERM`?143:1;a.exit(t)}};function ct(e){return new st(e)}const R=async(n,r,a)=>{process.platform===`win32`&&await D(`git`,[`config`,`--global`,`core.longpaths`,`true`]);let o=`https://${n.token?n.token+`@`:n.token}github.com/${n.owner}/${n.repository}.git`,s=t.resolve(i.tmpdir(),`${n.repository}-${Date.now()}${Math.random().toString(16).slice(2,6)}`),c=ct(),l=performance.now();r.watch||c.start(`Picking ${n.type}${n.type===`repository`?` without .git`:` from repository`}...`);try{await D(`git`,[`clone`,o,s,`--branch`,n.branch,`--depth`,`1`,`--single-branch`,...r.recursive?[`--recursive`]:[]])}catch{await D(`git`,[`clone`,o,s,...r.recursive?[`--recursive`]:[]]),await D(`git`,[`checkout`,n.branch],{cwd:s})}let u=t.resolve(s,n.path);(await e.promises.stat(u)).isDirectory()?(await e.promises.mkdir(a,{recursive:!0}),await h(u,a)):(await e.promises.mkdir(a.split(`/`).slice(0,-1).join(`/`),{recursive:!0}),await e.promises.copyFile(u,a)),r.watch?console.log(`- Synced at `+new Date().toLocaleTimeString()):c.success(`Picked ${n.type}${n.type===`repository`?` without .git`:` from repository`} in ${((performance.now()-l)/1e3).toFixed(2)} seconds.`),await e.promises.rm(s,{recursive:!0,force:!0})};function z(e){if(typeof e==`number`||/^\d+$/.test(e))return typeof e==`number`?e:parseInt(e,10);let t=/(\d+)([hms])/g,n=0,r;for(;(r=t.exec(e))!==null;){let e=parseInt(r[1],10);switch(r[2]){case`h`:n+=e*36e5;break;case`m`:n+=e*6e4;break;case`s`:n+=e*1e3;break}}return n}const lt=async e=>{let t=(await D(`git`,[`ls-remote`,e])).stdout,n=t.match(/(.+)\s+HEAD/)?.[1],r=t.match(RegExp(`${n}\\s+refs/heads/(.+)`))?.[1];if(!r)throw Error(`Could not determine default branch!`);return r};async function ut(e,{branch:t,target:n}){let r=/^https:\/\/([^@]+)@github\.com/,i=e.match(r),a=``;i&&(a=i[1],e=e.replace(r,`https://github.com`));for(let t of[`git@github.com:`,`https://github.com/`,`https://raw.githubusercontent.com/`])if(e.startsWith(t)){e=e.replace(t,``);break}let o=e.split(`/`),s=o[0],c=o[1].endsWith(`.git`)?o[1].slice(0,-4):o[1],l=o[2]===`blob`?`blob`:o[2]===`tree`?`tree`:o[2]+o[3]===`refsheads`?`raw`:`repository`,u=t||(l===`repository`?await lt(`https://${a&&a+`@`}github.com/${s}/${c}`):l===`raw`?o[4]:o[3]),d=l?l===`raw`?o.slice(5).join(`/`):o.slice(4).join(`/`):o.slice(2).join(`/`)||`/`,f=n||(l===`blob`?`.`:d.split(`/`).pop()||c);return{token:a,owner:s,repository:c,type:l,branch:u,path:d,target:f}}const B=Symbol(`singleComment`),V=Symbol(`multiComment`),dt=()=>``,ft=(e,t,n)=>e.slice(t,n).replace(/[^ \t\r\n]/g,` `),pt=(e,t)=>{let n=t-1,r=0;for(;e[n]===`\\`;)--n,r+=1;return!!(r%2)};function mt(e,{whitespace:t=!0,trailingCommas:n=!1}={}){if(typeof e!=`string`)throw TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof e}\``);let r=t?ft:dt,i=!1,a=!1,o=0,s=``,c=``,l=-1;for(let t=0;t<e.length;t++){let u=e[t],d=e[t+1];if(!a&&u===`"`&&(pt(e,t)||(i=!i)),!i)if(!a&&u+d===`//`)s+=e.slice(o,t),o=t,a=B,t++;else if(a===B&&u+d===`\r
|
|
7
7
|
`){t++,a=!1,s+=r(e,o,t),o=t;continue}else if(a===B&&u===`
|
|
8
8
|
`)a=!1,s+=r(e,o,t),o=t;else if(!a&&u+d===`/*`){s+=e.slice(o,t),o=t,a=V,t++;continue}else if(a===V&&u+d===`*/`){t++,a=!1,s+=r(e,o,t+1),o=t+1;continue}else n&&!a&&(l===-1?u===`,`&&(c+=s+e.slice(o,t),s=``,o=t,l=t):u===`}`||u===`]`?(s+=e.slice(o,t),c+=r(s,0,1)+s.slice(1),s=``,o=t,l=-1):u!==` `&&u!==` `&&u!==`\r`&&u!==`
|
|
9
|
-
`&&(s+=e.slice(o,t),o=t,l=-1))}let u=a===B?r(e,o):e.slice(o);return c+s+u}const
|
|
10
|
-
With ${
|
|
9
|
+
`&&(s+=e.slice(o,t),o=t,l=-1))}let u=a===B?r(e,o):e.slice(o);return c+s+u}const ht=[`.gitpick.json`,`.gitpick.jsonc`],gt=async()=>{let n;for(let r of ht){let i=t.resolve(r);if(e.existsSync(i)){n=i;break}}if(!n)return!1;let r=await e.promises.readFile(n,`utf-8`),i=JSON.parse(mt(r));if(!Array.isArray(i)||!i.every(e=>typeof e==`string`))throw Error(`${t.basename(n)} must be an array of strings`);for(let e of i)await D(process.argv[0],[...process.argv.slice(1),...e.split(/\s+/),`-o`],{stdio:`inherit`});return!0},H=globalThis.window?.document!==void 0;globalThis.process?.versions?.node,globalThis.process?.versions?.bun,globalThis.Deno?.version?.deno,globalThis.process?.versions?.electron,globalThis.navigator?.userAgent?.includes(`jsdom`),typeof WorkerGlobalScope<`u`&&globalThis instanceof WorkerGlobalScope,typeof DedicatedWorkerGlobalScope<`u`&&globalThis instanceof DedicatedWorkerGlobalScope,typeof SharedWorkerGlobalScope<`u`&&globalThis instanceof SharedWorkerGlobalScope,typeof ServiceWorkerGlobalScope<`u`&&globalThis instanceof ServiceWorkerGlobalScope;const U=globalThis.navigator?.userAgentData?.platform;U===`macOS`||globalThis.navigator?.platform===`MacIntel`||globalThis.navigator?.userAgent?.includes(` Mac `)===!0||globalThis.process?.platform,U===`Windows`||globalThis.navigator?.platform===`Win32`||globalThis.process?.platform,U===`Linux`||globalThis.navigator?.platform?.startsWith(`Linux`)===!0||globalThis.navigator?.userAgent?.includes(` Linux `)===!0||globalThis.process?.platform,U===`iOS`||globalThis.navigator?.platform===`MacIntel`&&globalThis.navigator?.maxTouchPoints>1||/iPad|iPhone|iPod/.test(globalThis.navigator?.platform),U===`Android`||globalThis.navigator?.platform===`Android`||globalThis.navigator?.userAgent?.includes(` Android `)===!0||globalThis.process?.platform,!H&&a.env.TERM_PROGRAM,!H&&a.platform,H||a.cwd;const _t=(e,t)=>[`\x1B]`,`8`,`;`,`;`,t,`\x07`,e,`\x1B]`,`8`,`;`,`;`,`\x07`].join(``);function W(e,t=p.argv){let n=e.startsWith(`-`)?``:e.length===1?`-`:`--`,r=t.indexOf(n+e),i=t.indexOf(`--`);return r!==-1&&(i===-1||r<i)}function G(e,t=globalThis.Deno?globalThis.Deno.args:a.argv){let n=e.startsWith(`-`)?``:e.length===1?`-`:`--`,r=t.indexOf(n+e),i=t.indexOf(`--`);return r!==-1&&(i===-1||r<i)}const{env:K}=a;let q;G(`no-color`)||G(`no-colors`)||G(`color=false`)||G(`color=never`)?q=0:(G(`color`)||G(`colors`)||G(`color=true`)||G(`color=always`))&&(q=1);function J(){if(!(`FORCE_COLOR`in K))return;if(K.FORCE_COLOR===`true`)return 1;if(K.FORCE_COLOR===`false`)return 0;if(K.FORCE_COLOR.length===0)return 1;let e=Math.min(Number.parseInt(K.FORCE_COLOR,10),3);if([0,1,2,3].includes(e))return e}function vt(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function yt(e,{streamIsTTY:t,sniffFlags:n=!0}={}){let r=J();r!==void 0&&(q=r);let o=n?q:r;if(o===0)return 0;if(n){if(G(`color=16m`)||G(`color=full`)||G(`color=truecolor`))return 3;if(G(`color=256`))return 2}if(`TF_BUILD`in K&&`AGENT_NAME`in K)return 1;if(e&&!t&&o===void 0)return 0;let s=o||0;if(K.TERM===`dumb`)return s;if(a.platform===`win32`){let e=i.release().split(`.`);return Number(e[0])>=10&&Number(e[2])>=10586?Number(e[2])>=14931?3:2:1}if(`CI`in K)return[`GITHUB_ACTIONS`,`GITEA_ACTIONS`,`CIRCLECI`].some(e=>e in K)?3:[`TRAVIS`,`APPVEYOR`,`GITLAB_CI`,`BUILDKITE`,`DRONE`].some(e=>e in K)||K.CI_NAME===`codeship`?1:s;if(`TEAMCITY_VERSION`in K)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(K.TEAMCITY_VERSION)?1:0;if(K.COLORTERM===`truecolor`||K.TERM===`xterm-kitty`)return 3;if(`TERM_PROGRAM`in K){let e=Number.parseInt((K.TERM_PROGRAM_VERSION||``).split(`.`)[0],10);switch(K.TERM_PROGRAM){case`iTerm.app`:return e>=3?3:2;case`Apple_Terminal`:return 2}}return/-256(color)?$/i.test(K.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(K.TERM)||`COLORTERM`in K?1:s}function Y(e,t={}){return vt(yt(e,{streamIsTTY:e&&e.isTTY,...t}))}Y({isTTY:f.isatty(1)}),Y({isTTY:f.isatty(2)});function X(e=``){if(/^\d{3,4}$/.test(e)){let t=/(\d{1,2})(\d{2})/.exec(e)??[];return{major:0,minor:Number.parseInt(t[1],10),patch:Number.parseInt(t[2],10)}}let t=(e??``).split(`.`).map(e=>Number.parseInt(e,10));return{major:t[0],minor:t[1],patch:t[2]}}function Z(e){let{CI:t,FORCE_HYPERLINK:n,NETLIFY:r,TEAMCITY_VERSION:i,TERM_PROGRAM:o,TERM_PROGRAM_VERSION:s,VTE_VERSION:c,TERM:l}=a.env;if(n)return!(n.length>0&&Number.parseInt(n,10)===0);if(W(`no-hyperlink`)||W(`no-hyperlinks`)||W(`hyperlink=false`)||W(`hyperlink=never`))return!1;if(W(`hyperlink=true`)||W(`hyperlink=always`)||r)return!0;if(!Y(e)||e&&!e.isTTY)return!1;if(`WT_SESSION`in a.env)return!0;if(a.platform===`win32`||t||i)return!1;if(o){let e=X(s);switch(o){case`iTerm.app`:return e.major===3?e.minor>=1:e.major>3;case`WezTerm`:return e.major>=20200620;case`vscode`:return e.major>1||e.major===1&&e.minor>=72;case`ghostty`:return!0}}if(c){if(c===`0.50.0`)return!1;let e=X(c);return e.major>0||e.minor>=50}switch(l){case`alacritty`:return!0}return!1}const Q={stdout:Z(a.stdout),stderr:Z(a.stderr)};function $(e,t,{target:n=`stdout`,...r}={}){return Q[n]?_t(e,t):r.fallback===!1?e:typeof r.fallback==`function`?r.fallback(e,t):`${e} (\u200B${t}\u200B)`}$.isSupported=Q.stdout,$.stderr=(e,t,n={})=>$(e,t,{target:`stderr`,...n}),$.stderr.isSupported=Q.stderr;var bt=`gitpick`,xt=`4.15.0-canary.2`;const St=`
|
|
10
|
+
With ${k(`${$(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific directories or files from GitHub!
|
|
11
11
|
|
|
12
|
-
$ gitpick ${
|
|
12
|
+
$ gitpick ${P(`<url>`)} ${N(`[target]`)} ${I(`[options]`)}
|
|
13
13
|
|
|
14
|
-
${
|
|
14
|
+
${k(`Hint:`)}
|
|
15
15
|
[target] and [options] are optional and if not specified,
|
|
16
16
|
GitPick fallbacks to the default behavior of \`git clone\`
|
|
17
17
|
|
|
18
|
-
${
|
|
19
|
-
${
|
|
20
|
-
${
|
|
18
|
+
${k(`Arguments:`)}
|
|
19
|
+
${P(`url`)} GitHub URL with path to file/folder/repository
|
|
20
|
+
${N(`target`)} Directory to clone into (optional)
|
|
21
21
|
|
|
22
|
-
${
|
|
23
|
-
${
|
|
24
|
-
${
|
|
25
|
-
${
|
|
26
|
-
${
|
|
22
|
+
${k(`Options:`)}
|
|
23
|
+
${I(`-b, --branch `)} Branch/SHA to clone
|
|
24
|
+
${I(`-o, --overwrite`)} Skip overwrite prompt
|
|
25
|
+
${I(`-r, --recursive`)} Clone submodules
|
|
26
|
+
${I(`-w, --watch [time]`)} Watch the repository and sync every [time]
|
|
27
27
|
(e.g. 1h, 30m, 15s)
|
|
28
|
-
${
|
|
29
|
-
${
|
|
28
|
+
${I(`-h, --help`)} display help for command
|
|
29
|
+
${I(`-v, --version`)} display the version number
|
|
30
30
|
|
|
31
|
-
${
|
|
31
|
+
${k(`Examples:`)}
|
|
32
32
|
$ gitpick <url>
|
|
33
33
|
$ gitpick <url> [target]
|
|
34
34
|
$ gitpick <url> [target] -b [branch/SHA]
|
|
35
35
|
$ gitpick <url> [target] -w [time]
|
|
36
36
|
$ gitpick <url> [target] -b [branch/SHA] -w [time]
|
|
37
37
|
|
|
38
|
-
🚀 More awesome tools at ${
|
|
38
|
+
🚀 More awesome tools at ${I(`https://github.com/nrjdalal`)}`,Ct=e=>{try{return n(e)}catch(e){throw Error(`Error parsing arguments: ${e.message}`)}};(async()=>{try{let{positionals:n,values:r}=Ct({allowPositionals:!0,options:{branch:{type:`string`,short:`b`},force:{type:`boolean`,short:`f`},help:{type:`boolean`,short:`h`},overwrite:{type:`boolean`,short:`o`},recursive:{type:`boolean`,short:`r`},version:{type:`boolean`,short:`v`},watch:{type:`string`,short:`w`}}});n.length||(r.version&&(console.log(`\n${bt}@${xt}`),process.exit(0)),await gt()&&process.exit(0),console.log(St),process.exit(0)),n[0]===`clone`&&n.shift();let[i,a]=n,o={branch:r.branch,force:r.force,overwrite:r.overwrite,recursive:r.recursive,watch:r.watch};console.log(`\nWith ${k(`${$(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific files, folders, branches, commits and more from GitHub!`);let s=await ut(i,{branch:o.branch,target:a});if(s.type===`blob`){let e=s.target.split(`/`).filter(e=>e!==``),t=e[e.length-1];t!==`.`&&t!==`..`&&t.includes(`.`)?e.pop():t=s.path.split(`/`).pop()||t,s.target=[...e,t].join(`/`)}console.info(`\n${N(`✔`)} ${s.owner}/${s.repository} ${I(s.type+`:`+s.branch)} ${s.type===`repository`?`> ${N(s.target)}`:`${s.path.length?P(s.path)+` >`:`>`} ${N(s.target)}`}`);let c=t.resolve(s.target);if(o.overwrite=o.overwrite||o.force,o.watch&&(o.overwrite=!0),e.existsSync(c)&&!o.overwrite&&(s.type===`blob`&&(console.log(`${P(`\nWarning: The target file exists at ${N(s.target)}. Use ${I(`-f`)} or ${I(`-o`)} to overwrite.`)}`),process.exit(1)),(await e.promises.readdir(c)).length&&(console.log(`${P(`\nWarning: The target directory exists at ${N(s.target)} and is not empty. Use ${I(`-f`)} or ${I(`-o`)} to overwrite.`)}`),process.exit(1))),o.watch){console.log(`\n👀 Watching every ${z(o.watch)/1e3+`s`}\n`),await R(s,o,c);let e=z(o.watch);setInterval(async()=>await R(s,o,c),e)}else await R(s,o,c),process.exit(0)}catch(e){e instanceof Error?console.log(k(`\n${M(`Error: `)}`)+e.message):console.log(k(`${M(`
|
|
39
39
|
Unexpected Error: `)}`)+JSON.stringify(e,null,2)),process.exit(1)}})();export{};
|