Files
2026-08-02 12:42:07 +02:00

63 lines
1.9 KiB
TypeScript

import {readFileSync, writeFileSync} from 'node:fs';
import path from 'node:path';
const repoRoot = process.env.SKILLS_REPO_ROOT
? path.resolve(process.env.SKILLS_REPO_ROOT)
: path.resolve(__dirname, '..', '..', '..');
const source = path.join(
repoRoot,
'packages',
'docs',
'docs',
'ai',
'skills.mdx',
);
const target = path.join(repoRoot, 'packages', 'skills', 'README.md');
const checkOnly = process.argv.includes('--check');
const frontmatterRegex = /^---\n[\s\S]*?\n---\n+/;
const suggestedPromptRegex = /<SuggestedPrompt prompt="([^"]+)" \/>/g;
const githubSourceParagraph =
'The skills are also available on GitHub [here](https://github.com/remotion-dev/remotion/tree/main/packages/skills).';
const documentationParagraph =
'For more information, see the [Remotion Agent Skills documentation](https://www.remotion.dev/docs/ai/skills).';
const sourceContents = readFileSync(source, 'utf-8');
if (!frontmatterRegex.test(sourceContents)) {
throw new Error(`Expected frontmatter in ${path.relative(repoRoot, source)}`);
}
if (!sourceContents.includes(githubSourceParagraph)) {
throw new Error(
`Expected the GitHub source paragraph in ${path.relative(repoRoot, source)}`,
);
}
const documentation = sourceContents
.replace(frontmatterRegex, '')
.replace(githubSourceParagraph, documentationParagraph)
.replace(suggestedPromptRegex, '> Example prompt: `$1`')
.replaceAll(' \n', '\n\n');
const expectedReadme = `<!-- This file is generated by packages/skills/scripts/sync-readme.ts. -->
# Remotion Agent Skills
${documentation}`;
const currentReadme = readFileSync(target, 'utf-8');
if (currentReadme === expectedReadme) {
console.log('The skills README is in sync.');
process.exit(0);
}
if (checkOnly) {
console.error(
`${path.relative(repoRoot, target)} is out of sync. Run \`bun run syncskills\` to update it.`,
);
process.exit(1);
}
writeFileSync(target, expectedReadme);
console.log(`Updated ${path.relative(repoRoot, target)}.`);