Make the docs renderer name match its purpose, add CMS_DOCS_SITE_PATH with ASTRO_SITE_PATH compatibility, and update docs publishing paths. --- Build: pass | Tests: pass — 2372 passed (704 files)
70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const __dirname = path.dirname(new URL(import.meta.url).pathname);
|
|
const siteRoot = path.resolve(__dirname, '..');
|
|
const repoRoot = path.resolve(siteRoot, '../../..');
|
|
const publicDocsRoot = path.join(repoRoot, 'docs', 'public');
|
|
const astroDocsRoot = path.join(siteRoot, 'src', 'content', 'docs');
|
|
const stateFile = path.join(repoRoot, 'tmp', 'cms-astro-generated-docs-sync.json');
|
|
|
|
function walkMarkdownFiles(rootDir, relPrefix = '') {
|
|
const out = [];
|
|
const entries = fs.readdirSync(rootDir, { withFileTypes: true });
|
|
for (const entry of entries) {
|
|
if (entry.name.startsWith('.')) continue;
|
|
const relPath = relPrefix ? path.join(relPrefix, entry.name) : entry.name;
|
|
const absPath = path.join(rootDir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
out.push(...walkMarkdownFiles(absPath, relPath));
|
|
continue;
|
|
}
|
|
if (!entry.isFile()) continue;
|
|
if (!/\.(md|mdx)$/u.test(entry.name)) continue;
|
|
out.push(relPath);
|
|
}
|
|
return out.sort();
|
|
}
|
|
|
|
function ensureDir(filePath) {
|
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
}
|
|
|
|
function writeFile(targetPath, content) {
|
|
ensureDir(targetPath);
|
|
fs.writeFileSync(targetPath, content, 'utf8');
|
|
}
|
|
|
|
if (!fs.existsSync(publicDocsRoot)) {
|
|
console.log(`Public docs root not found at ${publicDocsRoot}; assuming jail-local mirrored content`);
|
|
process.exit(0);
|
|
}
|
|
|
|
const relFiles = walkMarkdownFiles(publicDocsRoot);
|
|
|
|
fs.rmSync(astroDocsRoot, { recursive: true, force: true });
|
|
fs.mkdirSync(astroDocsRoot, { recursive: true });
|
|
|
|
for (const relPath of relFiles) {
|
|
const sourcePath = path.join(publicDocsRoot, relPath);
|
|
const targetPath = path.join(astroDocsRoot, relPath);
|
|
writeFile(targetPath, fs.readFileSync(sourcePath, 'utf8'));
|
|
}
|
|
|
|
fs.mkdirSync(path.dirname(stateFile), { recursive: true });
|
|
fs.writeFileSync(
|
|
stateFile,
|
|
JSON.stringify(
|
|
{
|
|
generatedAt: new Date().toISOString(),
|
|
files: relFiles.map((relPath) => relPath.replace(/\\/gu, '/')),
|
|
},
|
|
null,
|
|
2,
|
|
) + '\n',
|
|
'utf8',
|
|
);
|
|
|
|
console.log(
|
|
`Synced public docs -> Astro content: ${relFiles.length} files`,
|
|
);
|