Initial import
This commit is contained in:
63
scripts/capture-component-screenshot.mjs
Executable file
63
scripts/capture-component-screenshot.mjs
Executable file
@@ -0,0 +1,63 @@
|
||||
import process from 'node:process';
|
||||
import { chromium } from 'playwright';
|
||||
import { ensureDirectory, getKstDate, resolveCapturePaths, updateWorklogCaptureSection } from './worklog-capture-utils.mjs';
|
||||
|
||||
const cwd = process.cwd();
|
||||
const componentId = process.argv[2];
|
||||
const captureDate = process.argv[3] ?? getKstDate();
|
||||
const baseUrl = process.env.CAPTURE_BASE_URL ?? 'http://127.0.0.1:5174';
|
||||
|
||||
if (!componentId) {
|
||||
console.error('Usage: node scripts/capture-component-screenshot.mjs <component-id> [YYYY-MM-DD]');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const screenshotFileName = `${componentId}.png`;
|
||||
const { screenshotDir, screenshotPath, worklogPath, markdownImagePath } = resolveCapturePaths({
|
||||
cwd,
|
||||
captureDate,
|
||||
screenshotFileName,
|
||||
});
|
||||
const targetSelector = `#component-sample-${componentId}`;
|
||||
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
const page = await browser.newPage({
|
||||
viewport: {
|
||||
width: 1600,
|
||||
height: 1200,
|
||||
},
|
||||
deviceScaleFactor: 2,
|
||||
});
|
||||
|
||||
try {
|
||||
await ensureDirectory(screenshotDir);
|
||||
|
||||
const targetUrl = new URL(baseUrl);
|
||||
targetUrl.searchParams.set('topMenu', 'apis');
|
||||
|
||||
await page.goto(targetUrl.toString(), {
|
||||
waitUntil: 'domcontentloaded',
|
||||
});
|
||||
|
||||
await page.waitForLoadState('networkidle').catch(() => {});
|
||||
|
||||
const target = page.locator(targetSelector).first();
|
||||
await target.waitFor({ state: 'visible', timeout: 30000 });
|
||||
await target.scrollIntoViewIfNeeded();
|
||||
await target.screenshot({
|
||||
path: screenshotPath,
|
||||
animations: 'disabled',
|
||||
});
|
||||
|
||||
await updateWorklogCaptureSection({
|
||||
worklogPath,
|
||||
captureDate,
|
||||
imageAlt: componentId,
|
||||
markdownImagePath,
|
||||
});
|
||||
|
||||
console.log(`Saved: ${screenshotPath}`);
|
||||
console.log(`Linked in: ${worklogPath}`);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
Reference in New Issue
Block a user