-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
module.ts
executable file
·68 lines (57 loc) · 1.74 KB
/
module.ts
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
65
66
67
68
#!/usr/bin/env node
import { yellow, blue, underline } from "@colors/colors/safe";
import downloadMainRepo from "./downloadMainRepo";
import downloadPartialRepo from "./downloadPartialRepo";
import cli from "./cli";
import * as getData from "./getData";
import addProgressBar from "./addProgressBar";
async function cloneRemote(
outputDirectory: string,
options: {
filePath: string;
owner: string;
project: string;
isMainRepo: boolean;
branch: string;
}
) {
const { owner, project, isMainRepo } = options;
if (isMainRepo) {
await downloadMainRepo(outputDirectory, { owner, project });
} else {
await downloadPartialRepo(outputDirectory, options);
}
}
async function goGitIt(
gitURL: string,
outputDirectory?: string,
text?: string
) {
const urlData = new URL(gitURL).pathname.split("/");
const remoteInfo = {
owner: getData.getOwner(urlData),
project: getData.getProject(urlData),
filePath: getData.getFilePath(urlData),
branch: getData.getBranch(urlData),
};
const filePath = remoteInfo.filePath || remoteInfo.project;
const isMainRepo = filePath === remoteInfo.project;
// Output directory defaults to working directory
const outDir = outputDirectory || process.cwd();
const remoteSource = `@${remoteInfo.owner}/${remoteInfo.project} `;
await addProgressBar(
text || `Downloading ${yellow(filePath)} from ${blue(remoteSource)}`,
async () => {
await cloneRemote(outDir, { ...remoteInfo, filePath, isMainRepo });
}
);
if (!text) {
console.log(
`Success! Data downloaded to ${underline(outDir + "/" + filePath)}`
);
}
}
// Execute CLI if requested
if (require.main === module) cli(goGitIt);
// Export as a node module as well
export default goGitIt;