diff --git a/src/commands/devup/export-devup.ts b/src/commands/devup/export-devup.ts index 8e9341e..4d7af29 100644 --- a/src/commands/devup/export-devup.ts +++ b/src/commands/devup/export-devup.ts @@ -24,12 +24,14 @@ function isTextSearchNode(node: SceneNode): node is TextSearchNode { return 'findAllWithCriteria' in node } -export async function exportDevup( - output: 'json' | 'excel', +/** + * Build the Devup config object from the current Figma file. + * Extracts colors from Devup variable collection and typography from text styles. + * When treeshaking is enabled, only typography used in the document is included. + */ +export async function buildDevupConfig( treeshaking: boolean = true, -) { - perfReset() - const t = perfStart() +): Promise { const devup: Devup = {} const tColors = perfStart() @@ -236,6 +238,16 @@ export async function exportDevup( ) } + return devup +} + +export async function exportDevup( + output: 'json' | 'excel', + treeshaking: boolean = true, +) { + perfReset() + const t = perfStart() + const devup = await buildDevupConfig(treeshaking) perfEnd('exportDevup()', t) console.info(perfReport()) diff --git a/src/commands/devup/index.ts b/src/commands/devup/index.ts index d9e2f07..cecbfc7 100644 --- a/src/commands/devup/index.ts +++ b/src/commands/devup/index.ts @@ -1,2 +1,2 @@ -export { exportDevup } from './export-devup' +export { buildDevupConfig, exportDevup } from './export-devup' export { importDevup } from './import-devup' diff --git a/src/commands/exportPagesAndComponents.ts b/src/commands/exportPagesAndComponents.ts index 30c333e..908ac60 100644 --- a/src/commands/exportPagesAndComponents.ts +++ b/src/commands/exportPagesAndComponents.ts @@ -17,6 +17,7 @@ import { wrapComponent } from '../codegen/utils/wrap-component' import { getComponentName } from '../utils' import { downloadFile } from '../utils/download-file' import { toPascal } from '../utils/to-pascal' +import { buildDevupConfig } from './devup' const NOTIFY_TIMEOUT = 3000 // Figma throttles >4 concurrent exportAsync calls for large PNGs (screenshots). @@ -180,6 +181,9 @@ export async function exportPagesAndComponents() { // Deferred work collectors const screenshotTargets: ScreenshotTarget[] = [] + // Fire devup config build early — runs in parallel with codegen + const devupConfigPromise = buildDevupConfig() + // Reset global asset registry so buildTree() populates it fresh resetGlobalAssetNodes() @@ -341,6 +345,10 @@ export async function exportPagesAndComponents() { return } + // Await devup config (started in parallel with codegen) and add to ZIP + const devupConfig = await devupConfigPromise + zip.file('devup.json', JSON.stringify(devupConfig), ZIP_TEXT_FILE_OPTIONS) + // Asset nodes were already collected by Codegen's buildTree() into the // global registry — no need to re-walk the Figma node tree via IPC. const assetNodes = getGlobalAssetNodes()