gitpick 4.17.0 → 4.18.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
@@ -113,6 +113,8 @@ npx gitpick https://bitbucket.org/owner/repo # Bitbucket
113
113
  -w, --watch [time] Watch the repository and sync every [time]
114
114
  (e.g. 1h, 30m, 15s)
115
115
  --tree List copied files as a tree
116
+ -q, --quiet Suppress all output except errors
117
+ --verbose Show detailed clone information
116
118
  -h, --help display help for command
117
119
  -v, --version display the version number
118
120
  ```
package/dist/index.mjs CHANGED
@@ -1,33 +1,35 @@
1
1
  #!/usr/bin/env node
2
- import e from"node:fs";import t from"node:os";import n from"node:path";import{parseArgs as r,stripVTControlCharacters as i}from"node:util";import a from"node:tty";import{spawn as o}from"node:child_process";import{once as s}from"node:events";import c from"node:fs/promises";import l from"node:process";import{fileURLToPath as u}from"node:url";const d=a?.WriteStream?.prototype?.hasColors?.()??!1,f=(e,t)=>{if(!d)return e=>e;let n=`\u001B[${e}m`,r=`\u001B[${t}m`;return e=>{let i=e+``,a=i.indexOf(r);if(a===-1)return n+i+r;let o=n,s=0,c=(t===22?r:``)+n;for(;a!==-1;)o+=i.slice(s,a)+c,s=a+r.length,a=i.indexOf(r,s);return o+=i.slice(s)+r,o}},p=f(1,22),m=f(31,39),h=f(32,39),g=f(33,39),_=f(36,39);var v=class extends Error{constructor(...e){super(...e),this.name=`SubprocessError`,this.stdout=``,this.stderr=``}};const y=[`.exe`,`.com`],b={},x=e=>(...t)=>b[t.join(`\0`)]??=e(...t),S=x(async(...e)=>{try{return await c.access(e[0]),!0}catch{return!1}}),C=x(async(e,t,r)=>{let i=r.split(n.delimiter).filter(Boolean).map(e=>e.replace(/^"(.*)"$/,`$1`));try{await Promise.any([t,...i].flatMap(t=>y.map(r=>S(`${n.resolve(t,e)}${r}`))))}catch{return!1}return!0}),w=async(e,t)=>l.platform===`win32`&&!t.shell&&!y.some(t=>e.toLowerCase().endsWith(t))&&!await C(e,t.cwd??`.`,(l.env.PATH||l.env.Path)??``),T=e=>e.replaceAll(/([()\][%!^"`<>&|;, *?])/g,`^$1`),E=e=>T(T(`"${e.replaceAll(/(\\*)"/g,`$1$1\\"`).replace(/(\\*)$/,`$1$1`)}"`)),D=e=>/[^\w./-]/.test(e)?`'${e.replaceAll(`'`,`'\\''`)}'`:e;async function O(e,t=[],r={}){let{stdin:a,stdout:c,stderr:d,stdio:f,cwd:p=`.`,env:m,...h}=r,g=p instanceof URL?u(p):n.resolve(p),_=m?{...l.env,...m}:void 0,y=f??[a,c,d],b=[e,...t].map(e=>D(i(e))).join(` `);[`node`,`node.exe`].includes(e.toLowerCase())&&(e=l.execPath,t=[...l.execArgv.filter(e=>!e.startsWith(`--inspect`)),...t]);let x={...h,stdio:y,env:_,cwd:g};await w(e,x)&&(t=t.map(e=>E(e)),e=T(e),x={...x,shell:!0}),x.shell&&t.length>0&&(e=[e,...t].join(` `),t=[]);let S=o(e,t,x),C=``,O=``;S.stdout&&(S.stdout.setEncoding(`utf8`),S.stdout.on(`data`,e=>C+=e)),S.stderr&&(S.stderr.setEncoding(`utf8`),S.stderr.on(`data`,e=>O+=e)),S.once(`error`,()=>{});try{await s(S,`spawn`)}catch(e){throw Object.assign(new v(`Command failed: ${b}`,{cause:e}),{stdout:C,stderr:O})}await s(S,`close`);let k=e=>e.at(-1)===`
3
- `?e.slice(0,e.at(-2)===`\r`?-2:-1):e;if(S.exitCode&&S.exitCode>0)throw Object.assign(new v(`Command failed with exit code ${S.exitCode}: ${b}`),{stdout:k(C),stderr:k(O),exitCode:S.exitCode});if(S.signalCode)throw Object.assign(new v(`Command was terminated with ${S.signalCode}: ${b}`),{stdout:k(C),stderr:k(O)});return{stdout:k(C),stderr:k(O)}}const k=l.platform!==`win32`||!!l.env.WT_SESSION||l.env.TERM_PROGRAM===`vscode`,A=e=>!!(e.isTTY&&l.env.TERM!==`dumb`&&!(`CI`in l.env)),j=h(k?`✔`:`√`),M=k?[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`]:[`-`,`\\`,`|`,`/`],N=(e={})=>{let t=-1,n,r=e.text??``,a=e.stream??l.stderr,o=A(a),s=0,c=0,u=!1,d=e=>a.write(e),f=()=>{if(!(!o||s===0)){a.cursorTo(0);for(let e=0;e<s;e++)e>0&&a.moveCursor(0,-1),a.clearLine(1);s=0}},p=e=>{let t=a.columns??80,n=i(e).split(`
4
- `),r=0;for(let e of n)r+=Math.max(1,Math.ceil(e.length/t));return r},m=()=>{let e=Date.now();(t===-1||e-c>=80)&&(t=++t%M.length,c=e);let n=M[t],i=`${_(n)} ${r}`;o?(f(),d(i),s=p(i)):d(i+`
5
- `)};return{start(e){return r=e,u=!0,o&&d(`\x1B[?25l`),m(),o&&(n=setInterval(m,80)),this},success(e){return u?(u=!1,n&&=(clearInterval(n),void 0),f(),o&&d(`\x1B[?25h`),d(`${j} ${e??r}\n`),this):this}}},P=async(t,r,i)=>{let a=i??r,o=await e.promises.readdir(t,{withFileTypes:!0});await e.promises.mkdir(r,{recursive:!0});let s=[];for(let i of o){if(i.name===`.git`)continue;let o=n.join(t,i.name),c=n.join(r,i.name);if(i.isDirectory())s.push(...await P(o,c,a));else if(i.isSymbolicLink()){let t=await e.promises.readlink(o);await e.promises.symlink(t,c),s.push(n.relative(a,c))}else await e.promises.copyFile(o,c),s.push(n.relative(a,c))}return s},F=async(r,i,a)=>{let o=i.tree;process.platform===`win32`&&await O(`git`,[`config`,`--global`,`core.longpaths`,`true`]);let s=`https://${r.token?r.token+`@`:r.token}${r.host}/${r.owner}/${r.repository}.git`,c=n.resolve(t.tmpdir(),`${r.repository}-${Date.now()}${Math.random().toString(16).slice(2,6)}`),l=N(),u=performance.now();!i.watch&&!o&&l.start(`Picking ${r.type}${r.type===`repository`?` without .git`:` from repository`}...`);try{await O(`git`,[`clone`,s,c,`--branch`,r.branch,`--depth`,`1`,`--single-branch`,...i.recursive?[`--recursive`]:[]])}catch{await O(`git`,[`clone`,s,c,...i.recursive?[`--recursive`]:[]]),await O(`git`,[`checkout`,r.branch],{cwd:c})}let d=n.resolve(c,r.path),f=await e.promises.stat(d),p=[];f.isDirectory()?(await e.promises.mkdir(a,{recursive:!0}),p=await P(d,a)):(await e.promises.mkdir(n.dirname(a),{recursive:!0}),await e.promises.copyFile(d,a),p=[n.basename(a)]);let m=Number(((performance.now()-u)/1e3).toFixed(2));return o||(i.watch?console.log(`- Synced at `+new Date().toLocaleTimeString()):l.success(`Picked ${r.type}${r.type===`repository`?` without .git`:` from repository`} in ${m} seconds.`)),await e.promises.rm(c,{recursive:!0,force:!0}),{files:p,duration:m}};function I(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 L=async e=>{let t=(await O(`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},R=[{prefix:`git@github.com:`,host:`github.com`},{prefix:`https://github.com/`,host:`github.com`},{prefix:`https://raw.githubusercontent.com/`,host:`github.com`},{prefix:`git@gitlab.com:`,host:`gitlab.com`},{prefix:`https://gitlab.com/`,host:`gitlab.com`},{prefix:`git@bitbucket.org:`,host:`bitbucket.org`},{prefix:`https://bitbucket.org/`,host:`bitbucket.org`}];async function z(e,{branch:t,target:n}){let r=e.match(/^https:\/\/([^@]+)@(github\.com|gitlab\.com|bitbucket\.org)/),i=``;r&&(i=r[1],e=e.replace(`${r[1]}@`,``));let a=`github.com`;for(let{prefix:t,host:n}of R)if(e.startsWith(t)){a=n,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=`https://${i&&i+`@`}${a}/${s}/${c}`,u,d,f;a===`github.com`?o[2]===`refs`&&[`heads`,`tags`].includes(o[3])?(u=`raw`,d=t||o[4],f=o.slice(5).join(`/`)):o[2]===`refs`&&o[3]===`remotes`?(u=`raw`,d=t||`${o[4]}/${o[5]}`,f=o.slice(6).join(`/`)):o[2]===`blob`?(u=`blob`,d=t||o[3],f=o.slice(4).join(`/`)):o[2]===`tree`?(u=`tree`,d=t||o[3],f=o.slice(4).join(`/`)):o[2]===`commit`?(u=`repository`,d=t||o[3],f=``):(u=`repository`,d=t||await L(l),f=``):a===`gitlab.com`?o[2]===`-`&&o[3]===`blob`?(u=`blob`,d=t||o[4],f=o.slice(5).join(`/`)):o[2]===`-`&&o[3]===`tree`?(u=`tree`,d=t||o[4],f=o.slice(5).join(`/`)):(u=`repository`,d=t||await L(l),f=``):o[2]===`src`?(u=`tree`,d=t||o[3],f=o.slice(4).join(`/`)):(u=`repository`,d=t||await L(l),f=``);let p=n||(u===`blob`?`.`:f.split(`/`).pop()||c);return{token:i,host:a,owner:s,repository:c,type:u,branch:d,path:f,target:p}}const B=Symbol(`singleComment`),V=Symbol(`multiComment`),H=(e,t,n)=>e.slice(t,n).replace(/[^ \t\r\n]/g,` `),U=(e,t)=>{let n=t-1,r=0;for(;e[n]===`\\`;)--n,r+=1;return!!(r%2)};function W(e){if(typeof e!=`string`)throw TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof e}\``);let t=!1,n=!1,r=0,i=``,a=``,o=-1;for(let s=0;s<e.length;s++){let c=e[s],l=e[s+1];if(!n&&c===`"`&&(U(e,s)||(t=!t)),!t)if(!n&&c+l===`//`)i+=e.slice(r,s),r=s,n=B,s++;else if(n===B&&c+l===`\r
6
- `){s++,n=!1,i+=H(e,r,s),r=s;continue}else if(n===B&&c===`
7
- `)n=!1,i+=H(e,r,s),r=s;else if(!n&&c+l===`/*`){i+=e.slice(r,s),r=s,n=V,s++;continue}else if(n===V&&c+l===`*/`){s++,n=!1,i+=H(e,r,s+1),r=s+1;continue}else n||(o===-1?c===`,`&&(a+=i+e.slice(r,s),i=``,r=s,o=s):c===`}`||c===`]`?(i+=e.slice(r,s),a+=H(i,0,1)+i.slice(1),i=``,r=s,o=-1):c!==` `&&c!==` `&&c!==`\r`&&c!==`
8
- `&&(i+=e.slice(r,s),r=s,o=-1))}let s=n===B?H(e,r):e.slice(r);return a+i+s}const G=[`.gitpick.json`,`.gitpick.jsonc`],K=async()=>{let t;for(let r of G){let i=n.resolve(r);if(e.existsSync(i)){t=i;break}}if(!t)return!1;let r=await e.promises.readFile(t,`utf-8`),i=JSON.parse(W(r));if(!Array.isArray(i)||!i.every(e=>typeof e==`string`))throw Error(`${n.basename(t)} must be an array of strings`);for(let e of i)await O(process.argv[0],[...process.argv.slice(1),...e.split(/\s+/),`-o`],{stdio:`inherit`});return!0};var q=`gitpick`,J=`4.17.0`;const Y=(e,t)=>`\x1b]8;;${t}\x07${e}\x1b]8;;\x07`,X=`
9
- With ${p(`${Y(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific directories or files from GitHub, GitLab and Bitbucket!
2
+ import e from"node:fs";import t from"node:os";import n from"node:path";import{parseArgs as r,stripVTControlCharacters as i}from"node:util";import a from"node:tty";import{spawn as o}from"node:child_process";import{once as s}from"node:events";import c from"node:fs/promises";import l from"node:process";import{fileURLToPath as u}from"node:url";const d=a?.WriteStream?.prototype?.hasColors?.()??!1,f=(e,t)=>{if(!d)return e=>e;let n=`\u001B[${e}m`,r=`\u001B[${t}m`;return e=>{let i=e+``,a=i.indexOf(r);if(a===-1)return n+i+r;let o=n,s=0,c=(t===22?r:``)+n;for(;a!==-1;)o+=i.slice(s,a)+c,s=a+r.length,a=i.indexOf(r,s);return o+=i.slice(s)+r,o}},p=f(1,22),m=f(2,22),h=f(31,39),g=f(32,39),_=f(33,39),v=f(36,39);var y=class extends Error{constructor(...e){super(...e),this.name=`SubprocessError`,this.stdout=``,this.stderr=``}};const b=[`.exe`,`.com`],x={},S=e=>(...t)=>x[t.join(`\0`)]??=e(...t),C=S(async(...e)=>{try{return await c.access(e[0]),!0}catch{return!1}}),w=S(async(e,t,r)=>{let i=r.split(n.delimiter).filter(Boolean).map(e=>e.replace(/^"(.*)"$/,`$1`));try{await Promise.any([t,...i].flatMap(t=>b.map(r=>C(`${n.resolve(t,e)}${r}`))))}catch{return!1}return!0}),T=async(e,t)=>l.platform===`win32`&&!t.shell&&!b.some(t=>e.toLowerCase().endsWith(t))&&!await w(e,t.cwd??`.`,(l.env.PATH||l.env.Path)??``),E=e=>e.replaceAll(/([()\][%!^"`<>&|;, *?])/g,`^$1`),D=e=>E(E(`"${e.replaceAll(/(\\*)"/g,`$1$1\\"`).replace(/(\\*)$/,`$1$1`)}"`)),O=e=>/[^\w./-]/.test(e)?`'${e.replaceAll(`'`,`'\\''`)}'`:e;async function k(e,t=[],r={}){let{stdin:a,stdout:c,stderr:d,stdio:f,cwd:p=`.`,env:m,...h}=r,g=p instanceof URL?u(p):n.resolve(p),_=m?{...l.env,...m}:void 0,v=f??[a,c,d],b=[e,...t].map(e=>O(i(e))).join(` `);[`node`,`node.exe`].includes(e.toLowerCase())&&(e=l.execPath,t=[...l.execArgv.filter(e=>!e.startsWith(`--inspect`)),...t]);let x={...h,stdio:v,env:_,cwd:g};await T(e,x)&&(t=t.map(e=>D(e)),e=E(e),x={...x,shell:!0}),x.shell&&t.length>0&&(e=[e,...t].join(` `),t=[]);let S=o(e,t,x),C=``,w=``;S.stdout&&(S.stdout.setEncoding(`utf8`),S.stdout.on(`data`,e=>C+=e)),S.stderr&&(S.stderr.setEncoding(`utf8`),S.stderr.on(`data`,e=>w+=e)),S.once(`error`,()=>{});try{await s(S,`spawn`)}catch(e){throw Object.assign(new y(`Command failed: ${b}`,{cause:e}),{stdout:C,stderr:w})}await s(S,`close`);let k=e=>e.at(-1)===`
3
+ `?e.slice(0,e.at(-2)===`\r`?-2:-1):e;if(S.exitCode&&S.exitCode>0)throw Object.assign(new y(`Command failed with exit code ${S.exitCode}: ${b}`),{stdout:k(C),stderr:k(w),exitCode:S.exitCode});if(S.signalCode)throw Object.assign(new y(`Command was terminated with ${S.signalCode}: ${b}`),{stdout:k(C),stderr:k(w)});return{stdout:k(C),stderr:k(w)}}const A=l.platform!==`win32`||!!l.env.WT_SESSION||l.env.TERM_PROGRAM===`vscode`,j=e=>!!(e.isTTY&&l.env.TERM!==`dumb`&&!(`CI`in l.env)),M=g(A?`✔`:`√`),N=A?[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`]:[`-`,`\\`,`|`,`/`],P=(e={})=>{let t=-1,n,r=e.text??``,a=e.stream??l.stderr,o=j(a),s=0,c=0,u=!1,d=e=>a.write(e),f=()=>{if(!(!o||s===0)){a.cursorTo(0);for(let e=0;e<s;e++)e>0&&a.moveCursor(0,-1),a.clearLine(1);s=0}},p=e=>{let t=a.columns??80,n=i(e).split(`
4
+ `),r=0;for(let e of n)r+=Math.max(1,Math.ceil(e.length/t));return r},m=()=>{let e=Date.now();(t===-1||e-c>=80)&&(t=++t%N.length,c=e);let n=N[t],i=`${v(n)} ${r}`;o?(f(),d(i),s=p(i)):d(i+`
5
+ `)};return{start(e){return r=e,u=!0,o&&d(`\x1B[?25l`),m(),o&&(n=setInterval(m,80)),this},success(e){return u?(u=!1,n&&=(clearInterval(n),void 0),f(),o&&d(`\x1B[?25h`),d(`${M} ${e??r}\n`),this):this}}},F=async(t,r,i)=>{let a=i??r,o=await e.promises.readdir(t,{withFileTypes:!0});await e.promises.mkdir(r,{recursive:!0});let s=[];for(let i of o){if(i.name===`.git`)continue;let o=n.join(t,i.name),c=n.join(r,i.name);if(i.isDirectory())s.push(...await F(o,c,a));else if(i.isSymbolicLink()){let t=await e.promises.readlink(o);await e.promises.symlink(t,c),s.push(n.relative(a,c))}else await e.promises.copyFile(o,c),s.push(n.relative(a,c))}return s},I=async(r,i,a)=>{let o=i.tree||i.quiet,s=i.verbose&&!o;process.platform===`win32`&&await k(`git`,[`config`,`--global`,`core.longpaths`,`true`]);let c=`https://${r.token?r.token+`@`:r.token}${r.host}/${r.owner}/${r.repository}.git`,l=`https://${r.host}/${r.owner}/${r.repository}.git`,u=n.resolve(t.tmpdir(),`${r.repository}-${Date.now()}${Math.random().toString(16).slice(2,6)}`),d=P(),f=performance.now();!i.watch&&!o&&d.start(`Picking ${r.type}${r.type===`repository`?` without .git`:` from repository`}...`);let p=`shallow`;try{await k(`git`,[`clone`,c,u,`--branch`,r.branch,`--depth`,`1`,`--single-branch`,...i.recursive?[`--recursive`]:[]])}catch{p=`full`,await k(`git`,[`clone`,c,u,...i.recursive?[`--recursive`]:[]]),await k(`git`,[`checkout`,r.branch],{cwd:u})}let h=n.resolve(u,r.path),g=await e.promises.stat(h),_=[];g.isDirectory()?(await e.promises.mkdir(a,{recursive:!0}),_=await F(h,a)):(await e.promises.mkdir(n.dirname(a),{recursive:!0}),await e.promises.copyFile(h,a),_=[n.basename(a)]);let y=Number(((performance.now()-f)/1e3).toFixed(2));return o||(i.watch?console.log(`- Synced at `+new Date().toLocaleTimeString()):d.success(`Picked ${r.type}${r.type===`repository`?` without .git`:` from repository`} in ${y} seconds.`)),s&&(console.log(m(` clone: ${p} (depth=${p===`shallow`?`1`:`full`})`)),console.log(m(` from: ${l} @ ${v(r.branch)}`)),console.log(m(` to: ${a}`)),console.log(m(` files: ${_.length}`)),console.log(m(` duration: ${y}s`))),await e.promises.rm(u,{recursive:!0,force:!0}),{files:_,duration:y}};function L(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 R=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},z=[{prefix:`git@github.com:`,host:`github.com`},{prefix:`https://github.com/`,host:`github.com`},{prefix:`https://raw.githubusercontent.com/`,host:`github.com`},{prefix:`git@gitlab.com:`,host:`gitlab.com`},{prefix:`https://gitlab.com/`,host:`gitlab.com`},{prefix:`git@bitbucket.org:`,host:`bitbucket.org`},{prefix:`https://bitbucket.org/`,host:`bitbucket.org`}];async function B(e,{branch:t,target:n}){let r=e.match(/^https:\/\/([^@]+)@(github\.com|gitlab\.com|bitbucket\.org)/),i=``;r&&(i=r[1],e=e.replace(`${r[1]}@`,``));let a=`github.com`;for(let{prefix:t,host:n}of z)if(e.startsWith(t)){a=n,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=`https://${i&&i+`@`}${a}/${s}/${c}`,u,d,f;a===`github.com`?o[2]===`refs`&&[`heads`,`tags`].includes(o[3])?(u=`raw`,d=t||o[4],f=o.slice(5).join(`/`)):o[2]===`refs`&&o[3]===`remotes`?(u=`raw`,d=t||`${o[4]}/${o[5]}`,f=o.slice(6).join(`/`)):o[2]===`blob`?(u=`blob`,d=t||o[3],f=o.slice(4).join(`/`)):o[2]===`tree`?(u=`tree`,d=t||o[3],f=o.slice(4).join(`/`)):o[2]===`commit`?(u=`repository`,d=t||o[3],f=``):(u=`repository`,d=t||await R(l),f=``):a===`gitlab.com`?o[2]===`-`&&o[3]===`blob`?(u=`blob`,d=t||o[4],f=o.slice(5).join(`/`)):o[2]===`-`&&o[3]===`tree`?(u=`tree`,d=t||o[4],f=o.slice(5).join(`/`)):(u=`repository`,d=t||await R(l),f=``):o[2]===`src`?(u=`tree`,d=t||o[3],f=o.slice(4).join(`/`)):(u=`repository`,d=t||await R(l),f=``);let p=n||(u===`blob`?`.`:f.split(`/`).pop()||c);return{token:i,host:a,owner:s,repository:c,type:u,branch:d,path:f,target:p}}const V=Symbol(`singleComment`),H=Symbol(`multiComment`),U=(e,t,n)=>e.slice(t,n).replace(/[^ \t\r\n]/g,` `),W=(e,t)=>{let n=t-1,r=0;for(;e[n]===`\\`;)--n,r+=1;return!!(r%2)};function G(e){if(typeof e!=`string`)throw TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof e}\``);let t=!1,n=!1,r=0,i=``,a=``,o=-1;for(let s=0;s<e.length;s++){let c=e[s],l=e[s+1];if(!n&&c===`"`&&(W(e,s)||(t=!t)),!t)if(!n&&c+l===`//`)i+=e.slice(r,s),r=s,n=V,s++;else if(n===V&&c+l===`\r
6
+ `){s++,n=!1,i+=U(e,r,s),r=s;continue}else if(n===V&&c===`
7
+ `)n=!1,i+=U(e,r,s),r=s;else if(!n&&c+l===`/*`){i+=e.slice(r,s),r=s,n=H,s++;continue}else if(n===H&&c+l===`*/`){s++,n=!1,i+=U(e,r,s+1),r=s+1;continue}else n||(o===-1?c===`,`&&(a+=i+e.slice(r,s),i=``,r=s,o=s):c===`}`||c===`]`?(i+=e.slice(r,s),a+=U(i,0,1)+i.slice(1),i=``,r=s,o=-1):c!==` `&&c!==` `&&c!==`\r`&&c!==`
8
+ `&&(i+=e.slice(r,s),r=s,o=-1))}let s=n===V?U(e,r):e.slice(r);return a+i+s}const K=[`.gitpick.json`,`.gitpick.jsonc`],q=async()=>{let t;for(let r of K){let i=n.resolve(r);if(e.existsSync(i)){t=i;break}}if(!t)return!1;let r=await e.promises.readFile(t,`utf-8`),i=JSON.parse(G(r));if(!Array.isArray(i)||!i.every(e=>typeof e==`string`))throw Error(`${n.basename(t)} 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};var J=`gitpick`,Y=`4.18.0-canary.0`;const X=(e,t)=>`\x1b]8;;${t}\x07${e}\x1b]8;;\x07`,Z=`
9
+ With ${p(`${X(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific directories or files from GitHub, GitLab and Bitbucket!
10
10
 
11
- $ gitpick ${g(`<url>`)} ${h(`[target]`)} ${_(`[options]`)}
11
+ $ gitpick ${_(`<url>`)} ${g(`[target]`)} ${v(`[options]`)}
12
12
 
13
13
  ${p(`Hint:`)}
14
14
  [target] and [options] are optional and if not specified,
15
15
  GitPick fallbacks to the default behavior of \`git clone\`
16
16
 
17
17
  ${p(`Arguments:`)}
18
- ${g(`url`)} GitHub/GitLab/Bitbucket URL with path to file/folder/repository
19
- ${h(`target`)} Directory to clone into (optional)
18
+ ${_(`url`)} GitHub/GitLab/Bitbucket URL with path to file/folder/repository
19
+ ${g(`target`)} Directory to clone into (optional)
20
20
 
21
21
  ${p(`Options:`)}
22
- ${_(`-b, --branch `)} Branch/SHA to clone
23
- ${_(`-n, --dry-run`)} Show what would be cloned without cloning
24
- ${_(`-o, --overwrite`)} Skip overwrite prompt
25
- ${_(`-r, --recursive`)} Clone submodules
26
- ${_(`-w, --watch [time]`)} Watch the repository and sync every [time]
22
+ ${v(`-b, --branch `)} Branch/SHA to clone
23
+ ${v(`-n, --dry-run`)} Show what would be cloned without cloning
24
+ ${v(`-o, --overwrite`)} Skip overwrite prompt
25
+ ${v(`-r, --recursive`)} Clone submodules
26
+ ${v(`-w, --watch [time]`)} Watch the repository and sync every [time]
27
27
  (e.g. 1h, 30m, 15s)
28
- ${_(` --tree`)} List copied files as a tree
29
- ${_(`-h, --help`)} display help for command
30
- ${_(`-v, --version`)} display the version number
28
+ ${v(` --tree`)} List copied files as a tree
29
+ ${v(`-q, --quiet`)} Suppress all output except errors
30
+ ${v(` --verbose`)} Show detailed clone information
31
+ ${v(`-h, --help`)} display help for command
32
+ ${v(`-v, --version`)} display the version number
31
33
 
32
34
  ${p(`Examples:`)}
33
35
  $ gitpick <url>
@@ -39,6 +41,6 @@ ${p(`Examples:`)}
39
41
  $ gitpick https://gitlab.com/owner/repo
40
42
  $ gitpick https://bitbucket.org/owner/repo
41
43
 
42
- 🚀 More awesome tools at ${_(`https://github.com/nrjdalal`)}`,Z=e=>{let r=process.cwd(),i=t.homedir(),a=n.sep;return e===r?`.`:e.startsWith(r+a)?`./`+n.relative(r,e).replaceAll(a,`/`):e.startsWith(i+a)?`~/`+n.relative(i,e).replaceAll(a,`/`):e},Q=async(t,r=``)=>{let i=(await e.promises.readdir(t,{withFileTypes:!0})).filter(e=>e.name!==`.git`).sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`}));for(let a=0;a<i.length;a++){let o=i[a],s=a===i.length-1,c=s?`└── `:`├── `,l=n.join(t,o.name);if(o.isSymbolicLink()){let t=await e.promises.readlink(l),n=!1;try{n=e.statSync(l).isDirectory()}catch{}process.stdout.write(`${r}${c}${g(o.name)} -> ${n?_(t):t}\n`)}else o.isDirectory()?(process.stdout.write(`${r}${c}${_(o.name)}\n`),await Q(l,`${r}${s?` `:`│ `}`)):process.stdout.write(`${r}${c}${o.name}\n`)}},$=e=>{try{return r(e)}catch(e){throw Error(`Error parsing arguments: ${e.message}`)}};(async()=>{try{let{positionals:r,values:i}=$({allowPositionals:!0,options:{branch:{type:`string`,short:`b`},"dry-run":{type:`boolean`,short:`n`},force:{type:`boolean`,short:`f`},help:{type:`boolean`,short:`h`},tree:{type:`boolean`},overwrite:{type:`boolean`,short:`o`},recursive:{type:`boolean`,short:`r`},version:{type:`boolean`,short:`v`},watch:{type:`string`,short:`w`}}});r.length||(i.version&&(console.log(`\n${q}@${J}`),process.exit(0)),await K()&&process.exit(0),console.log(X),process.exit(0)),r[0]===`clone`&&r.shift();let[a,o]=r,s={branch:i.branch,dryRun:i[`dry-run`],force:i.force,tree:i.tree,overwrite:i.overwrite,recursive:i.recursive,watch:i.watch},c=s.tree;c||console.log(`\nWith ${p(`${Y(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific files, folders, branches, commits and more from GitHub, GitLab and Bitbucket!`);let l=await z(a,{branch:s.branch,target:o});if(l.type===`blob`){let e=l.target.split(/[/\\]/).filter(e=>e!==``),t=e[e.length-1];t!==`.`&&t!==`..`&&t.includes(`.`)?e.pop():t=l.path.split(`/`).pop()||t,l.target=[...e,t].join(`/`)}c||console.info(`\n${h(`✔`)} ${l.owner}/${l.repository} ${_(l.type+`:`+l.branch)} ${l.type===`repository`?`> ${h(l.target)}`:`${l.path.length?g(l.path)+` >`:`>`} ${h(l.target)}`}`);let u=n.resolve(l.target),d=async t=>{e.statSync(t).isDirectory()?(process.stdout.write(`${p(_(Z(u)))}\n`),await Q(t)):(process.stdout.write(`${p(_(Z(n.dirname(u))))}\n`),process.stdout.write(`└── ${n.basename(u)}\n`)),process.stdout.write(`
43
- `)};if(s.dryRun){if(s.tree){let r=n.resolve(t.tmpdir(),`gitpick-dry-${Date.now()}${Math.random().toString(16).slice(2,6)}`);try{await F(l,s,r),await d(r)}finally{await e.promises.rm(r,{recursive:!0,force:!0})}}c||console.log(),process.exit(0)}if(s.overwrite=s.overwrite||s.force,s.watch&&(s.overwrite=!0),e.existsSync(u)&&!s.overwrite&&(l.type===`blob`&&(console.log(`${g(`\nWarning: The target file exists at ${h(l.target)}. Use ${_(`-f`)} or ${_(`-o`)} to overwrite.`)}`),process.exit(1)),(await e.promises.readdir(u)).length&&(console.log(`${g(`\nWarning: The target directory exists at ${h(l.target)} and is not empty. Use ${_(`-f`)} or ${_(`-o`)} to overwrite.`)}`),process.exit(1))),s.watch){c||console.log(`\n👀 Watching every ${I(s.watch)/1e3+`s`}\n`),await F(l,s,u),s.tree&&await d(u);let e=I(s.watch);setInterval(async()=>{await F(l,s,u),s.tree&&await d(u)},e)}else await F(l,s,u),s.tree&&await d(u),process.exit(0)}catch(e){e instanceof Error?console.log(p(`\n${m(`Error: `)}`)+e.message):console.log(p(`${m(`
44
+ 🚀 More awesome tools at ${v(`https://github.com/nrjdalal`)}`,Q=e=>{let r=process.cwd(),i=t.homedir(),a=n.sep;return e===r?`.`:e.startsWith(r+a)?`./`+n.relative(r,e).replaceAll(a,`/`):e.startsWith(i+a)?`~/`+n.relative(i,e).replaceAll(a,`/`):e},$=async(t,r=``)=>{let i=(await e.promises.readdir(t,{withFileTypes:!0})).filter(e=>e.name!==`.git`).sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`}));for(let a=0;a<i.length;a++){let o=i[a],s=a===i.length-1,c=s?`└── `:`├── `,l=n.join(t,o.name);if(o.isSymbolicLink()){let t=await e.promises.readlink(l),n=!1;try{n=e.statSync(l).isDirectory()}catch{}process.stdout.write(`${r}${c}${_(o.name)} -> ${n?v(t):t}\n`)}else o.isDirectory()?(process.stdout.write(`${r}${c}${v(o.name)}\n`),await $(l,`${r}${s?` `:`│ `}`)):process.stdout.write(`${r}${c}${o.name}\n`)}},ee=e=>{try{return r(e)}catch(e){throw Error(`Error parsing arguments: ${e.message}`)}};(async()=>{try{let{positionals:r,values:i}=ee({allowPositionals:!0,options:{branch:{type:`string`,short:`b`},"dry-run":{type:`boolean`,short:`n`},force:{type:`boolean`,short:`f`},help:{type:`boolean`,short:`h`},quiet:{type:`boolean`,short:`q`},tree:{type:`boolean`},verbose:{type:`boolean`},overwrite:{type:`boolean`,short:`o`},recursive:{type:`boolean`,short:`r`},version:{type:`boolean`,short:`v`},watch:{type:`string`,short:`w`}}});r.length||(i.version&&(console.log(`\n${J}@${Y}`),process.exit(0)),await q()&&process.exit(0),console.log(Z),process.exit(0)),r[0]===`clone`&&r.shift();let[a,o]=r,s={branch:i.branch,dryRun:i[`dry-run`],force:i.force,quiet:i.quiet,tree:i.tree,verbose:i.verbose,overwrite:i.overwrite,recursive:i.recursive,watch:i.watch},c=s.tree||s.quiet;c||console.log(`\nWith ${p(`${X(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific files, folders, branches,\ncommits and much more from GitHub, GitLab and Bitbucket!`);let l=await B(a,{branch:s.branch,target:o});if(l.type===`blob`){let e=l.target.split(/[/\\]/).filter(e=>e!==``),t=e[e.length-1];t!==`.`&&t!==`..`&&t.includes(`.`)?e.pop():t=l.path.split(`/`).pop()||t,l.target=[...e,t].join(`/`)}c||console.info(`\n${g(`✔`)} ${l.owner}/${l.repository} ${v(l.type+`:`+l.branch)} ${l.type===`repository`?`> ${g(l.target)}`:`${l.path.length?_(l.path)+` >`:`>`} ${g(l.target)}`}`);let u=n.resolve(l.target),d=async t=>{e.statSync(t).isDirectory()?(process.stdout.write(`${p(v(Q(u)))}\n`),await $(t)):(process.stdout.write(`${p(v(Q(n.dirname(u))))}\n`),process.stdout.write(`└── ${n.basename(u)}\n`)),process.stdout.write(`
45
+ `)};if(s.dryRun){if(s.tree){let r=n.resolve(t.tmpdir(),`gitpick-dry-${Date.now()}${Math.random().toString(16).slice(2,6)}`);try{await I(l,s,r),await d(r)}finally{await e.promises.rm(r,{recursive:!0,force:!0})}}c||console.log(),process.exit(0)}if(s.overwrite=s.overwrite||s.force,s.watch&&(s.overwrite=!0),e.existsSync(u)&&!s.overwrite&&(l.type===`blob`&&(console.log(`${_(`\nWarning: The target file exists at ${g(l.target)}. Use ${v(`-f`)} or ${v(`-o`)} to overwrite.`)}`),process.exit(1)),(await e.promises.readdir(u)).length&&(console.log(`${_(`\nWarning: The target directory exists at ${g(l.target)} and is not empty. Use ${v(`-f`)} or ${v(`-o`)} to overwrite.`)}`),process.exit(1))),s.watch){c||console.log(`\n👀 Watching every ${L(s.watch)/1e3+`s`}\n`),await I(l,s,u),s.tree&&await d(u);let e=L(s.watch);setInterval(async()=>{await I(l,s,u),s.tree&&await d(u)},e)}else await I(l,s,u),s.tree&&await d(u),process.exit(0)}catch(e){e instanceof Error?console.log(p(`\n${h(`Error: `)}`)+e.message):console.log(p(`${h(`
44
46
  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.17.0",
3
+ "version": "4.18.0-canary.0",
4
4
  "description": "Clone exactly what you need aka straightforward project scaffolding!",
5
5
  "keywords": [
6
6
  "clone",