gitpick 3.12.1 → 3.12.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Neeraj Dalal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -6,13 +6,13 @@ With [gitpick](https://www.npmjs.com/package/gitpick), you can clone precisely w
6
6
  [![npm](https://img.shields.io/npm/dt/gitpick?color=red&logo=npm)](https://www.npmjs.com/package/gitpick)
7
7
  [![GitHub](https://img.shields.io/github/stars/nrjdalal/gitpick?color=blue)](https://github.com/nrjdalal/gitpick)
8
8
 
9
- Tired of cloning an entire repository when you only need a specific file or folder?
9
+ Tired of cloning an entire repository when you only need a specific file or folder? Need to watch remote changes and sync them locally? GitPick is here to help!
10
10
 
11
- Simply copy the Github URL and run with `npx gitpick <url> [target] [options]`, be that a public or a private repository.
11
+ Simply copy the Github URL and run with `npx gitpick <url>`, be that a public or a private repository.
12
12
 
13
- - Target is optional, and follows default git clone behavior. Read [usage](#usage) for more details.
13
+ - Target is optional, and `gitpick` follows default git clone behavior. Read [usage](#usage) for more details.
14
14
 
15
- <img width="640" alt="Image" src="https://github.com/user-attachments/assets/7d7f281d-2268-4951-a785-7979c639140f" />
15
+ <img width="800" alt="Image" src="https://github.com/user-attachments/assets/78b92ed3-7d5c-48f4-8975-23bd744d3a3c" />
16
16
 
17
17
  ## Usage
18
18
 
@@ -83,22 +83,22 @@ Run `npx gitpick <url> [target] [options]` to clone a file or directory from a G
83
83
 
84
84
  Say your files are located at following GitHub URL with a directory:
85
85
 
86
- > https://github.com/zce/velite/tree/main/docs
86
+ > https://github.com/nrjdalal/nrjdalal/tree/main/.config
87
87
 
88
88
  You can sync them to a target directory in your project using:
89
89
 
90
90
  ```bash
91
- npx gitpick https://github.com/zce/velite/tree/main/docs awesome-docs
91
+ npx gitpick https://github.com/nrjdalal/nrjdalal/tree/main/.config config
92
92
  ```
93
93
 
94
- > This will clone the `docs` directory from the `zce/velite` repository to the `awesome-docs` directory in your project. If no target directory is given, it will use the last segment of the URL, e.g., in this case, `docs`.
94
+ > This will clone the `.config` directory from the `nrjdalal/nrjdalal` repository to the `config` directory in your project. If no target directory is given, it will use the last segment of the URL, e.g., in this case, `.config`.
95
95
 
96
96
  ---
97
97
 
98
98
  If you need to watch for changes, just add `-w` or `-w [time]` (e.g., `1s`, `1m`, `1h` which is time in a human-readable format, default is `1m`):
99
99
 
100
100
  ```bash
101
- gitpick https://github.com/zce/velite/tree/main/docs -w
101
+ gitpick https://github.com/nrjdalal/nrjdalal/tree/main/.config -w
102
102
  ```
103
103
 
104
104
  ---
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var y=Object.getOwnPropertySymbols;var C=Object.prototype.hasOwnProperty,W=Objec
5
5
  `);let c=G().start();try{c.stop();let l=g.resolve(t.target);if(r.watch&&(r.overwrite=!0),p.existsSync(l+(t.type==="blob"?"/"+t.path.split("/").pop():""))&&(await p.promises.readdir(l)).length&&!r.overwrite){let m=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 A.prompt([{type:"confirm",name:"overwrite",message:m,default:!1}]);if(!u)throw new Error("Chose not to overwrite files");c.info("You can use -o | --overwrite flag to skip this prompt")}if(await x(c,t,r,l),r.watch){let m=d(r.watch);setInterval(async()=>await x(c,t,r,l),m)}}catch(l){console.log(`
6
6
  `),c.fail("An error occurred");let m=R(l);console.log(`
7
7
  `+m.toString()+`
8
- `),process.exit(1)}});async function D(e,o){let r=await p.promises.readdir(e,{withFileTypes:!0});await p.promises.mkdir(o,{recursive:!0});for(let t of r){if(t.name===".git")continue;let n=g.join(e,t.name),s=g.join(o,t.name);t.isDirectory()?await D(n,s):await p.promises.copyFile(n,s)}}var x=async(e,o,r,t)=>{try{let n=N(),s=`https://${o.token?o.token+"@":o.token}github.com/${o.owner}/${o.repository}.git`,c=g.join(H.tmpdir(),`${o.repository}-${Date.now()}`);r.watch||e.start(`Cloning ${o.type} from repository`),await n.clone(s,c,["--depth","1","--single-branch","--branch",o.branch]);let i=g.join(c,o.path);(await p.promises.stat(i)).isDirectory()?(await p.promises.mkdir(t,{recursive:!0}),await D(i,t)):(await p.promises.mkdir(t,{recursive:!0}),await p.promises.copyFile(i,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 p.promises.rm(c,{recursive:!0,force:!0})}catch(n){throw new Error("An error occurred while cloning the repository")}};import a from"chalk";import{Command as F}from"commander";var b={name:"gitpick",version:"3.12.0",description:"With gitpick, you can clone precisely what you need.",license:"MIT",author:{name:"Neeraj Dalal",url:"https://nrjdalal.com",email:"admin@nrjdalal.com"},scripts:{dev:"tsup --watch",build:"tsup",test:"bun run build && node dist/index.js",tests:"bash tests.sh",prepare:'if [ "$NODE_ENV" != "production" ]; then npx simple-git-hooks; fi',"publish:local":"bun run build && npm version minor && changeset publish","publish:latest":"NODE_ENV=production changeset publish"},"simple-git-hooks":{"pre-commit":"npx lint-staged","commit-msg":"npx commitlint --edit $1"},repository:"nrjdalal/gitpick",homepage:"https://github.com/nrjdalal/gitpick#readme",bugs:"https://github.com/nrjdalal/gitpick/issues",keywords:["branch","checkout","cli","clone","directories","directory","file","files","folder","folders","gh","git","github","gitpick","path","sparse","specific","url"],type:"module",files:["dist"],bin:{gitpick:"./dist/index.js"},devDependencies:{"@changesets/changelog-github":"^0.5.0","@changesets/cli":"^2.27.12","@commitlint/cli":"^19.7.1","@commitlint/config-conventional":"^19.7.1","@ianvs/prettier-plugin-sort-imports":"^4.4.1","@types/node":"^22.13.1","lint-staged":"^15.4.3",prettier:"^3.4.2","simple-git-hooks":"^2.11.1",tsup:"^8.3.6",typescript:"^5.7.3"},dependencies:{chalk:"^5.4.1",commander:"^13.1.0",inquirer:"^12.4.1",ora:"^8.2.0","simple-git":"^3.27.0",zod:"^3.24.1","zod-validation-error":"^3.4.0"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function O(){let e=new F().name("gitpick").description("With gitpick, you can clone precisely what you need.").version(b.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(j),e.configureHelp({formatHelp:()=>`${a.bold("With gitpick, you can clone precisely what you need.")}
8
+ `),process.exit(1)}});async function D(e,o){let r=await p.promises.readdir(e,{withFileTypes:!0});await p.promises.mkdir(o,{recursive:!0});for(let t of r){if(t.name===".git")continue;let n=g.join(e,t.name),s=g.join(o,t.name);t.isDirectory()?await D(n,s):await p.promises.copyFile(n,s)}}var x=async(e,o,r,t)=>{try{let n=N(),s=`https://${o.token?o.token+"@":o.token}github.com/${o.owner}/${o.repository}.git`,c=g.join(H.tmpdir(),`${o.repository}-${Date.now()}`);r.watch||e.start(`Cloning ${o.type} from repository`),await n.clone(s,c,["--depth","1","--single-branch","--branch",o.branch]);let i=g.join(c,o.path);(await p.promises.stat(i)).isDirectory()?(await p.promises.mkdir(t,{recursive:!0}),await D(i,t)):(await p.promises.mkdir(t,{recursive:!0}),await p.promises.copyFile(i,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 p.promises.rm(c,{recursive:!0,force:!0})}catch(n){throw new Error("An error occurred while cloning the repository")}};import a from"chalk";import{Command as F}from"commander";var b={name:"gitpick",version:"3.12.2",description:"With gitpick, you can clone precisely what you need.",license:"MIT",author:{name:"Neeraj Dalal",url:"https://nrjdalal.com",email:"admin@nrjdalal.com"},scripts:{dev:"tsup --watch",build:"tsup",test:"bun run build && node dist/index.js",tests:"bash tests.sh",prepare:'if [ "$NODE_ENV" != "production" ]; then npx simple-git-hooks; fi',"publish:local":"bun run build && npm version minor && changeset publish","publish:latest":"NODE_ENV=production changeset publish"},"simple-git-hooks":{"pre-commit":"npx lint-staged","commit-msg":"npx commitlint --edit $1"},repository:"nrjdalal/gitpick",homepage:"https://github.com/nrjdalal/gitpick#readme",bugs:"https://github.com/nrjdalal/gitpick/issues",keywords:["branch","checkout","cli","clone","directories","directory","file","files","folder","folders","gh","git","github","gitpick","path","sparse","specific","url"],type:"module",files:["dist"],bin:{gitpick:"./dist/index.js"},devDependencies:{"@changesets/changelog-github":"^0.5.0","@changesets/cli":"^2.27.12","@commitlint/cli":"^19.7.1","@commitlint/config-conventional":"^19.7.1","@ianvs/prettier-plugin-sort-imports":"^4.4.1","@types/node":"^22.13.1","lint-staged":"^15.4.3",prettier:"^3.4.2","simple-git-hooks":"^2.11.1",tsup:"^8.3.6",typescript:"^5.7.3"},dependencies:{chalk:"^5.4.1",commander:"^13.1.0",inquirer:"^12.4.1",ora:"^8.2.0","simple-git":"^3.27.0",zod:"^3.24.1","zod-validation-error":"^3.4.0"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function O(){let e=new F().name("gitpick").description("With gitpick, you can clone precisely what you need.").version(b.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(j),e.configureHelp({formatHelp:()=>`${a.bold("With gitpick, you can clone precisely what you need.")}
9
9
 
10
10
  \u{1F680} More awesome tools at ${a.cyan("https://github.com/nrjdalal")}
11
11
 
@@ -36,4 +36,3 @@ ${a.bold("Examples:")}
36
36
  `}),console.log(`
37
37
  gitpick v${b.version}
38
38
  `),e.parse()}O();
39
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,29 +1,7 @@
1
1
  {
2
2
  "name": "gitpick",
3
- "version": "3.12.1",
3
+ "version": "3.12.3",
4
4
  "description": "With gitpick, you can clone precisely what you need.",
5
- "license": "MIT",
6
- "author": {
7
- "name": "Neeraj Dalal",
8
- "url": "https://nrjdalal.com",
9
- "email": "admin@nrjdalal.com"
10
- },
11
- "scripts": {
12
- "dev": "tsup --watch",
13
- "build": "tsup",
14
- "test": "bun run build && node dist/index.js",
15
- "tests": "bash tests.sh",
16
- "prepare": "if [ \"$NODE_ENV\" != \"production\" ]; then npx simple-git-hooks; fi",
17
- "publish:local": "bun run build && npm version minor && changeset publish",
18
- "publish:latest": "NODE_ENV=production changeset publish"
19
- },
20
- "simple-git-hooks": {
21
- "pre-commit": "npx lint-staged",
22
- "commit-msg": "npx commitlint --edit $1"
23
- },
24
- "repository": "nrjdalal/gitpick",
25
- "homepage": "https://github.com/nrjdalal/gitpick#readme",
26
- "bugs": "https://github.com/nrjdalal/gitpick/issues",
27
5
  "keywords": [
28
6
  "branch",
29
7
  "checkout",
@@ -44,12 +22,43 @@
44
22
  "specific",
45
23
  "url"
46
24
  ],
47
- "type": "module",
25
+ "homepage": "https://github.com/nrjdalal/gitpick#readme",
26
+ "bugs": "https://github.com/nrjdalal/gitpick/issues",
27
+ "repository": "nrjdalal/gitpick",
28
+ "funding": "https://github.com/sponsors/nrjdalal",
29
+ "license": "MIT",
30
+ "author": {
31
+ "name": "Neeraj Dalal",
32
+ "email": "admin@nrjdalal.com",
33
+ "url": "https://nrjdalal.com"
34
+ },
35
+ "bin": {
36
+ "gitpick": "./dist/index.js"
37
+ },
48
38
  "files": [
49
39
  "dist"
50
40
  ],
51
- "bin": {
52
- "gitpick": "./dist/index.js"
41
+ "scripts": {
42
+ "build": "tsup",
43
+ "dev": "tsup --watch",
44
+ "prepare": "if [ \"$NODE_ENV\" != \"production\" ]; then npx simple-git-hooks; fi",
45
+ "publish:latest": "NODE_ENV=production changeset publish",
46
+ "publish:local": "bun run build && npm version minor && changeset publish",
47
+ "test": "bun run build && node dist/index.js",
48
+ "tests": "bash tests.sh"
49
+ },
50
+ "simple-git-hooks": {
51
+ "pre-commit": "npx lint-staged",
52
+ "commit-msg": "npx commitlint --edit $1"
53
+ },
54
+ "dependencies": {
55
+ "chalk": "^5.4.1",
56
+ "commander": "^13.1.0",
57
+ "inquirer": "^12.4.1",
58
+ "ora": "^8.2.0",
59
+ "simple-git": "^3.27.0",
60
+ "zod": "^3.24.1",
61
+ "zod-validation-error": "^3.4.0"
53
62
  },
54
63
  "devDependencies": {
55
64
  "@changesets/changelog-github": "^0.5.0",
@@ -61,16 +70,8 @@
61
70
  "lint-staged": "^15.4.3",
62
71
  "prettier": "^3.4.2",
63
72
  "simple-git-hooks": "^2.11.1",
73
+ "sort-package-json": "^2.14.0",
64
74
  "tsup": "^8.3.6",
65
75
  "typescript": "^5.7.3"
66
- },
67
- "dependencies": {
68
- "chalk": "^5.4.1",
69
- "commander": "^13.1.0",
70
- "inquirer": "^12.4.1",
71
- "ora": "^8.2.0",
72
- "simple-git": "^3.27.0",
73
- "zod": "^3.24.1",
74
- "zod-validation-error": "^3.4.0"
75
76
  }
76
77
  }
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/clone.ts","../src/utils/parse-time-string.ts","../src/utils/get-default-branch.ts","../src/utils/transform-url.ts","../src/index.ts","../package.json"],"sourcesContent":["import fs from \"fs\"\nimport os from \"os\"\nimport path from \"path\"\nimport { parseTimeString } from \"@/utils/parse-time-string\"\nimport { githubConfigFromUrl } from \"@/utils/transform-url\"\nimport { Command } from \"commander\"\nimport inquirer from \"inquirer\"\nimport ora, { Ora } from \"ora\"\nimport simpleGit from \"simple-git\"\nimport { z } from \"zod\"\nimport { fromError } from \"zod-validation-error\"\n\nconst schema = z.object({\n url: z.string(),\n target: z.string().optional(),\n branch: z.string().optional(),\n overwrite: z.boolean().optional(),\n watch: z.union([z.string(), z.number(), z.boolean()]).optional(),\n})\n\nexport const clone = new Command()\n .name(\"clone\")\n .argument(\"<url>\", \"GitHub URL with path to file/folder\")\n .argument(\"[target]\", \"Directory to clone into (optional)\")\n .option(\"-b, --branch <branch>\", \"Branch to clone\")\n .option(\"-o, --overwrite\", \"Skip overwrite prompt\")\n .option(\n \"-w, --watch [time]\",\n `Watch the repository and sync every [time]\n(e.g. 1h, 30m, 15s) default: 1m`,\n )\n .action(\n async (\n url: string,\n target: string | undefined,\n options: z.infer<typeof schema>,\n ) => {\n schema.parse({\n url,\n target,\n branch: options.branch,\n overwrite: options.overwrite,\n watch: options.watch,\n })\n\n if (options.watch) {\n if (typeof options.watch === \"boolean\") options.watch = \"1m\"\n\n console.log(\n `šŸ‘€ Watching every ${parseTimeString(options.watch) / 1000 + \"s\"}\\n`,\n )\n }\n\n const config = await githubConfigFromUrl(url, {\n branch: options.branch,\n target,\n })\n\n const { token, ...configWithoutToken } = config\n console.log(configWithoutToken, \"\\n\")\n\n const spinner = ora().start()\n\n try {\n spinner.stop()\n\n const targetPath = path.resolve(config.target)\n\n if (options.watch) options.overwrite = true\n\n if (\n fs.existsSync(\n targetPath +\n (config.type === \"blob\"\n ? \"/\" + config.path.split(\"/\").pop()\n : \"\"),\n ) &&\n (await fs.promises.readdir(targetPath)).length &&\n !options.overwrite\n ) {\n const message =\n config.type === \"tree\"\n ? \"The target directory is not empty. Do you want to overwrite the files?\"\n : \"The target file already exists. Do you want to overwrite the file?\"\n\n const { overwrite } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"overwrite\",\n message,\n default: false,\n },\n ])\n\n if (!overwrite) {\n throw new Error(\"Chose not to overwrite files\")\n }\n\n spinner.info(\"You can use -o | --overwrite flag to skip this prompt\")\n }\n\n await cloneAction(spinner, config, options, targetPath)\n\n if (options.watch) {\n const watchInterval = parseTimeString(options.watch)\n setInterval(\n async () => await cloneAction(spinner, config, options, targetPath),\n watchInterval,\n )\n }\n } catch (err) {\n console.log(\"\\n\")\n spinner.fail(\"An error occurred\")\n const validationError = fromError(err)\n console.log(\"\\n\" + validationError.toString() + \"\\n\")\n process.exit(1)\n }\n },\n )\n\nasync function copyDir(src: string, dest: string) {\n const entries = await fs.promises.readdir(src, { withFileTypes: true })\n await fs.promises.mkdir(dest, { recursive: true })\n\n for (let entry of entries) {\n if (entry.name === \".git\") continue\n const srcPath = path.join(src, entry.name)\n const destPath = path.join(dest, entry.name)\n\n if (entry.isDirectory()) {\n await copyDir(srcPath, destPath)\n } else {\n await fs.promises.copyFile(srcPath, destPath)\n }\n }\n}\n\nconst cloneAction = async (\n spinner: Ora,\n config: {\n token: string\n owner: string\n repository: string\n branch: string\n type: string\n path: string\n },\n options: {\n watch?: string | number | boolean\n },\n targetPath: string,\n) => {\n try {\n const git = simpleGit()\n const repoUrl = `https://${config.token ? config.token + \"@\" : config.token}github.com/${config.owner}/${config.repository}.git`\n const tempDir = path.join(os.tmpdir(), `${config.repository}-${Date.now()}`)\n\n if (!options.watch) spinner.start(`Cloning ${config.type} from repository`)\n\n await git.clone(repoUrl, tempDir, [\n \"--depth\",\n \"1\",\n \"--single-branch\",\n \"--branch\",\n config.branch,\n ])\n\n const sourcePath = path.join(tempDir, config.path)\n\n const sourceStat = await fs.promises.stat(sourcePath)\n if (sourceStat.isDirectory()) {\n await fs.promises.mkdir(targetPath, { recursive: true })\n await copyDir(sourcePath, targetPath)\n } else {\n await fs.promises.mkdir(targetPath, {\n recursive: true,\n })\n await fs.promises.copyFile(\n sourcePath,\n targetPath + \"/\" + config.path.split(\"/\").pop(),\n )\n }\n if (!options.watch) {\n spinner.succeed(\n `${config.type.slice(0, 1).toUpperCase() + config.type.slice(1)} cloned from repository`,\n )\n } else spinner.succeed(\"Synced at \" + new Date().toLocaleTimeString())\n\n await fs.promises.rm(tempDir, { recursive: true, force: true })\n } catch {\n throw new Error(\"An error occurred while cloning the repository\")\n }\n}\n","export function parseTimeString(timeString: string | number): number {\n if (typeof timeString === \"number\" || /^\\d+$/.test(timeString)) {\n return typeof timeString === \"number\"\n ? timeString\n : parseInt(timeString, 10)\n }\n\n const regex = /(\\d+)([hms])/g\n let totalMilliseconds = 0\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(timeString)) !== null) {\n const value = parseInt(match[1], 10)\n const unit = match[2] as \"h\" | \"m\" | \"s\"\n\n switch (unit) {\n case \"h\":\n totalMilliseconds += value * 3600000\n break\n case \"m\":\n totalMilliseconds += value * 60000\n break\n case \"s\":\n totalMilliseconds += value * 1000\n break\n }\n }\n\n return totalMilliseconds\n}\n","import simpleGit from \"simple-git\"\n\nexport const getDefaultBranch = async (url: string) => {\n const remotes = await simpleGit().listRemote([url])\n const headHash = remotes.match(/(.+)\\s+HEAD/)?.[1]\n const branch = remotes.match(\n new RegExp(`${headHash}\\\\s+refs/heads/(.+)`),\n )?.[1]\n if (!branch) {\n throw new Error(\"Could not determine default branch!\")\n }\n return branch\n}\n","import { getDefaultBranch } from \"./get-default-branch\"\n\nexport async function githubConfigFromUrl(\n url: string,\n {\n branch,\n target,\n }: {\n branch?: string | null\n target?: string | null\n },\n) {\n const regex = /^https:\\/\\/([^@]+)@github\\.com/\n const match = url.match(regex)\n\n let token = \"\"\n if (match) {\n token = match[1]\n url = url.replace(regex, \"https://github.com\")\n }\n\n const prefixes = [\n \"git@github.com:\",\n \"https://github.com/\",\n \"https://raw.githubusercontent.com/\",\n ]\n\n for (const prefix of prefixes) {\n if (url.startsWith(prefix)) {\n url = url.replace(prefix, \"\")\n break\n }\n }\n\n const split = url.split(\"/\")\n\n const owner = split[0]\n const repository = split[1].endsWith(\".git\")\n ? split[1].slice(0, -4)\n : split[1]\n const type =\n split[2] === \"blob\"\n ? \"blob\"\n : split[2] === \"tree\"\n ? \"tree\"\n : split[2] + split[3] === \"refsheads\"\n ? \"raw\"\n : \"repository\"\n const resolvedBranch = branch\n ? branch\n : type === \"repository\"\n ? await getDefaultBranch(\n `https://${token ? token + \"@\" : token}github.com/${owner}/${repository}`,\n )\n : type === \"raw\"\n ? split[4]\n : split[3]\n const path = type\n ? type === \"raw\"\n ? split.slice(5).join(\"/\")\n : split.slice(4).join(\"/\")\n : split.slice(2).join(\"/\") || \"/\"\n const resolvedTarget = target\n ? target\n : type === \"blob\"\n ? \".\"\n : path.split(\"/\").pop() || repository\n\n return {\n token,\n owner,\n repository,\n type,\n branch: resolvedBranch,\n path,\n target: resolvedTarget,\n }\n}\n","#!/usr/bin/env node\nimport { clone } from \"@/commands/clone\"\nimport chalk from \"chalk\"\nimport { Command } from \"commander\"\nimport packageJson from \"../package.json\"\n\nprocess.on(\"SIGINT\", () => process.exit(0))\nprocess.on(\"SIGTERM\", () => process.exit(0))\n\nasync function main() {\n const program = new Command()\n .name(\"gitpick\")\n .description(\"With gitpick, you can clone precisely what you need.\")\n .version(\n packageJson.version || \"1.0.0\",\n \"-v, --version\",\n \"display the version number\",\n )\n\n const args = process.argv.slice(2)\n const validCommands = [\"-v\", \"--version\", \"-h\", \"--help\", \"help\", \"clone\"]\n if (args.length && !validCommands.includes(args[0])) {\n process.argv.splice(2, 0, \"clone\")\n }\n\n program.addCommand(clone)\n\n program.configureHelp({\n formatHelp: () => {\n return `${chalk.bold(\"With gitpick, you can clone precisely what you need.\")}\n\nšŸš€ More awesome tools at ${chalk.cyan(\"https://github.com/nrjdalal\")}\n\n-------------------------------------\n ${chalk.cyan(\"gitpick <url>\")} ${chalk.green(\"[target]\")} ${chalk.blue(\"[options]\")}\n-------------------------------------\n\n${chalk.bold(\"Hint:\")} Target is optional, and follows default git clone behavior.\n\n${chalk.bold(\"Arguments:\")}\n ${chalk.cyan(\"url\")} GitHub URL with path to file/folder\n ${chalk.green(\"target\")} Directory to clone into (optional)\n\n${chalk.bold(\"Options:\")}\n ${chalk.blue(\"-b, --branch \")} Branch to clone\n ${chalk.blue(\"-o, --overwrite\")} Skip overwrite prompt\n ${chalk.blue(\"-w, --watch [time]\")} Watch the repository and sync every [time]\n (e.g. 1h, 30m, 15s) default: 1m\n ${chalk.blue(\"-h, --help\")} display help for command\n ${chalk.blue(\"-v, --version\")} display the version number\n\n${chalk.bold(\"Examples:\")}\n $ gitpick <url>\n $ gitpick <url> [target]\n $ gitpick <url> [target] -b [branch]\n $ gitpick <url> [target] -w [time]\n $ gitpick <url> [target] -b [branch] -w [time]\n`\n },\n })\n\n console.log(`\\ngitpick v${packageJson.version}\\n`)\n\n program.parse()\n}\n\nmain()\n","{\n \"name\": \"gitpick\",\n \"version\": \"3.12.0\",\n \"description\": \"With gitpick, you can clone precisely what you need.\",\n \"license\": \"MIT\",\n \"author\": {\n \"name\": \"Neeraj Dalal\",\n \"url\": \"https://nrjdalal.com\",\n \"email\": \"admin@nrjdalal.com\"\n },\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"build\": \"tsup\",\n \"test\": \"bun run build && node dist/index.js\",\n \"tests\": \"bash tests.sh\",\n \"prepare\": \"if [ \\\"$NODE_ENV\\\" != \\\"production\\\" ]; then npx simple-git-hooks; fi\",\n \"publish:local\": \"bun run build && npm version minor && changeset publish\",\n \"publish:latest\": \"NODE_ENV=production changeset publish\"\n },\n \"simple-git-hooks\": {\n \"pre-commit\": \"npx lint-staged\",\n \"commit-msg\": \"npx commitlint --edit $1\"\n },\n \"repository\": \"nrjdalal/gitpick\",\n \"homepage\": \"https://github.com/nrjdalal/gitpick#readme\",\n \"bugs\": \"https://github.com/nrjdalal/gitpick/issues\",\n \"keywords\": [\n \"branch\",\n \"checkout\",\n \"cli\",\n \"clone\",\n \"directories\",\n \"directory\",\n \"file\",\n \"files\",\n \"folder\",\n \"folders\",\n \"gh\",\n \"git\",\n \"github\",\n \"gitpick\",\n \"path\",\n \"sparse\",\n \"specific\",\n \"url\"\n ],\n \"type\": \"module\",\n \"files\": [\n \"dist\"\n ],\n \"bin\": {\n \"gitpick\": \"./dist/index.js\"\n },\n \"devDependencies\": {\n \"@changesets/changelog-github\": \"^0.5.0\",\n \"@changesets/cli\": \"^2.27.12\",\n \"@commitlint/cli\": \"^19.7.1\",\n \"@commitlint/config-conventional\": \"^19.7.1\",\n \"@ianvs/prettier-plugin-sort-imports\": \"^4.4.1\",\n \"@types/node\": \"^22.13.1\",\n \"lint-staged\": \"^15.4.3\",\n \"prettier\": \"^3.4.2\",\n \"simple-git-hooks\": \"^2.11.1\",\n \"tsup\": \"^8.3.6\",\n \"typescript\": \"^5.7.3\"\n },\n \"dependencies\": {\n \"chalk\": \"^5.4.1\",\n \"commander\": \"^13.1.0\",\n \"inquirer\": \"^12.4.1\",\n \"ora\": \"^8.2.0\",\n \"simple-git\": \"^3.27.0\",\n \"zod\": \"^3.24.1\",\n \"zod-validation-error\": \"^3.4.0\"\n }\n}\n"],"mappings":";mRAAA,OAAOA,MAAQ,KACf,OAAOC,MAAQ,KACf,OAAOC,MAAU,OCFV,SAASC,EAAgBC,EAAqC,CACnE,GAAI,OAAOA,GAAe,UAAY,QAAQ,KAAKA,CAAU,EAC3D,OAAO,OAAOA,GAAe,SACzBA,EACA,SAASA,EAAY,EAAE,EAG7B,IAAMC,EAAQ,gBACVC,EAAoB,EACpBC,EAEJ,MAAQA,EAA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,WAAW,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAQvB,CAAC,EAED,QAAQ,IAAI;AAAA,WAAcJ,EAAY,OAAO;AAAA,CAAI,EAEjDF,EAAQ,MAAM,CAChB,CAEAD,EAAK","names":["fs","os","path","parseTimeString","timeString","regex","totalMilliseconds","match","value","simpleGit","getDefaultBranch","url","_a","_b","remotes","headHash","branch","githubConfigFromUrl","url","branch","target","regex","match","token","prefixes","prefix","split","owner","repository","type","resolvedBranch","getDefaultBranch","path","resolvedTarget","Command","inquirer","ora","simpleGit","z","fromError","schema","z","clone","Command","url","target","options","parseTimeString","config","githubConfigFromUrl","_a","token","configWithoutToken","__objRest","spinner","ora","targetPath","path","fs","message","overwrite","inquirer","cloneAction","watchInterval","err","validationError","fromError","copyDir","src","dest","entries","entry","srcPath","destPath","git","simpleGit","repoUrl","tempDir","os","sourcePath","e","chalk","Command","package_default","main","program","Command","package_default","args","validCommands","clone","chalk"]}