Skip to content

Commit 7144eab

Browse files
committed
Make downloaded file executable
1 parent 3ccd5e6 commit 7144eab

File tree

1 file changed

+55
-54
lines changed

1 file changed

+55
-54
lines changed

src/postinstall.ts

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
1-
import * as request from 'request'
2-
import * as path from 'path'
3-
import * as fs from 'fs'
4-
5-
function version() {
6-
return '1.2.1'
7-
}
8-
9-
function platform() {
10-
switch (process.platform) {
11-
case 'linux': return 'linux-x86_64'
12-
case 'darwin': return 'darwin-x86_64'
13-
case 'win32': return 'windows-x86_64'
14-
default: throw new Error(`Unsupported platform '${process.platform}'.`)
15-
}
16-
}
17-
18-
function extension() {
19-
switch (process.platform) {
20-
case 'win32': return '.exe'
21-
default: return ''
22-
}
23-
}
24-
25-
const filename = `protoc-gen-grpc-web-${version()}-${platform()}${extension()}`
26-
const destDir = path.join(__dirname, '../bin')
27-
const dest = path.join(destDir, `protoc-gen-grpc-web${extension()}`)
28-
29-
const headers = { 'User-Agent': 'request module' }
30-
31-
console.log(`Finding grpc/grpc-web release ${version()}...`)
32-
33-
request({
34-
url: `https://api.github.com/repos/grpc/grpc-web/releases`,
35-
headers,
36-
encoding: null
37-
}, (err, _req, body) => {
38-
if (err) throw new Error(`Failed to download (${err})!`)
39-
40-
const url = JSON.parse(body.toString()).find((release: any) => release.tag_name === version()).assets.find((asset: any) => asset.name === filename).browser_download_url
41-
42-
console.log(`Downloading '${url}'...`)
43-
44-
request({
45-
url,
46-
headers,
47-
encoding: null
48-
}, (err, _req, body) => {
49-
if (err) throw new Error(`Failed to download (${err})!`)
50-
51-
fs.mkdirSync(destDir, { recursive: true })
52-
53-
fs.writeFileSync(dest, body)
54-
})
1+
import * as request from 'request'
2+
import * as path from 'path'
3+
import * as fs from 'fs'
4+
5+
function version() {
6+
return '1.2.1'
7+
}
8+
9+
function platform() {
10+
switch (process.platform) {
11+
case 'linux': return 'linux-x86_64'
12+
case 'darwin': return 'darwin-x86_64'
13+
case 'win32': return 'windows-x86_64'
14+
default: throw new Error(`Unsupported platform '${process.platform}'.`)
15+
}
16+
}
17+
18+
function extension() {
19+
switch (process.platform) {
20+
case 'win32': return '.exe'
21+
default: return ''
22+
}
23+
}
24+
25+
const filename = `protoc-gen-grpc-web-${version()}-${platform()}${extension()}`
26+
const destDir = path.join(__dirname, '../bin')
27+
const dest = path.join(destDir, `protoc-gen-grpc-web${extension()}`)
28+
29+
const headers = { 'User-Agent': 'request module' }
30+
31+
console.log(`Finding grpc/grpc-web release ${version()}...`)
32+
33+
request({
34+
url: `https://api.github.com/repos/grpc/grpc-web/releases`,
35+
headers,
36+
encoding: null
37+
}, (err, _req, body) => {
38+
if (err) throw new Error(`Failed to download (${err})!`)
39+
40+
const url = JSON.parse(body.toString()).find((release: any) => release.tag_name === version()).assets.find((asset: any) => asset.name === filename).browser_download_url
41+
42+
console.log(`Downloading '${url}'...`)
43+
44+
request({
45+
url,
46+
headers,
47+
encoding: null
48+
}, (err, _req, body) => {
49+
if (err) throw new Error(`Failed to download (${err})!`)
50+
51+
fs.mkdirSync(destDir, { recursive: true })
52+
53+
fs.writeFileSync(dest, body)
54+
fs.chmodSync(dest, '0775')
55+
})
5556
})

0 commit comments

Comments
 (0)