-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.js
38 lines (32 loc) · 1.29 KB
/
shared.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
const path = require('path');
const { promises: fs } = require('fs');
const { spawn: spawnSync } = require('child_process');
const spawn = (...args) => new Promise((resolve, reject) => {
let stdout = Buffer.alloc(0);
let stderr = Buffer.alloc(0);
const child = spawnSync(...args);
child.stdout.on('data', (b) => stdout = Buffer.concat([stdout, b]));
child.stderr.on('data', (b) => stderr = Buffer.concat([stderr, b]));
child.on('close', function (code) {
if (code !== 0) {
reject(stderr ? new Error(stderr.toString()) : new Error(`Command ${command} failed ${code}`));
} else {
resolve(stdout);
}
});
child.on('error', function (error) {
reject(error);
})
});
module.exports.spawn = spawn;
const exists = async (filePath) => fs.access(filePath).then(() => true).catch(e => e.code !== 'ENOENT');
module.exports.exists = exists;
const exe = process.platform === 'win32' ? '.exe' : '';
const paths = {
submodule: path.join(__dirname, 'deps', 'dump_syms'),
bin: path.join(__dirname, 'bin', `${process.platform}-${process.arch}`),
build: path.join(__dirname, 'build'),
exeOut: path.join(__dirname, 'build', 'release', `dump_syms${exe}`),
exeFinal: path.join(__dirname, 'bin', `${process.platform}-${process.arch}`, `dump_syms${exe}`),
};
module.exports.paths = paths;