@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
70 lines (69 loc) • 2.35 kB
JavaScript
;var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _defineProperty = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/define-property"));var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
(0, _defineProperty["default"])(exports, "__esModule", { value: true });
var child_process_1 = require("child_process");
var fs = require("fs");
var path = require("path");
var chromePathGetter = require("chrome-paths");
function lookupChromeWindows() {
return new _promise["default"](function (resolve, reject) {
var chromePath = '';
var chromeSysRegHKey = '"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe" /v path';
child_process_1.exec("REG QUERY ".concat(chromeSysRegHKey), {}, function (err, stdout) {
if (!err) {
chromePath = downgradLookup();
if (!chromePath) {
reject(err);
return;
} else
{
resolve(chromePath);
return;
}
}
if (typeof stdout === 'string') {
chromePath = parseChromePathFromRegOutput(stdout);
}
if (!chromePath) {
chromePath = chromePathGetter.chrome || chromePathGetter.chromeCanary;
}
resolve(chromePath);
});
});
}
exports["default"] = lookupChromeWindows;
function downgradLookup() {
var chromePath = '';
var suffix = '\\Google\\Chrome\\Application\\chrome.exe';
var prefixes = [
process.env.LOCALAPPDATA || '',
process.env.PROGRAMFILES || '',
process.env['PROGRAMFILES(X86)'] || ''];
for (var _i = 0, _prefixes = prefixes; _i < _prefixes.length; _i++) {var prefix = _prefixes[_i];
try {
chromePath = path.join(prefix, suffix);
fs.accessSync(chromePath);
break;
}
catch (err) {}
}
return chromePath;
}
function parseChromePathFromRegOutput(stdout) {
var lines = stdout.split('\n');
var testPath = '',chromePath = '';
lines.every(function (line) {
var targLine = line.match(/path\s+reg_sz\s+(.+)/i);
if (targLine) {
testPath = targLine[1];
return false;
}
return true;
});
try {
testPath = path.resolve(testPath, 'chrome.exe');
fs.accessSync(testPath);
chromePath = testPath;
}
catch (err) {}
return chromePath;
}