How yinm/figma-text-style-guide works
Project Type and Purpose
• This project is a Figma plugin with an accompanying user interface (UI). Its goal is to help manage and apply text style guides and design tokens within Figma. The design tokens (managed in the design-tokens directory) provide consistent styling, and the “plugin” code adds functionality (like creating frames and text style objects) directly within Figma.
• The README commands (e.g., “pnpm sync-design-tokens”, “pnpm dev:ui”) confirm that there is active synchronization between design tokens and the plugin/UI elements.
File Structure
• The top-level directories and configuration files indicate robust development tooling:
• Configuration files (.prettierrc.json, eslint.config.js, etc.) ensure code quality.
• GitHub workflows (.github/workflows/ci.yml) and renovate.json illustrate CI/CD and dependency management.
• The source code is split primarily into two main areas:
• The plugin itself (in src/plugin) which handles core functionality and operations within Figma. This includes various “nodes” (such as createBodyFrame, createHeadingFrame, etc.) each with its own implementation and testing.
• The UI (in src/ui) which includes an index.html, main.tsx, and several React (or similar) components (like Button, Switch, LabelAndSwitch). This indicates a separation of concerns between the plugin logic and the interactive user interface.
• Additionally, there is a standalone “design-tokens” directory that contains token configuration files and JSON definitions (primitive.tokens.json and semantic.tokens.json), which are likely integrated into both the plugin and UI parts.
Architectural Patterns and Design Principles
• The project follows a modular design by separating functionality into distinct directories:
• Plugin modules (various “nodes”) help maintain a clear separation of responsibilities (each node for a particular frame or text style operation).
• The UI is self-contained and uses component-based architecture.
• There is evidence of a message-passing mechanism between the UI and plugin parts (see files like src/ui/utils/postMessageFromUi.ts and the shared types under src/shared/types), which suggests a loosely-coupled design where the UI sends messages (commands, updates) to the plugin runtime.
Relevant Technologies/Frameworks/Libraries
• Build and dependency management: pnpm with a pnpm-lock.yaml file.
• Modern JavaScript/TypeScript: Use of TS configuration files (tsconfig.*.json) throughout the project.
• Vite: Two Vite configuration files (vite.config.plugin.ts and vite.config.ui.ts) drive the separate builds for the plugin and the UI.
• Testing: Unit tests (.spec.ts) are present for both plugin nodes and UI components.
• Scaffdog: Template/scaffolding configuration (files under .scaffdog) to speed up file/component generation.
• Design tokens: Maintained under design-tokens and synced via pnpm commands.