webdriverio-automation
Version:
WebdriverIO-Automation android ios project
112 lines (94 loc) • 4.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _path = _interopRequireDefault(require("path"));
var _child_process = require("child_process");
var _utils = require("@wdio/utils");
var _utils2 = require("../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @license Copyright 2016 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
const newLineRegex = /\r?\n/;
function darwin() {
const suffixes = ['/Contents/MacOS/firefox-bin'];
const LSREGISTER = '/System/Library/Frameworks/CoreServices.framework' + '/Versions/A/Frameworks/LaunchServices.framework' + '/Versions/A/Support/lsregister';
const installations = [];
(0, _child_process.execSync)(`${LSREGISTER} -dump` + ' | grep -i \'Firefox Nightly\\?.app.*$\'' + ' | awk \'{$1=""; print $0}\'').toString().split(newLineRegex).forEach(inst => {
suffixes.forEach(suffix => {
const execPath = _path.default.join(inst.substring(0, inst.indexOf('.app') + 4).trim(), suffix);
if ((0, _utils.canAccess)(execPath) && installations.indexOf(execPath) === -1) {
installations.push(execPath);
}
});
});
const priorities = [{
regex: new RegExp(`^${process.env.HOME}/Applications/.*Firefox.app`),
weight: 50
}, {
regex: /^\/Applications\/.*Firefox.app/,
weight: 100
}, {
regex: /^\/Volumes\/.*Firefox.app/,
weight: -2
}];
const whichFinds = (0, _utils2.findByWhich)(['firefox-nightly'], [{
regex: /firefox-nightly/,
weight: 51
}]);
const installFinds = (0, _utils2.sort)(installations, priorities);
return [...installFinds, ...whichFinds];
}
function linux() {
let installations = [];
const desktopInstallationFolders = [_path.default.join(require('os').homedir(), '.local/share/applications/'), '/usr/share/applications/'];
desktopInstallationFolders.forEach(folder => {
installations = installations.concat(findFirefoxExecutables(folder));
});
return (0, _utils2.findByWhich)(['firefox-nightly', 'firefox'], [{
regex: /firefox/,
weight: 51
}]);
}
function win32() {
const installations = [];
const suffixes = [`${_path.default.sep}Firefox Nightly${_path.default.sep}Application${_path.default.sep}firefox.exe`];
const prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']].filter(Boolean);
prefixes.forEach(prefix => suffixes.forEach(suffix => {
const firefoxPath = _path.default.join(prefix, suffix);
if ((0, _utils.canAccess)(firefoxPath)) {
installations.push(firefoxPath);
}
}));
return installations;
}
function findFirefoxExecutables(folder) {
const argumentsRegex = /(^[^ ]+).*/;
const edgeExecRegex = '^Exec=/.*/(firefox)-.*';
let installations = [];
if ((0, _utils.canAccess)(folder)) {
let execPaths;
try {
execPaths = (0, _child_process.execSync)(`grep -ER "${edgeExecRegex}" ${folder} | awk -F '=' '{print $2}'`, {
stdio: 'pipe'
});
} catch (e) {
execPaths = (0, _child_process.execSync)(`grep -Er "${edgeExecRegex}" ${folder} | awk -F '=' '{print $2}'`, {
stdio: 'pipe'
});
}
execPaths = execPaths.toString().split(newLineRegex).map(execPath => execPath.replace(argumentsRegex, '$1'));
execPaths.forEach(execPath => (0, _utils.canAccess)(execPath) && installations.push(execPath));
}
return installations;
}
var _default = {
darwin,
linux,
win32
};
exports.default = _default;