包含后厨 团餐 门店分支
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

40 regels
1.2 KiB

  1. /* eslint-disable global-require */
  2. /* eslint-disable import/no-extraneous-dependencies */
  3. const { execSync } = require('child_process');
  4. const { join } = require('path');
  5. const findChrome = require('carlo/lib/find_chrome');
  6. const detectInstaller = require('detect-installer');
  7. const installPuppeteer = () => {
  8. // find can use package manger
  9. const packages = detectInstaller(join(__dirname, '../../'));
  10. // get installed package manger
  11. const packageName = packages.find(detectInstaller.hasPackageCommand) || 'npm';
  12. console.log(`🤖 will use ${packageName} install puppeteer`);
  13. const command = `${packageName} ${packageName.includes('yarn') ? 'add' : 'i'} puppeteer`;
  14. execSync(command, {
  15. stdio: 'inherit',
  16. });
  17. };
  18. const initPuppeteer = async () => {
  19. try {
  20. // eslint-disable-next-line import/no-unresolved
  21. const findChromePath = await findChrome({});
  22. const { executablePath } = findChromePath;4
  23. console.log(`🧲 find you browser in ${executablePath}`);
  24. return;
  25. } catch (error) {
  26. console.log('🧲 no find chrome');
  27. }
  28. try {
  29. require.resolve('puppeteer');
  30. } catch (error) {
  31. // need install puppeteer
  32. await installPuppeteer();
  33. }
  34. };
  35. initPuppeteer();