forked from coleam00/bolt.new-any-llm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync-fixer-bolt.cjs
64 lines (59 loc) · 2.04 KB
/
sync-fixer-bolt.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const https = require('node:https');
const readline = require('node:readline');
const fs = require('node:fs');
const parseGitHubUrl = (url) => {
const match = url.match(/github\.com\/([^/]+)\/([^/]+)/);
if (!match) throw new Error("Invalid GitHub URL format");
return { owner: match[1], repo: match[2] };
};
const fetchData = (url, options) => {
return new Promise((resolve, reject) => {
const req = https.get(url, options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(JSON.parse(data));
} else {
reject(new Error(data));
}
});
});
req.on('error', reject);
req.end();
});
};
const getRawFileLinks = async (url) => {
try {
const { owner, repo } = parseGitHubUrl(url);
const branch = "main";
const apiUrl = `https://api.github.com/repos/${owner}/${repo}/git/trees/${branch}?recursive=1`;
const treeData = await fetchData(apiUrl, {
headers: {
'User-Agent': 'Node.js - Manual Webcontainers Clone-Like Behavior for bolt.new-any-llm users',
},
});
const files = treeData.tree.filter((item) => item.type === "blob");
const rawLinks = files.map((file) => ({
link: `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/${file.path}`,
path: file.path,
}));
const scriptContent = rawLinks.map(({ link, path }) => {
const dir = path.includes('/') ? `mkdir -p "${path.substring(0, path.lastIndexOf('/'))}" && ` : '';
return `${dir}curl -o "${path}" "${link}"`;
}).join('\n');
fs.writeFileSync(`Cloner_${owner}_${repo}.txt`, scriptContent, 'utf-8');
console.log('Script written to creator.txt');
} catch (error) {
console.error("Error:", error.message);
}
};
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question("Enter the GitHub repository URL: ", (url) => {
getRawFileLinks(url).finally(() => rl.close());
});