UNPKG

@honor-minigame/cli

Version:

honor minigame pack cli

71 lines (69 loc) 2.28 kB
import { require } from "../packager/lib/require.js"; const child_process_1 = require("child_process"); const fs = require("fs"); const path = require("path"); const chromePathGetter = require("chrome-paths"); function lookupChromeWindows() { return new Promise((resolve, reject) => { let chromePath = ''; const chromeSysRegHKey = '"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe" /v path'; child_process_1.exec(`REG QUERY ${chromeSysRegHKey}`, {}, (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); }); }); } function downgradLookup() { let chromePath = ''; const suffix = '\\Google\\Chrome\\Application\\chrome.exe'; const prefixes = [ process.env.LOCALAPPDATA || '', process.env.PROGRAMFILES || '', process.env['PROGRAMFILES(X86)'] || '', ]; for (const prefix of prefixes) { try { chromePath = path.join(prefix, suffix); fs.accessSync(chromePath); break; } catch (err) { } } return chromePath; } function parseChromePathFromRegOutput(stdout) { const lines = stdout.split('\n'); let testPath = '', chromePath = ''; lines.every(line => { const 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; } export {lookupChromeWindows};