editors/vscode/binary.js
1
'use strict';
3
const fs = require('fs');
4
const path = require('path');
6
const bundledDirectory = 'bin';
7
const executableBits = 0o111;
9
function bundledBinary(extensionPath, platform) {
10
const name = platform === 'win32' ? 'koment.exe' : 'koment';
11
return path.join(extensionPath, bundledDirectory, name);
12
}
14
function resolveBinary({ configured, extensionPath, platform, exists = fs.existsSync }) {
15
const explicit = (configured ?? '').trim();
16
if (explicit) {
17
return { command: explicit, source: 'configured' };
18
}
19
const bundled = bundledBinary(extensionPath, platform);
20
if (exists(bundled)) {
21
return { command: bundled, source: 'bundled' };
22
}
23
return { command: 'koment', source: 'path' };
24
}
26
function ensureExecutable(binary, { platform = process.platform, stat = fs.statSync, chmod = fs.chmodSync } = {}) {
27
if (platform === 'win32') {
28
return false;
29
}
30
const { mode } = stat(binary);
31
if ((mode & executableBits) === executableBits) {
32
return false;
33
}
34
chmod(binary, mode | executableBits);
35
return true;
36
}
38
module.exports = { bundledBinary, ensureExecutable, resolveBinary };