CRITICAL FIX: Server would CRASH ON STARTUP (multiple import errors)
REMOVED (2 scripts):
1. scripts/framework-watchdog.js
- Monitored .claude/session-state.json (OUR Claude Code setup)
- Monitored .claude/token-checkpoints.json (OUR file structure)
- Implementers won't have our .claude/ directory
2. scripts/init-db.js
- Created website collections: blog_posts, media_inquiries, case_submissions
- Created website collections: resources, moderation_queue, users, citations
- Created website collections: translations, koha_donations
- Next steps referenced deleted scripts (npm run seed:admin)
REWRITTEN (2 files):
src/models/index.js (29 lines → 27 lines)
- REMOVED imports: Document, BlogPost, MediaInquiry, CaseSubmission, Resource
- REMOVED imports: ModerationQueue, User (all deleted in Phase 2)
- KEPT imports: AuditLog, DeliberationSession, GovernanceLog, GovernanceRule
- KEPT imports: Precedent, Project, SessionState, VariableValue, VerificationLog
- Result: Only framework models exported
src/server.js (284 lines → 163 lines, 43% reduction)
- REMOVED: Imports to deleted middleware (csrf-protection, response-sanitization)
- REMOVED: Stripe webhook handling (/api/koha/webhook)
- REMOVED: Static file caching (for deleted public/ directory)
- REMOVED: Static file serving (public/ deleted in Phase 6)
- REMOVED: CSRF token endpoint
- REMOVED: Website homepage with "auth, documents, blog, admin" references
- REMOVED: Instruction sync (scripts/sync-instructions-to-db.js reference)
- REMOVED: Hardcoded log path (${process.env.HOME}/var/log/tractatus/...)
- REMOVED: Website-specific security middleware
- KEPT: Security headers, rate limiting, CORS, body parsers
- KEPT: API routes, governance services, MongoDB connections
- RESULT: Clean framework-only server
RESULT: Repository can now start without crashes, all imports resolve
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
96 lines
3.1 KiB
JavaScript
96 lines
3.1 KiB
JavaScript
/**
|
|
* Quick PDF Generator for Markdown Files
|
|
* Uses Puppeteer to generate PDFs directly from markdown files
|
|
*/
|
|
|
|
const puppeteer = require('puppeteer');
|
|
const marked = require('marked');
|
|
const fs = require('fs').promises;
|
|
const path = require('path');
|
|
|
|
async function generatePdfFromMarkdown(markdownPath, outputPath, title) {
|
|
const markdown = await fs.readFile(markdownPath, 'utf-8');
|
|
const html = marked.parse(markdown);
|
|
|
|
const fullHtml = `
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>${title}</title>
|
|
<style>
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
font-size: 11pt;
|
|
line-height: 1.6;
|
|
color: #1f2937;
|
|
max-width: 900px;
|
|
margin: 0 auto;
|
|
padding: 2cm;
|
|
}
|
|
h1 { font-size: 2rem; margin-top: 2rem; margin-bottom: 1rem; page-break-after: avoid; }
|
|
h2 { font-size: 1.5rem; margin-top: 1.5rem; margin-bottom: 0.75rem; page-break-after: avoid; }
|
|
h3 { font-size: 1.25rem; margin-top: 1.25rem; margin-bottom: 0.5rem; page-break-after: avoid; }
|
|
p { margin-bottom: 1rem; line-height: 1.75; }
|
|
code { background: #f3f4f6; padding: 0.125rem 0.375rem; border-radius: 0.25rem; font-size: 0.875rem; }
|
|
pre { background: #f9fafb; padding: 1rem; border-radius: 0.375rem; overflow-x: auto; page-break-inside: avoid; }
|
|
pre code { background: transparent; padding: 0; }
|
|
table { width: 100%; border-collapse: collapse; margin-bottom: 1.25rem; page-break-inside: avoid; }
|
|
th, td { border: 1px solid #d1d5db; padding: 0.625rem 0.875rem; text-align: left; }
|
|
th { background: #f3f4f6; font-weight: 600; }
|
|
blockquote { border-left: 4px solid #3b82f6; padding-left: 1rem; margin: 1.25rem 0; background: #f9fafb; padding: 0.875rem; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>${title}</h1>
|
|
${html}
|
|
</body>
|
|
</html>
|
|
`;
|
|
|
|
const browser = await puppeteer.launch({
|
|
headless: true,
|
|
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
|
});
|
|
|
|
const page = await browser.newPage();
|
|
await page.setContent(fullHtml, { waitUntil: 'networkidle0' });
|
|
|
|
await page.pdf({
|
|
path: outputPath,
|
|
format: 'A4',
|
|
printBackground: true,
|
|
margin: { top: '2cm', right: '2cm', bottom: '2cm', left: '2cm' }
|
|
});
|
|
|
|
await browser.close();
|
|
console.log(`✓ Generated: ${path.basename(outputPath)}`);
|
|
}
|
|
|
|
async function main() {
|
|
const files = [
|
|
{
|
|
input: 'docs/research/pluralistic-values-research-foundations.md',
|
|
output: 'public/downloads/pluralistic-values-research-foundations.pdf',
|
|
title: 'Pluralistic Values: Research Foundations'
|
|
},
|
|
{
|
|
input: 'docs/value-pluralism-faq.md',
|
|
output: 'public/downloads/value-pluralism-faq.pdf',
|
|
title: 'Value Pluralism in Tractatus: FAQ'
|
|
},
|
|
{
|
|
input: 'docs/pluralistic-values-deliberation-plan-v2.md',
|
|
output: 'public/downloads/pluralistic-values-deliberation-plan-v2.pdf',
|
|
title: 'Pluralistic Values Deliberation Enhancement Plan'
|
|
}
|
|
];
|
|
|
|
for (const file of files) {
|
|
await generatePdfFromMarkdown(file.input, file.output, file.title);
|
|
}
|
|
|
|
console.log('\n✓ All PDFs generated successfully');
|
|
}
|
|
|
|
main().catch(console.error);
|