2024-06-26 01:11:57 -05:00
|
|
|
import { sleep } from '@common/sleep';
|
2024-06-18 02:50:38 -05:00
|
|
|
|
|
|
|
import { sendMessage } from '@ui/context';
|
2024-06-25 07:12:37 -05:00
|
|
|
import { PenpotFile } from '@ui/lib/types/penpotFile';
|
2024-06-18 02:50:38 -05:00
|
|
|
import { PenpotPage } from '@ui/lib/types/penpotPage';
|
2024-06-26 01:11:57 -05:00
|
|
|
import { components, identifiers } from '@ui/parser';
|
2024-06-25 09:08:59 -05:00
|
|
|
import {
|
|
|
|
createColorsLibrary,
|
|
|
|
createComponentsLibrary,
|
|
|
|
createPage,
|
|
|
|
createTextLibrary
|
|
|
|
} from '@ui/parser/creators';
|
2024-06-18 02:50:38 -05:00
|
|
|
|
2024-06-25 07:12:37 -05:00
|
|
|
export const buildFile = async (file: PenpotFile, children: PenpotPage[]) => {
|
2024-06-18 02:50:38 -05:00
|
|
|
let pagesBuilt = 1;
|
|
|
|
|
2024-06-26 01:11:57 -05:00
|
|
|
components.clear();
|
|
|
|
identifiers.clear();
|
2024-06-18 02:50:38 -05:00
|
|
|
|
|
|
|
sendMessage({
|
|
|
|
type: 'PROGRESS_TOTAL_ITEMS',
|
|
|
|
data: children.length
|
|
|
|
});
|
|
|
|
|
|
|
|
sendMessage({
|
|
|
|
type: 'PROGRESS_STEP',
|
|
|
|
data: 'building'
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const page of children) {
|
2024-06-26 01:11:57 -05:00
|
|
|
createPage(file, page);
|
2024-06-18 02:50:38 -05:00
|
|
|
|
|
|
|
sendMessage({
|
|
|
|
type: 'PROGRESS_PROCESSED_ITEMS',
|
|
|
|
data: pagesBuilt++
|
|
|
|
});
|
|
|
|
|
|
|
|
await sleep(0);
|
|
|
|
}
|
|
|
|
|
2024-06-25 07:12:37 -05:00
|
|
|
await createColorsLibrary(file);
|
2024-06-25 09:08:59 -05:00
|
|
|
await createTextLibrary(file);
|
2024-06-25 07:12:37 -05:00
|
|
|
|
2024-06-18 02:50:38 -05:00
|
|
|
await createComponentsLibrary(file);
|
|
|
|
|
|
|
|
return file;
|
|
|
|
};
|