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>
171 lines
3.8 KiB
JavaScript
171 lines
3.8 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const puppeteer = require('puppeteer');
|
|
const marked = require('marked');
|
|
const fs = require('fs').promises;
|
|
const path = require('path');
|
|
|
|
const inputPath = '/home/theflow/Desktop/Presentation-to-Commissioners.md';
|
|
const outputPath = '/home/theflow/Desktop/Presentation-to-Commissioners.pdf';
|
|
|
|
function generateHtml(title, content) {
|
|
return `
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>${title}</title>
|
|
<style>
|
|
@page {
|
|
margin: 2cm 2cm 3cm 2cm;
|
|
size: A4;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
font-size: 11pt;
|
|
line-height: 1.6;
|
|
color: #1f2937;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
h1 {
|
|
font-size: 1.875rem;
|
|
font-weight: 700;
|
|
color: #111827;
|
|
margin-top: 2rem;
|
|
margin-bottom: 1rem;
|
|
border-bottom: 2px solid #e5e7eb;
|
|
padding-bottom: 0.5rem;
|
|
page-break-after: avoid;
|
|
}
|
|
|
|
h2 {
|
|
font-size: 1.5rem;
|
|
font-weight: 600;
|
|
color: #111827;
|
|
margin-top: 1.75rem;
|
|
margin-bottom: 0.875rem;
|
|
border-bottom: 1px solid #e5e7eb;
|
|
padding-bottom: 0.375rem;
|
|
page-break-after: avoid;
|
|
}
|
|
|
|
h3 {
|
|
font-size: 1.25rem;
|
|
font-weight: 600;
|
|
color: #1f2937;
|
|
margin-top: 1.5rem;
|
|
margin-bottom: 0.75rem;
|
|
page-break-after: avoid;
|
|
}
|
|
|
|
p {
|
|
margin-bottom: 1rem;
|
|
line-height: 1.75;
|
|
orphans: 3;
|
|
widows: 3;
|
|
}
|
|
|
|
ul, ol {
|
|
margin-bottom: 1rem;
|
|
padding-left: 1.75rem;
|
|
line-height: 1.75;
|
|
}
|
|
|
|
li {
|
|
margin-bottom: 0.375rem;
|
|
}
|
|
|
|
strong, b {
|
|
font-weight: 600;
|
|
color: #111827;
|
|
}
|
|
|
|
em, i {
|
|
font-style: italic;
|
|
}
|
|
|
|
hr {
|
|
border: none;
|
|
border-top: 1px solid #d1d5db;
|
|
margin: 1.5rem 0;
|
|
}
|
|
|
|
h1, h2, h3, h4, h5, h6 {
|
|
page-break-inside: avoid;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
${content}
|
|
</body>
|
|
</html>
|
|
`;
|
|
}
|
|
|
|
async function main() {
|
|
console.log('=== Generating PDF with Custom Footer ===\n');
|
|
|
|
let browser;
|
|
|
|
try {
|
|
console.log(`Reading: ${inputPath}`);
|
|
const markdown = await fs.readFile(inputPath, 'utf8');
|
|
|
|
const titleMatch = markdown.match(/^#\s+(.+)$/m);
|
|
const title = titleMatch ? titleMatch[1] : 'Presentation to Commissioners';
|
|
|
|
console.log(`Title: ${title}`);
|
|
console.log('Converting markdown to HTML...');
|
|
const contentHtml = marked.parse(markdown);
|
|
const html = generateHtml(title, contentHtml);
|
|
|
|
console.log('Launching browser...');
|
|
browser = await puppeteer.launch({
|
|
headless: true,
|
|
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
|
});
|
|
|
|
const page = await browser.newPage();
|
|
|
|
console.log('Rendering HTML...');
|
|
await page.setContent(html, {
|
|
waitUntil: 'networkidle0'
|
|
});
|
|
|
|
console.log(`Generating PDF: ${outputPath}`);
|
|
await page.pdf({
|
|
path: outputPath,
|
|
format: 'A4',
|
|
printBackground: true,
|
|
margin: {
|
|
top: '2cm',
|
|
right: '2cm',
|
|
bottom: '3cm',
|
|
left: '2cm'
|
|
},
|
|
displayHeaderFooter: true,
|
|
headerTemplate: '<div></div>',
|
|
footerTemplate: `
|
|
<div style="width: 100%; font-size: 9pt; text-align: center; color: #374151; padding: 0 2cm; font-family: -apple-system, sans-serif;">
|
|
John Stroh -- https://agenticgovernance.digital -- 16th October 2025 -- Page <span class="pageNumber"></span> of <span class="totalPages"></span>
|
|
</div>
|
|
`
|
|
});
|
|
|
|
console.log('\n✓ PDF generated successfully!\n');
|
|
console.log(`Output: ${outputPath}`);
|
|
|
|
} catch (error) {
|
|
console.error('\n✗ Error:', error.message);
|
|
console.error(error.stack);
|
|
process.exit(1);
|
|
} finally {
|
|
if (browser) await browser.close();
|
|
}
|
|
}
|
|
|
|
main();
|