gitpick 3.27.0-canary.4 → 3.27.0-canary.6

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.js +19 -19
  2. package/package.json +2 -3
package/dist/index.js CHANGED
@@ -1,32 +1,32 @@
1
1
  #!/usr/bin/env node
2
- import T from"fs";import{parseArgs as H}from"node:util";import I from"path";import{cancel as M,confirm as S,intro as U,isCancel as L,log as A}from"@clack/prompts";import R from"terminal-link";import o from"yoctocolors";var v="gitpick",k="3.27.0-canary.4";import m from"node:fs";import G from"node:os";import j from"node:path";import{log as f,spinner as P}from"@clack/prompts";import W from"simple-git";import g from"node:fs";import x from"node:path";var u=async(t,i)=>{let a=await g.promises.readdir(t,{withFileTypes:!0});await g.promises.mkdir(i,{recursive:!0});for(let s of a){if(s.name===".git")continue;let e=x.join(t,s.name),r=x.join(i,s.name);s.isDirectory()?await u(e,r):await g.promises.copyFile(e,r)}};var w=async(t,i,a)=>{let s=P();try{let e=W();process.platform==="win32"&&await e.raw(["config","--global","core.longpaths","true"]);let r=`https://${t.token?t.token+"@":t.token}github.com/${t.owner}/${t.repository}.git`,c=j.join(G.tmpdir(),`${t.repository}-${Date.now()}${Math.random().toString(16).slice(2,6)}`);i.watch||s.start(`Picking ${t.type}${t.type==="repository"?" without .git":" from repository"}`);let n=performance.now();await e.clone(r,c,["--depth","1","--single-branch","--branch",t.branch]);let p=j.join(c,t.path);(await m.promises.stat(p)).isDirectory()?(await m.promises.mkdir(a,{recursive:!0}),await u(p,a)):(await m.promises.mkdir(a,{recursive:!0}),await m.promises.copyFile(p,a+"/"+t.path.split("/").pop())),i.watch?f.success("Synced at "+new Date().toLocaleTimeString()):s.stop(`Picked ${t.type}${t.type==="repository"?" without .git":" from repository"} in ${((performance.now()-n)/1e3).toFixed(2)} seconds!`),await m.promises.rm(c,{recursive:!0,force:!0})}catch(e){s.stop("Level 2: An error occurred while cloning!"),e instanceof Error?f.error("Error: "+e.message):f.error("Unexpected Error: "+JSON.stringify(e,null,2)),process.exit(1)}};function d(t){if(typeof t=="number"||/^\d+$/.test(t))return typeof t=="number"?t:parseInt(t,10);let i=/(\d+)([hms])/g,a=0,s;for(;(s=i.exec(t))!==null;){let e=parseInt(s[1],10);switch(s[2]){case"h":a+=e*36e5;break;case"m":a+=e*6e4;break;case"s":a+=e*1e3;break}}return a}import B from"simple-git";var D=async t=>{var e,r;let i=await B().listRemote([t]),a=(e=i.match(/(.+)\s+HEAD/))==null?void 0:e[1],s=(r=i.match(new RegExp(`${a}\\s+refs/heads/(.+)`)))==null?void 0:r[1];if(!s)throw new Error("Could not determine default branch!");return s};async function E(t,{branch:i,target:a}){let s=/^https:\/\/([^@]+)@github\.com/,e=t.match(s),r="";e&&(r=e[1],t=t.replace(s,"https://github.com"));let c=["git@github.com:","https://github.com/","https://raw.githubusercontent.com/"];for(let b of c)if(t.startsWith(b)){t=t.replace(b,"");break}let n=t.split("/"),p=n[0],h=n[1].endsWith(".git")?n[1].slice(0,-4):n[1],l=n[2]==="blob"?"blob":n[2]==="tree"?"tree":n[2]+n[3]==="refsheads"?"raw":"repository",C=i||(l==="repository"?await D(`https://${r&&r+"@"}github.com/${p}/${h}`):l==="raw"?n[4]:n[3]),y=l?l==="raw"?n.slice(5).join("/"):n.slice(4).join("/"):n.slice(2).join("/")||"/",F=a||(l==="blob"?".":y.split("/").pop()||h);return{token:r,owner:p,repository:h,type:l,branch:C,path:y,target:F}}var O=`
3
- ${o.whiteBright("With GitPick, you can clone precisely what you need.")}
2
+ var R=Object.defineProperty;var S=(t,s)=>{for(var a in s)R(t,a,{get:s[a],enumerable:!0})};import M from"fs";import{parseArgs as At}from"node:util";import Mt from"path";var i={};S(i,{bgBlack:()=>st,bgBlue:()=>pt,bgBlueBright:()=>Bt,bgCyan:()=>ht,bgCyanBright:()=>Dt,bgGray:()=>gt,bgGreen:()=>at,bgGreenBright:()=>vt,bgMagenta:()=>lt,bgMagentaBright:()=>jt,bgRed:()=>nt,bgRedBright:()=>$t,bgWhite:()=>mt,bgWhiteBright:()=>Ct,bgYellow:()=>ct,bgYellowBright:()=>kt,black:()=>V,blue:()=>tt,blueBright:()=>bt,bold:()=>L,cyan:()=>ot,cyanBright:()=>yt,dim:()=>Y,gray:()=>it,green:()=>Z,greenBright:()=>dt,hidden:()=>K,inverse:()=>z,italic:()=>N,magenta:()=>et,magentaBright:()=>wt,overline:()=>q,red:()=>X,redBright:()=>ut,reset:()=>U,strikethrough:()=>Q,underline:()=>J,white:()=>rt,whiteBright:()=>xt,yellow:()=>_,yellowBright:()=>ft});import H from"node:tty";var v,k,u,B,j,O=(j=(B=(u=(k=(v=H)==null?void 0:v.WriteStream)==null?void 0:k.prototype)==null?void 0:u.hasColors)==null?void 0:B.call(u))!=null?j:!1,e=(t,s)=>{if(!O)return o=>o;let a=`\x1B[${t}m`,n=`\x1B[${s}m`;return o=>{let r=o+"",p=r.indexOf(n);if(p===-1)return a+r+n;let c=a,l=0;for(;p!==-1;)c+=r.slice(l,p)+a,l=p+n.length,p=r.indexOf(n,l);return c+=r.slice(l)+n,c}},U=e(0,0),L=e(1,22),Y=e(2,22),N=e(3,23),J=e(4,24),q=e(53,55),z=e(7,27),K=e(8,28),Q=e(9,29),V=e(30,39),X=e(31,39),Z=e(32,39),_=e(33,39),tt=e(34,39),et=e(35,39),ot=e(36,39),rt=e(37,39),it=e(90,39),st=e(40,49),nt=e(41,49),at=e(42,49),ct=e(43,49),pt=e(44,49),lt=e(45,49),ht=e(46,49),mt=e(47,49),gt=e(100,49),ut=e(91,39),dt=e(92,39),ft=e(93,39),bt=e(94,39),wt=e(95,39),yt=e(96,39),xt=e(97,39),$t=e(101,49),vt=e(102,49),kt=e(103,49),Bt=e(104,49),jt=e(105,49),Dt=e(106,49),Ct=e(107,49);import m from"node:fs";import Et from"node:os";import C from"node:path";import d from"node:fs";import D from"node:path";var f=async(t,s)=>{let a=await d.promises.readdir(t,{withFileTypes:!0});await d.promises.mkdir(s,{recursive:!0});for(let n of a){if(n.name===".git")continue;let o=D.join(t,n.name),r=D.join(s,n.name);n.isDirectory()?await f(o,r):await d.promises.copyFile(o,r)}};import{log as b,spinner as Gt}from"@clack/prompts";import Tt from"simple-git";var w=async(t,s,a)=>{let n=Gt();try{let o=Tt();process.platform==="win32"&&await o.raw(["config","--global","core.longpaths","true"]);let r=`https://${t.token?t.token+"@":t.token}github.com/${t.owner}/${t.repository}.git`,p=C.join(Et.tmpdir(),`${t.repository}-${Date.now()}${Math.random().toString(16).slice(2,6)}`);s.watch||n.start(`Picking ${t.type}${t.type==="repository"?" without .git":" from repository"}`);let c=performance.now();await o.clone(r,p,["--depth","1","--single-branch","--branch",t.branch]);let l=C.join(p,t.path);(await m.promises.stat(l)).isDirectory()?(await m.promises.mkdir(a,{recursive:!0}),await f(l,a)):(await m.promises.mkdir(a,{recursive:!0}),await m.promises.copyFile(l,a+"/"+t.path.split("/").pop())),s.watch?b.success("Synced at "+new Date().toLocaleTimeString()):n.stop(`Picked ${t.type}${t.type==="repository"?" without .git":" from repository"} in ${((performance.now()-c)/1e3).toFixed(2)} seconds!`),await m.promises.rm(p,{recursive:!0,force:!0})}catch(o){n.stop("Level 2: An error occurred while cloning!"),o instanceof Error?b.error("Error: "+o.message):b.error("Unexpected Error: "+JSON.stringify(o,null,2)),process.exit(1)}};function y(t){if(typeof t=="number"||/^\d+$/.test(t))return typeof t=="number"?t:parseInt(t,10);let s=/(\d+)([hms])/g,a=0,n;for(;(n=s.exec(t))!==null;){let o=parseInt(n[1],10);switch(n[2]){case"h":a+=o*36e5;break;case"m":a+=o*6e4;break;case"s":a+=o*1e3;break}}return a}import Wt from"simple-git";var E=async t=>{var o,r;let s=await Wt().listRemote([t]),a=(o=s.match(/(.+)\s+HEAD/))==null?void 0:o[1],n=(r=s.match(new RegExp(`${a}\\s+refs/heads/(.+)`)))==null?void 0:r[1];if(!n)throw new Error("Could not determine default branch!");return n};async function G(t,{branch:s,target:a}){let n=/^https:\/\/([^@]+)@github\.com/,o=t.match(n),r="";o&&(r=o[1],t=t.replace(n,"https://github.com"));let p=["git@github.com:","https://github.com/","https://raw.githubusercontent.com/"];for(let $ of p)if(t.startsWith($)){t=t.replace($,"");break}let c=t.split("/"),l=c[0],g=c[1].endsWith(".git")?c[1].slice(0,-4):c[1],h=c[2]==="blob"?"blob":c[2]==="tree"?"tree":c[2]+c[3]==="refsheads"?"raw":"repository",I=s||(h==="repository"?await E(`https://${r&&r+"@"}github.com/${l}/${g}`):h==="raw"?c[4]:c[3]),x=h?h==="raw"?c.slice(5).join("/"):c.slice(4).join("/"):c.slice(2).join("/")||"/",P=a||(h==="blob"?".":x.split("/").pop()||g);return{token:r,owner:l,repository:g,type:h,branch:I,path:x,target:P}}import{cancel as Ft,confirm as It,intro as Pt,isCancel as Rt,log as F}from"@clack/prompts";var W="gitpick",A="3.27.0-canary.6";import St from"terminal-link";var Ht=`
3
+ ${i.whiteBright("With GitPick, you can clone precisely what you need.")}
4
4
 
5
- ${o.cyan("gitpick <url>")} ${o.green("[target]")} ${o.blue("[options]")}
5
+ ${i.cyan("gitpick <url>")} ${i.green("[target]")} ${i.blue("[options]")}
6
6
 
7
- ${o.bold("Hint:")} Target is optional, and follows default git clone behavior.
7
+ ${i.bold("Hint:")} Target is optional, and follows default git clone behavior.
8
8
 
9
- ${o.bold("Arguments:")}
10
- ${o.cyan("url")} GitHub URL with path to file/folder/repository
11
- ${o.green("target")} Directory to clone into (optional)
9
+ ${i.bold("Arguments:")}
10
+ ${i.cyan("url")} GitHub URL with path to file/folder/repository
11
+ ${i.green("target")} Directory to clone into (optional)
12
12
 
13
- ${o.bold("Options:")}
14
- ${o.blue("-b, --branch ")} Branch to clone
15
- ${o.blue("-o, --overwrite")} Skip overwrite prompt
16
- ${o.blue("-w, --watch [time]")} Watch the repository and sync every [time]
13
+ ${i.bold("Options:")}
14
+ ${i.blue("-b, --branch ")} Branch to clone
15
+ ${i.blue("-o, --overwrite")} Skip overwrite prompt
16
+ ${i.blue("-w, --watch [time]")} Watch the repository and sync every [time]
17
17
  (e.g. 1h, 30m, 15s) default: 1m
18
- ${o.blue("-h, --help")} display help for command
19
- ${o.blue("-v, --version")} display the version number
18
+ ${i.blue("-h, --help")} display help for command
19
+ ${i.blue("-v, --version")} display the version number
20
20
 
21
- ${o.bold("Examples:")}
21
+ ${i.bold("Examples:")}
22
22
  $ gitpick <url>
23
23
  $ gitpick <url> [target]
24
24
  $ gitpick <url> [target] -b [branch]
25
25
  $ gitpick <url> [target] -w [time]
26
26
  $ gitpick <url> [target] -b [branch] -w [time]
27
27
 
28
- \u{1F680} More awesome tools at ${o.cyan("https://github.com/nrjdalal")}`,N=t=>{try{return H(t)}catch(i){throw new Error(`Error parsing arguments: ${i.message}`)}},J=async()=>{try{let{positionals:t,values:i}=N({allowPositionals:!0,options:{branch:{type:"string",short:"b"},overwrite:{type:"boolean",short:"o"},force:{type:"boolean",short:"f"},watch:{type:"string",short:"w"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}});t.length||(i.version&&(console.log(`${v}@${k}`),process.exit(0)),console.log(O),process.exit(0)),t[0]==="clone"&&t.shift();let[a,s]=t,e={branch:i.branch,overwrite:i.overwrite,force:i.force,watch:i.watch};e.overwrite=e.overwrite||e.force,e.watch&&(typeof e.watch=="boolean"&&(e.watch="1m"),console.log(`\u{1F440} Watching every ${d(e.watch)/1e3+"s"}
29
- `));let r=await E(a,{branch:e.branch,target:s});console.log(o.white(`
30
- ${R("GitPick \u2197\uFE0F ","https://github.com/nrjdalal/gitpick")} - Clone specific directories or files from GitHub!
31
- `)),U(`${o.bold(r.owner)}/${o.bold(r.repository)} ${o.green(`<${r.type}:${r.branch}>`)} ${r.type==="repository"?`> ${o.cyan(r.target)}`:`${o.yellow(r.path)} > ${o.cyan(`${r.target}${r.type==="blob"?`/${r.path.split("/").pop()}`:""}`)}`}`);let c=I.resolve(r.target);if(e.watch&&(e.overwrite=!0),T.existsSync(c+(r.type==="blob"?"/"+r.path.split("/").pop():""))&&(await T.promises.readdir(c)).length&&!e.overwrite){let n=r.type==="tree"?"The target directory is not empty. Do you want to overwrite the files?":"The target file already exists. Do you want to overwrite the file?",p=await S({message:n});L(p)&&(M("Operation cancelled."),process.exit(0)),p||(A.info("Chose not to overwrite files."),process.exit(0)),A.info("You can use -o | --overwrite or -f | --force flag to skip this prompt next time.")}if(await w(r,e,c),e.watch){let n=d(e.watch);setInterval(async()=>await w(r,e,c),n)}process.exit(0)}catch(t){console.error(`
32
- Error: ${t.message}`),process.exit(1)}};J();
28
+ \u{1F680} More awesome tools at ${i.cyan("https://github.com/nrjdalal")}`,Ot=t=>{try{return At(t)}catch(s){throw new Error(`Error parsing arguments: ${s.message}`)}},Ut=async()=>{try{let{positionals:t,values:s}=Ot({allowPositionals:!0,options:{branch:{type:"string",short:"b"},overwrite:{type:"boolean",short:"o"},force:{type:"boolean",short:"f"},watch:{type:"string",short:"w"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}});t.length||(s.version&&(console.log(`${W}@${A}`),process.exit(0)),console.log(Ht),process.exit(0)),t[0]==="clone"&&t.shift();let[a,n]=t,o={branch:s.branch,overwrite:s.overwrite,force:s.force,watch:s.watch};o.overwrite=o.overwrite||o.force,o.watch&&(typeof o.watch=="boolean"&&(o.watch="1m"),console.log(`\u{1F440} Watching every ${y(o.watch)/1e3+"s"}
29
+ `));let r=await G(a,{branch:o.branch,target:n});console.log(i.white(`
30
+ ${St("GitPick \u2197\uFE0F ","https://github.com/nrjdalal/gitpick")} - Clone specific directories or files from GitHub!
31
+ `)),Pt(`${i.bold(r.owner)}/${i.bold(r.repository)} ${i.green(`<${r.type}:${r.branch}>`)} ${r.type==="repository"?`> ${i.cyan(r.target)}`:`${i.yellow(r.path)} > ${i.cyan(`${r.target}${r.type==="blob"?`/${r.path.split("/").pop()}`:""}`)}`}`);let p=Mt.resolve(r.target);if(o.watch&&(o.overwrite=!0),M.existsSync(p+(r.type==="blob"?"/"+r.path.split("/").pop():""))&&(await M.promises.readdir(p)).length&&!o.overwrite){let c=r.type==="tree"?"The target directory is not empty. Do you want to overwrite the files?":"The target file already exists. Do you want to overwrite the file?",l=await It({message:c});Rt(l)&&(Ft("Operation cancelled."),process.exit(0)),l||(F.info("Chose not to overwrite files."),process.exit(0)),F.info("You can use -o | --overwrite or -f | --force flag to skip this prompt next time.")}if(await w(r,o,p),o.watch){let c=y(o.watch);setInterval(async()=>await w(r,o,p),c)}process.exit(0)}catch(t){console.error(`
32
+ Error: ${t.message}`),process.exit(1)}};Ut();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitpick",
3
- "version": "3.27.0-canary.4",
3
+ "version": "3.27.0-canary.6",
4
4
  "description": "With gitpick, you can clone precisely what you need.",
5
5
  "keywords": [
6
6
  "clone",
@@ -35,7 +35,6 @@
35
35
  "dependencies": {
36
36
  "@clack/prompts": "^0.10.0",
37
37
  "simple-git": "^3.27.0",
38
- "terminal-link": "^4.0.0",
39
- "yoctocolors": "^2.1.1"
38
+ "terminal-link": "^4.0.0"
40
39
  }
41
40
  }