Skip to content

Commit 2dd36b6

Browse files
committed
Add functionality to copy preview images during component build
1 parent 055658f commit 2dd36b6

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/utils/buildComponents.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
copyFileSync,
23
existsSync,
34
mkdirSync,
45
readdirSync,
@@ -51,6 +52,7 @@ export function buildComponents() {
5152
const componentPath = join(typePath, componentName);
5253
const metadataPath = join(componentPath, 'metadata.json');
5354
const htmlPath = join(componentPath, 'index.html');
55+
const previewPath = join(componentPath, 'preview.png');
5456

5557
if (existsSync(metadataPath) && existsSync(htmlPath)) {
5658
try {
@@ -65,6 +67,11 @@ export function buildComponents() {
6567
// Write HTML file to dist
6668
writeFileSync(join(distPath, type, `${metadata.id}.html`), html);
6769

70+
// Copy preview.png file if it exists
71+
if (existsSync(previewPath)) {
72+
copyFileSync(previewPath, join(distPath, type, `${metadata.id}.png`));
73+
}
74+
6875
console.log(`✓ Built ${type}/${metadata.id}`);
6976
} catch (error) {
7077
console.error(`✗ Error building ${type}/${componentName}:`, error);
@@ -77,12 +84,12 @@ export function buildComponents() {
7784
// Helper function to create paginated files
7885
function createPaginatedFiles(items: ComponentMetadata[], type: string) {
7986
const totalPages = Math.ceil(items.length / ITEMS_PER_PAGE);
80-
87+
8188
for (let page = 1; page <= totalPages; page++) {
8289
const startIndex = (page - 1) * ITEMS_PER_PAGE;
8390
const endIndex = startIndex + ITEMS_PER_PAGE;
8491
const pageItems = items.slice(startIndex, endIndex);
85-
92+
8693
const paginatedData: PaginatedOutput = {
8794
items: pageItems,
8895
page: page,

0 commit comments

Comments
 (0)