|
1 | 1 | #! /usr/bin/env node
|
2 | 2 |
|
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") |
13 | 13 |
|
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"); |
22 | 75 | }
|
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 | + )*/ |
47 | 84 | }
|
48 | 85 |
|
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(); |
56 | 101 | }
|
57 | 102 |
|
58 | 103 | argv[2] == "clone" ?
|
59 |
| - clone() |
| 104 | + clone() |
60 | 105 | :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") |
62 | 107 | :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") |
64 | 109 | :argv[2] == "ping"?
|
65 |
| - ping() |
| 110 | + ping() |
66 | 111 | :git(argv)
|
67 | 112 |
|
0 commit comments