-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
81 lines (66 loc) · 2.48 KB
/
gulpfile.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
var gulp = require('gulp');
var download = require("gulp-download2");
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var crypto = require('crypto');
var fs = require('fs');
var args = require('yargs').argv;
// Parse URL
function httpGet(theUrl){
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}
// Check SHA256
function checkSHA(file, sha256) {
var buffer = fs.readFileSync(file);
var fsHash = crypto.createHash('sha256');
fsHash.update(buffer);
var fileSha256 = fsHash.digest('hex');
if(fileSha256 != sha256){
throw (file + ": Checksum Failed!");
}
}
var version = args.jdkVersion;
var arch = args.arch;
var archJDK = arch;
var vscAPI;
if ( arch == "x64"){
vscAPI = "https://update.code.visualstudio.com/api/update/win32-x64/stable/version";
}
else {
vscAPI = "https://update.code.visualstudio.com/api/update/win32/stable/version";
archJDK = "x32";
}
var obj = JSON.parse(httpGet(vscAPI));
var strs = obj.url.split("/");
var fileName = strs[strs.length-1];
// Download VS Code
gulp.task('downloadVSC', function(){
return download(obj.url).pipe(gulp.dest('binaries/vscode/'+ arch +'/'));
});
gulp.task('checkVSC', gulp.series('downloadVSC', function(){
checkSHA('binaries/vscode/'+ arch +'/' + fileName, obj.sha256hash);
console.log("success");
return Promise.resolve("Done");
}));
// Download JDK
var API = "https://api.adoptopenjdk.net/v2/latestAssets/nightly/openjdk"+version+"?os=windows&arch="+ archJDK + "&type=jdk&heap_size=normal&openjdk_impl=hotspot";
var jdkobj = JSON.parse(httpGet(API))[0];
gulp.task("downloadJDKChecksum", function(){
return download(jdkobj.installer_checksum_link).pipe(gulp.dest('binaries/JDK/'+arch+'/'+version+'/'));
});
gulp.task("downloadJDK", function(){
return download(jdkobj.installer_link).pipe(gulp.dest('binaries/JDK/'+arch+'/'+version+'/'));
});
gulp.task("checkJDK", gulp.series("downloadJDK", "downloadJDKChecksum", function(){
var sha256TXT = 'binaries/JDK/'+arch+'/'+version+'/'+jdkobj.installer_name+'.sha256.txt'
var sha256 = fs.readFileSync(sha256TXT).toString().split(" ")[0];
checkSHA('binaries/JDK/'+arch+'/'+version+'/'+ jdkobj.installer_name, sha256);
console.log("success");
return Promise.resolve("Done");
}));
// Main
gulp.task("default", gulp.series("checkVSC", "checkJDK", function(){
return Promise.resolve("Done");
}));