-
Notifications
You must be signed in to change notification settings - Fork 2
/
solc-manager.js
executable file
·55 lines (47 loc) · 1.49 KB
/
solc-manager.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
var fs = require('fs');
var path = require('path');
var os = require('os');
let osType = os.type().toLowerCase();
const binaryDirectory = path.join(__dirname, 'bin');
const getBinaryDirectory = function () {
if (!fs.existsSync(binaryDirectory)) {
fs.mkdirSync(binaryDirectory);
if (!osType.startsWith('windows')) {
fs.chmodSync(binaryDirectory, '0777');
}
}
return binaryDirectory;
};
const getInstalledVersion = function () {
if (!fs.existsSync(binaryDirectory)) {
return [];
}
let files = fs.readdirSync(binaryDirectory);
const binFiles = files.filter((item) => {
if (osType.startsWith('windows')) {
return item.match(/^(solc-\d+\.\d+\.\d+.exe)$/);
}
return item.match(/^(solc-\d+\.\d+\.\d+)$/);
});
const versions = binFiles.map((item) => {
if (osType.startsWith('windows')) {
return item.substring(5, item.length - 4);
}
return item.substring(5, item.length);
});
return versions;
};
const removeBinary = function (version) {
if (!fs.existsSync(binaryDirectory)) return;
fs.unlinkSync(path.join(binaryDirectory, binaryName(version)));
};
function binaryName (version) {
if (osType.startsWith('windows')) {
return 'solc-' + version + '.exe';
}
return 'solc-' + version;
}
function getBinary (version) {
return path.join(binaryDirectory, binaryName(version));
}
module.exports = { getBinaryDirectory, getInstalledVersion, binaryName, removeBinary, getBinary };