UNPKG

alinea

Version:
51 lines (49 loc) 1.67 kB
import "../../chunks/chunk-NZLE2WMY.js"; // src/cli/util/ViewsPlugin.ts import { Config } from "alinea/core/Config"; import { code } from "alinea/core/util/CodeGen"; import { values } from "alinea/core/util/Objects"; import { viewKeys } from "alinea/dashboard/editor/ViewKeys"; function viewsPlugin(rootDir, cms) { return { name: viewsPlugin.entry, setup(build) { const views = new Set( values(viewKeys).concat( Config.referencedViews(cms.config).filter(Boolean) ) ); const entry = `${[...views].map((view, index) => { const separatorIndex = view.slice(1).lastIndexOf("#"); const pkg = separatorIndex > -1 ? view.slice(0, separatorIndex + 1) : view; const name = separatorIndex > -1 ? view.slice(separatorIndex + 2) : "default"; const alias = `view_${index}`; return `import {${name} as ${alias}} from ${JSON.stringify(pkg)}`; }).join("\n")} ${code` import 'alinea/css' export const views = { ${[...views].map((view, index) => { const alias = `view_${index}`; return ` ${JSON.stringify(view)}: ${alias}`; }).join(",\n")} } `}`; build.onResolve({ filter: new RegExp(`^${viewsPlugin.entry}$`) }, (args) => { return { path: args.path, namespace: viewsPlugin.entry }; }); build.onLoad({ filter: /.*/, namespace: viewsPlugin.entry }, () => { return { contents: entry, resolveDir: rootDir }; }); } }; } ((viewsPlugin2) => { viewsPlugin2.entry = "#alinea/views"; })(viewsPlugin || (viewsPlugin = {})); export { viewsPlugin };