import { chownSync, copyFileSync, existsSync, mkdirSync, readdirSync, statSync } from 'node:fs'; import { resolve } from 'node:path'; /** The demo plugin the seed projects switch on (#119); `DEMO_PLUGIN` is its file name. */ export const DEMO_PLUGIN = 'demo-plugin.js'; /** * Puts the plugins that ship with the repository (`plugins/*.js`) where the editor loads them from, * `data/plugins/`. Used by the build and by the e2e seeder. * * Which of them run is not decided here any more (#119): a plugin is switched on by the project * that wants it, so the seeders name it in the projects they write. What lies in `data/plugins/` * is only what is available. * * The API reads the folder as the web server's user. When this runs as root (the build on the * host), the folder and what it wrote are handed to the owner of `data/`, which is that user. */ export function publishPlugins(root) { const target = resolve(root, 'data/plugins'); mkdirSync(target, { recursive: true }); const written = [target]; for (const file of readdirSync(resolve(root, 'plugins')).filter((f) => f.endsWith('.js'))) { copyFileSync(resolve(root, 'plugins', file), resolve(target, file)); written.push(resolve(target, file)); } if (process.getuid?.() === 0) { const { uid, gid } = statSync(resolve(root, 'data')); for (const path of written) if (existsSync(path)) chownSync(path, uid, gid); } }