Skip to content

Commit 9cff41a

Browse files
author
lihai2333
committed
1.1.4
cn 1. 全部输出统一为英文 2. d选项下载完毕后会输出下载耗时,如果是非可加速链接,也会继续下载 3. 改进ping选项 4. 修改帮助列表 5. 增加fh选项 6. 重写克隆程序 en 1. All outputs unified English 2. d option will outputs for time-consuming downloads after downloading, and will continue to download if it is a non-accelerable link 3. Improved ping option 4. Modify the help list 5. Increase the fh option 6. Rewrite the clone program
1 parent 3066b5d commit 9cff41a

File tree

10 files changed

+132
-98
lines changed

10 files changed

+132
-98
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
<img width="150" height="150" align="left" style="float: left; margin: 0 10px 0 0;" alt="fastgit" src="https://avatars2.githubusercontent.com/u/62810231?s=200&v=4">
1+
<img width="150" height="150" align="left" style="float: left; margin: 0 10px 0 0;" alt="fastgit" src="https://s1.ax1x.com/2020/09/06/weTnud.png">
22

33
# fgit nodejs
44

5-
<img src="https://badgen.net/badge/fgit-nodejs/1.0/blue">
6-
75
## fgit nodejs能做什么?
86

9-
它可以帮助你加快 GitHub 仓库的克隆速度,记住是 GitHub 。还具备 git 的功能,使用前提是安装了 gitgit 是必须安装的否则将无法使用本工具。
7+
它可以帮助你加快 GitHub 仓库的克隆速度,记住是 GitHub 。还具备 git 的功能,使用前提是安装了 gitgit 是必须安装的否则将无法使用本工具。
108

119
## 如何使用?
1210

1311
`fgit` 来查看说明
1412

15-
`fgit r` 加速raw下载速度
13+
## 和git有什么不同?
1614

17-
`fgit d` 加速github仓库版本源码下载速度
15+
增加了4个额外选项,如果克隆的是github的仓库,则会加速

bin/fgit.js

Lines changed: 98 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,112 @@
11
#! /usr/bin/env node
22

3-
var git = require("./../lib/git"),
4-
exec = require('child_process').exec,
5-
argv = process.argv,
6-
raw = require("./../lib/raw"),
7-
dl = require("./../lib/dl"),
8-
fs = require("fs"),
9-
ping = require("./../lib/ping"),
10-
cloneRe = new RegExp("^(https?|git)://(github\\.com|hub\\.fastgit\\.org)/.*/.*", "i"),
11-
huan = new RegExp(":github.com/", "i"),
12-
githttp = new RegExp("^(https?|git)://.*\..*", "i")
3+
const git = require("./../lib/git"),
4+
exec = require('child_process').exec,
5+
argv = process.argv,
6+
raw = require("./../lib/raw"),
7+
dl = require("./../lib/dl"),
8+
fs = require("fs"),
9+
ping = require("./../lib/ping"),
10+
cloneRe = new RegExp("^(https?|git)://github\\.com/[a-z]*/[a-z]*", "i"),
11+
//huan = new RegExp(":github.com/", "i"),
12+
githttp = new RegExp("^((https?|git)://.*\\..*|git@.*\\..*:)", "i")
1313

