Skip to content

Commit 9105a4a

Browse files
committed
feat: expose hookable CLI command registration so host CLIs can customize command lifecycles, descriptions, and options without reimplementing tw-patch wiring
1 parent 32a199a commit 9105a4a

File tree

7 files changed

+614
-225
lines changed

7 files changed

+614
-225
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tailwindcss-patch': minor
3+
---
4+
5+
expose hookable CLI command registration so host CLIs can customize command lifecycles, descriptions, and options without reimplementing tw-patch wiring

packages/tailwindcss-patch/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,42 @@ cli.help()
5959
cli.parse()
6060
```
6161

62+
63+
#### Custom command hooks
64+
65+
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.
66+
67+
```ts
68+
mountTailwindcssPatchCommands(cli, {
69+
commandHandlers: {
70+
install: async (ctx) => {
71+
const patcher = await ctx.createPatcher()
72+
await clearTailwindcssPatcherCache(ctx.cwd)
73+
await patcher.patch()
74+
await saveCliPatchTargetRecord({ cwd: ctx.cwd })
75+
},
76+
extract: async (ctx, next) => {
77+
const result = await next() // run the default extract implementation
78+
ctx.logger.success(`[host] wrote ${result.classList.length} classes`)
79+
return result
80+
},
81+
},
82+
commandOptions: {
83+
extract: {
84+
description: 'Localised extract command',
85+
appendDefaultOptions: false,
86+
optionDefs: [
87+
{ flags: '--entry <file>', description: 'Tailwind CSS entry file' },
88+
{ flags: '--preview', description: 'Print a preview instead of writing' },
89+
],
90+
},
91+
},
92+
})
93+
```
94+
95+
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.
96+
97+
6298
### Extract options
6399

64100
| Flag | Description |

0 commit comments

Comments
 (0)