tailwind-unwind 0.1.1 → 0.3.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 +78 -5
- package/dist/{chunk-N7HD4T2I.js → chunk-4GXMK3NB.js} +1079 -107
- package/dist/chunk-4GXMK3NB.js.map +1 -0
- package/dist/cli/index.js +190 -27
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +204 -69
- package/dist/index.js +27 -1
- package/package.json +12 -2
- package/tailwind-unwind.config.example.json +27 -0
- package/dist/chunk-N7HD4T2I.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# tailwind-unwind
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/tailwind-unwind)
|
|
4
|
+
|
|
3
5
|
CLI tool to analyze, extract, and refactor repeated Tailwind CSS utility patterns in React and Next.js projects.
|
|
4
6
|
|
|
5
7
|
**Repository:** [github.com/AVPletnev/tailwind-unwind](https://github.com/AVPletnev/tailwind-unwind)
|
|
@@ -23,6 +25,52 @@ npx tailwind-unwind analyze ./src
|
|
|
23
25
|
|
|
24
26
|
Requires **Node.js 18+**.
|
|
25
27
|
|
|
28
|
+
## Configuration
|
|
29
|
+
|
|
30
|
+
Copy [`tailwind-unwind.config.example.json`](tailwind-unwind.config.example.json) to your project root:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
cp node_modules/tailwind-unwind/tailwind-unwind.config.example.json tailwind-unwind.config.json
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Supported filenames: `tailwind-unwind.config.json`, `.tailwind-unwindrc`, `tailwind-unwind.config.js` / `.mjs` / `.cjs`.
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"include": ["src/**/*.tsx"],
|
|
41
|
+
"exclude": ["**/*.test.tsx", "**/*.stories.tsx"],
|
|
42
|
+
"names": {
|
|
43
|
+
"flex items-center justify-between p-4": "page-header",
|
|
44
|
+
"w-full h-auto object-cover rounded-lg": "media-cover"
|
|
45
|
+
},
|
|
46
|
+
"analyze": {
|
|
47
|
+
"minOccurrences": 5,
|
|
48
|
+
"top": 10
|
|
49
|
+
},
|
|
50
|
+
"generate": {
|
|
51
|
+
"minOccurrences": 3,
|
|
52
|
+
"prefix": "twu-",
|
|
53
|
+
"output": "src/styles/components.css"
|
|
54
|
+
},
|
|
55
|
+
"apply": {
|
|
56
|
+
"output": "src/styles/components.css"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
| Key | Description |
|
|
62
|
+
|-----|-------------|
|
|
63
|
+
| `include` / `exclude` | Glob patterns for file scanning |
|
|
64
|
+
| `names` | Custom class names (utilities string → base name, prefix added automatically) |
|
|
65
|
+
| `analyze` / `generate` / `apply` | Per-command overrides (`minOccurrences`, `top`, `prefix`, `output`, …) |
|
|
66
|
+
|
|
67
|
+
Config is discovered from the current directory **and** ancestors of `<path>`. CLI flags override config values.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npx tailwind-unwind analyze ./src --config ./tailwind-unwind.config.json
|
|
71
|
+
npx tailwind-unwind generate ./src --include "src/components/**/*.tsx"
|
|
72
|
+
```
|
|
73
|
+
|
|
26
74
|
## Quick start
|
|
27
75
|
|
|
28
76
|
```bash
|
|
@@ -57,6 +105,9 @@ npx tailwind-unwind analyze <path>
|
|
|
57
105
|
| `--top <n>` | `10` | Number of top combinations to show |
|
|
58
106
|
| `--format <type>` | `console` | Output format: `console` or `json` |
|
|
59
107
|
| `--no-dedupe-subsets` | — | Include subset combinations in results |
|
|
108
|
+
| `--config <file>` | — | Path to config file |
|
|
109
|
+
| `--include <patterns>` | all `src` | Comma-separated glob include patterns |
|
|
110
|
+
| `--exclude <patterns>` | — | Comma-separated glob exclude patterns |
|
|
60
111
|
|
|
61
112
|
```bash
|
|
62
113
|
# JSON report for CI
|
|
@@ -80,6 +131,7 @@ Unique class combinations: 89
|
|
|
80
131
|
1. "flex items-center justify-between p-4"
|
|
81
132
|
Occurrences: 24
|
|
82
133
|
Suggestion: .page-header
|
|
134
|
+
Extractable: yes — use generate/apply
|
|
83
135
|
Found in: src/components/Header.tsx:12, src/layout/Toolbar.tsx:5 (+18 more)
|
|
84
136
|
|
|
85
137
|
💡 Potential code reduction: 38%
|
|
@@ -107,11 +159,15 @@ npx tailwind-unwind generate <path> --output <file.css>
|
|
|
107
159
|
| `--max-size <n>` | `5` | Maximum classes per set |
|
|
108
160
|
| `--top <n>` | `10` | Max number of component classes to generate |
|
|
109
161
|
| `--prefix <name>` | `twu-` | Namespace prefix for generated classes |
|
|
162
|
+
| `--format <type>` | `console` | Output format: `console` or `json` |
|
|
163
|
+
| `--from-report <file>` | — | Generate from `analyze --format json` output |
|
|
164
|
+
| `--extractable-only` | — | Only patterns marked extractable in analyze |
|
|
110
165
|
|
|
111
166
|
```bash
|
|
112
167
|
npx tailwind-unwind generate ./src --output styles.css
|
|
113
|
-
npx tailwind-unwind
|
|
114
|
-
npx tailwind-unwind generate
|
|
168
|
+
npx tailwind-unwind analyze ./src --format json > report.json
|
|
169
|
+
npx tailwind-unwind generate --from-report report.json --output styles.css
|
|
170
|
+
npx tailwind-unwind generate ./src --output styles.css --extractable-only --format json
|
|
115
171
|
```
|
|
116
172
|
|
|
117
173
|
**Example output (`styles.css`):**
|
|
@@ -154,10 +210,13 @@ Supports the same flags as `generate`, plus:
|
|
|
154
210
|
| Flag | Description |
|
|
155
211
|
|------|-------------|
|
|
156
212
|
| `--dry-run` | Preview replacements without writing files |
|
|
213
|
+
| `--prettier` | Format modified files with Prettier (optional peer dependency) |
|
|
214
|
+
| `--format json` | Machine-readable output for CI |
|
|
157
215
|
|
|
158
216
|
```bash
|
|
159
217
|
npx tailwind-unwind apply ./src --output styles.css --dry-run
|
|
160
|
-
npx tailwind-unwind apply ./src --output styles.css
|
|
218
|
+
npx tailwind-unwind apply ./src --output styles.css --prettier
|
|
219
|
+
npx tailwind-unwind apply ./src --output styles.css --from-report report.json --format json
|
|
161
220
|
```
|
|
162
221
|
|
|
163
222
|
**What gets replaced:**
|
|
@@ -166,8 +225,10 @@ npx tailwind-unwind apply ./src --output styles.css
|
|
|
166
225
|
|---------|-----------|
|
|
167
226
|
| `className="flex items-center p-4"` | ✅ |
|
|
168
227
|
| `className={cn('flex', 'items-center', 'p-4')}` | ✅ (static args only) |
|
|
228
|
+
| `className={cn('flex p-4', isActive && 'bg-blue')}` | ✅ partial |
|
|
229
|
+
| `` className={`flex p-4 ${active ? 'bg-blue' : ''}`} `` | ✅ partial (static part) |
|
|
230
|
+
| `className={buttonVariants()}` | ✅ (cva/tv, no args) |
|
|
169
231
|
| `className={getClasses()}` | ❌ skipped |
|
|
170
|
-
| `` className={`flex ${active ? 'p-4' : ''}`} `` | ❌ skipped (dynamic) |
|
|
171
232
|
|
|
172
233
|
**Before → After:**
|
|
173
234
|
|
|
@@ -193,7 +254,18 @@ Generated classes use a **`twu-` prefix** by default to avoid conflicts with exi
|
|
|
193
254
|
| `grid grid-cols-3 gap-4` | `twu-card-grid` |
|
|
194
255
|
| `fixed inset-0 bg-black/50` | `twu-backdrop` |
|
|
195
256
|
|
|
196
|
-
Customize with `--prefix app-`
|
|
257
|
+
Customize with `--prefix app-` or the `names` field in config:
|
|
258
|
+
|
|
259
|
+
```json
|
|
260
|
+
{
|
|
261
|
+
"names": {
|
|
262
|
+
"flex items-center justify-between p-4": "page-header"
|
|
263
|
+
},
|
|
264
|
+
"generate": { "prefix": "app-" }
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
→ `.app-page-header`
|
|
197
269
|
|
|
198
270
|
---
|
|
199
271
|
|
|
@@ -204,6 +276,7 @@ Scans `.tsx`, `.jsx`, `.ts`, `.js` recursively. Ignores `node_modules`, `.next`,
|
|
|
204
276
|
- **Static strings:** `className="flex p-4"` / `class="flex p-4"`
|
|
205
277
|
- **Template literals:** static segments extracted; `${...}` expressions flagged
|
|
206
278
|
- **Merge utilities:** `cn()`, `clsx()`, `classnames()`, `twMerge()`, `cx()`
|
|
279
|
+
- **Variant APIs:** `cva()`, `tv()` definitions and no-arg calls like `buttonVariants()`
|
|
207
280
|
- **Dynamic expressions:** `className={getClasses()}` — warning, skipped
|
|
208
281
|
|
|
209
282
|
Class order is normalized: `flex p-4` and `p-4 flex` are treated as the same set.
|