UNPKG

@quick-game/cli

Version:

Command line interface for rapid qg development

49 lines (43 loc) 1.63 kB
const { execSync } = require('child_process') function isChromeInstalled () { try { // 方法1:直接检查应用是否存在(更快更轻量) const chromePath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; const fs = require('fs'); if (fs.existsSync(chromePath)) { return true; } // 方法2:或者使用 mdfind 查找(更全面) try { const result = execSync('mdfind "kMDItemCFBundleIdentifier == \'com.google.Chrome\'"').toString(); return result.includes('Google Chrome.app'); } catch { const standardPath = '/Applications/Google Chrome.app'; const userPath = path.join(process.env.HOME, 'Applications/Google Chrome.app'); return fs.existsSync(standardPath) || fs.existsSync(userPath); } } catch (error) { console.error('Error checking Chrome installation:', error.message); return false; } } try { // Windows 特殊处理 if (process.platform === 'win32') { execSync('SET PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1&& npm install puppeteer@18.2.1 --no-save --no-progress --loglevel=verbose --ignore-scripts', { stdio: 'inherit', shell: 'cmd.exe' }) } else { if (isChromeInstalled()) { process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = '1' } execSync('npm install puppeteer@18.2.1 --no-save --no-progress --loglevel=verbose --ignore-scripts', { stdio: 'inherit' }) } console.log('\x1b[32m安装成功\x1b[0m') } catch (error) { console.error('\x1b[31m错误代码:\x1b[0m', error.status) console.error('\x1b[31m错误信息:\x1b[0m', error.message) }