@paroicms/site-generator-plugin
Version:
ParoiCMS Site Generator Plugin
45 lines (39 loc) • 1.55 kB
JavaScript
import { docsDir, jtDir } from "@paroicms/public-server-lib";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { projectDir } from "../../context.js";
import { buildPromptTemplate } from "./prompt-template.js";
const contextContent = await readFile(join(docsDir, "introduction-to-paroicms.md"), "utf-8");
const siteSchemaTsDefs = await readFile(join(jtDir, "site-schema-json-types.d.ts"), "utf-8");
const predefinedFields = JSON.parse(await readPromptFile("predefined-fields.json"));
export async function createPromptTemplate(options) {
const { filename, withSiteSchemaTsDefs } = options;
const promptContent = await readPromptFile(filename);
const schemaTypeDefTemplate = withSiteSchemaTsDefs
? `
All the site structure is described in a site-schema in JSON format. Here is the TypeScript definition for the site schema:
<site_schema_ts_defs>
{siteSchemaTsDefs}
</site_schema_ts_defs>`
: "";
const template = `
# Context
${contextContent}${schemaTypeDefTemplate}
# Task to do
${promptContent}
`;
return buildPromptTemplate(template);
}
export async function readPromptFile(filename) {
return await readFile(join(projectDir, "prompts", filename), "utf-8");
}
export function getPredefinedFields() {
if (!predefinedFields)
throw new Error("Predefined fields not loaded");
return predefinedFields;
}
export function getSiteSchemaTsDefs() {
if (!siteSchemaTsDefs)
throw new Error("Site-schema defs not loaded");
return siteSchemaTsDefs;
}