doxa-maps/internal/profile-meta.mjs
Doxa Maps 219331bcf1
Some checks are pending
Deploy to GitHub Pages / build (push) Waiting to run
Deploy to GitHub Pages / deploy (push) Blocked by required conditions
Update from source ee1cbc05
2026-09-27 10:21:12 +00:00

35 lines
1.6 KiB
JavaScript

/**
* profile-meta.mjs — the per-profile fields a host reads from <profile>.meta.json, in ONE place.
*
* generate-tree (the built manifest.json) and the dev server's /__plugin-gallery/manifest.json both call
* this, so the dev Studio and the built Studio cannot disagree (rega: the corner widget never mounted in
* dev because only the built manifest carried "widget").
* stage "production" | "experimental" default experimental
* heavy true when the element holds live WebGL contexts
* widget { corner } for a corner widget the Plugin Studio mounts once, fixed
*/
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
const CORNERS = ['bottom-right', 'bottom-left', 'top-right', 'top-left']
export function readProfileMeta(dir, profileName) {
try {
const meta = JSON.parse(readFileSync(join(dir, `${profileName}.meta.json`), 'utf8'))
const corner = meta?.widget?.corner
return {
stage: meta?.stage === 'production' ? 'production' : 'experimental',
heavy: meta?.heavy === true,
widget: CORNERS.includes(corner) ? { corner } : null,
}
} catch { return { stage: 'experimental', heavy: false, widget: null } }
}
/** The optional manifest keys for one profile (stage always; heavy / widget only when set). */
export function profileMetaFields(dir, profileName) {
const m = readProfileMeta(dir, profileName)
return { stage: m.stage, ...(m.heavy ? { heavy: true } : {}), ...(m.widget ? { widget: m.widget } : {}) }
}
/** A bundle is production if ANY of its profiles says so. */
export const bundleStage = (profiles) => (profiles.some((p) => p.stage === 'production') ? 'production' : 'experimental')