figma-sprite-tool 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,196 @@
1
+ # Figma Sprite Tool
2
+
3
+ CLI tool to generate PNG/SVG sprite sheets, SCSS mixins, and JSON metadata from Figma design systems.
4
+
5
+ ## Features
6
+
7
+ - **Single Source of Truth**: Use Figma as your design system source
8
+ - **Deterministic Output**: Same input always produces the same output
9
+ - **Multiple Formats**: Generate PNG (@1x/@2x), SVG sprites, SCSS mixins, and JSON metadata
10
+ - **Type-Safe**: Built with TypeScript in strict mode
11
+ - **Fast**: Optimized with Sharp for image processing
12
+
13
+ ## Requirements
14
+
15
+ - Node.js 20 LTS or higher
16
+ - pnpm 8.x or higher
17
+ - Figma account with API access token
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm i -g figma-sprite-tool
23
+ ```
24
+
25
+ Without global install:
26
+
27
+ ```bash
28
+ npx figma-sprite --help
29
+ ```
30
+
31
+ ## Development
32
+
33
+ ```bash
34
+ # Install dependencies
35
+ pnpm install
36
+
37
+ # Run in development mode
38
+ pnpm dev
39
+
40
+ # Build for production
41
+ pnpm build
42
+
43
+ # Run tests
44
+ pnpm test
45
+
46
+ # Run tests with coverage
47
+ pnpm test:coverage
48
+
49
+ # Lint code
50
+ pnpm lint
51
+
52
+ # Format code
53
+ pnpm format
54
+ ```
55
+
56
+ ## Getting Started
57
+
58
+ ### Quick Start (Recommended)
59
+
60
+ 1. **Run interactive setup**:
61
+ ```bash
62
+ figma-sprite init
63
+ ```
64
+
65
+ 2. **Follow the prompts** to configure your project:
66
+ - Enter your Figma file URL
67
+ - Specify the page containing icons
68
+ - Choose icon name prefix for filtering
69
+ - Select icon ID format
70
+ - Set output directory
71
+
72
+ 3. **Set your Figma token**:
73
+ ```bash
74
+ export FIGMA_TOKEN="your-figma-token"
75
+ ```
76
+ Get your token from: https://www.figma.com/developers/api#access-tokens
77
+
78
+ 4. **Generate sprites**:
79
+ ```bash
80
+ figma-sprite generate
81
+ ```
82
+
83
+ ### Manual Configuration (Advanced)
84
+
85
+ If you prefer to create the configuration file manually, create a `figma.sprite.config.json` file in your project root:
86
+
87
+ ```json
88
+ {
89
+ "figma": {
90
+ "fileKey": "AbCdEf123456",
91
+ "page": "Design System / Icons",
92
+ "scope": {
93
+ "type": "prefix",
94
+ "value": "ic/"
95
+ }
96
+ },
97
+ "output": {
98
+ "dir": "assets/sprite",
99
+ "name": "sprite"
100
+ },
101
+ "formats": {
102
+ "png": {
103
+ "enabled": true,
104
+ "scale": 2,
105
+ "padding": 2
106
+ },
107
+ "svg": {
108
+ "enabled": true,
109
+ "svgo": true
110
+ }
111
+ },
112
+ "naming": {
113
+ "idFormat": "{name}-{size}-{style}{theme?--{theme}}",
114
+ "sanitize": true
115
+ }
116
+ }
117
+ ```
118
+
119
+ ## Usage
120
+
121
+ ### Available Commands
122
+
123
+ ```bash
124
+ # Create configuration interactively
125
+ figma-sprite init
126
+
127
+ # Generate sprite from config
128
+ figma-sprite generate
129
+ # or
130
+ figma-sprite build # alias for generate
131
+
132
+ # With custom config file
133
+ figma-sprite generate -c custom.config.json
134
+
135
+ # With output directory override
136
+ figma-sprite generate -o ./custom-output
137
+
138
+ # Verbose mode for debugging
139
+ figma-sprite generate --verbose
140
+
141
+ # Dry run (preview without writing files)
142
+ figma-sprite generate --dry-run
143
+
144
+ # Set Figma token via environment variable
145
+ FIGMA_TOKEN=your_token_here figma-sprite generate
146
+ ```
147
+
148
+ ## Output Files
149
+
150
+ The tool generates the following files:
151
+
152
+ ```
153
+ assets/sprite/{Page}/
154
+ ├── sprite.png # 1x PNG sprite sheet (packed layout)
155
+ ├── sprite@2x.png # 2x retina PNG sprite sheet (packed layout)
156
+ ├── sprite.preview.png # Preview PNG sprite sheet (grid layout)
157
+ ├── sprite.svg # SVG symbol sprite (root viewBox included)
158
+ ├── sprite.preview.svg # Preview grid SVG for viewers and backgrounds
159
+ ├── sprite.scss # Sprite data maps ($icons, $preview-icons)
160
+ ├── mixins.scss # PNG/SVG/Preview mixin APIs
161
+ └── sprite.json # Metadata + all coordinates + failedAssets report
162
+ ```
163
+
164
+ Notes:
165
+ - Output directory is page-scoped: `{output.dir}/{sanitized-page-name}`.
166
+ - If `sprite.*` already exists, a suffix is applied automatically (`sprite(1)`, `sprite(2)`, ...).
167
+ - If some assets fail export, generation continues with successful assets and failure details are recorded.
168
+
169
+ ### Usage Guides
170
+
171
+ For detailed usage instructions on how to use generated sprite files:
172
+ - 🇰🇷 [스프라이트 사용 가이드 (한국어)](./docs/SPRITE_USAGE_GUIDE.md)
173
+ - 🇬🇧 [Sprite Usage Guide (English)](./docs/SPRITE_USAGE_GUIDE_EN.md)
174
+
175
+ ## Architecture
176
+
177
+ - **CLI Layer**: Commander.js for command-line interface
178
+ - **Engine Layer**: Core orchestration and workflow management
179
+ - **Processor Layer**: Specialized processors for Figma API, sprite generation, and output
180
+
181
+ ## Tech Stack
182
+
183
+ - **Runtime**: Node.js 20 LTS
184
+ - **Language**: TypeScript 5.x (strict mode)
185
+ - **Build Tool**: tsup
186
+ - **Package Manager**: pnpm 8.x
187
+ - **Image Processing**: Sharp
188
+ - **Bin-packing**: potpack
189
+ - **SVG Optimization**: SVGO
190
+ - **Config Validation**: Zod
191
+ - **Template Engine**: Handlebars
192
+ - **Testing**: Vitest
193
+
194
+ ## License
195
+
196
+ MIT
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node