gitpick 4.19.0-canary.6 → 4.19.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.
Files changed (2) hide show
  1. package/dist/index.mjs +1 -1
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import e from"node:fs";import t from"node:os";import n from"node:path";import{pa
4
4
  `),r=0;for(let e of n)r+=Math.max(1,Math.ceil(e.length/t));return r},m=()=>{if(!o)return;let e=Date.now();(t===-1||e-c>=80)&&(t=++t%j.length,c=e);let n=j[t],i=`${y(n)} ${r}`;f(),d(i),s=p(i)};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(`${A} ${e??r}\n`),this):this}}},M=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 M(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},N=new Set;function P(){for(let t of N)try{e.rmSync(t,{recursive:!0,force:!0})}catch{}process.exit(1)}process.on(`SIGINT`,P),process.on(`SIGTERM`,P);const ie=e=>e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`,F=async(r,i,a)=>{let o=i.tree||i.quiet,s=i.verbose&&!o;process.platform===`win32`&&await O(`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)}`);N.add(u);let d=re(),f=performance.now();!i.watch&&!o&&d.start(`Picking ${r.type}${r.type===`repository`?` without .git`:` from repository`}...`);let p=`shallow`,m=performance.now();try{await O(`git`,[`clone`,c,u,`--branch`,r.branch,`--depth`,`1`,`--single-branch`,...i.recursive?[`--recursive`]:[]])}catch{p=`full`,await O(`git`,[`clone`,c,u,...i.recursive?[`--recursive`]:[]]),await O(`git`,[`checkout`,r.branch],{cwd:u})}let g=Number(((performance.now()-m)/1e3).toFixed(2)),_=n.resolve(u,r.path),v=await e.promises.stat(_),b=[],x=performance.now();v.isDirectory()?(await e.promises.mkdir(a,{recursive:!0}),b=await M(_,a)):(await e.promises.mkdir(n.dirname(a),{recursive:!0}),await e.promises.copyFile(_,a),b=[n.basename(a)]);let S=Number(((performance.now()-x)/1e3).toFixed(2)),C=Number(((performance.now()-f)/1e3).toFixed(2)),w=0;for(let t of b)try{let r=await e.promises.stat(n.join(a,t));w+=r.size}catch{let t=await e.promises.stat(a);w+=t.size;break}return o||(i.watch?console.log(`- Synced at `+new Date().toLocaleTimeString()):d.success(`Picked ${r.type}${r.type===`repository`?` without .git`:` from repository`} in ${C} seconds.`)),s&&(console.log(h(` clone: ${p} (depth=${p===`shallow`?`1`:`full`})`)),console.log(h(` from: ${l} @ ${y(r.branch)}`)),console.log(h(` to: ${a}`)),console.log(h(` files: ${b.length} (${ie(w)})`)),console.log(h(` network: ${g}s`)),console.log(h(` copy: ${S}s`)),console.log(h(` total: ${C}s`))),await e.promises.rm(u,{recursive:!0,force:!0}),N.delete(u),{files:b,duration:C,networkTime:g,copyTime:S,totalSize:w,cloneStrategy:p}};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 ae(e,{branch:t,target:n}){let r=e.match(/^https:\/\/([^@]+)@(github\.com|gitlab\.com|bitbucket\.org)/),i=``;if(r)i=r[1],e=e.replace(`${r[1]}@`,``);else{let t={"github.com":process.env.GITHUB_TOKEN||process.env.GH_TOKEN||``,"gitlab.com":process.env.GITLAB_TOKEN||``,"bitbucket.org":process.env.BITBUCKET_TOKEN||``};for(let{prefix:n,host:r}of R)if(e.startsWith(n)){i=t[r];break}!i&&!e.startsWith(`https://`)&&!e.startsWith(`git@`)&&(i=t[`github.com`])}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 z=n.join(t.homedir(),`.cache`,`gitpick`),B=n.join(z,`update-check.json`);function V(){try{return JSON.parse(e.readFileSync(B,`utf-8`))}catch{return null}}function oe(t){try{e.mkdirSync(z,{recursive:!0}),e.writeFileSync(B,JSON.stringify(t))}catch{}}function H(){return new Promise(e=>{let t=d.get(`https://registry.npmjs.org/gitpick/latest`,{headers:{Accept:`application/json`},timeout:3e3},t=>{if(t.statusCode!==200)return t.resume(),e(null);let n=``;t.on(`data`,e=>n+=e),t.on(`end`,()=>{try{e(JSON.parse(n).version||null)}catch{e(null)}})});t.on(`error`,()=>e(null)),t.on(`timeout`,()=>{t.destroy(),e(null)})})}function U(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){if((n[e]||0)>(r[e]||0))return!0;if((n[e]||0)<(r[e]||0))return!1}return!1}function W(e,t){if(t)return;let n=V();n&&U(n.latestVersion,e)&&console.log(h(`\n Update available: ${v(e)} → ${y(m(n.latestVersion))}\n Run ${y(`npm i -g gitpick`)} to update\n`))}function G(){let e=V();e&&Date.now()-e.lastCheck<864e5||setTimeout(async()=>{let e=await H();e&&oe({lastCheck:Date.now(),latestVersion:e})},0)}const K=Symbol(`singleComment`),q=Symbol(`multiComment`),J=(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){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===`"`&&(se(e,s)||(t=!t)),!t)if(!n&&c+l===`//`)i+=e.slice(r,s),r=s,n=K,s++;else if(n===K&&c+l===`\r
5
5
  `){s++,n=!1,i+=J(e,r,s),r=s;continue}else if(n===K&&c===`
6
6
  `)n=!1,i+=J(e,r,s),r=s;else if(!n&&c+l===`/*`){i+=e.slice(r,s),r=s,n=q,s++;continue}else if(n===q&&c+l===`*/`){s++,n=!1,i+=J(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+=J(i,0,1)+i.slice(1),i=``,r=s,o=-1):c!==` `&&c!==` `&&c!==`\r`&&c!==`
7
- `&&(i+=e.slice(r,s),r=s,o=-1))}let s=n===K?J(e,r):e.slice(r);return a+i+s}const le=[`.gitpick.json`,`.gitpick.jsonc`],ue=async()=>{let t;for(let r of le){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(ce(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 Y=`gitpick`,X=`4.19.0-canary.6`;const Z=(e,t)=>`\x1b]8;;${t}\x07${e}\x1b]8;;\x07`,de=`
7
+ `&&(i+=e.slice(r,s),r=s,o=-1))}let s=n===K?J(e,r):e.slice(r);return a+i+s}const le=[`.gitpick.json`,`.gitpick.jsonc`],ue=async()=>{let t;for(let r of le){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(ce(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 Y=`gitpick`,X=`4.19.0`;const Z=(e,t)=>`\x1b]8;;${t}\x07${e}\x1b]8;;\x07`,de=`
8
8
  With ${m(`${Z(`GitPick`,`https://github.com/nrjdalal/gitpick`)}`)} clone specific directories or files from GitHub, GitLab and Bitbucket!
9
9
 
10
10
  $ gitpick ${v(`<url>`)} ${_(`[target]`)} ${y(`[options]`)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitpick",
3
- "version": "4.19.0-canary.6",
3
+ "version": "4.19.0",
4
4
  "description": "Clone exactly what you need aka straightforward project scaffolding!",
5
5
  "keywords": [
6
6
  "clone",