mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2025-01-07 23:50:05 -05:00
8697902e08
* Add loaders when the file is being built so we can track the progress * add changelog * improve * refactor
41 lines
957 B
TypeScript
41 lines
957 B
TypeScript
import { sleep } from '@plugin/utils/sleep';
|
|
|
|
import { sendMessage } from '@ui/context';
|
|
import { createFile as createPenpotFile } from '@ui/lib/penpot';
|
|
import { PenpotPage } from '@ui/lib/types/penpotPage';
|
|
import { idLibrary } from '@ui/parser';
|
|
import { createComponentsLibrary, createPage } from '@ui/parser/creators';
|
|
import { uiComponents } from '@ui/parser/libraries';
|
|
|
|
export const createFile = async (name: string, children: PenpotPage[]) => {
|
|
const file = createPenpotFile(name);
|
|
let pagesBuilt = 1;
|
|
|
|
uiComponents.init();
|
|
idLibrary.init();
|
|
|
|
sendMessage({
|
|
type: 'PROGRESS_TOTAL_ITEMS',
|
|
data: children.length
|
|
});
|
|
|
|
sendMessage({
|
|
type: 'PROGRESS_STEP',
|
|
data: 'building'
|
|
});
|
|
|
|
for (const page of children) {
|
|
await createPage(file, page);
|
|
|
|
sendMessage({
|
|
type: 'PROGRESS_PROCESSED_ITEMS',
|
|
data: pagesBuilt++
|
|
});
|
|
|
|
await sleep(0);
|
|
}
|
|
|
|
await createComponentsLibrary(file);
|
|
|
|
return file;
|
|
};
|