gitpick 3.27.0-canary.2 → 3.27.0-canary.3

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 +21 -23
  2. package/package.json +2 -5
package/dist/index.js CHANGED
@@ -1,34 +1,32 @@
1
1
  #!/usr/bin/env node
2
- import l from"fs";import S from"os";import u from"path";function w(e){if(typeof e=="number"||/^\d+$/.test(e))return typeof e=="number"?e:parseInt(e,10);let n=/(\d+)([hms])/g,t=0,r;for(;(r=n.exec(e))!==null;){let o=parseInt(r[1],10);switch(r[2]){case"h":t+=o*36e5;break;case"m":t+=o*6e4;break;case"s":t+=o*1e3;break}}return t}import C from"simple-git";var v=async e=>{var o,i;let n=await C().listRemote([e]),t=(o=n.match(/(.+)\s+HEAD/))==null?void 0:o[1],r=(i=n.match(new RegExp(`${t}\\s+refs/heads/(.+)`)))==null?void 0:i[1];if(!r)throw new Error("Could not determine default branch!");return r};async function $(e,{branch:n,target:t}){let r=/^https:\/\/([^@]+)@github\.com/,o=e.match(r),i="";o&&(i=o[1],e=e.replace(r,"https://github.com"));let m=["git@github.com:","https://github.com/","https://raw.githubusercontent.com/"];for(let y of m)if(e.startsWith(y)){e=e.replace(y,"");break}let a=e.split("/"),h=a[0],f=a[1].endsWith(".git")?a[1].slice(0,-4):a[1],g=a[2]==="blob"?"blob":a[2]==="tree"?"tree":a[2]+a[3]==="refsheads"?"raw":"repository",D=n||(g==="repository"?await v(`https://${i&&i+"@"}github.com/${h}/${f}`):g==="raw"?a[4]:a[3]),b=g?g==="raw"?a.slice(5).join("/"):a.slice(4).join("/"):a.slice(2).join("/")||"/",T=t||(g==="blob"?".":b.split("/").pop()||f);return{token:i,owner:h,repository:f,type:g,branch:D,path:b,target:T}}import{cancel as G,confirm as H,intro as I,isCancel as W,log as p,spinner as A}from"@clack/prompts";import{Command as U}from"commander";import F from"simple-git";import d from"yoctocolors";import{z as c}from"zod";import{fromError as L}from"zod-validation-error";var R=c.object({url:c.string(),target:c.string().optional(),branch:c.string().optional(),overwrite:c.boolean().optional(),force:c.boolean().optional(),watch:c.union([c.string(),c.number(),c.boolean()]).optional()}),x=new U().name("clone").argument("<url>","GitHub URL with path to file/folder").argument("[target]","Directory to clone into (optional)").option("-b, --branch <branch>","Branch to clone").option("-o, --overwrite","Skip overwrite prompt").option("-f, --force","Alias for --overwrite").option("-w, --watch [time]",`Watch the repository and sync every [time]
3
- (e.g. 1h, 30m, 15s) default: 1m`).action(async(e,n,t)=>{R.parse({url:e,target:n,branch:t.branch,overwrite:t.overwrite,force:t.force,watch:t.watch}),t.overwrite=t.overwrite||t.force,t.watch&&(typeof t.watch=="boolean"&&(t.watch="1m"),console.log(`\u{1F440} Watching every ${w(t.watch)/1e3+"s"}
4
- `));let r=await $(e,{branch:t.branch,target:n});I(`${d.bold(r.owner)}/${d.bold(r.repository)} ${d.green(`<${r.type}:${r.branch}>`)} ${r.type==="repository"?`> ${d.cyan(r.target)}`:`${d.yellow(r.path)} > ${d.cyan(`${r.target}${r.type==="blob"?`/${r.path.split("/").pop()}`:""}`)}`}`);try{let o=u.resolve(r.target);if(t.watch&&(t.overwrite=!0),l.existsSync(o+(r.type==="blob"?"/"+r.path.split("/").pop():""))&&(await l.promises.readdir(o)).length&&!t.overwrite){let i=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?",m=await H({message:i});W(m)&&(G("Operation cancelled."),process.exit(0)),m||(p.info("Chose not to overwrite files."),process.exit(0)),p.info("You can use -o | --overwrite or -f | --force flag to skip this prompt next time.")}if(await k(r,t,o),t.watch){let i=w(t.watch);setInterval(async()=>await k(r,t,o),i)}}catch(o){if(p.error("Level 1: An error occurred"),o instanceof c.ZodError){let i=L(o);p.error("Validation Error: "+i.toString())}else o instanceof Error?p.error("Error: "+o.message):p.error("Unexpected Error: "+JSON.stringify(o,null,2));process.exit(1)}});async function j(e,n){let t=await l.promises.readdir(e,{withFileTypes:!0});await l.promises.mkdir(n,{recursive:!0});for(let r of t){if(r.name===".git")continue;let o=u.join(e,r.name),i=u.join(n,r.name);r.isDirectory()?await j(o,i):await l.promises.copyFile(o,i)}}var k=async(e,n,t)=>{let r=A();try{let o=F();process.platform==="win32"&&await o.raw(["config","--global","core.longpaths","true"]);let i=`https://${e.token?e.token+"@":e.token}github.com/${e.owner}/${e.repository}.git`,m=u.join(S.tmpdir(),`${e.repository}-${Date.now()}${Math.random().toString(16).slice(2,6)}`);n.watch||r.start(`Picking ${e.type}${e.type==="repository"?" without .git":" from repository"}`);let a=performance.now();await o.clone(i,m,["--depth","1","--single-branch","--branch",e.branch]);let h=u.join(m,e.path);(await l.promises.stat(h)).isDirectory()?(await l.promises.mkdir(t,{recursive:!0}),await j(h,t)):(await l.promises.mkdir(t,{recursive:!0}),await l.promises.copyFile(h,t+"/"+e.path.split("/").pop())),n.watch?p.success("Synced at "+new Date().toLocaleTimeString()):r.stop(`Picked ${e.type}${e.type==="repository"?" without .git":" from repository"} in ${((performance.now()-a)/1e3).toFixed(2)} seconds!`),await l.promises.rm(m,{recursive:!0,force:!0})}catch(o){r.stop("Level 2: An error occurred while cloning!"),o instanceof Error?p.error("Error: "+o.message):p.error("Unexpected Error: "+JSON.stringify(o,null,2)),process.exit(1)}};import{Command as M}from"commander";import z from"terminal-link";import s from"yoctocolors";var E={name:"gitpick",version:"3.26.0",description:"With gitpick, you can clone precisely what you need.",keywords:["clone","degit","directory","file","folder","git","github","scaffolding","template","url"],homepage:"https://github.com/nrjdalal/gitpick#readme",bugs:"https://github.com/nrjdalal/gitpick/issues",repository:"nrjdalal/gitpick",funding:"https://github.com/sponsors/nrjdalal",license:"MIT",author:{name:"Neeraj Dalal",email:"admin@nrjdalal.com",url:"https://nrjdalal.com"},type:"module",bin:{degit:"./dist/index.js",gitpick:"./dist/index.js"},files:["dist"],scripts:{build:"tsup",dev:"tsup --watch",prepare:"npx simple-git-hooks",test:"bun run build && node dist/index.js",tests:"bash tests.sh"},"simple-git-hooks":{"pre-commit":"npx lint-staged","commit-msg":"npx commitlint --edit $1"},dependencies:{"@clack/prompts":"^0.10.0",commander:"^13.1.0","simple-git":"^3.27.0","terminal-link":"^4.0.0",yoctocolors:"^2.1.1",zod:"^3.24.2","zod-validation-error":"^3.4.0"},devDependencies:{"@commitlint/cli":"^19.8.0","@commitlint/config-conventional":"^19.8.0","@ianvs/prettier-plugin-sort-imports":"^4.4.1","@types/node":"^22.13.13","lint-staged":"^15.5.0",prettier:"^3.5.3","simple-git-hooks":"^2.12.1","sort-package-json":"^2.15.1",tsup:"^8.4.0",typescript:"^5.8.2"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function N(){let e=new M().name("gitpick").description("With gitpick, you can clone precisely what you need.").version(E.version||"1.0.0","-v, --version","display the version number"),n=process.argv.slice(2),t=["-v","--version","-h","--help","help","clone"];n.length&&!t.includes(n[0])&&process.argv.splice(2,0,"clone"),e.addCommand(x),e.configureHelp({formatHelp:()=>`${s.bold("With gitpick, you can clone precisely what you need.")}
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.26.0";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 y(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]),d=l?l==="raw"?n.slice(5).join("/"):n.slice(4).join("/"):n.slice(2).join("/")||"/",F=a||(l==="blob"?".":d.split("/").pop()||h);return{token:r,owner:p,repository:h,type:l,branch:C,path:d,target:F}}var O=`
3
+ ${o.whiteBright("With GitPick, you can clone precisely what you need.")}
5
4
 
6
- \u{1F680} More awesome tools at ${s.cyan("https://github.com/nrjdalal")}
5
+ ${o.cyan("gitpick <url>")} ${o.green("[target]")} ${o.blue("[options]")}
7
6
 
8
- -------------------------------------
9
- ${s.cyan("gitpick <url>")} ${s.green("[target]")} ${s.blue("[options]")}
10
- -------------------------------------
7
+ ${o.bold("Hint:")} Target is optional, and follows default git clone behavior.
11
8
 
12
- ${s.bold("Hint:")} Target is optional, and follows default git clone behavior.
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)
13
12
 
14
- ${s.bold("Arguments:")}
15
- ${s.cyan("url")} GitHub URL with path to file/folder
16
- ${s.green("target")} Directory to clone into (optional)
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]
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
17
20
 
18
- ${s.bold("Options:")}
19
- ${s.blue("-b, --branch ")} Branch to clone
20
- ${s.blue("-o, --overwrite")} Skip overwrite prompt
21
- ${s.blue("-w, --watch [time]")} Watch the repository and sync every [time]
22
- (e.g. 1h, 30m, 15s) default: 1m
23
- ${s.blue("-h, --help")} display help for command
24
- ${s.blue("-v, --version")} display the version number
25
-
26
- ${s.bold("Examples:")}
21
+ ${o.bold("Examples:")}
27
22
  $ gitpick <url>
28
23
  $ gitpick <url> [target]
29
24
  $ gitpick <url> [target] -b [branch]
30
25
  $ gitpick <url> [target] -w [time]
31
26
  $ gitpick <url> [target] -b [branch] -w [time]
32
- `}),console.log(s.dim(`
33
- ${z("GitPick \u2197\uFE0F ","https://github.com/nrjdalal/gitpick")} - Clone specific directories or files from GitHub!
34
- `)),e.parse()}N();
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 ${y(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=y(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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitpick",
3
- "version": "3.27.0-canary.2",
3
+ "version": "3.27.0-canary.3",
4
4
  "description": "With gitpick, you can clone precisely what you need.",
5
5
  "keywords": [
6
6
  "clone",
@@ -45,12 +45,9 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@clack/prompts": "^0.10.0",
48
- "commander": "^13.1.0",
49
48
  "simple-git": "^3.27.0",
50
49
  "terminal-link": "^4.0.0",
51
- "yoctocolors": "^2.1.1",
52
- "zod": "^3.24.2",
53
- "zod-validation-error": "^3.4.0"
50
+ "yoctocolors": "^2.1.1"
54
51
  },
55
52
  "devDependencies": {
56
53
  "@commitlint/cli": "^19.8.0",