generated from sonofmagic/monorepo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcli.ts
47 lines (40 loc) · 1.17 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import process from 'node:process'
import { CONFIG_NAME, getConfig, initConfig } from '@tailwindcss-mangle/config'
import { defuOverrideArray } from '@tailwindcss-mangle/shared'
import cac from 'cac'
import { TailwindcssPatcher } from './core'
import { getPatchOptions } from './defaults'
import logger from './logger'
function init() {
const cwd = process.cwd()
return initConfig(cwd)
}
const cli = cac()
cli.command('install', 'patch install').action(() => {
const twPatcher = new TailwindcssPatcher({
patch: getPatchOptions(),
})
twPatcher.patch()
})
cli.command('init').action(async () => {
await init()
logger.success(`✨ ${CONFIG_NAME}.config.ts initialized!`)
})
cli.command('extract').action(async () => {
const { config } = await getConfig()
if (config) {
const twPatcher = new TailwindcssPatcher(
{
patch: defuOverrideArray(config.patch!, {
resolve: {
paths: [import.meta.url],
},
}),
},
)
const p = await twPatcher.extract()
p && logger.success(`✨ tailwindcss-patch extract success! file path: ${p.filename}, classList length: ${p.classList.length}`)
}
})
cli.help()
cli.parse()