gitpick 4.14.0 ā 4.15.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 +24 -0
- package/dist/index.mjs +22 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,6 +59,7 @@ npx gitpick https://<token>@github.com/owner/repo
|
|
|
59
59
|
- š¦ Can easily clone all submodules with `-r` | `--recursive`
|
|
60
60
|
- š Sync changes remotely with `--watch` using intervals (e.g., `15s`, `1m`, `1h`)
|
|
61
61
|
- š Seamlessly works with both public and private repositories using a PAT
|
|
62
|
+
- š Config file support (`.gitpick.json` / `.gitpick.jsonc`) for multi-path picks
|
|
62
63
|
|
|
63
64
|
---
|
|
64
65
|
|
|
@@ -114,6 +115,29 @@ npx gitpick https://<token>@github.com/owner/repo
|
|
|
114
115
|
|
|
115
116
|
---
|
|
116
117
|
|
|
118
|
+
## š Config File
|
|
119
|
+
|
|
120
|
+
Create a `.gitpick.json` or `.gitpick.jsonc` in your project to pick multiple files/folders in one command:
|
|
121
|
+
|
|
122
|
+
```jsonc
|
|
123
|
+
// .gitpick.jsonc
|
|
124
|
+
[
|
|
125
|
+
"owner/repo/tree/main/src",
|
|
126
|
+
"owner/repo/blob/main/README.md docs",
|
|
127
|
+
"other/repo/tree/main/configs my-configs",
|
|
128
|
+
]
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Then just run:
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
npx gitpick
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Each entry follows the same `<url> [target]` syntax as the CLI. All entries are cloned with `-o` (overwrite) by default.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
117
141
|
## š¦ Install Globally (Optional)
|
|
118
142
|
|
|
119
143
|
```sh
|
package/dist/index.mjs
CHANGED
|
@@ -1,36 +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{
|
|
3
|
-
|
|
4
|
-
|
|
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"yoctocolors";import p from"supports-hyperlinks";import ee from"node:tty";const m=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 m(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,h=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=g([],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)}},g=(e,n)=>e.at(-1)===n?e:g([...e,n],t.resolve(n,`..`)),_=async e=>{let[[t,n]]=await Promise.all([Promise.allSettled(e),v(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}},v=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})=>y(e))),t}},y=async e=>{let{stdin:t}=await e;t.end()},se=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=>ce(e))]),le(n,S(r)),C(n)}catch(e){throw await Promise.allSettled([i]),b(e,r,n)}},ce=async e=>{for await(let[t]of c(e,`error`))if(![`ERR_STREAM_PREMATURE_CLOSE`,`EPIPE`].includes(t?.code))throw t},le=({command:e},{exitCode:t,signalName:n})=>{if(n!==void 0)throw new x(`Command was terminated with ${n}: ${e}`);if(t!==void 0)throw new x(`Command failed with exit code ${t}: ${e}`)},b=(e,t,n)=>Object.assign(ue(e,n),S(t),C(n)),ue=(e,{command:t})=>e instanceof x?e:new x(`Command failed: ${t}`,{cause:e});var x=class extends Error{name=`SubprocessError`};const S=({exitCode:e,signalCode:t})=>({...e<1?{}:{exitCode:e},...t===null?{}:{signalName:t}}),C=({state:{stdout:e,stderr:t,output:n},command:r,start:i})=>({stdout:w(e),stderr:w(t),output:w(n),command:r,durationMs:Number(a.hrtime.bigint()-i)/1e6}),w=e=>e.at(-1)===`
|
|
4
|
+
`?e.slice(0,e.at(-2)===`\r`?-2:-1):e,de=async(e,t,n)=>await fe(e,n)?[E(e),t.map(e=>ge(e)),{...n,shell:!0}]:[e,t,n],fe=async(e,{shell:t,cwd:n,env:r=a.env})=>a.platform===`win32`&&!t&&!await pe(e,n,r),pe=async(e,t,{Path:n=``,PATH:r=n})=>T.some(t=>e.toLowerCase().endsWith(t))||(me[`${e}\0${t}\0${r}`]??=await he(e,t,r)),me={},he=async(e,n,r)=>{let i=r.split(t.delimiter).filter(Boolean).map(e=>e.replace(/^"(.*)"$/,`$1`));try{await Promise.all(T.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},T=[`.exe`,`.com`],ge=e=>E(E(`"${e.replaceAll(/(\\*)"/g,`$1$1\\"`).replace(/(\\*)$/,`$1$1`)}"`)),E=e=>e.replaceAll(/([()\][%!^"`<>&|;, *?])/g,`^$1`),D=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 de(e,t,n));return O(i.stdout,r,`stdout`),O(i.stderr,r,`stderr`),i.once(`error`,()=>{}),await l(i,`spawn`),i}catch(e){throw b(e,{},r)}},O=(e,{state:t},n)=>{e&&(e.setEncoding(`utf8`),t.isIterating||(t.isIterating=!1,e.on(`data`,e=>{t[n]+=e,t.output+=e})))};function k(e,t,n,r){let[i=[],a={}]=Array.isArray(t)?[t,n]:[[],t],o=te([e,...i]),s=ae(a),c=D(e,i,s,o),l=se(c,s,o);Object.assign(l,{nodeChildProcess:c}),l=r?_([r,l]):l;let u=h(l,o,`stdout`),d=h(l,o,`stderr`);return Object.assign(l,{nodeChildProcess:c,stdout:u,stderr:d,[Symbol.asyncIterator]:()=>re(u,d),pipe:(e,t,n)=>k(e,t,n,l)})}const A=a.platform!==`win32`||!!a.env.WT_SESSION,j=e=>!!(e.isTTY&&a.env.TERM!==`dumb`&&!(`CI`in a.env)),M=f.blue(A?`ā¹`:`i`),N=f.green(A?`ā`:`ā`),P=f.yellow(A?`ā `:`ā¼`),F=f.red(A?`āļø`:`Ć`),I={frames:A?[`ā `,`ā `,`ā ¹`,`ā ø`,`ā ¼`,`ā “`,`ā ¦`,`ā §`,`ā `,`ā `]:[`-`,`\\`,`|`,`/`],interval:80};var L=class{#e;#t;#n=-1;#r;#i;#a;#o;#s=0;#c;#l;#u=0;constructor(e={}){let t=e.spinner??I;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=j(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(N,e)}error(e){return this.#d(F,e)}warning(e){return this.#d(P,e)}info(e){return this.#d(M,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=f[this.#o]??f.cyan,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
|
|
7
|
-
|
|
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 _e(e){return new L(e)}const R=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=_e(),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 m(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 ve=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 ye(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 ve(`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`),be=()=>``,xe=(e,t,n)=>e.slice(t,n).replace(/[^ \t\r\n]/g,` `),Se=(e,t)=>{let n=t-1,r=0;for(;e[n]===`\\`;)--n,r+=1;return!!(r%2)};function Ce(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?xe:be,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===`"`&&(Se(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
|
+
`){t++,a=!1,s+=r(e,o,t),o=t;continue}else if(a===B&&u===`
|
|
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 we=[`.gitpick.json`,`.gitpick.jsonc`],Te=async()=>{let n;for(let r of we){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(Ce(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 k(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;const Ee=!H&&a.platform===`win32`,De=!H&&(a.env.TERM?.startsWith(`screen`)||a.env.TERM?.startsWith(`tmux`)||a.env.TMUX!==void 0);H||a.cwd;const W=e=>De?`\x1BPtmux;`+e.replaceAll(`\x1B`,`\x1B\x1B`)+`\x1B\\`:e,G=`\x1B[2J`;`${G}`,(()=>{if(H||!Ee)return!1;let e=i.release().split(`.`),t=Number(e[0]),n=Number(e[2]??0);return t<10||t===10&&n<10586})(),`${G}`;const K=(e,t)=>{let n=W(`]8;;${t}`),r=W(`\x1B]8;;\x07`);return n+e+r};function q(e,t,{target:n=`stdout`,...r}={}){return p[n]?K(e,t):r.fallback===!1?e:typeof r.fallback==`function`?r.fallback(e,t):`${e} (\u200B${t}\u200B)`}q.isSupported=p.stdout,q.stderr=(e,t,n={})=>q(e,t,{target:`stderr`,...n}),q.stderr.isSupported=p.stderr;const Oe=ee?.WriteStream?.prototype?.hasColors?.()??!1,J=(e,t)=>{if(!Oe)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(0,0);const Y=J(1,22);J(2,22),J(3,23),J(4,24),J(53,55),J(7,27),J(8,28),J(9,29),J(30,39);const X=J(31,39),Z=J(32,39),Q=J(33,39);J(34,39),J(35,39);const $=J(36,39);J(37,39),J(90,39),J(40,49),J(41,49),J(42,49),J(43,49),J(44,49),J(45,49),J(46,49),J(47,49),J(100,49),J(91,39),J(92,39),J(93,39),J(94,39),J(95,39),J(96,39),J(97,39),J(101,49),J(102,49),J(103,49),J(104,49),J(105,49),J(106,49),J(107,49);var ke=`gitpick`,Ae=`4.15.0-canary.0`;const je=`
|
|
10
|
+
With ${Y(`${q(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific directories or files from GitHub!
|
|
8
11
|
|
|
9
|
-
$ gitpick ${
|
|
12
|
+
$ gitpick ${Q(`<url>`)} ${Z(`[target]`)} ${$(`[options]`)}
|
|
10
13
|
|
|
11
|
-
${
|
|
14
|
+
${Y(`Hint:`)}
|
|
12
15
|
[target] and [options] are optional and if not specified,
|
|
13
16
|
GitPick fallbacks to the default behavior of \`git clone\`
|
|
14
17
|
|
|
15
|
-
${
|
|
16
|
-
${
|
|
17
|
-
${
|
|
18
|
+
${Y(`Arguments:`)}
|
|
19
|
+
${Q(`url`)} GitHub URL with path to file/folder/repository
|
|
20
|
+
${Z(`target`)} Directory to clone into (optional)
|
|
18
21
|
|
|
19
|
-
${
|
|
20
|
-
${
|
|
21
|
-
${
|
|
22
|
-
${
|
|
23
|
-
${
|
|
22
|
+
${Y(`Options:`)}
|
|
23
|
+
${$(`-b, --branch `)} Branch/SHA to clone
|
|
24
|
+
${$(`-o, --overwrite`)} Skip overwrite prompt
|
|
25
|
+
${$(`-r, --recursive`)} Clone submodules
|
|
26
|
+
${$(`-w, --watch [time]`)} Watch the repository and sync every [time]
|
|
24
27
|
(e.g. 1h, 30m, 15s)
|
|
25
|
-
${
|
|
26
|
-
${
|
|
28
|
+
${$(`-h, --help`)} display help for command
|
|
29
|
+
${$(`-v, --version`)} display the version number
|
|
27
30
|
|
|
28
|
-
${
|
|
31
|
+
${Y(`Examples:`)}
|
|
29
32
|
$ gitpick <url>
|
|
30
33
|
$ gitpick <url> [target]
|
|
31
34
|
$ gitpick <url> [target] -b [branch/SHA]
|
|
32
35
|
$ gitpick <url> [target] -w [time]
|
|
33
36
|
$ gitpick <url> [target] -b [branch/SHA] -w [time]
|
|
34
37
|
|
|
35
|
-
š More awesome tools at ${
|
|
38
|
+
š More awesome tools at ${$(`https://github.com/nrjdalal`)}`,Me=e=>{try{return n(e)}catch(e){throw Error(`Error parsing arguments: ${e.message}`)}};(async()=>{try{let{positionals:n,values:r}=Me({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${ke}@${Ae}`),process.exit(0)),await Te()&&process.exit(0),console.log(je),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 ${Y(`${q(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific files, folders, branches, commits and more from GitHub!`);let s=await ye(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${Z(`ā`)} ${s.owner}/${s.repository} ${$(s.type+`:`+s.branch)} ${s.type===`repository`?`> ${Z(s.target)}`:`${s.path.length?Q(s.path)+` >`:`>`} ${Z(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(`${Q(`\nWarning: The target file exists at ${Z(s.target)}. Use ${$(`-f`)} or ${$(`-o`)} to overwrite.`)}`),process.exit(1)),(await e.promises.readdir(c)).length&&(console.log(`${Q(`\nWarning: The target directory exists at ${Z(s.target)} and is not empty. Use ${$(`-f`)} or ${$(`-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(Y(`\n${X(`Error: `)}`)+e.message):console.log(Y(`${X(`
|
|
36
39
|
Unexpected Error: `)}`)+JSON.stringify(e,null,2)),process.exit(1)}})();export{};
|