ext.mjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. // TODO: https://pptr.dev/browsers-api/
  27. // const { stdout, stderr } = await exec('node install.js', {
  28. // cwd: path.join(WIKI.SERVERPATH, 'node_modules/puppeteer-core'),
  29. // timeout: 300000,
  30. // windowsHide: true
  31. // })
  32. // this.isInstalled = true
  33. // WIKI.logger.info(stdout)
  34. // WIKI.logger.warn(stderr)
  35. throw new Error('Not implemented yet.')
  36. } catch (err) {
  37. WIKI.logger.error(err)
  38. throw err
  39. }
  40. }
  41. }