git-ripper 1.1.2 → 1.2.1
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/bin/git-ripper.js +4 -3
- package/package.json +2 -1
- package/src/downloader.js +13 -9
- package/src/index.js +16 -7
- package/src/parser.js +2 -6
package/bin/git-ripper.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { initializeCLI } from '../src/index.js';
|
|
3
|
+
|
|
4
|
+
initializeCLI();
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "git-ripper",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "CLI tool that lets you download specific folders from GitHub repositories without cloning the entire repo.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"bin": {
|
|
7
8
|
"git-ripper": "./bin/git-ripper.js"
|
|
8
9
|
},
|
package/src/downloader.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { dirname } from "path";
|
|
6
|
+
import cliProgress from "cli-progress";
|
|
7
|
+
import pLimit from "p-limit";
|
|
6
8
|
|
|
7
9
|
// Set concurrency limit (adjustable based on network performance)
|
|
8
10
|
const limit = pLimit(5);
|
|
9
11
|
|
|
12
|
+
// Ensure __dirname and __filename are available in ESM
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = dirname(__filename);
|
|
15
|
+
|
|
10
16
|
/**
|
|
11
17
|
* Fetches the contents of a folder from a GitHub repository
|
|
12
18
|
* @param {string} owner - Repository owner
|
|
@@ -78,7 +84,6 @@ const downloadFolder = async ({ owner, repo, branch, folderPath }, outputDir) =>
|
|
|
78
84
|
|
|
79
85
|
// Progress bar setup
|
|
80
86
|
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
|
81
|
-
totalFiles = contents.filter(item => item.type === "blob").length;
|
|
82
87
|
bar.start(totalFiles, 0);
|
|
83
88
|
|
|
84
89
|
// Create download promises with concurrency control
|
|
@@ -106,6 +111,5 @@ const downloadFolder = async ({ owner, repo, branch, folderPath }, outputDir) =>
|
|
|
106
111
|
console.log(`Downloaded ${succeeded} files successfully${failed > 0 ? `, ${failed} files failed` : ""}`);
|
|
107
112
|
};
|
|
108
113
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
114
|
+
// Export functions in ESM format
|
|
115
|
+
export { downloadFolder };
|
package/src/index.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { program } from 'commander';
|
|
2
|
+
import { parseGitHubUrl } from './parser.js';
|
|
3
|
+
import { downloadFolder } from './downloader.js';
|
|
4
4
|
|
|
5
5
|
const initializeCLI = () => {
|
|
6
6
|
program
|
|
7
|
-
.version('1.1
|
|
7
|
+
.version('1.2.1')
|
|
8
8
|
.description('Clone specific folders from GitHub repositories')
|
|
9
9
|
.argument('<url>', 'GitHub URL of the folder to clone')
|
|
10
10
|
.option('-o, --output <directory>', 'Output directory', process.cwd())
|
|
11
11
|
.action(async (url, options) => {
|
|
12
12
|
try {
|
|
13
|
+
console.log(`Parsing URL: ${url}`);
|
|
13
14
|
const parsedUrl = parseGitHubUrl(url);
|
|
15
|
+
console.log(`Parsed URL:`, parsedUrl);
|
|
16
|
+
|
|
17
|
+
console.log(`Downloading folder to: ${options.output}`);
|
|
14
18
|
await downloadFolder(parsedUrl, options.output);
|
|
19
|
+
|
|
15
20
|
console.log('Folder cloned successfully!');
|
|
16
21
|
} catch (error) {
|
|
17
22
|
console.error('Error:', error.message);
|
|
@@ -22,6 +27,10 @@ const initializeCLI = () => {
|
|
|
22
27
|
program.parse(process.argv);
|
|
23
28
|
};
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
// Ensure function is executed when run directly
|
|
31
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
32
|
+
initializeCLI();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ✅ Fix the incorrect export
|
|
36
|
+
export { initializeCLI, downloadFolder };
|
package/src/parser.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
export function parseGitHubUrl(url) {
|
|
2
2
|
const urlParts = url.split('/');
|
|
3
3
|
const owner = urlParts[3];
|
|
4
4
|
const repo = urlParts[4];
|
|
5
5
|
const branch = urlParts[6] || 'main';
|
|
6
6
|
const folderPath = urlParts.slice(7).join('/');
|
|
7
7
|
return { owner, repo, branch, folderPath };
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
parseGitHubUrl
|
|
11
|
-
};
|
|
12
|
-
|
|
8
|
+
}
|