forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaths.js
More file actions
61 lines (54 loc) · 1.6 KB
/
Copy pathpaths.js
File metadata and controls
61 lines (54 loc) · 1.6 KB
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
56
57
58
59
60
61
// @ts-check
const {exec} = require('child_process');
const fs = require('fs-extra');
const path = require('path');
async function winProgramFiles(relPath) {
const x64Path = path.join(process.env.PROGRAMFILES, relPath);
if (await fs.exists(x64Path)) {
return x64Path;
}
return path.join(process.env['ProgramFiles(x86)'], relPath);
}
function linuxAppPath(app) {
return new Promise((resolve, reject) => {
exec(`which ${app}`, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result.trim());
}
});
});
}
/**
* @returns {Promise<string>}
*/
async function getChromePath() {
if (process.platform === 'darwin') {
return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
}
if (process.platform === 'win32') {
return await winProgramFiles('Google\\Chrome\\Application\\chrome.exe');
}
return await linuxAppPath('google-chrome');
}
/**
* @returns {Promise<string>}
*/
async function getFirefoxPath() {
if (process.platform === 'darwin') {
return '/Applications/Firefox Nightly.app/Contents/MacOS/firefox-bin';
}
if (process.platform === 'win32') {
return await winProgramFiles('Firefox Nightly\\firefox.exe');
}
return await linuxAppPath('firefox-nightly');
}
const chromeExtensionDebugDir = path.join(__dirname, '../../debug');
const firefoxExtensionDebugDir = path.join(__dirname, '../../debug-firefox');
module.exports = {
getChromePath,
getFirefoxPath,
chromeExtensionDebugDir,
firefoxExtensionDebugDir,
};