ext.mjs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import os from 'node:os'
  2. import path from 'node:path'
  3. import util from 'node:util'
  4. import { exec as execSync } from 'node:child_process'
  5. import fse from 'fs-extra'
  6. const exec = util.promisify(execSync)
  7. export default {
  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 fse.pathExists(path.join(WIKI.SERVERPATH, '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(WIKI.SERVERPATH, '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. }