Skip to content

Commit 86ba2e6

Browse files
committed
Merge branch 'master' of https://github.com/Stevertus/mcscript
2 parents 74c3206 + e09677c commit 86ba2e6

File tree

11 files changed

+3171
-2829
lines changed

11 files changed

+3171
-2829
lines changed

bin/add.js

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,89 @@
11
const http = require('https');
22
const fs = require('fs');
33

4-
// Add Pack (downloading pack from mediafire)
5-
exports.addPack = function(name){
64

7-
let patt = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/)
5+
// Download File From url
6+
const download = function (url, name) {
87

9-
if(patt.test(name)){
8+
console.log("\x1b[36m", "Downloading " + name + ".zip ...", "\x1b[0m");
109

11-
download(name, "external")
10+
let file = fs.createWriteStream(name + '.zip');
11+
let request = http.get(url, function (response) {
1212

13-
} else http.get("https://download1350.mediafire.com/q7aa9e774jug/oyrbdi6fbpqo1bl/mcscri%27%2B%27pt+packages.json", (res) => {
13+
response.pipe(file);
14+
response.on('end', () => {
15+
console.log("\x1b[32m", "Download of " + name + ".zip finished!", "\x1b[0m")
16+
});
1417

15-
res.setEncoding('utf8');
16-
res.on('data', function (chunk) {
18+
}).on('error', function (e) {
1719

18-
let packs = JSON.parse(chunk)
19-
let obj = packs.find(obj => obj.name === name.toLowerCase())
20+
console.log("\x1b[31m", "Got error: " + e.message, "\x1b[0m");
2021

21-
if(obj && obj.url){
22-
console.log(obj.url.slice(0, 17))
23-
if(obj.url.slice(0, 17) == "https://github.com" || obj.url.slice(0, 16) == "http://github.com") downloadFromRedirectLink(obj.url, obj.name)
22+
});
23+
};
24+
// Add Pack (downloading pack from mediafire)
25+
exports.addPack = function (name) {
2426

25-
else download(obj.url, obj.name)
27+
let patt = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/);
2628

27-
} else {
29+
if (patt.test(name)) {
2830

29-
let packStr = ""
30-
packs.forEach((e, i) => {
31+
download(name, "external")
3132

32-
packStr += e.name
33-
if(i != packs.length - 1) packStr += ", "
33+
} else http.get("https://download1350.mediafire.com/q7aa9e774jug/oyrbdi6fbpqo1bl/mcscri%27%2B%27pt+packages.json", (res) => {
3434

35-
})
35+
res.setEncoding('utf8');
36+
res.on('data', function (chunk) {
3637

37-
console.log("\x1b[31m","Your pack was not found! Please use one of these: ","\x1b[0m")
38-
console.log("\x1b[36m",packStr,"\x1b[0m")
38+
let packs = JSON.parse(chunk);
39+
let obj = packs.find(obj => obj.name === name.toLowerCase());
3940

40-
}
41-
});
41+
if (obj && obj.url) {
42+
console.log(obj.url.slice(0, 17));
43+
if (obj.url.slice(0, 17) === "https://github.com" || obj.url.slice(0, 16) === "http://github.com") downloadFromRedirectLink(obj.url, obj.name);
4244

43-
}).on('error', function(e) {
45+
else download(obj.url, obj.name)
4446

45-
console.log("\x1b[31m","Got error: " + e.message,"\x1b[0m");
47+
} else {
4648

47-
});
48-
}
49+
let packStr = "";
50+
packs.forEach((e, i) => {
4951

50-
// Download File From url
51-
var download = function (url, name){
52+
packStr += e.name;
53+
if (i !== packs.length - 1) packStr += ", "
5254

53-
console.log("\x1b[36m","Downloading "+name+".zip ...","\x1b[0m")
55+
});
5456

55-
let file = fs.createWriteStream(name + '.zip');
56-
let request = http.get(url, function(response) {
57+
console.log("\x1b[31m", "Your pack was not found! Please use one of these: ", "\x1b[0m");
58+
console.log("\x1b[36m", packStr, "\x1b[0m")
5759

58-
response.pipe(file)
59-
response.on('end', () => {
60-
console.log("\x1b[32m","Download of "+name+".zip finished!","\x1b[0m")
61-
});
60+
}
61+
});
6262

63-
}).on('error', function(e) {
63+
}).on('error', function (e) {
6464

65-
console.log("\x1b[31m","Got error: " + e.message,"\x1b[0m");
65+
console.log("\x1b[31m", "Got error: " + e.message, "\x1b[0m");
6666

67-
});
68-
}
67+
});
68+
};
6969

7070
// Download File From Redirected-Url (in this programm mostly github.com)
7171
function downloadFromRedirectLink(url, file) {
7272

73-
http.get(url, function(res) {
73+
http.get(url, function (res) {
7474

75-
if(res.statusCode != 302){ // No redirect
75+
if (res.statusCode !== 302) { // No redirect
7676

7777
console.log("error: no redirect found");
7878
return;
7979

8080
}
8181

82-
download(res.headers.location,file);
82+
download(res.headers.location, file);
8383

84-
}).on('error', function(e) {
84+
}).on('error', function (e) {
8585

86-
console.log("\x1b[31m", "Got error: " + e.message,"\x1b[0m");
86+
console.log("\x1b[31m", "Got error: " + e.message, "\x1b[0m");
8787

8888
});
8989
}

bin/modal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env node
22
const lib = require('../lib/index.js');
3-
lib.genModals(process.argv[2] || './')
3+
lib.genModals(process.argv[2] || './');

bin/test-module.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ const addPack = require('./add.js');
55
const gen_new = require('../lib/gen_new.js');
66
const consoletheme = require('../lib/consoletheme.js');
77

8-
var fullError = false;
9-
if(process.argv.indexOf("-fullErr") != -1){ //does our flag exist?
10-
fullError = true
8+
let fullError = false;
9+
if(process.argv.indexOf("-fullErr") !== -1){ //does our flag exist?
10+
fullError = true;
1111
process.argv.splice(process.argv.indexOf("-fullErr"),1)
1212
}
1313

bin/watch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env node
22
const lib = require('../lib/index.js');
3-
lib.watch(process.argv[2] || './')
3+
lib.watch(process.argv[2] || './');

lib/consoletheme.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ module.exports = {
2424
BgMagenta: "\x1b[45m",
2525
BgCyan: "\x1b[46m",
2626
BgWhite: "\x1b[47m",
27-
}
27+
};

0 commit comments

Comments
 (0)