Add lockfile, dependabot, and improve PDF script reliability

- Add package-lock.json for reproducible builds (npm ci)
- Add dependabot.yml for npm and GitHub Actions updates
- Add .gitignore for node_modules and generated PDF
- Update workflow to use npm ci with caching
- Improve PDF script with proper error handling and HTTP server
This commit is contained in:
Claude 2025-11-23 16:41:14 +00:00
parent f58462df32
commit 499c842b45
No known key found for this signature in database
5 changed files with 134 additions and 24 deletions

View file

@ -1,38 +1,67 @@
const { chromium } = require('playwright');
const http = require('http');
const fs = require('fs');
const path = require('path');
async function generatePDF() {
const browser = await chromium.launch();
// Start a simple HTTP server to serve the HTML file
const htmlPath = path.join(__dirname, '..', 'index.html');
const htmlContent = fs.readFileSync(htmlPath, 'utf8');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(htmlContent);
});
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
const port = server.address().port;
console.log(`Server started on port ${port}`);
const browser = await chromium.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage'
]
});
const context = await browser.newContext();
const page = await context.newPage();
// Load the local HTML file
const htmlPath = path.join(__dirname, '..', 'index.html');
await page.goto(`file://${htmlPath}`);
try {
// Load the page from local server and wait for network to settle
await page.goto(`http://127.0.0.1:${port}`, { waitUntil: 'networkidle' });
// Wait for AlpineJS to initialize and generate labels
await page.waitForFunction(() => {
const labels = document.querySelectorAll('ol li');
return labels.length === 189; // 7 columns x 27 rows
});
// Wait for AlpineJS to initialize and generate labels
console.log('Waiting for labels to be generated...');
await page.waitForFunction(() => {
const labels = document.querySelectorAll('ol li');
return labels.length === 189; // 7 columns x 27 rows
}, { timeout: 60000 });
// Wait for all QR code images to load
await page.waitForFunction(() => {
const images = document.querySelectorAll('ol li img');
return Array.from(images).every(img => img.complete && img.naturalHeight > 0);
}, { timeout: 60000 });
console.log('Labels generated, waiting for QR code images to load...');
// Generate PDF with A4 format and print media
await page.pdf({
path: 'asn-labels.pdf',
format: 'A4',
printBackground: true,
margin: { top: 0, right: 0, bottom: 0, left: 0 }
});
// Wait for all QR code images to load
await page.waitForFunction(() => {
const images = document.querySelectorAll('ol li img');
if (images.length === 0) return false;
return Array.from(images).every(img => img.complete && img.naturalHeight > 0);
}, { timeout: 120000 });
console.log('PDF generated successfully: asn-labels.pdf');
console.log('All images loaded, generating PDF...');
await browser.close();
// Generate PDF with A4 format and print media
await page.pdf({
path: 'asn-labels.pdf',
format: 'A4',
printBackground: true,
margin: { top: 0, right: 0, bottom: 0, left: 0 }
});
console.log('PDF generated successfully: asn-labels.pdf');
} finally {
await browser.close();
server.close();
}
}
generatePDF().catch(err => {