ext.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. module.exports = {
  7. key: 'puppeteer',
  8. title: 'Puppeteer',
  9. 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)',
  10. async isCompatible () {
  11. return os.arch() === 'x64'
  12. },
  13. isInstalled: false,
  14. isInstallable: true,
  15. async check () {
  16. try {
  17. this.isInstalled = await fs.pathExists(path.join(process.cwd(), 'node_modules/puppeteer-core/.local-chromium'))
  18. } catch (err) {
  19. this.isInstalled = false
  20. }
  21. return this.isInstalled
  22. },
  23. async install () {
  24. try {
  25. const { stdout, stderr } = await exec('node install.js', {
  26. cwd: path.join(process.cwd(), 'node_modules/puppeteer-core'),
  27. timeout: 300000,
  28. windowsHide: true
  29. })
  30. this.isInstalled = true
  31. WIKI.logger.info(stdout)
  32. WIKI.logger.warn(stderr)
  33. } catch (err) {
  34. WIKI.logger.error(err)
  35. }
  36. }
  37. }