// Load and normalize browser region scripts for server-rendered player pages. const fs = require('fs'); const path = require('path'); const PUBLIC_JS_ROOT = path.join(__dirname, '..', 'public', 'js'); const REGION_ROOT_DIR = path.join(PUBLIC_JS_ROOT, 'regions'); const REGION_TYPE_DIR = path.join(REGION_ROOT_DIR, 'type'); const REGION_CORE_SCRIPTS = ['js/shared/placeholder-utils.js', 'js/shared/placeholder-chips.js', 'js/shared/placeholder-info.js', 'js/shared/time-date-placeholders.js', 'js/regions/region-utils.js', 'js/regions/region-types.js']; function withAssetVersion(scriptPath, assetVersion) { if (!assetVersion) { return scriptPath; } return scriptPath + (String(scriptPath).indexOf('?') === -1 ? '?v=' : '&v=') + encodeURIComponent(String(assetVersion)); } function getRegionModuleScripts(assetVersion) { if (!fs.existsSync(REGION_TYPE_DIR)) { return []; } return fs.readdirSync(REGION_TYPE_DIR, { withFileTypes: true }) .filter((entry) => entry.isFile() && entry.name.toLowerCase().endsWith('.js')) .map((entry) => withAssetVersion(`js/regions/type/${entry.name}`, assetVersion)) .sort((left, right) => left.localeCompare(right)); } function getRegionEditorScripts(assetVersion) { return REGION_CORE_SCRIPTS.map((script) => withAssetVersion(script, assetVersion)).concat(getRegionModuleScripts(assetVersion)); } module.exports = { getRegionModuleScripts, getRegionEditorScripts, withAssetVersion };