#!/usr/bin/env node // SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC // SPDX-License-Identifier: Apache-2.0 /** * Put a built Programming+ inside a copy of the Quarto extension, so a site renders the rendered views * ({{< pplus-run >}}, {{< pplus-steps >}}, ...) without a checkout of this repository beside it: * * pixi run quarto-engine ../my-site/_extensions/pplus * * copies dist/ (without the source maps and the interpreter's test fixture) to /engine/dist, where pplus.lua * looks for it after pplus-engine and PPLUS_ENGINE (quarto/README.md), pplus-core's core/dist/ to * /engine/core/dist, and a package.json that maps the app's #core/ imports to it. Run it again after rebuilding. The copy is * the app's compiled JavaScript; the site still needs Node 20 or later on the machine that renders it. */ import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const ROOT = fileURLToPath(new URL('..', import.meta.url)); const dir = process.argv[2]; const die = (m) => { console.error(`quarto-engine: ${m}`); process.exit(1); }; if (!dir) die('usage: pixi run quarto-engine '); if (!fs.existsSync(path.join(dir, 'pplus.lua'))) die(`${dir} is not the extension's folder (no pplus.lua in it); copy quarto/_extensions/pplus there first`); const dist = path.join(ROOT, 'dist'); if (!fs.existsSync(path.join(dist, 'quarto', 'render.js'))) die('dist/ is missing; run `pixi run build` first'); const out = path.join(dir, 'engine', 'dist'); fs.rmSync(path.join(dir, 'engine'), { recursive: true, force: true }); let files = 0, bytes = 0; fs.cpSync(dist, out, { recursive: true, filter: (src) => { const rel = path.relative(dist, src); if (rel.endsWith('.map') || rel === 'curriculum' || rel.startsWith('curriculum' + path.sep)) return false; if (fs.statSync(src).isFile()) { files++; bytes += fs.statSync(src).size; } return true; }, }); // pplus-core's modules, which the app's modules import as #core/...: Node finds the mapping in engine/package.json const coreDist = path.join(ROOT, 'core', 'dist'); if (!fs.existsSync(path.join(coreDist, 'common', 'workspace.js'))) die('core/dist/ is missing; run `pixi run build` first'); fs.cpSync(coreDist, path.join(dir, 'engine', 'core', 'dist'), { recursive: true, filter: (src) => { const rel = path.relative(coreDist, src); if (rel.endsWith('.map') || rel.endsWith('.d.ts') || rel === 'curriculum' || rel.startsWith('curriculum' + path.sep)) return false; if (fs.statSync(src).isFile()) { files++; bytes += fs.statSync(src).size; } return true; }, }); fs.writeFileSync(path.join(dir, 'engine', 'package.json'), JSON.stringify({ private: true, type: 'module', imports: { '#core/*': './core/dist/*' } }, null, 2) + '\n'); // the extension's own copy of the version, so a page can say which Programming+ rendered it let version = 'dev'; try { version = fs.readFileSync(path.join(ROOT, '.git', 'HEAD'), 'utf8').trim(); } catch { /* not a checkout */ } fs.writeFileSync(path.join(dir, 'engine', 'VERSION'), version + '\n'); console.log(`quarto-engine: copied ${files} files (${(bytes / 1e6).toFixed(1)} MB) to ${out}`);