gitpick 3.19.0 → 3.20.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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import p from"fs";import S from"os";import g from"path";function f(r){if(typeof r=="number"||/^\d+$/.test(r))return typeof r=="number"?r:parseInt(r,10);let o=/(\d+)([hms])/g,t=0,e;for(;(e=o.exec(r))!==null;){let i=parseInt(e[1],10);switch(e[2]){case"h":t+=i*36e5;break;case"m":t+=i*6e4;break;case"s":t+=i*1e3;break}}return t}import T from"simple-git";var v=async r=>{var i,n;let o=await T().listRemote([r]),t=(i=o.match(/(.+)\s+HEAD/))==null?void 0:i[1],e=(n=o.match(new RegExp(`${t}\\s+refs/heads/(.+)`)))==null?void 0:n[1];if(!e)throw new Error("Could not determine default branch!");return e};async function $(r,{branch:o,target:t}){let e=/^https:\/\/([^@]+)@github\.com/,i=r.match(e),n="";i&&(n=i[1],r=r.replace(e,"https://github.com"));let c=["git@github.com:","https://github.com/","https://raw.githubusercontent.com/"];for(let y of c)if(r.startsWith(y)){r=r.replace(y,"");break}let s=r.split("/"),u=s[0],d=s[1].endsWith(".git")?s[1].slice(0,-4):s[1],m=s[2]==="blob"?"blob":s[2]==="tree"?"tree":s[2]+s[3]==="refsheads"?"raw":"repository",E=o||(m==="repository"?await v(`https://${n&&n+"@"}github.com/${u}/${d}`):m==="raw"?s[4]:s[3]),w=m?m==="raw"?s.slice(5).join("/"):s.slice(4).join("/"):s.slice(2).join("/")||"/",D=t||(m==="blob"?".":w.split("/").pop()||d);return{token:n,owner:u,repository:d,type:m,branch:E,path:w,target:D}}import h from"chalk";import{Command as C}from"commander";import I from"inquirer";import W from"ora";import H from"simple-git";import{z as l}from"zod";import{fromError as U}from"zod-validation-error";var A=l.object({url:l.string(),target:l.string().optional(),branch:l.string().optional(),overwrite:l.boolean().optional(),watch:l.union([l.string(),l.number(),l.boolean()]).optional()}),x=new C().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("-w, --watch [time]",`Watch the repository and sync every [time]
3
3
  (e.g. 1h, 30m, 15s) default: 1m`).action(async(r,o,t)=>{A.parse({url:r,target:o,branch:t.branch,overwrite:t.overwrite,watch:t.watch}),t.watch&&(typeof t.watch=="boolean"&&(t.watch="1m"),console.log(`\u{1F440} Watching every ${f(t.watch)/1e3+"s"}
4
- `));let e=await $(r,{branch:t.branch,target:o});console.log(`${h.bold(e.owner)}/${h.bold(e.repository)} ${h.green(`<${e.type}:${e.branch}>`)} ${e.type==="repository"?`> ${h.cyan(e.target)}`:`${h.yellow(e.path)} > ${h.cyan(`${e.target}${e.type==="blob"?`/${e.path}`:""}`)}`}`,`
4
+ `));let e=await $(r,{branch:t.branch,target:o});console.log(`${h.bold(e.owner)}/${h.bold(e.repository)} ${h.green(`<${e.type}:${e.branch}>`)} ${e.type==="repository"?`> ${h.cyan(e.target)}`:`${h.yellow(e.path)} > ${h.cyan(`${e.target}${e.type==="blob"?`/${e.path.split("/").pop()}`:""}`)}`}`,`
5
5
  `);let i=W().start();try{i.stop();let n=g.resolve(e.target);if(t.watch&&(t.overwrite=!0),p.existsSync(n+(e.type==="blob"?"/"+e.path.split("/").pop():""))&&(await p.promises.readdir(n)).length&&!t.overwrite){let c=e.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?",{overwrite:s}=await I.prompt([{type:"confirm",name:"overwrite",message:c,default:!1}]);if(!s)throw new Error("Chose not to overwrite files");i.info("You can use -o | --overwrite flag to skip this prompt")}if(await k(i,e,t,n),t.watch){let c=f(t.watch);setInterval(async()=>await k(i,e,t,n),c)}}catch(n){if(console.log(`
6
6
  `),i.fail(" Level 1: An error occurred"),n instanceof l.ZodError){let c=U(n);console.error(`
7
7
  Validation Error:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitpick",
3
- "version": "3.19.0",
3
+ "version": "3.20.0-canary.0",
4
4
  "description": "With gitpick, you can clone precisely what you need.",
5
5
  "keywords": [
6
6
  "clone",