14-
function clone () {
15-
var k = "";
16-
for (i = 2;i<argv.length;i++){
17-
if (githttp.test(argv[i])) {
18-
var j = i;
19-
continue;
20-
}
21-
k += " " + argv[i] ;
14+
function clone() {
15+
var k = "";
16+
for (i = 2;i<argv.length;i++){
17+
if (githttp.test(argv[i])) {
18+
var j = i;
19+
continue;
20+
}
21+
k += " " + argv[i] ;
22+
}
23+
k.replace("clone", "")
24+
if (!k) k = "";
25+
if (argv[2] === "clone") {
26+
// ssh
27+
if (/^git@github.com:/i.test(argv[j])) {
28+
console.log("For a number of reasons, we can not accelerate for github ssh :(");
29+
console.log("Start download...")
30+
exec("git clone " + argv[j], function(err, stdout, srderr) {
31+
if (err) return console.log("Whoa, there's been a mistake! :(\n\n" + srderr);
32+
return console.log("Download complete! :)");
33+
}
34+
)
35+
}
36+
37+
// http/https/git
38+
if (cloneRe.test(argv[j])) {
39+
var z = 1;
40+
console.log("Start speeding up the download...");
41+
exec("git clone " + argv[j], function(err, stdout, srderr) {
42+
if (err) return console.log("There's been a mistake! :(\n\n" + srderr);
43+
return console.log("Download complete! :)");
44+
})
45+
}
46+
47+
// Other
48+
if (argv[j] && !z) {
49+
console.log("Start download...");
50+
exec("git clone " + argv[j], function(err, stdout, srderr) {
51+
if (err) return console.log("There's been a mistake! :(\n\n" + srderr);
52+
return console.log("Download complete! :)");
53+
})
54+
}
55+
56+
// error
57+
if (!j) {
58+
return console.log("What you provide is not a link!")
59+
}
60+
if (/git@hub.fastgit.org:/.test(argv[j])) {
61+
return console.log("We will cancel this acceleration for various reasons!");
62+
}
63+
}
64+
/*argv[2] == "clone"?/[email protected]/i.test(argv[j])?
65+
(
66+
console.log("开始下载..."),
67+
k.replace("clone", ""),
68+
exec("git clone " + argv[j] + k, function (err, stdout, srderr) {
69+
if (err) return console.log("There's been a mistake!\n\n" + srderr)
70+
console.log("\n克隆完成\n由于一系列原因,我们无法为您提供github ssh 克隆加速:(\n");
71+
})):(console.log("开始下载..."),
72+
exec("git clone " + argv[j].replace(huan, "://hub.fastgit.org/") + k.replace("clone", ""), function (err, stdout, srderr) {
73+
if (err) {
74+
return console.log("\n出错了请重试\n\n" + srderr + "\n");
2275
}
23-
if (!k) k = "";
24-
argv[2] == "clone"?/git@github.com/i.test(argv[j])?
25-
(
26-
console.log("开始下载..."),
27-
k.replace("clone", ""),
28-
exec("git clone " + argv[j] + k, function (err, stdout, srderr) {
29-
if (err) return console.log("出错啦!\n\n" + srderr)
30-
console.log("\n克隆完成\n由于一系列原因,我们无法为您提供github ssh 克隆加速:(\n");
31-
})):
32-
(console.log("开始下载..."),
33-
exec("git clone " + argv[j].replace(huan, "://hub.fastgit.org/") + k.replace("clone", ""), function (err, stdout, srderr) {
34-
if (err) {
35-
return console.log("\n出错了请重试\n\n" + srderr + "\n");
36-
}
37-
cloneRe.test(argv[j])?console.log("\n看来加速还是不错滴2333\n"):console.log("\n下载完毕\n")
38-
}
39-
)
40-
):(
41-
k.replace("clone", ""),
42-
exec("git clone " + argv[j] + k, function (err, stdout, srderr) {
43-
console.log(srderr);
44-
}),
45-
console.log("开始下载")
46-
)
76+
cloneRe.test(argv[j])?console.log("\nIt seems that the speed is still good\n"):console.log("\n下载完毕\n")
77+
})):(
78+
k.replace("clone", ""),
79+
exec("git clone " + argv[j] + k, function (err, stdout, srderr) {
80+
console.log(srderr);
81+
}),
82+
console.log("开始下载")
83+
)*/
4784
}
4885

49-
if (!argv[2]) {
50-
console.log(`\n欢迎使用fgit。\n
51-
由厉害制作\n\n用 fgit clone [github仓库链接,只能是http或https的] 加速仓库克隆。
52-
附加几个参数:
53-
r 加速raw.githubusercontent.com的下载速度
54-
d 加速github仓库打包代码下载速度\n`);
55-
process.exit();
86+
if (!argv[2] || argv[2] === "fh") {
87+
console.log(`
88+
Welcome to fgit-nodejs!
89+
Made by lihai2333
90+
91+
help:
92+
fgit clone <Git warehouse link>
93+
Additional options:
94+
r Speed up raw.githubusercontent.com download
95+
d Speed up github Releases download
96+
fh List this help
97+
ping Test whether acceleration is available
98+
99+
`);
100+
process.exit();
56101
}
57102

58103
argv[2] == "clone" ?
59-
clone()
104+
clone()
60105
:argv[2] == "r"?
61-
argv[3]?raw(argv[3]):console.log("\n请给个raw.githubusercontent.com链接\n")
106+
argv[3]?raw(argv[3]):console.log("\nNeed a raw.githubusercontent.com link\n")
62107
:argv[2] == "d"?
63-
argv[3]?dl(argv[3]):console.log("\n请给个github下载链接吧\n")
108+
argv[3]?dl(argv[3]):console.log("\nNeed a github Releases link\n")
64109
:argv[2] == "ping"?
65-
ping()
110+
ping()
66111
:git(argv)
67112

lib/dl.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
var exec = require('child_process').exec,
2-
Re = new RegExp("^https?://github\\.com|hub\\.fastgit\\.org/.*/.*/.*/.*", "i"),
3-
fastRe = new RegExp("^https?://download\\.fastgit\\.org/.*/.*/.*/.*", "i")
2+
Re = new RegExp("^https?://(github\\.com|hub\\.fastgit\\.org)/.*/.*/.*/.*", "i"),
3+
fastRe = new RegExp("^https?://download\\.fastgit\\.org/.*/.*/.*/.*", "i")
4+
5+
function date() {
6+
return new Date().getTime();
7+
}
48

59
function dl (link) {
6-
Re.test(link)?exec("wget " + link.replace(/github.com|hub.fastgit.org/, "download.fastgit.org"), function (err, stdout, srderr) {
7-
err?console.log("哎呀出错了!\n\n" + srderr):console.log("看来速度还是不错滴2333");
8-
}):fastRe.test(link)?exec("wget " + link, function (err ,stdout, srderr) {
9-
err?console.log("哎呀出错了!\n\n" + srderr):console.log("下载完毕,享受读代码的乐趣吧:)");
10-
}):console.log("解析链接,导致加速失败(っ﹏-) .。")
10+
var start = date()
11+
Re.test(link)?exec("wget " + link.replace(/github.com|hub.fastgit.org/, "download.fastgit.org"), function (err, stdout, srderr) {
12+
err?console.log("Oops, there's been a mistake!\n\n" + srderr):console.log("Download complete :)" + " Use time " + (date() - start) + "ms");
13+
}):fastRe.test(link)?exec("wget " + link, function (err ,stdout, srderr) {
14+
err?console.log("Oops, there's been a mistake!\n\n" + srderr):console.log("Download complete :)" + " Use time " + (date() - start) + "ms");
15+
}):(console.log("Link resolution failed and download non-accelerable files began (っ﹏-) ."),exec("wget " + link))
1116
}
1217

1318
module.exports = dl;

lib/git.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
var exec = require('child_process').exec;
2-
var Git = "git";
1+
var exec = require('child_process').exec,
2+
Git = "git";
33

44
function send (data) {
5-
for (var i = 2;i < data.length;i++) {
6-
Git += " " + data[i];
7-
}
8-
exec(Git, function (err, stdout, srderr) {
9-
err?console.log(srderr):console.log(`${srderr}
5+
for (var i = 2;i < data.length;i++) {
6+
Git += " " + data[i];
7+
}
8+
console.log("The command is equivalent to: " + Git + "\n")
9+
exec(Git, function (err, stdout, srderr) {
10+
err?console.log(srderr):console.log(`${srderr}
11+
1012
${stdout}`);
11-
})
13+
})
1214
}
1315

1416
function git (data) {
15-
send(data);
17+
send(data);
1618
}
1719

1820
module.exports = git;

lib/ping.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
var dns = require("dns");
2+
23
function ping() {
3-
console.log("fgit\u6B63\u5E38\n\u53EF\u4EE5\u4F7F\u7528fgit\n\n\u6B63\u5728\u68C0\u67E5\u52A0\u901F\u94FE\u63A5\u662F\u5426\u6B63\u5E38...");
4+
console.log("You can use fgit \n\nIt's being tested...");
45
dns.lookup("hub.fastgit.org", function (err, address, family) {
5-
address && address == "45.80.189.136" ? console.log("\u52A0\u901F\u94FE\u63A5\u6B63\u5E38\n\u68C0\u6D4B\u5B8C\u6BD5:)") : console.log("\u68C0\u6D4B\u5230\u52A0\u901F\u94FE\u63A5\u6709\u95EE\u9898\uFF0C\u8BF7\u91CD\u8BD5\n\u68C0\u6D4B\u5931\u8D25:(\n");
6+
address && address ? console.log("Accelerated link is normal\nTest complete :)") : console.log("There's a problem with the acceleration link! :(\n");
67
});
78
}
89
module.exports = ping;

lib/raw.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var exec = require('child_process').exec,
2-
Re = new RegExp("https?://raw\\.githubusercontent\\.com|raw\\.fastgit\\.org/.*/.*/.*","i");
2+
Re = new RegExp("https?://(raw\\.githubusercontent\\.com|raw\\.fastgit\\.org|hub.fastgit.org)/.*/.*/.*","i");
33

44
function raw (link) {
55
Re.test(link)?exec("wget " + link.replace("raw.githubusercontent.com", "raw.fastgit.org"), function (err, stdout, srderr) {
6-
err?console.log("哎呀出错了!\n\n" + srderr):console.log("看来速度还是不错滴2333");
7-
}):console.log("链接有问题,加速失败:(");
6+
err?console.log("Oops, there's been a mistake! \n\n" + srderr):console.log("It seems that the speed is still good");
7+
}):console.log("Parsing error :(");
88
}
99

1010
module.exports = raw;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fgit-cli",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"main": "./lib/main.js",
55
"bin": {
66
"fgit": "bin/fgit.js"

src/ping.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/README.md

Whitespace-only changes.

test/package.json

Whitespace-only changes.

0 commit comments

Comments
 (0)