forked from hronro/protoc-gen-grpc-web-npm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-install.js
40 lines (32 loc) · 1.1 KB
/
post-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
const path = require('path');
const fs = require('fs-extra');
const download = require('download');
const PLUGIN = require("./");
const VERSION = '1.0.4';
const DL_PREFIX = 'https://github.com/grpc/grpc-web/releases/download/';
const BIN_DIR = path.resolve(__dirname, "bin");
const EXT = process.platform === 'win32' ? '.exe' : '';
const PLATFORM_NAME = process.platform === 'win32' ? 'windows' : process.platform;
async function run() {
if (process.arch !== 'x64') {
throw new Error(`Unsupported arch: only support x86_64, but you're using ${process.arch}`);
}
await fs.ensureDir(BIN_DIR);
const execFilename = `protoc-gen-grpc-web-${VERSION}-${PLATFORM_NAME}-x86_64${EXT}`;
const downloadUrl = DL_PREFIX + VERSION + '/' + execFilename;
console.log("Downloading", downloadUrl);
const buffer = await download(downloadUrl).catch(err => {
console.error(err.message);
process.exit(1);
});
const pluginStream = fs.createWriteStream(PLUGIN);
pluginStream.write(buffer);
pluginStream.end(() => {
fs.chmodSync(PLUGIN, '0755');
});
}
try {
run();
} catch (error) {
throw error;
}