-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
executable file
·80 lines (72 loc) · 2.06 KB
/
install.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
#!/usr/bin/env node
const version = '1.15.1'
const https = require('follow-redirects').https
const os = require('os')
const fs = require('fs')
const decompress = require('decompress')
const decompressTargz = require('decompress-targz')
const ProgressBar = require('progress')
var runTime = ''
if (os.type() === 'Darwin') {
runTime = 'osx-x64'
} else if (os.type() === 'Linux') {
runTime = 'linux-x64'
} else if (os.type() === 'Windows_NT') {
if (process.arch === 'ia32') {
runTime = 'win-x86'
} else if (process.arch === 'x64') {
runTime = 'win-x64'
}
} else {
throw new Error(`Invalid Platform: ${os.type()}`)
}
function download (url, dest) {
return new Promise((resolve, reject) => {
var file = fs.createWriteStream(dest)
var request = https.get(url, function (response) {
response.pipe(file)
file.on('finish', function () {
file.close(resolve)
})
})
.on('response', (res) => {
if (res.statusCode != 200) {
fs.unlink(dest)
return reject(new Error(`There was a problem downloading ${url}`))
}
var len = parseInt(res.headers['content-length'], 10)
var bar = new ProgressBar(`Downloading TSQLLint ${runTime} Runtime [:bar] :rate/bps :percent :etas`, {
complete: '=',
incomplete: ' ',
width: 20,
total: len
})
res.on('data', function (chunk) {
bar.tick(chunk.length)
})
})
.on('error', function (err) {
fs.unlink(dest)
reject(err)
})
})
};
var urlBase = `https://github.com/tsqllint/tsqllint/releases/download/${version}`
download(`${urlBase}/${runTime}.tgz`, `${runTime}.tgz`, (err) => {
if (err) {
console.log(err)
}
}).then((err) => {
if (err) {
console.log(err)
return
}
decompress(`${runTime}.tgz`, './assemblies', {
plugins: [
decompressTargz()
]
})
}).catch((err) => {
console.log(err)
process.exit(1)
})