gitpick 3.17.0 → 3.18.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 +13 -13
  2. package/package.json +2 -4
package/dist/index.js CHANGED
@@ -1,25 +1,25 @@
1
1
  #!/usr/bin/env node
2
- var y=Object.getOwnPropertySymbols;var C=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable;var v=(e,o)=>{var r={};for(var t in e)C.call(e,t)&&o.indexOf(t)<0&&(r[t]=e[t]);if(e!=null&&y)for(var t of y(e))o.indexOf(t)<0&&S.call(e,t)&&(r[t]=e[t]);return r};import m from"fs";import I from"os";import g from"path";function d(e){if(typeof e=="number"||/^\d+$/.test(e))return typeof e=="number"?e:parseInt(e,10);let o=/(\d+)([hms])/g,r=0,t;for(;(t=o.exec(e))!==null;){let i=parseInt(t[1],10);switch(t[2]){case"h":r+=i*36e5;break;case"m":r+=i*6e4;break;case"s":r+=i*1e3;break}}return r}import W from"simple-git";var k=async e=>{var i,s;let o=await W().listRemote([e]),r=(i=o.match(/(.+)\s+HEAD/))==null?void 0:i[1],t=(s=o.match(new RegExp(`${r}\\s+refs/heads/(.+)`)))==null?void 0:s[1];if(!t)throw new Error("Could not determine default branch!");return t};async function $(e,{branch:o,target:r}){let t=/^https:\/\/([^@]+)@github\.com/,i=e.match(t),s="";i&&(s=i[1],e=e.replace(t,"https://github.com"));let l=["git@github.com:","https://github.com/","https://raw.githubusercontent.com/"];for(let w of l)if(e.startsWith(w)){e=e.replace(w,"");break}let n=e.split("/"),c=n[0],h=n[1].endsWith(".git")?n[1].slice(0,-4):n[1],u=n[2]==="blob"?"blob":n[2]==="tree"?"tree":n[2]+n[3]==="refsheads"?"raw":"repository",D=o||(u==="repository"?await k(`https://${s&&s+"@"}github.com/${c}/${h}`):u==="raw"?n[4]:n[3]),b=u?u==="raw"?n.slice(5).join("/"):n.slice(4).join("/"):n.slice(2).join("/")||"/",T=r||(u==="blob"?".":b.split("/").pop()||h);return{token:s,owner:c,repository:h,type:u,branch:D,path:b,target:T}}import{Command as N}from"commander";import U from"inquirer";import H from"ora";import O from"simple-git";import{z as p}from"zod";import{fromError as A}from"zod-validation-error";var G=p.object({url:p.string(),target:p.string().optional(),branch:p.string().optional(),overwrite:p.boolean().optional(),watch:p.union([p.string(),p.number(),p.boolean()]).optional()}),E=new N().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
- (e.g. 1h, 30m, 15s) default: 1m`).action(async(e,o,r)=>{G.parse({url:e,target:o,branch:r.branch,overwrite:r.overwrite,watch:r.watch}),r.watch&&(typeof r.watch=="boolean"&&(r.watch="1m"),console.log(`\u{1F440} Watching every ${d(r.watch)/1e3+"s"}
4
- `));let t=await $(e,{branch:r.branch,target:o}),n=t,{token:i}=n,s=v(n,["token"]);console.log(s,`
5
- `);let l=H().start();try{l.stop();let c=g.resolve(t.target);if(r.watch&&(r.overwrite=!0),m.existsSync(c+(t.type==="blob"?"/"+t.path.split("/").pop():""))&&(await m.promises.readdir(c)).length&&!r.overwrite){let h=t.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:u}=await U.prompt([{type:"confirm",name:"overwrite",message:h,default:!1}]);if(!u)throw new Error("Chose not to overwrite files");l.info("You can use -o | --overwrite flag to skip this prompt")}if(await x(l,t,r,c),r.watch){let h=d(r.watch);setInterval(async()=>await x(l,t,r,c),h)}}catch(c){if(console.log(`
6
- `),l.fail(" Level 1: An error occurred"),c instanceof p.ZodError){let h=A(c);console.error(`
2
+ import p from"fs";import T from"os";import h from"path";function d(r){if(typeof r=="number"||/^\d+$/.test(r))return typeof r=="number"?r:parseInt(r,10);let o=/(\d+)([hms])/g,e=0,t;for(;(t=o.exec(r))!==null;){let i=parseInt(t[1],10);switch(t[2]){case"h":e+=i*36e5;break;case"m":e+=i*6e4;break;case"s":e+=i*1e3;break}}return e}import D from"simple-git";var y=async r=>{var i,n;let o=await D().listRemote([r]),e=(i=o.match(/(.+)\s+HEAD/))==null?void 0:i[1],t=(n=o.match(new RegExp(`${e}\\s+refs/heads/(.+)`)))==null?void 0:n[1];if(!t)throw new Error("Could not determine default branch!");return t};async function v(r,{branch:o,target:e}){let t=/^https:\/\/([^@]+)@github\.com/,i=r.match(t),n="";i&&(n=i[1],r=r.replace(t,"https://github.com"));let c=["git@github.com:","https://github.com/","https://raw.githubusercontent.com/"];for(let b of c)if(r.startsWith(b)){r=r.replace(b,"");break}let s=r.split("/"),g=s[0],u=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",j=o||(m==="repository"?await y(`https://${n&&n+"@"}github.com/${g}/${u}`):m==="raw"?s[4]:s[3]),w=m?m==="raw"?s.slice(5).join("/"):s.slice(4).join("/"):s.slice(2).join("/")||"/",E=e||(m==="blob"?".":w.split("/").pop()||u);return{token:n,owner:g,repository:u,type:m,branch:j,path:w,target:E}}import{Command as C}from"commander";import S from"inquirer";import I from"ora";import U from"simple-git";import{z as l}from"zod";import{fromError as W}from"zod-validation-error";var H=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()}),k=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
+ (e.g. 1h, 30m, 15s) default: 1m`).action(async(r,o,e)=>{H.parse({url:r,target:o,branch:e.branch,overwrite:e.overwrite,watch:e.watch}),e.watch&&(typeof e.watch=="boolean"&&(e.watch="1m"),console.log(`\u{1F440} Watching every ${d(e.watch)/1e3+"s"}
4
+ `));let t=await v(r,{branch:e.branch,target:o});console.log(`${t.owner}/${t.repository} \x1B[32m<${t.type}:${t.branch}>\x1B[0m ${t.type==="repository"?"":t.path}`,`
5
+ `);let i=I().start();try{i.stop();let n=h.resolve(t.target);if(e.watch&&(e.overwrite=!0),p.existsSync(n+(t.type==="blob"?"/"+t.path.split("/").pop():""))&&(await p.promises.readdir(n)).length&&!e.overwrite){let c=t.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 S.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 $(i,t,e,n),e.watch){let c=d(e.watch);setInterval(async()=>await $(i,t,e,n),c)}}catch(n){if(console.log(`
6
+ `),i.fail(" Level 1: An error occurred"),n instanceof l.ZodError){let c=W(n);console.error(`
7
7
  Validation Error:
8
- `+h.toString()+`
9
- `)}else c instanceof Error?console.error(`
8
+ `+c.toString()+`
9
+ `)}else n instanceof Error?console.error(`
10
10
  Error:
11
- `+c.message+`
11
+ `+n.message+`
12
12
  `):console.error(`
13
13
  Unexpected Error:
14
- `+JSON.stringify(c,null,2)+`
15
- `);process.exit(1)}});async function j(e,o){let r=await m.promises.readdir(e,{withFileTypes:!0});await m.promises.mkdir(o,{recursive:!0});for(let t of r){if(t.name===".git")continue;let i=g.join(e,t.name),s=g.join(o,t.name);t.isDirectory()?await j(i,s):await m.promises.copyFile(i,s)}}var x=async(e,o,r,t)=>{try{let i=O();process.platform==="win32"&&await i.raw(["config","--global","core.longpaths","true"]);let s=`https://${o.token?o.token+"@":o.token}github.com/${o.owner}/${o.repository}.git`,l=g.join(I.tmpdir(),`${o.repository}-${Math.random().toString(16).slice(2,8)}`);r.watch||e.start(`Cloning ${o.type} from repository`),await i.clone(s,l,["--depth","1","--single-branch","--branch",o.branch]);let n=g.join(l,o.path);(await m.promises.stat(n)).isDirectory()?(await m.promises.mkdir(t,{recursive:!0}),await j(n,t)):(await m.promises.mkdir(t,{recursive:!0}),await m.promises.copyFile(n,t+"/"+o.path.split("/").pop())),r.watch?e.succeed("Synced at "+new Date().toLocaleTimeString()):e.succeed(`${o.type.slice(0,1).toUpperCase()+o.type.slice(1)} cloned from repository`),await m.promises.rm(l,{recursive:!0,force:!0})}catch(i){console.log(`
16
- `),e.fail(" Level 2: An error occurred!"),i instanceof Error?console.error(`
14
+ `+JSON.stringify(n,null,2)+`
15
+ `);process.exit(1)}});async function x(r,o){let e=await p.promises.readdir(r,{withFileTypes:!0});await p.promises.mkdir(o,{recursive:!0});for(let t of e){if(t.name===".git")continue;let i=h.join(r,t.name),n=h.join(o,t.name);t.isDirectory()?await x(i,n):await p.promises.copyFile(i,n)}}var $=async(r,o,e,t)=>{try{let i=U();process.platform==="win32"&&await i.raw(["config","--global","core.longpaths","true"]);let n=`https://${o.token?o.token+"@":o.token}github.com/${o.owner}/${o.repository}.git`,c=h.join(T.tmpdir(),`${o.repository}-${Math.random().toString(16).slice(2,8)}`);e.watch||r.start(`Cloning ${o.type} from repository`),await i.clone(n,c,["--depth","1","--single-branch","--branch",o.branch]);let s=h.join(c,o.path);(await p.promises.stat(s)).isDirectory()?(await p.promises.mkdir(t,{recursive:!0}),await x(s,t)):(await p.promises.mkdir(t,{recursive:!0}),await p.promises.copyFile(s,t+"/"+o.path.split("/").pop())),e.watch?r.succeed("Synced at "+new Date().toLocaleTimeString()):r.succeed(`${o.type.slice(0,1).toUpperCase()+o.type.slice(1)} cloned from repository`),await p.promises.rm(c,{recursive:!0,force:!0})}catch(i){console.log(`
16
+ `),r.fail(" Level 2: An error occurred!"),i instanceof Error?console.error(`
17
17
  Error:
18
18
  `+i.message+`
19
19
  `):console.error(`
20
20
  Unexpected Error:
21
21
  `+JSON.stringify(i,null,2)+`
22
- `),process.exit(1)}};import a from"chalk";import{Command as B}from"commander";var f={name:"gitpick",version:"3.17.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:'if [ "$NODE_ENV" != "production" ]; then npx simple-git-hooks; fi',"publish:latest":"NODE_ENV=production changeset publish","publish:local":"bun run build && npm version minor && changeset publish",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:{chalk:"^5.4.1",commander:"^13.1.0",inquirer:"^12.5.0",ora:"^8.2.0","simple-git":"^3.27.0",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 F(){let e=new B().name("gitpick").description("With gitpick, you can clone precisely what you need.").version(f.version||"1.0.0","-v, --version","display the version number"),o=process.argv.slice(2),r=["-v","--version","-h","--help","help","clone"];o.length&&!r.includes(o[0])&&process.argv.splice(2,0,"clone"),e.addCommand(E),e.configureHelp({formatHelp:()=>`${a.bold("With gitpick, you can clone precisely what you need.")}
22
+ `),process.exit(1)}};import a from"chalk";import{Command as G}from"commander";var f={name:"gitpick",version:"3.18.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:{chalk:"^5.4.1",commander:"^13.1.0",inquirer:"^12.5.0",ora:"^8.2.0","simple-git":"^3.27.0",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 R(){let r=new G().name("gitpick").description("With gitpick, you can clone precisely what you need.").version(f.version||"1.0.0","-v, --version","display the version number"),o=process.argv.slice(2),e=["-v","--version","-h","--help","help","clone"];o.length&&!e.includes(o[0])&&process.argv.splice(2,0,"clone"),r.addCommand(k),r.configureHelp({formatHelp:()=>`${a.bold("With gitpick, you can clone precisely what you need.")}
23
23
 
24
24
  \u{1F680} More awesome tools at ${a.cyan("https://github.com/nrjdalal")}
25
25
 
@@ -49,4 +49,4 @@ ${a.bold("Examples:")}
49
49
  $ gitpick <url> [target] -b [branch] -w [time]
50
50
  `}),console.log(`
51
51
  gitpick v${f.version}
52
- `),e.parse()}F();
52
+ `),r.parse()}R();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitpick",
3
- "version": "3.17.0",
3
+ "version": "3.18.0",
4
4
  "description": "With gitpick, you can clone precisely what you need.",
5
5
  "keywords": [
6
6
  "clone",
@@ -35,9 +35,7 @@
35
35
  "scripts": {
36
36
  "build": "tsup",
37
37
  "dev": "tsup --watch",
38
- "prepare": "if [ \"$NODE_ENV\" != \"production\" ]; then npx simple-git-hooks; fi",
39
- "publish:latest": "NODE_ENV=production changeset publish",
40
- "publish:local": "bun run build && npm version minor && changeset publish",
38
+ "prepare": "npx simple-git-hooks",
41
39
  "test": "bun run build && node dist/index.js",
42
40
  "tests": "bash tests.sh"
43
41
  },