gitpick 4.13.0-canary.9 → 4.14.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  **Clone exactly what you need aka straightforward project scaffolding!**
6
6
 
7
- šŸ“¦ `Zero dependencies` / `Un/packed (<35/15kb)` / `Faster and more features` yet drop-in replacement for `degit`
7
+ šŸ“¦ `Zero dependencies` / `Un/packed (<27/11kb)` / `Faster and more features` yet drop-in replacement for `degit`
8
8
 
9
9
  [![Twitter](https://img.shields.io/twitter/follow/nrjdalal_dev?label=%40nrjdalal_dev)](https://twitter.com/nrjdalal_dev)
10
10
  [![npm](https://img.shields.io/npm/v/gitpick?color=red&logo=npm)](https://www.npmjs.com/package/gitpick)
@@ -13,7 +13,7 @@
13
13
 
14
14
  > #### Just `copy-and-paste` any GitHub URL - no editing required (shorthands work too) - to clone individual files, folders, branches, commits, raw content or even entire repositories without the `.git` directory.
15
15
 
16
- Unlike other tools that force you to tweak URLs or follow strict formats to clone files or folders, GitPick works seamlessly with any URL.
16
+ Unlike other tools that force you to tweak URLs or follow strict formats to clone files, folders, branches or commits GitPick works seamlessly with any URL.
17
17
 
18
18
  <img width="400" alt="GitPick Meme" src="https://github.com/user-attachments/assets/180c3e5b-320c-48d7-aaf9-a7402e74c882" />
19
19
 
@@ -129,9 +129,27 @@ Check out more projects at [github.com/nrjdalal](https://github.com/nrjdalal)
129
129
 
130
130
  ## šŸ”— Related Projects
131
131
 
132
- - [degit](https://github.com/tiged/tiged) - community driven fork of degit
132
+ - [tiged](https://github.com/tiged/tiged) - community driven fork of degit
133
133
  - [giget](https://github.com/unjs/giget) - alternative approach
134
134
 
135
+ [![Star History Chart](https://api.star-history.com/svg?repos=nrjdalal/gitpick,tiged/tiged,unjs/giget&type=timeline&logscale&legend=top-left)](https://www.star-history.com/#nrjdalal/gitpick&tiged/tiged&unjs/giget&type=timeline&logscale&legend=top-left)
136
+
137
+ ## šŸ¤ Contributing
138
+
139
+ Contributions welcome — any help is appreciated!
140
+
141
+ - Fork the repo and create a branch (use descriptive names, e.g. feat/<name> or fix/<name>).
142
+ - Make your changes, add tests if applicable, and run the checks:
143
+ - bun install
144
+ - bun run sync:external
145
+ - bun test
146
+ - Follow the existing code style and commit message conventions (use conventional commits: feat, fix, docs, chore).
147
+ - Open a PR describing the change, motivation, and any migration notes; link related issues.
148
+ - For breaking changes or large features, open an issue first to discuss the approach.
149
+ - By contributing you agree to the MIT license and the project's Code of Conduct.
150
+
151
+ Thank you for helping improve GitPick!
152
+
135
153
  ## šŸ“„ License
136
154
 
137
155
  MIT – [LICENSE](LICENSE)
package/dist/index.mjs ADDED
@@ -0,0 +1,36 @@
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{spawn as s}from"node:child_process";import{on as c,once as l}from"node:events";import{stat as u}from"node:fs/promises";import{pipeline as d}from"node:stream/promises";import f from"node:tty";import p from"process";var m=Object.defineProperty,h=(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 g=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);a.isDirectory()?await g(i,o):await e.promises.copyFile(i,o)}},ee=e=>({start:a.hrtime.bigint(),command:e.map(e=>te(r(e))).join(` `),state:{stdout:``,stderr:``,output:``}}),te=e=>/[^\w./-]/.test(e)?`'${e.replaceAll(`'`,`'\\''`)}'`:e,ne=({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?re(f??a.env,d):f,cwd:d}},re=({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,`..`)),ie=async(e,t,n)=>await ae(e,n)?[b(e),t.map(e=>ce(e)),{...n,shell:!0}]:[e,t,n],ae=async(e,{shell:t,cwd:n,env:r=a.env})=>a.platform===`win32`&&!t&&!await oe(e,n,r),oe=async(e,t,{Path:n=``,PATH:r=n})=>y.some(t=>e.toLowerCase().endsWith(t))||(se[`${e}\0${t}\0${r}`]??=await v(e,t,r)),se={},v=async(e,n,r)=>{let i=r.split(t.delimiter).filter(Boolean).map(e=>e.replace(/^"(.*)"$/,`$1`));try{await Promise.all(y.flatMap(r=>[n,...i].map(n=>`${t.resolve(n,e)}${r}`)).map(async e=>{try{await u(e)}catch{return}throw 0}))}catch{return!0}return!1},y=[`.exe`,`.com`],ce=e=>b(b(`"${e.replaceAll(/(\\*)"/g,`$1$1\\"`).replace(/(\\*)$/,`$1$1`)}"`)),b=e=>e.replaceAll(/([()\][%!^"`<>&|;, *?])/g,`^$1`),le=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,C(r)),w(n)}catch(e){throw await Promise.allSettled([i]),x(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 S(`Command was terminated with ${n}: ${e}`);if(t!==void 0)throw new S(`Command failed with exit code ${t}: ${e}`)},x=(e,t,n)=>Object.assign(fe(e,n),C(t),w(n)),fe=(e,{command:t})=>e instanceof S?e:new S(`Command failed: ${t}`,{cause:e});var S=class extends Error{name=`SubprocessError`};const C=({exitCode:e,signalCode:t})=>({...e<1?{}:{exitCode:e},...t===null?{}:{signalName:t}}),w=({state:{stdout:e,stderr:t,output:n},command:r,start:i})=>({stdout:T(e),stderr:T(t),output:T(n),command:r,durationMs:Number(a.hrtime.bigint()-i)/1e6}),T=e=>e.at(-1)===`
3
+ `?e.slice(0,e.at(-2)===`\r`?-2:-1):e,E=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=s(...await ie(e,t,n));return D(i.stdout,r,`stdout`),D(i.stderr,r,`stderr`),i.once(`error`,()=>{}),await l(i,`spawn`),i}catch(e){throw x(e,{},r)}},D=(e,{state:t},n)=>{e&&(e.setEncoding(`utf8`),t.isIterating||(t.isIterating=!1,e.on(`data`,e=>{t[n]+=e,t.output+=e})))},pe=async e=>{let[[t,n]]=await Promise.all([Promise.allSettled(e),me(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}},me=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.`);d(t,n).catch(()=>{})}catch(t){throw await Promise.allSettled(e.map(({nodeChildProcess:e})=>he(e))),t}},he=async e=>{let{stdin:t}=await e;t.end()},O=async function*(e,{state:t},n){if(t.isIterating===!1)throw Error(`The subprocess must be iterated right away, for example:
4
+ 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}},ge=async function*(...e){try{let t=[];for(;e.length>0;){t=e.map((e,n)=>t[n]??_e(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()))}},_e=async e=>{try{return await e.next()}catch(t){await e.throw(t)}};function k(e,t,n,r){let[i=[],a={}]=Array.isArray(t)?[t,n]:[[],t],o=ee([e,...i]),s=ne(a),c=E(e,i,s,o),l=le(c,s,o);Object.assign(l,{nodeChildProcess:c}),l=r?pe([r,l]):l;let u=O(l,o,`stdout`),d=O(l,o,`stderr`);return Object.assign(l,{nodeChildProcess:c,stdout:u,stderr:d,[Symbol.asyncIterator]:()=>ge(u,d),pipe:(e,t,n)=>k(e,t,n,l)})}var ve=h({bgBlack:()=>ke,bgBlue:()=>Ne,bgBlueBright:()=>Je,bgCyan:()=>Fe,bgCyanBright:()=>Xe,bgGray:()=>Le,bgGreen:()=>je,bgGreenBright:()=>Ke,bgMagenta:()=>Pe,bgMagentaBright:()=>Ye,bgRed:()=>Ae,bgRedBright:()=>Ge,bgWhite:()=>Ie,bgWhiteBright:()=>Ze,bgYellow:()=>Me,bgYellowBright:()=>qe,black:()=>Te,blue:()=>R,blueBright:()=>Ve,bold:()=>M,cyan:()=>z,cyanBright:()=>Ue,dim:()=>N,gray:()=>Oe,green:()=>I,greenBright:()=>ze,hidden:()=>Ce,inverse:()=>Se,italic:()=>P,magenta:()=>Ee,magentaBright:()=>He,overline:()=>xe,red:()=>F,redBright:()=>Re,reset:()=>j,strikethrough:()=>we,underline:()=>be,white:()=>De,whiteBright:()=>We,yellow:()=>L,yellowBright:()=>Be});const ye=f?.WriteStream?.prototype?.hasColors?.()??!1,A=(e,t)=>{if(!ye)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}},j=A(0,0),M=A(1,22),N=A(2,22),P=A(3,23),be=A(4,24),xe=A(53,55),Se=A(7,27),Ce=A(8,28),we=A(9,29),Te=A(30,39),F=A(31,39),I=A(32,39),L=A(33,39),R=A(34,39),Ee=A(35,39),z=A(36,39),De=A(37,39),Oe=A(90,39),ke=A(40,49),Ae=A(41,49),je=A(42,49),Me=A(43,49),Ne=A(44,49),Pe=A(45,49),Fe=A(46,49),Ie=A(47,49),Le=A(100,49),Re=A(91,39),ze=A(92,39),Be=A(93,39),Ve=A(94,39),He=A(95,39),Ue=A(96,39),We=A(97,39),Ge=A(101,49),Ke=A(102,49),qe=A(103,49),Je=A(104,49),Ye=A(105,49),Xe=A(106,49),Ze=A(107,49),B=a.platform!==`win32`||!!a.env.WT_SESSION,Qe=e=>!!(e.isTTY&&a.env.TERM!==`dumb`&&!(`CI`in a.env)),$e=R(B?`ℹ`:`i`),et=I(B?`āœ”`:`√`),tt=L(B?`⚠`:`‼`),nt=F(B?`āœ–ļø`:`Ɨ`),rt={frames:B?[`ā ‹`,`ā ™`,`ā ¹`,`ā ø`,`ā ¼`,`ā “`,`ā ¦`,`ā §`,`ā ‡`,`ā `]:[`-`,`\\`,`|`,`/`],interval:80};var it=class{#e;#t;#n=-1;#r;#i;#a;#o;#s=0;#c;#l;#u=0;constructor(e={}){let t=e.spinner??rt;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=Qe(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(et,e)}error(e){return this.#d(nt,e)}warning(e){return this.#d(tt,e)}info(e){return this.#d($e,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=ve[this.#o]??z,n=this.#e[this.#n],r=`${t(n)} ${this.#i}`;this.#l||(r+=`
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 at(e){return new it(e)}const V=async(n,r,a)=>{process.platform===`win32`&&await k(`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=at(),l=performance.now();r.watch||c.start(`Picking ${n.type}${n.type===`repository`?` without .git`:` from repository`}...`);try{await k(`git`,[`clone`,o,s,`--branch`,n.branch,`--depth`,`1`,`--single-branch`,...r.recursive?[`--recursive`]:[]])}catch{await k(`git`,[`clone`,o,s,...r.recursive?[`--recursive`]:[]]),await k(`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 g(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 H(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 ot=async e=>{let t=(await k(`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 st(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 ot(`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 U=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 W=globalThis.navigator?.userAgentData?.platform;W===`macOS`||globalThis.navigator?.platform===`MacIntel`||globalThis.navigator?.userAgent?.includes(` Mac `)===!0||globalThis.process?.platform,W===`Windows`||globalThis.navigator?.platform===`Win32`||globalThis.process?.platform,W===`Linux`||globalThis.navigator?.platform?.startsWith(`Linux`)===!0||globalThis.navigator?.userAgent?.includes(` Linux `)===!0||globalThis.process?.platform,W===`iOS`||globalThis.navigator?.platform===`MacIntel`&&globalThis.navigator?.maxTouchPoints>1||/iPad|iPhone|iPod/.test(globalThis.navigator?.platform),W===`Android`||globalThis.navigator?.platform===`Android`||globalThis.navigator?.userAgent?.includes(` Android `)===!0||globalThis.process?.platform,!U&&a.env.TERM_PROGRAM,!U&&a.platform,U||a.cwd;const ct=(e,t)=>[`\x1B]`,`8`,`;`,`;`,t,`\x07`,e,`\x1B]`,`8`,`;`,`;`,`\x07`].join(``);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 lt(){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 ut(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function dt(e,{streamIsTTY:t,sniffFlags:n=!0}={}){let r=lt();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 J(e,t={}){return ut(dt(e,{streamIsTTY:e&&e.isTTY,...t}))}J({isTTY:f.isatty(1)}),J({isTTY:f.isatty(2)});function Y(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 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(Y(`no-hyperlink`)||Y(`no-hyperlinks`)||Y(`hyperlink=false`)||Y(`hyperlink=never`))return!1;if(Y(`hyperlink=true`)||Y(`hyperlink=always`)||r)return!0;if(!J(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]?ct(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 ft=`gitpick`,pt=`4.14.0-canary.0`;const mt=`
7
+ With ${M(`${$(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific directories or files from GitHub!
8
+
9
+ $ gitpick ${L(`<url>`)} ${I(`[target]`)} ${z(`[options]`)}
10
+
11
+ ${M(`Hint:`)}
12
+ [target] and [options] are optional and if not specified,
13
+ GitPick fallbacks to the default behavior of \`git clone\`
14
+
15
+ ${M(`Arguments:`)}
16
+ ${L(`url`)} GitHub URL with path to file/folder/repository
17
+ ${I(`target`)} Directory to clone into (optional)
18
+
19
+ ${M(`Options:`)}
20
+ ${z(`-b, --branch `)} Branch/SHA to clone
21
+ ${z(`-o, --overwrite`)} Skip overwrite prompt
22
+ ${z(`-r, --recursive`)} Clone submodules
23
+ ${z(`-w, --watch [time]`)} Watch the repository and sync every [time]
24
+ (e.g. 1h, 30m, 15s)
25
+ ${z(`-h, --help`)} display help for command
26
+ ${z(`-v, --version`)} display the version number
27
+
28
+ ${M(`Examples:`)}
29
+ $ gitpick <url>
30
+ $ gitpick <url> [target]
31
+ $ gitpick <url> [target] -b [branch/SHA]
32
+ $ gitpick <url> [target] -w [time]
33
+ $ gitpick <url> [target] -b [branch/SHA] -w [time]
34
+
35
+ šŸš€ More awesome tools at ${z(`https://github.com/nrjdalal`)}`,ht=e=>{try{return n(e)}catch(e){throw Error(`Error parsing arguments: ${e.message}`)}};(async()=>{try{let{positionals:n,values:r}=ht({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${ft}@${pt}`),process.exit(0)),console.log(mt),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 ${M(`${$(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific files, folders, branches, commits and more from GitHub!`);let s=await st(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${I(`āœ”`)} ${s.owner}/${s.repository} ${z(s.type+`:`+s.branch)} ${s.type===`repository`?`> ${I(s.target)}`:`${s.path.length?L(s.path)+` >`:`>`} ${I(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(`${L(`\nWarning: The target file exists at ${I(s.target)}. Use ${z(`-f`)} or ${z(`-o`)} to overwrite.`)}`),process.exit(1)),(await e.promises.readdir(c)).length&&(console.log(`${L(`\nWarning: The target directory exists at ${I(s.target)} and is not empty. Use ${z(`-f`)} or ${z(`-o`)} to overwrite.`)}`),process.exit(1))),o.watch){console.log(`\nšŸ‘€ Watching every ${H(o.watch)/1e3+`s`}\n`),await V(s,o,c);let e=H(o.watch);setInterval(async()=>await V(s,o,c),e)}else await V(s,o,c),process.exit(0)}catch(e){e instanceof Error?console.log(M(`\n${F(`Error: `)}`)+e.message):console.log(M(`${F(`
36
+ Unexpected Error: `)}`)+JSON.stringify(e,null,2)),process.exit(1)}})();export{};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitpick",
3
- "version": "4.13.0-canary.9",
3
+ "version": "4.14.0-canary.0",
4
4
  "description": "Clone exactly what you need aka straightforward project scaffolding!",
5
5
  "keywords": [
6
6
  "clone",
@@ -27,8 +27,8 @@
27
27
  },
28
28
  "type": "module",
29
29
  "bin": {
30
- "degit": "./dist/index.js",
31
- "gitpick": "./dist/index.js"
30
+ "degit": "./dist/index.mjs",
31
+ "gitpick": "./dist/index.mjs"
32
32
  },
33
33
  "files": [
34
34
  "dist"
package/dist/index.js DELETED
@@ -1,45 +0,0 @@
1
- #!/usr/bin/env node
2
- var jt=Object.defineProperty,nr=Object.defineProperties;var ir=Object.getOwnPropertyDescriptors;var ct=Object.getOwnPropertySymbols;var Lt=Object.prototype.hasOwnProperty,Wt=Object.prototype.propertyIsEnumerable;var U=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),xt=t=>{throw TypeError(t)};var bt=(t,e,r)=>e in t?jt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,y=(t,e)=>{for(var r in e||(e={}))Lt.call(e,r)&&bt(t,r,e[r]);if(ct)for(var r of ct(e))Wt.call(e,r)&&bt(t,r,e[r]);return t},F=(t,e)=>nr(t,ir(e));var X=(t,e)=>{var r={};for(var o in t)Lt.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o]);if(t!=null&&ct)for(var o of ct(t))e.indexOf(o)<0&&Wt.call(t,o)&&(r[o]=t[o]);return r};var Ft=(t,e)=>{for(var r in e)jt(t,r,{get:e[r],enumerable:!0})};var Gt=(t,e,r)=>bt(t,typeof e!="symbol"?e+"":e,r),yt=(t,e,r)=>e.has(t)||xt("Cannot "+r);var u=(t,e,r)=>(yt(t,e,"read from private field"),r?r.call(t):e.get(t)),E=(t,e,r)=>e.has(t)?xt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),b=(t,e,r,o)=>(yt(t,e,"write to private field"),o?o.call(t,r):e.set(t,r),r),x=(t,e,r)=>(yt(t,e,"access private method"),r);var _t=(t,e,r,o)=>({set _(s){b(t,e,s,r)},get _(){return u(t,e,o)}});var O=function(t,e){this[0]=t,this[1]=e},vt=(t,e,r)=>{var o=(i,a,c,p)=>{try{var d=r[i](a),g=(a=d.value)instanceof O,v=d.done;Promise.resolve(g?a[0]:a).then(w=>g?o(i==="return"?i:"next",a[1]?{done:w.done,value:w.value}:w,c,p):c({value:w,done:v})).catch(w=>o("throw",w,c,p))}catch(w){p(w)}},s=i=>n[i]=a=>new Promise((c,p)=>o(i,a,c,p)),n={};return r=r.apply(t,e),n[U("asyncIterator")]=()=>n,s("next"),s("throw"),s("return"),n},Nt=t=>{var e=t[U("asyncIterator")],r=!1,o,s={};return e==null?(e=t[U("iterator")](),o=n=>s[n]=i=>e[n](i)):(e=e.call(t),o=n=>s[n]=i=>{if(r){if(r=!1,n==="throw")throw i;return i}return r=!0,{done:!1,value:new O(new Promise(a=>{var c=e[n](i);c instanceof Object||xt("Object expected"),a(c)}),1)}}),s[U("iterator")]=()=>s,o("next"),"throw"in e?o("throw"):s.throw=n=>{throw n},"return"in e&&o("return"),s},lt=(t,e,r)=>(e=t[U("asyncIterator")])?e.call(t):(t=t[U("iterator")](),e={},r=(o,s)=>(s=t[o])&&(e[o]=n=>new Promise((i,a,c)=>(n=s.call(t,n),c=n.done,Promise.resolve(n.value).then(p=>i({value:p,done:c}),a)))),r("next"),r("return"),e);import sr from"fs";import os from"path";import{parseArgs as ss}from"util";import q from"fs";import vo from"os";import z from"path";import $t from"fs";import Dt from"path";var Tt=async(t,e)=>{let r=await $t.promises.readdir(t,{withFileTypes:!0});await $t.promises.mkdir(e,{recursive:!0});for(let o of r){if(o.name===".git")continue;let s=Dt.join(t,o.name),n=Dt.join(e,o.name);o.isDirectory()?await Tt(s,n):await $t.promises.copyFile(s,n)}};import ar from"process";import{stripVTControlCharacters as cr}from"util";var Ht=t=>({start:ar.hrtime.bigint(),command:t.map(e=>lr(cr(e))).join(" "),state:{stdout:"",stderr:"",output:""}}),lr=t=>/[^\w./-]/.test(t)?`'${t.replaceAll("'","'\\''")}'`:t;import V from"path";import{fileURLToPath as pr}from"url";import Ut from"process";var Vt=c=>{var p=c,{stdin:t,stdout:e,stderr:r,stdio:o=[t,e,r],env:s,preferLocal:n,cwd:i="."}=p,a=X(p,["stdin","stdout","stderr","stdio","env","preferLocal","cwd"]);var w;let d=i instanceof URL?pr(i):V.resolve(i),g=s?y(y({},Ut.env),s):void 0,v=(w=o[0])==null?void 0:w.string;return F(y({},a),{input:v,stdio:v===void 0?o:["pipe",...o.slice(1)],env:n?ur(g!=null?g:Ut.env,d):g,cwd:d})},ur=(s,o)=>{var n=s,{Path:t="",PATH:e=t}=n,r=X(n,["Path","PATH"]);let i=e.split(V.delimiter),a=Yt([],V.resolve(o)).map(c=>V.join(c,"node_modules/.bin")).filter(c=>!i.includes(c));return F(y({},r),{PATH:[...a,e].filter(Boolean).join(V.delimiter)})},Yt=(t,e)=>t.at(-1)===e?t:Yt([...t,e],V.resolve(e,".."));import{spawn as Tr}from"child_process";import{once as Er}from"events";import te from"process";import{stat as hr}from"fs/promises";import Jt from"path";import Kt from"process";var qt=async(t,e,r)=>await mr(t,r)?[St(t),e.map(o=>gr(o)),F(y({},r),{shell:!0})]:[t,e,r],mr=async(t,{shell:e,cwd:r,env:o=Kt.env})=>Kt.platform==="win32"&&!e&&!await fr(t,r,o),fr=async(t,e,{Path:r="",PATH:o=r})=>{var s,n;return zt.some(i=>t.toLowerCase().endsWith(i))||((n=Et[s=`${t}\0${e}\0${o}`])!=null?n:Et[s]=await dr(t,e,o))},Et={},dr=async(t,e,r)=>{let o=r.split(Jt.delimiter).filter(Boolean).map(s=>s.replace(/^"(.*)"$/,"$1"));try{await Promise.all(zt.flatMap(s=>[e,...o].map(n=>`${Jt.resolve(n,t)}${s}`)).map(async s=>{try{await hr(s)}catch(n){return}throw 0}))}catch(s){return!0}return!1},zt=[".exe",".com"],gr=t=>St(St(`"${t.replaceAll(/(\\*)"/g,'$1$1\\"').replace(/(\\*)$/,"$1$1")}"`)),St=t=>t.replaceAll(/([()\][%!^"`<>&|;, *?])/g,"^$1");import{once as wr,on as br}from"events";import xr from"process";var Qt=async(t,{input:e},r)=>{let o=await t;e!==void 0&&o.stdin.end(e);let s=wr(o,"close");try{return await Promise.race([s,...o.stdio.filter(Boolean).map(n=>yr(n))]),vr(r,Xt(o)),Zt(r)}catch(n){throw await Promise.allSettled([s]),Rt(n,o,r)}},yr=async t=>{try{for(var e=lt(br(t,"error")),r,o,s;r=!(o=await e.next()).done;r=!1){let[n]=o.value;if(!["ERR_STREAM_PREMATURE_CLOSE","EPIPE"].includes(n==null?void 0:n.code))throw n}}catch(o){s=[o]}finally{try{r&&(o=e.return)&&await o.call(e)}finally{if(s)throw s[0]}}},vr=({command:t},{exitCode:e,signalName:r})=>{if(r!==void 0)throw new G(`Command was terminated with ${r}: ${t}`);if(e!==void 0)throw new G(`Command failed with exit code ${e}: ${t}`)},Rt=(t,e,r)=>Object.assign($r(t,r),Xt(e),Zt(r)),$r=(t,{command:e})=>t instanceof G?t:new G(`Command failed: ${e}`,{cause:t}),G=class extends Error{constructor(){super(...arguments);Gt(this,"name","SubprocessError")}},Xt=({exitCode:t,signalCode:e})=>y(y({},t<1?{}:{exitCode:t}),e===null?{}:{signalName:e}),Zt=({state:{stdout:t,stderr:e,output:r},command:o,start:s})=>({stdout:kt(t),stderr:kt(e),output:kt(r),command:o,durationMs:Number(xr.hrtime.bigint()-s)/1e6}),kt=t=>t.at(-1)===`
3
- `?t.slice(0,t.at(-2)==="\r"?-2:-1):t;var re=async(t,e,r,o)=>{try{[t,e]=["node","node.exe"].includes(t.toLowerCase())?[te.execPath,[...te.execArgv.filter(n=>!n.startsWith("--inspect")),...e]]:[t,e];let s=Tr(...await qt(t,e,r));return ee(s.stdout,o,"stdout"),ee(s.stderr,o,"stderr"),s.once("error",()=>{}),await Er(s,"spawn"),s}catch(s){throw Rt(s,{},o)}},ee=(t,{state:e},r)=>{t&&(t.setEncoding("utf8"),e.isIterating||(e.isIterating=!1,t.on("data",o=>{e[r]+=o,e.output+=o})))};import{pipeline as Sr}from"stream/promises";var oe=async t=>{var o;let[[e,r]]=await Promise.all([Promise.allSettled(t),kr(t)]);if(r.reason)throw r.reason.pipedFrom=(o=e.reason)!=null?o:e.value,r.reason;if(e.reason)throw e.reason;return F(y({},r.value),{pipedFrom:e.value})},kr=async t=>{try{let[{stdout:e},{stdin:r}]=await Promise.all(t.map(({nodeChildProcess:o})=>o));if(r===null)throw new Error('The "stdin" option must be set on the first "spawn()" call in the pipeline.');if(e===null)throw new Error('The "stdout" option must be set on the last "spawn()" call in the pipeline.');Sr(e,r).catch(()=>{})}catch(e){throw await Promise.allSettled(t.map(({nodeChildProcess:r})=>Rr(r))),e}},Rr=async t=>{let{stdin:e}=await t;e.end()};var Ct=function(o,s,n){return vt(this,arguments,function*(t,{state:e},r){if(e.isIterating===!1)throw new Error(`The subprocess must be iterated right away, for example:
4
- for await (const line of spawn(...)) { ... }`);e.isIterating=!0;try{let{[r]:d}=yield new O(t.nodeChildProcess);if(!d)return;let g="";try{for(var i=lt(d.iterator({destroyOnReturn:!1})),a,c,p;a=!(c=yield new O(i.next())).done;a=!1){let v=c.value;let w=`${g}${v}`.split(/\r?\n/);g=w.pop(),yield*Nt(w)}}catch(c){p=[c]}finally{try{a&&(c=i.return)&&(yield new O(c.call(i)))}finally{if(p)throw p[0]}}g&&(yield g)}finally{yield new O(t)}})},se=function(...t){return vt(this,null,function*(){try{let e=[];for(;t.length>0;){e=t.map((i,a)=>{var c;return(c=e[a])!=null?c:Cr(i)});let[{value:r,done:o},s]=yield new O(Promise.race(e.map((i,a)=>Promise.all([i,a])))),[n]=t.splice(s,1);e.splice(s,1),o||(t.push(n),yield r)}}finally{yield new O(Promise.all(t.map(e=>e.return())))}})},Cr=async t=>{try{return await t.next()}catch(e){await t.throw(e)}};function T(t,e,r,o){let[s=[],n={}]=Array.isArray(e)?[e,r]:[[],e],i=Ht([t,...s]),a=Vt(n),c=re(t,s,a,i),p=Qt(c,a,i);Object.assign(p,{nodeChildProcess:c}),p=o?oe([o,p]):p;let d=Ct(p,i,"stdout"),g=Ct(p,i,"stderr");return Object.assign(p,{nodeChildProcess:c,stdout:d,stderr:g,[Symbol.asyncIterator]:()=>se(d,g),pipe:(v,w,W)=>T(v,w,W,p)})}import A from"process";import{stripVTControlCharacters as mo}from"util";var I={};Ft(I,{bgBlack:()=>Ur,bgBlue:()=>Kr,bgBlueBright:()=>lo,bgCyan:()=>zr,bgCyanBright:()=>uo,bgGray:()=>Xr,bgGreen:()=>Yr,bgGreenBright:()=>ao,bgMagenta:()=>qr,bgMagentaBright:()=>po,bgRed:()=>Vr,bgRedBright:()=>io,bgWhite:()=>Qr,bgWhiteBright:()=>ho,bgYellow:()=>Jr,bgYellowBright:()=>co,black:()=>Gr,blue:()=>_r,blueBright:()=>ro,bold:()=>C,cyan:()=>$,cyanBright:()=>so,dim:()=>Pr,gray:()=>Hr,green:()=>k,greenBright:()=>to,hidden:()=>Wr,inverse:()=>Lr,italic:()=>Br,magenta:()=>Nr,magentaBright:()=>oo,overline:()=>jr,red:()=>ut,redBright:()=>Zr,reset:()=>Or,strikethrough:()=>Fr,underline:()=>Mr,white:()=>Dr,whiteBright:()=>no,yellow:()=>_,yellowBright:()=>eo});import Ir from"tty";var ne,ie,pt,ae,ce,Ar=(ce=(ae=(pt=(ie=(ne=Ir)==null?void 0:ne.WriteStream)==null?void 0:ie.prototype)==null?void 0:pt.hasColors)==null?void 0:ae.call(pt))!=null?ce:!1,l=(t,e)=>{if(!Ar)return s=>s;let r=`\x1B[${t}m`,o=`\x1B[${e}m`;return s=>{let n=s+"",i=n.indexOf(o);if(i===-1)return r+n+o;let a=r,c=0;for(;i!==-1;)a+=n.slice(c,i)+r,c=i+o.length,i=n.indexOf(o,c);return a+=n.slice(c)+o,a}},Or=l(0,0),C=l(1,22),Pr=l(2,22),Br=l(3,23),Mr=l(4,24),jr=l(53,55),Lr=l(7,27),Wr=l(8,28),Fr=l(9,29),Gr=l(30,39),ut=l(31,39),k=l(32,39),_=l(33,39),_r=l(34,39),Nr=l(35,39),$=l(36,39),Dr=l(37,39),Hr=l(90,39),Ur=l(40,49),Vr=l(41,49),Yr=l(42,49),Jr=l(43,49),Kr=l(44,49),qr=l(45,49),zr=l(46,49),Qr=l(47,49),Xr=l(100,49),Zr=l(91,39),to=l(92,39),eo=l(93,39),ro=l(94,39),oo=l(95,39),so=l(96,39),no=l(97,39),io=l(101,49),ao=l(102,49),co=l(103,49),lo=l(104,49),po=l(105,49),uo=l(106,49),ho=l(107,49);var rt=A.platform!=="win32"||!!A.env.WT_SESSION,fo=t=>!!(t.isTTY&&A.env.TERM!=="dumb"&&!("CI"in A.env)),go=I.blue(rt?"\u2139":"i"),wo=I.green(rt?"\u2714":"\u221A"),bo=I.yellow(rt?"\u26A0":"\u203C"),xo=I.red(rt?"\u2716\uFE0F":"\xD7"),yo={frames:rt?["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]:["-","\\","|","/"],interval:80},Y,J,N,D,P,R,H,K,M,B,et,m,Z,tt,ht,le,pe,ue,he,me,fe,It=class{constructor(e={}){E(this,m);E(this,Y);E(this,J);E(this,N,-1);E(this,D);E(this,P);E(this,R);E(this,H);E(this,K,0);E(this,M);E(this,B);E(this,et,0);var o,s,n,i;let r=(o=e.spinner)!=null?o:yo;b(this,Y,r.frames),b(this,J,r.interval),b(this,P,(s=e.text)!=null?s:""),b(this,R,(n=e.stream)!=null?n:A.stderr),b(this,H,(i=e.color)!=null?i:"cyan"),b(this,B,fo(u(this,R))),b(this,M,x(this,m,fe).bind(this))}start(e){return e&&b(this,P,e),this.isSpinning?this:(x(this,m,pe).call(this),x(this,m,tt).call(this),x(this,m,he).call(this),b(this,D,setInterval(()=>{x(this,m,tt).call(this)},u(this,J))),this)}stop(e){return this.isSpinning?(clearInterval(u(this,D)),b(this,D,void 0),x(this,m,ue).call(this),this.clear(),x(this,m,me).call(this),e&&u(this,R).write(`${e}
5
- `),this):this}success(e){return x(this,m,Z).call(this,wo,e)}error(e){return x(this,m,Z).call(this,xo,e)}warning(e){return x(this,m,Z).call(this,bo,e)}info(e){return x(this,m,Z).call(this,go,e)}get isSpinning(){return u(this,D)!==void 0}get text(){return u(this,P)}set text(e){b(this,P,e!=null?e:""),x(this,m,tt).call(this)}get color(){return u(this,H)}set color(e){b(this,H,e),x(this,m,tt).call(this)}clear(){if(!u(this,B))return this;u(this,R).cursorTo(0);for(let e=0;e<u(this,K);e++)e>0&&u(this,R).moveCursor(0,-1),u(this,R).clearLine(1);return b(this,K,0),this}};Y=new WeakMap,J=new WeakMap,N=new WeakMap,D=new WeakMap,P=new WeakMap,R=new WeakMap,H=new WeakMap,K=new WeakMap,M=new WeakMap,B=new WeakMap,et=new WeakMap,m=new WeakSet,Z=function(e,r){return this.stop(`${e} ${r!=null?r:u(this,P)}`)},tt=function(){var n;let e=Date.now();(u(this,N)===-1||e-u(this,et)>=u(this,J))&&(b(this,N,++_t(this,N)._%u(this,Y).length),b(this,et,e));let r=(n=I[u(this,H)])!=null?n:I.cyan,o=u(this,Y)[u(this,N)],s=`${r(o)} ${u(this,P)}`;u(this,B)||(s+=`
6
- `),this.clear(),x(this,m,ht).call(this,s),u(this,B)&&b(this,K,x(this,m,le).call(this,s))},ht=function(e){u(this,R).write(e)},le=function(e){var n;let r=(n=u(this,R).columns)!=null?n:80,o=mo(e).split(`
7
- `),s=0;for(let i of o)s+=Math.max(1,Math.ceil(i.length/r));return s},pe=function(){u(this,B)&&x(this,m,ht).call(this,"\x1B[?25l")},ue=function(){u(this,B)&&x(this,m,ht).call(this,"\x1B[?25h")},he=function(){A.once("SIGINT",u(this,M)),A.once("SIGTERM",u(this,M))},me=function(){A.off("SIGINT",u(this,M)),A.off("SIGTERM",u(this,M))},fe=function(e){this.isSpinning&&this.stop();let r=e==="SIGINT"?130:e==="SIGTERM"?143:1;A.exit(r)};function At(t){return new It(t)}var mt=async(t,e,r)=>{process.platform==="win32"&&await T("git",["config","--global","core.longpaths","true"]);let o=`https://${t.token?t.token+"@":t.token}github.com/${t.owner}/${t.repository}.git`,s=z.resolve(vo.tmpdir(),`${t.repository}-${Date.now()}${Math.random().toString(16).slice(2,6)}`),n=W=>W.split(z.sep).join("/"),i=At(),a=performance.now();e.watch||i.start(`Picking ${t.type}${t.type==="repository"?" without .git":" from repository"}...`);let c=!!t.path&&t.path!=="."&&t.type!=="repository",p=c&&z.extname(t.path)!=="",d=c?n(p?z.dirname(t.path):t.path):"",g=!1;try{c?(await q.promises.mkdir(s,{recursive:!0}),await T("git",["clone",o,s,"--branch",t.branch,"--depth=1","--single-branch","--no-tags","--filter=blob:none","--sparse"]),await T("git",["sparse-checkout","init",...p?["--no-cone"]:["--cone"]],{cwd:s}),await T("git",["sparse-checkout","set",d],{cwd:s}),await T("git",["checkout"],{cwd:s}),e.recursive&&await T("git",["submodule","update","--init","--recursive"],{cwd:s}),g=!0):await T("git",["clone",o,s,"--branch",t.branch,"--depth=1","--single-branch","--no-tags",...e.recursive?["--recursive"]:[]])}catch(W){try{await T("git",["clone",o,s,...e.recursive?["--recursive"]:[]]),await T("git",["checkout",t.branch],{cwd:s})}catch(cs){throw new Error("Failed to clone repository")}}let v=z.resolve(s,t.path);(await q.promises.stat(v)).isDirectory()?(await q.promises.mkdir(r,{recursive:!0}),await Tt(v,r)):(await q.promises.mkdir(z.dirname(r),{recursive:!0}),await q.promises.copyFile(v,r)),e.watch?console.log("- Synced at "+new Date().toLocaleTimeString()):i.success(`Picked ${t.type}${t.type==="repository"?" without .git":" from repository"} in ${((performance.now()-a)/1e3).toFixed(2)} seconds${g?k(" (sparse)"):""}.`),await q.promises.rm(s,{recursive:!0,force:!0})};function Ot(t){if(typeof t=="number"||/^\d+$/.test(t))return typeof t=="number"?t:parseInt(t,10);let e=/(\d+)([hms])/g,r=0,o;for(;(o=e.exec(t))!==null;){let s=parseInt(o[1],10);switch(o[2]){case"h":r+=s*36e5;break;case"m":r+=s*6e4;break;case"s":r+=s*1e3;break}}return r}var de=async t=>{var s,n;let e=(await T("git",["ls-remote",t])).stdout,r=(s=e.match(/(.+)\s+HEAD/))==null?void 0:s[1],o=(n=e.match(new RegExp(`${r}\\s+refs/heads/(.+)`)))==null?void 0:n[1];if(!o)throw new Error("Could not determine default branch!");return o};async function ge(t,{branch:e,target:r}){let o=/^https:\/\/([^@]+)@github\.com/,s=t.match(o),n="";s&&(n=s[1],t=t.replace(o,"https://github.com"));let i=["git@github.com:","https://github.com/","https://raw.githubusercontent.com/"];for(let W of i)if(t.startsWith(W)){t=t.replace(W,"");break}let a=t.split("/"),c=a[0],p=a[1].endsWith(".git")?a[1].slice(0,-4):a[1],d=a[2]==="blob"?"blob":a[2]==="tree"?"tree":a[2]+a[3]==="refsheads"?"raw":"repository",g=e||(d==="repository"?await de(`https://${n&&n+"@"}github.com/${c}/${p}`):d==="raw"?a[4]:a[3]),v=d?d==="raw"?a.slice(5).join("/"):a.slice(4).join("/"):a.slice(2).join("/")||"/",w=r||(d==="blob"?".":v.split("/").pop()||p);return{token:n,owner:c,repository:p,type:d,branch:g,path:v,target:w}}var it={};Ft(it,{beep:()=>Jo,clearScreen:()=>Ho,clearTerminal:()=>Uo,cursorBackward:()=>Co,cursorDown:()=>ko,cursorForward:()=>Ro,cursorGetPosition:()=>Oo,cursorHide:()=>Mo,cursorLeft:()=>ze,cursorMove:()=>So,cursorNextLine:()=>Po,cursorPrevLine:()=>Bo,cursorRestorePosition:()=>Ao,cursorSavePosition:()=>Io,cursorShow:()=>jo,cursorTo:()=>Eo,cursorUp:()=>qe,enterAlternativeScreen:()=>Vo,eraseDown:()=>Go,eraseEndLine:()=>Wo,eraseLine:()=>Qe,eraseLines:()=>Lo,eraseScreen:()=>Pt,eraseStartLine:()=>Fo,eraseUp:()=>_o,exitAlternativeScreen:()=>Yo,iTerm:()=>zo,image:()=>qo,link:()=>Ko,scrollDown:()=>Do,scrollUp:()=>No});import Bt from"process";var we,ft=((we=globalThis.window)==null?void 0:we.document)!==void 0,be,xe,wn=((xe=(be=globalThis.process)==null?void 0:be.versions)==null?void 0:xe.node)!==void 0,ye,ve,bn=((ve=(ye=globalThis.process)==null?void 0:ye.versions)==null?void 0:ve.bun)!==void 0,$e,Te,xn=((Te=($e=globalThis.Deno)==null?void 0:$e.version)==null?void 0:Te.deno)!==void 0,Ee,Se,yn=((Se=(Ee=globalThis.process)==null?void 0:Ee.versions)==null?void 0:Se.electron)!==void 0,ke,Re,vn=((Re=(ke=globalThis.navigator)==null?void 0:ke.userAgent)==null?void 0:Re.includes("jsdom"))===!0,$n=typeof WorkerGlobalScope!="undefined"&&globalThis instanceof WorkerGlobalScope,Tn=typeof DedicatedWorkerGlobalScope!="undefined"&&globalThis instanceof DedicatedWorkerGlobalScope,En=typeof SharedWorkerGlobalScope!="undefined"&&globalThis instanceof SharedWorkerGlobalScope,Sn=typeof ServiceWorkerGlobalScope!="undefined"&&globalThis instanceof ServiceWorkerGlobalScope,Ce,Ie,ot=(Ie=(Ce=globalThis.navigator)==null?void 0:Ce.userAgentData)==null?void 0:Ie.platform,Ae,Oe,Pe,Be,kn=ot==="macOS"||((Ae=globalThis.navigator)==null?void 0:Ae.platform)==="MacIntel"||((Pe=(Oe=globalThis.navigator)==null?void 0:Oe.userAgent)==null?void 0:Pe.includes(" Mac "))===!0||((Be=globalThis.process)==null?void 0:Be.platform)==="darwin",Me,je,Rn=ot==="Windows"||((Me=globalThis.navigator)==null?void 0:Me.platform)==="Win32"||((je=globalThis.process)==null?void 0:je.platform)==="win32",Le,We,Fe,Ge,_e,Cn=ot==="Linux"||((We=(Le=globalThis.navigator)==null?void 0:Le.platform)==null?void 0:We.startsWith("Linux"))===!0||((Ge=(Fe=globalThis.navigator)==null?void 0:Fe.userAgent)==null?void 0:Ge.includes(" Linux "))===!0||((_e=globalThis.process)==null?void 0:_e.platform)==="linux",Ne,De,He,In=ot==="iOS"||((Ne=globalThis.navigator)==null?void 0:Ne.platform)==="MacIntel"&&((De=globalThis.navigator)==null?void 0:De.maxTouchPoints)>1||/iPad|iPhone|iPod/.test((He=globalThis.navigator)==null?void 0:He.platform),Ue,Ve,Ye,Je,An=ot==="Android"||((Ue=globalThis.navigator)==null?void 0:Ue.platform)==="Android"||((Ye=(Ve=globalThis.navigator)==null?void 0:Ve.userAgent)==null?void 0:Ye.includes(" Android "))===!0||((Je=globalThis.process)==null?void 0:Je.platform)==="android";var h="\x1B[",nt="\x1B]",Q="\x07",st=";",Ke=!ft&&Bt.env.TERM_PROGRAM==="Apple_Terminal",$o=!ft&&Bt.platform==="win32",To=ft?()=>{throw new Error("`process.cwd()` only works in Node.js, not the browser.")}:Bt.cwd,Eo=(t,e)=>{if(typeof t!="number")throw new TypeError("The `x` argument is required");return typeof e!="number"?h+(t+1)+"G":h+(e+1)+st+(t+1)+"H"},So=(t,e)=>{if(typeof t!="number")throw new TypeError("The `x` argument is required");let r="";return t<0?r+=h+-t+"D":t>0&&(r+=h+t+"C"),e<0?r+=h+-e+"A":e>0&&(r+=h+e+"B"),r},qe=(t=1)=>h+t+"A",ko=(t=1)=>h+t+"B",Ro=(t=1)=>h+t+"C",Co=(t=1)=>h+t+"D",ze=h+"G",Io=Ke?"\x1B7":h+"s",Ao=Ke?"\x1B8":h+"u",Oo=h+"6n",Po=h+"E",Bo=h+"F",Mo=h+"?25l",jo=h+"?25h",Lo=t=>{let e="";for(let r=0;r<t;r++)e+=Qe+(r<t-1?qe():"");return t&&(e+=ze),e},Wo=h+"K",Fo=h+"1K",Qe=h+"2K",Go=h+"J",_o=h+"1J",Pt=h+"2J",No=h+"S",Do=h+"T",Ho="\x1Bc",Uo=$o?`${Pt}${h}0f`:`${Pt}${h}3J${h}H`,Vo=h+"?1049h",Yo=h+"?1049l",Jo=Q,Ko=(t,e)=>[nt,"8",st,st,e,Q,t,nt,"8",st,st,Q].join(""),qo=(t,e={})=>{let r=`${nt}1337;File=inline=1`;return e.width&&(r+=`;width=${e.width}`),e.height&&(r+=`;height=${e.height}`),e.preserveAspectRatio===!1&&(r+=";preserveAspectRatio=0"),r+":"+Buffer.from(t).toString("base64")+Q},zo={setCwd:(t=To())=>`${nt}50;CurrentDir=${t}${Q}`,annotation(t,e={}){let r=`${nt}1337;`,o=e.x!==void 0,s=e.y!==void 0;if((o||s)&&!(o&&s&&e.length!==void 0))throw new Error("`x`, `y` and `length` must be defined when `x` or `y` is defined");return t=t.replaceAll("|",""),r+=e.isHidden?"AddHiddenAnnotation=":"AddAnnotation=",e.length>0?r+=(o?[t,e.length,e.x,e.y]:[e.length,t]).join("|"):r+=t,r+Q}};import at from"process";import Mt from"process";import Qo from"os";import Xe from"tty";function S(t,e=globalThis.Deno?globalThis.Deno.args:Mt.argv){let r=t.startsWith("-")?"":t.length===1?"-":"--",o=e.indexOf(r+t),s=e.indexOf("--");return o!==-1&&(s===-1||o<s)}var{env:f}=Mt,dt;S("no-color")||S("no-colors")||S("color=false")||S("color=never")?dt=0:(S("color")||S("colors")||S("color=true")||S("color=always"))&&(dt=1);function Xo(){if(!("FORCE_COLOR"in f))return;if(f.FORCE_COLOR==="true")return 1;if(f.FORCE_COLOR==="false")return 0;if(f.FORCE_COLOR.length===0)return 1;let t=Math.min(Number.parseInt(f.FORCE_COLOR,10),3);if([0,1,2,3].includes(t))return t}function Zo(t){return t===0?!1:{level:t,hasBasic:!0,has256:t>=2,has16m:t>=3}}function ts(t,{streamIsTTY:e,sniffFlags:r=!0}={}){let o=Xo();o!==void 0&&(dt=o);let s=r?dt:o;if(s===0)return 0;if(r){if(S("color=16m")||S("color=full")||S("color=truecolor"))return 3;if(S("color=256"))return 2}if("TF_BUILD"in f&&"AGENT_NAME"in f)return 1;if(t&&!e&&s===void 0)return 0;let n=s||0;if(f.TERM==="dumb")return n;if(Mt.platform==="win32"){let i=Qo.release().split(".");return Number(i[0])>=10&&Number(i[2])>=10586?Number(i[2])>=14931?3:2:1}if("CI"in f)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(i=>i in f)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(i=>i in f)||f.CI_NAME==="codeship"?1:n;if("TEAMCITY_VERSION"in f)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(f.TEAMCITY_VERSION)?1:0;if(f.COLORTERM==="truecolor"||f.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in f){let i=Number.parseInt((f.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(f.TERM_PROGRAM){case"iTerm.app":return i>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(f.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(f.TERM)||"COLORTERM"in f?1:n}function gt(t,e={}){let r=ts(t,y({streamIsTTY:t&&t.isTTY},e));return Zo(r)}var Gn={stdout:gt({isTTY:Xe.isatty(1)}),stderr:gt({isTTY:Xe.isatty(2)})};import es from"process";function j(t,e=es.argv){let r=t.startsWith("-")?"":t.length===1?"-":"--",o=e.indexOf(r+t),s=e.indexOf("--");return o!==-1&&(s===-1||o<s)}function Ze(t=""){var r;if(/^\d{3,4}$/.test(t)){let o=(r=/(\d{1,2})(\d{2})/.exec(t))!=null?r:[];return{major:0,minor:Number.parseInt(o[1],10),patch:Number.parseInt(o[2],10)}}let e=(t!=null?t:"").split(".").map(o=>Number.parseInt(o,10));return{major:e[0],minor:e[1],patch:e[2]}}function tr(t){let{CI:e,FORCE_HYPERLINK:r,NETLIFY:o,TEAMCITY_VERSION:s,TERM_PROGRAM:n,TERM_PROGRAM_VERSION:i,VTE_VERSION:a,TERM:c}=at.env;if(r)return!(r.length>0&&Number.parseInt(r,10)===0);if(j("no-hyperlink")||j("no-hyperlinks")||j("hyperlink=false")||j("hyperlink=never"))return!1;if(j("hyperlink=true")||j("hyperlink=always")||o)return!0;if(!gt(t)||t&&!t.isTTY)return!1;if("WT_SESSION"in at.env)return!0;if(at.platform==="win32"||e||s)return!1;if(n){let p=Ze(i);switch(n){case"iTerm.app":return p.major===3?p.minor>=1:p.major>3;case"WezTerm":return p.major>=20200620;case"vscode":return p.major>1||p.major===1&&p.minor>=72;case"ghostty":return!0}}if(a){if(a==="0.50.0")return!1;let p=Ze(a);return p.major>0||p.minor>=50}switch(c){case"alacritty":return!0}return!1}var rs={stdout:tr(at.stdout),stderr:tr(at.stderr)},wt=rs;function L(t,e,s={}){var n=s,{target:r="stdout"}=n,o=X(n,["target"]);return wt[r]?it.link(t,e):o.fallback===!1?t:typeof o.fallback=="function"?o.fallback(t,e):`${t} (\u200B${e}\u200B)`}L.isSupported=wt.stdout;L.stderr=(t,e,r={})=>L(t,e,y({target:"stderr"},r));L.stderr.isSupported=wt.stderr;var rr="gitpick",or="4.13.0-canary.9";var ns=`
8
- With ${C(`${L("GitPick","https://github.com/nrjdalal/gitpick")}`)} clone specific directories or files from GitHub!
9
-
10
- $ gitpick ${_("<url>")} ${k("[target]")} ${$("[options]")}
11
-
12
- ${C("Hint:")}
13
- [target] and [options] are optional and if not specified,
14
- GitPick fallbacks to the default behavior of \`git clone\`
15
-
16
- ${C("Arguments:")}
17
- ${_("url")} GitHub URL with path to file/folder/repository
18
- ${k("target")} Directory to clone into (optional)
19
-
20
- ${C("Options:")}
21
- ${$("-b, --branch ")} Branch/SHA to clone
22
- ${$("-o, --overwrite")} Skip overwrite prompt
23
- ${$("-r, --recursive")} Clone submodules
24
- ${$("-w, --watch [time]")} Watch the repository and sync every [time]
25
- (e.g. 1h, 30m, 15s)
26
- ${$("-h, --help")} display help for command
27
- ${$("-v, --version")} display the version number
28
-
29
- ${C("Examples:")}
30
- $ gitpick <url>
31
- $ gitpick <url> [target]
32
- $ gitpick <url> [target] -b [branch/SHA]
33
- $ gitpick <url> [target] -w [time]
34
- $ gitpick <url> [target] -b [branch/SHA] -w [time]
35
-
36
- \u{1F680} More awesome tools at ${$("https://github.com/nrjdalal")}`,is=t=>{try{return ss(t)}catch(e){throw new Error(`Error parsing arguments: ${e.message}`)}},as=async()=>{try{let{positionals:t,values:e}=is({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"}}});t.length||(e.version&&(console.log(`
37
- ${rr}@${or}`),process.exit(0)),console.log(ns),process.exit(0)),t[0]==="clone"&&t.shift();let[r,o]=t,s={branch:e.branch,force:e.force,overwrite:e.overwrite,recursive:e.recursive,watch:e.watch};console.log(`
38
- With ${C(`${L("GitPick","https://github.com/nrjdalal/gitpick")}`)} clone specific directories or files from GitHub!`);let n=await ge(r,{branch:s.branch,target:o});if(n.type==="blob"){let a=n.target.split("/").filter(p=>p!==""),c=a[a.length-1];c!=="."&&c!==".."&&c.includes(".")?a.pop():c=n.path.split("/").pop()||c,n.target=[...a,c].join("/")}console.info(`
39
- ${k("\u2714")} ${n.owner}/${n.repository} ${$(n.type+":"+n.branch)} ${n.type==="repository"?`> ${k(n.target)}`:`${n.path.length?_(n.path)+" >":">"} ${k(n.target)}`}`);let i=os.resolve(n.target);if(s.overwrite=s.overwrite||s.force,s.watch&&(s.overwrite=!0),sr.existsSync(i)&&!s.overwrite&&(n.type==="blob"&&(console.log(`${_(`
40
- Warning: The target file exists at ${k(n.target)}. Use ${$("-f")} or ${$("-o")} to overwrite.`)}`),process.exit(1)),(await sr.promises.readdir(i)).length&&(console.log(`${_(`
41
- Warning: The target directory exists at ${k(n.target)} and is not empty. Use ${$("-f")} or ${$("-o")} to overwrite.`)}`),process.exit(1))),s.watch){console.log(`
42
- \u{1F440} Watching every ${Ot(s.watch)/1e3+"s"}
43
- `),await mt(n,s,i);let a=Ot(s.watch);setInterval(async()=>await mt(n,s,i),a)}else await mt(n,s,i),process.exit(0)}catch(t){t instanceof Error?console.log(C(`
44
- ${ut("Error: ")}`)+t.message):console.log(C(`${ut(`
45
- Unexpected Error: `)}`)+JSON.stringify(t,null,2)),process.exit(1)}};as();