ext.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const os = require('os')
  2. const path = require('path')
  3. const util = require('util')
  4. const exec = util.promisify(require('child_process').exec)
  5. const fs = require('fs-extra')
  6. /* global WIKI */
  7. module.exports = {
  8. key: 'puppeteer',
  9. title: 'Puppeteer',
  10. description: 'Headless chromium browser for server-side rendering. Required for generating PDF versions of pages and render content elements on the server (e.g. Mermaid diagrams)',
  11. async isCompatible () {
  12. return os.arch() === 'x64'
  13. },
  14. isInstalled: false,
  15. isInstallable: true,
  16. async check () {
  17. try {
  18. this.isInstalled = await fs.pathExists(path.join(process.cwd(), 'node_modules/puppeteer-core/.local-chromium'))
  19. } catch (err) {
  20. this.isInstalled = false
  21. }
  22. return this.isInstalled
  23. },
  24. async install () {
  25. try {
  26. const { stdout, stderr } = await exec('node install.js', {
  27. cwd: path.join(process.cwd(), 'node_modules/puppeteer-core'),
  28. timeout: 300000,
  29. windowsHide: true
  30. })
  31. this.isInstalled = true
  32. WIKI.logger.info(stdout)
  33. WIKI.logger.warn(stderr)
  34. } catch (err) {
  35. WIKI.logger.error(err)
  36. }
  37. }
  38. }