mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 15:33:56 +08:00
refactor(build): share generated skill text normalization (#16375)
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { mkdir, readFile, rm } from "node:fs/promises";
|
||||
import { mkdir, rm } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
|
||||
import {
|
||||
checkOnly,
|
||||
ensureGeneratedFile,
|
||||
readNormalizedText,
|
||||
regularFilePaths,
|
||||
} from "./lib/generated-file.mjs";
|
||||
import { importVerifierSource } from "./lib/verifier-source-loader.mjs";
|
||||
@@ -19,9 +20,7 @@ const check = checkOnly("skill metadata");
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const sourceRoot = join(root, ".agents/skills/reverse-engineer-anything");
|
||||
const outputRoot = join(root, "skills/reverse-engineer-anything");
|
||||
const current = (
|
||||
await readFile(join(sourceRoot, "SKILL.md"), "utf8")
|
||||
).replaceAll("\r\n", "\n");
|
||||
const current = await readNormalizedText(join(sourceRoot, "SKILL.md"));
|
||||
const cacheBust = String(Date.now());
|
||||
const { DEFAULT_CATALOG_IDENTITY } = await import(
|
||||
`${pathToFileURL(join(root, "dist/contracts/catalog/catalogIdentity.js")).href}?${cacheBust}`
|
||||
@@ -51,10 +50,7 @@ for (const relativePath of paths) {
|
||||
source:
|
||||
relativePath === "SKILL.md"
|
||||
? source
|
||||
: (await readFile(join(sourceRoot, relativePath), "utf8")).replaceAll(
|
||||
"\r\n",
|
||||
"\n",
|
||||
),
|
||||
: await readNormalizedText(join(sourceRoot, relativePath)),
|
||||
check,
|
||||
generateCommand: "npm run docs:generate",
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
import { ensureGeneratedFile } from "./generated-file.mjs";
|
||||
import { ensureGeneratedFile, readNormalizedText } from "./generated-file.mjs";
|
||||
|
||||
// Identity fields follow the shared plugin manifest checked for local Cursor
|
||||
// publication (name, release version, repository, skill, and icon). The
|
||||
@@ -57,12 +57,11 @@ const cursorPluginSkillPaths = async (directory, prefix = "") => {
|
||||
};
|
||||
|
||||
const skillFrontmatter = (content) => {
|
||||
const normalized = content.replaceAll("\r\n", "\n");
|
||||
if (!normalized.startsWith("---\n")) return null;
|
||||
const closing = normalized.indexOf("\n---\n", 4);
|
||||
if (!content.startsWith("---\n")) return null;
|
||||
const closing = content.indexOf("\n---\n", 4);
|
||||
if (closing === -1) return null;
|
||||
const fields = {};
|
||||
for (const line of normalized.slice(4, closing).split("\n")) {
|
||||
for (const line of content.slice(4, closing).split("\n")) {
|
||||
const separator = line.indexOf(":");
|
||||
if (separator === -1) continue;
|
||||
const key = line.slice(0, separator).trim();
|
||||
@@ -135,9 +134,7 @@ export const syncCursorPluginSkill = async ({ root, check }) => {
|
||||
);
|
||||
if (!check) await rm(outputRoot, { recursive: true, force: true });
|
||||
for (const relativePath of sourcePaths) {
|
||||
const source = (
|
||||
await readFile(join(sourceRoot, relativePath), "utf8")
|
||||
).replaceAll("\r\n", "\n");
|
||||
const source = await readNormalizedText(join(sourceRoot, relativePath));
|
||||
if (!check)
|
||||
await mkdir(dirname(join(outputRoot, relativePath)), { recursive: true });
|
||||
try {
|
||||
@@ -182,9 +179,8 @@ export const inspectCursorPluginBundle = async (root) => {
|
||||
});
|
||||
const skillDirectory = join(root, CURSOR_PLUGIN_SKILLS);
|
||||
const skillNames = await readdir(skillDirectory);
|
||||
const skillContent = await readFile(
|
||||
const skillContent = await readNormalizedText(
|
||||
join(skillDirectory, CURSOR_PLUGIN_SKILL, "SKILL.md"),
|
||||
"utf8",
|
||||
);
|
||||
return {
|
||||
manifest,
|
||||
|
||||
@@ -10,3 +10,5 @@ export function checkOnly(generator: string, args?: readonly string[]): boolean;
|
||||
export function ensureGeneratedFile(
|
||||
options: GeneratedFileOptions,
|
||||
): Promise<{ readonly changed: boolean }>;
|
||||
|
||||
export function readNormalizedText(path: string): Promise<string>;
|
||||
|
||||
@@ -17,6 +17,10 @@ const isMissing = (cause) =>
|
||||
|
||||
const normalizeLineEndings = (value) => value.replaceAll("\r\n", "\n");
|
||||
|
||||
/** Read generator input as UTF-8 with LF line endings. */
|
||||
export const readNormalizedText = async (path) =>
|
||||
normalizeLineEndings(await readFile(path, "utf8"));
|
||||
|
||||
const preserveLineEndings = (source, existing) =>
|
||||
existing?.includes("\r\n") === true
|
||||
? normalizeLineEndings(source).replaceAll("\n", "\r\n")
|
||||
|
||||
Reference in New Issue
Block a user