tailwindcss-patch 8.2.4 → 8.4.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 CHANGED
@@ -39,6 +39,60 @@ pnpm dlx tw-patch extract
39
39
  pnpm dlx tw-patch tokens --format lines
40
40
  ```
41
41
 
42
+ ### Embed into another CLI
43
+
44
+ Reuse the same commands inside your own `cac` program:
45
+
46
+ ```ts
47
+ import cac from 'cac'
48
+ import { mountTailwindcssPatchCommands } from 'tailwindcss-patch'
49
+
50
+ const cli = cac('my-tool')
51
+ mountTailwindcssPatchCommands(cli, {
52
+ commandPrefix: 'tw:', // optional
53
+ commands: ['install', 'tokens'], // mount a subset if needed (defaults to all)
54
+ commandOptions: {
55
+ install: { name: 'patch-install', aliases: ['tw-install'] }, // override names/aliases
56
+ },
57
+ })
58
+ cli.help()
59
+ cli.parse()
60
+ ```
61
+
62
+ #### Custom command hooks
63
+
64
+ Hosts can override per-command lifecycles by supplying `commandHandlers`. Each handler receives a context object (with the resolved `cwd`, parsed `args`, memoized `loadConfig`/`createPatcher` helpers, and the shared `logger`) plus a `next()` callback that runs the built-in action.
65
+
66
+ ```ts
67
+ mountTailwindcssPatchCommands(cli, {
68
+ commandHandlers: {
69
+ install: async (ctx) => {
70
+ const patcher = await ctx.createPatcher()
71
+ await clearTailwindcssPatcherCache(ctx.cwd)
72
+ await patcher.patch()
73
+ await saveCliPatchTargetRecord({ cwd: ctx.cwd })
74
+ },
75
+ extract: async (ctx, next) => {
76
+ const result = await next() // run the default extract implementation
77
+ ctx.logger.success(`[host] wrote ${result.classList.length} classes`)
78
+ return result
79
+ },
80
+ },
81
+ commandOptions: {
82
+ extract: {
83
+ description: 'Localised extract command',
84
+ appendDefaultOptions: false,
85
+ optionDefs: [
86
+ { flags: '--entry <file>', description: 'Tailwind CSS entry file' },
87
+ { flags: '--preview', description: 'Print a preview instead of writing' },
88
+ ],
89
+ },
90
+ },
91
+ })
92
+ ```
93
+
94
+ Skip `next()` to fully replace a command (e.g. custom `init` or cache clearing before `install`). Calling `next()` returns the default result—`ExtractResult`, `TailwindTokenReport`, etc.—so hosts can log metadata or feed it into their own telemetry without re-implementing the commands.
95
+
42
96
  ### Extract options
43
97
 
44
98
  | Flag | Description |
@@ -53,13 +107,13 @@ The CLI loads `tailwindcss-patch.config.ts` via `@tailwindcss-mangle/config`. Le
53
107
 
54
108
  ### Token report options
55
109
 
56
- | Flag | Description |
57
- | ------------------------ | --------------------------------------------------------------------------- |
58
- | `--cwd <dir>` | Use a different working directory when loading configuration. |
59
- | `--output <file>` | Override the token report target file (defaults to `.tw-patch/tw-token-report.json`). |
110
+ | Flag | Description |
111
+ | -------------------------------------- | ----------------------------------------------------------------------------------------- |
112
+ | `--cwd <dir>` | Use a different working directory when loading configuration. |
113
+ | `--output <file>` | Override the token report target file (defaults to `.tw-patch/tw-token-report.json`). |
60
114
  | `--format <json\|lines\|grouped-json>` | Choose between a JSON payload (default), newline summaries, or JSON grouped by file path. |
61
- | `--group-key <relative\|absolute>` | Control grouped-json keys (defaults to relative paths). |
62
- | `--no-write` | Skip writing to disk and only print a preview. |
115
+ | `--group-key <relative\|absolute>` | Control grouped-json keys (defaults to relative paths). |
116
+ | `--no-write` | Skip writing to disk and only print a preview. |
63
117
 
64
118
  ## Programmatic API
65
119