Skip to content

Commit 8be692f

Browse files
authored
chore: release tailwindcss-patch 2.0.0 (#34)
* refactor: tailwindcss-patch stage 0 * chore: add postcss test * feat: commit class list * feat: commit options * chore: release tailwindcss-patch 2.0.0 * chore: ci remove unplugin-tailwindcss-mangle test * chore: remove tailwindcss-patch test for tmp * chore: default remove "*"
1 parent 74d3635 commit 8be692f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1194
-200
lines changed

.vscode/launch.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
"type": "node-terminal",
1212
"cwd": "${workspaceFolder}/packages/tailwindcss-patch"
1313
},
14+
{
15+
"command": "npm run test:dev",
16+
"name": "[tailwindcss-patch] test:dev",
17+
"request": "launch",
18+
"type": "node-terminal",
19+
"cwd": "${workspaceFolder}/packages/tailwindcss-patch"
20+
},
1421
{
1522
"command": "npm run build",
1623
"name": "Debug nuxt-app",

apps/vite-svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"prepare": "tw-patch"
1212
},
1313
"devDependencies": {
14-
"@sveltejs/vite-plugin-svelte": "^2.4.3",
14+
"@sveltejs/vite-plugin-svelte": "^2.4.4",
1515
"@tsconfig/svelte": "^5.0.0",
1616
"autoprefixer": "^10.4.14",
1717
"postcss": "^8.4.27",
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
[
2+
"*",
3+
"after:-z-20",
4+
"after:absolute",
5+
"after:blur-2xl",
6+
"after:content-['']",
7+
"after:dark:from-sky-900",
8+
"after:dark:via-[#0141ff]/40",
9+
"after:from-sky-200",
10+
"after:h-[180px]",
11+
"after:translate-x-1/3",
12+
"after:via-blue-200",
13+
"after:w-[240px]",
14+
"backdrop-blur-2xl",
15+
"before:-translate-x-1/2",
16+
"before:absolute",
17+
"before:blur-2xl",
18+
"before:content-['']",
19+
"before:dark:bg-gradient-to-br",
20+
"before:dark:from-transparent",
21+
"before:dark:to-blue-700/10",
22+
"before:from-white",
23+
"before:h-[300px]",
24+
"before:lg:h-[360px]",
25+
"before:rounded-full",
26+
"before:to-transparent",
27+
"before:w-[480px]",
28+
"bg-gradient-to-b",
29+
"bg-gradient-to-t",
30+
"bg-red-200",
31+
"bg-red-200/40",
32+
"bg-red-200/70",
33+
"bg-red-200/90",
34+
"border",
35+
"border-b",
36+
"border-gray-300",
37+
"border-transparent",
38+
"bottom-0",
39+
"dark:bg-zinc-800/30",
40+
"dark:border-neutral-800",
41+
"dark:drop-shadow-[0_0_0.3rem_#ffffff70]",
42+
"dark:from-black",
43+
"dark:from-inherit",
44+
"dark:invert",
45+
"dark:via-black",
46+
"drop-shadow",
47+
"ease-out",
48+
"filter",
49+
"fixed",
50+
"flex",
51+
"flex-col",
52+
"font-bold",
53+
"font-mono",
54+
"font-semibold",
55+
"from-white",
56+
"from-zinc-200",
57+
"gap-2",
58+
"grid",
59+
"group-hover:translate-x-1",
60+
"h-48",
61+
"hover:bg-gray-100",
62+
"hover:border-gray-300",
63+
"hover:dark:bg-neutral-800/30",
64+
"hover:dark:border-neutral-700",
65+
"inline-block",
66+
"items-center",
67+
"items-end",
68+
"justify-between",
69+
"justify-center",
70+
"left-0",
71+
"lg:bg-gray-200",
72+
"lg:bg-none",
73+
"lg:border",
74+
"lg:dark:bg-zinc-800/30",
75+
"lg:flex",
76+
"lg:grid-cols-4",
77+
"lg:h-auto",
78+
"lg:mb-0",
79+
"lg:p-0",
80+
"lg:p-4",
81+
"lg:pointer-events-auto",
82+
"lg:rounded-xl",
83+
"lg:static",
84+
"lg:text-left",
85+
"lg:w-auto",
86+
"m-0",
87+
"max-w-5xl",
88+
"max-w-[30ch]",
89+
"mb-3",
90+
"mb-32",
91+
"min-h-screen",
92+
"motion-reduce:transform-none",
93+
"opacity-50",
94+
"p-24",
95+
"p-8",
96+
"pb-6",
97+
"place-items-center",
98+
"pointer-events-none",
99+
"pt-8",
100+
"px-5",
101+
"py-4",
102+
"relative",
103+
"rounded-lg",
104+
"text-2xl",
105+
"text-[16px]",
106+
"text-center",
107+
"text-sm",
108+
"top-0",
109+
"transition",
110+
"transition-colors",
111+
"transition-transform",
112+
"via-white",
113+
"w-full",
114+
"z-10"
115+
]

apps/vite-vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dev": "vite",
88
"build": "vite build",
99
"preview": "vite preview",
10-
"prepare": "tw-patch"
10+
"prepare": "tw-patch install"
1111
},
1212
"dependencies": {
1313
"vue": "^3.3.4"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineConfig } from 'tailwindcss-patch'
2+
3+
export default defineConfig({})

packages/core/test/js.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { jsHandler } from '@/js'
22
import { getCss, getTestCase } from './utils'
33
import { ClassGenerator } from '@/shared'
4-
// import { getClassCacheSet } from 'tailwindcss-patch'
54

65
describe('js handler', () => {
76
let classGenerator: ClassGenerator

packages/tailwindcss-patch/README.md

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# tailwindcss-patch
22

3-
get tailwindcss context at runtime!
3+
get tailwindcss context at runtime ! extract all class to json file!
4+
5+
- [tailwindcss-patch](#tailwindcss-patch)
6+
- [Setup](#setup)
7+
- [Usage](#usage)
8+
- [Cli](#cli)
9+
- [Init Config File](#init-config-file)
10+
- [Extract all class into a json](#extract-all-class-into-a-json)
11+
- [Nodejs](#nodejs)
12+
- [Migration form v1 to v2](#migration-form-v1-to-v2)
13+
- [2. cli command change](#2-cli-command-change)
14+
- [1. default remove `*` in json array result](#1-default-remove--in-json-array-result)
15+
- [Notice](#notice)
416

517
## Setup
618

@@ -13,7 +25,7 @@ get tailwindcss context at runtime!
1325
2. Patch tailwindcss
1426

1527
```sh
16-
npx tw-patch
28+
npx tw-patch install
1729
```
1830

1931
3. Add `prepare` script (keeps patch persisted after npm install)
@@ -24,19 +36,64 @@ npx tw-patch
2436
{
2537
/* ... */
2638
"scripts": {
27-
"prepare": "tw-patch"
39+
"prepare": "tw-patch install"
2840
}
2941
}
3042
```
3143

3244
## Usage
3345

46+
## Cli
47+
48+
### Init Config File
49+
50+
```sh
51+
tw-patch init
52+
```
53+
54+
Then there will be a ts file called `tailwindcss-patch.config.ts` exist in your `cwd`.
55+
56+
### Extract all class into a json
57+
58+
```sh
59+
tw-patch extract
60+
```
61+
62+
default there will be a json in `.tw-patch/tw-class-list.json` in your project.
63+
64+
you can custom this behavior by config `tailwindcss-patch.config.ts`
65+
66+
### Nodejs
67+
3468
```js
35-
import { getContexts, getClassCacheSet } from 'tailwindcss-patch'
69+
import { TailwindcssPatcher } from 'tailwindcss-patch'
70+
71+
const twPatcher = new TailwindcssPatcher(/* options */)
3672
// get all contexts at runtime
37-
getContexts()
73+
twPatcher.getContexts()
3874
// get all class generated by tailwindcss utilities
39-
getClassCacheSet()
75+
twPatcher.getClassSet()
76+
```
77+
78+
## Migration form v1 to v2
79+
80+
### 2. cli command change
81+
82+
```diff
83+
{
84+
- "tw-patch"
85+
+ "tw-patch install"
86+
}
87+
```
88+
89+
### 1. default remove `*` in json array result
90+
91+
```diff
92+
[
93+
- "*",
94+
"text-[99px]",
95+
"text-[100px]"
96+
]
4097
```
4198

4299
## Notice

packages/tailwindcss-patch/build.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from 'node:path'
12
import { defineBuildConfig } from 'unbuild'
23

34
export default defineBuildConfig({
@@ -11,5 +12,8 @@ export default defineBuildConfig({
1112
respectExternal: false
1213
}
1314
},
15+
alias: {
16+
'@': path.resolve(__dirname, './src')
17+
},
1418
declaration: true
1519
})

packages/tailwindcss-patch/package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tailwindcss-patch",
3-
"version": "1.2.7",
3+
"version": "2.0.0",
44
"description": "patch tailwindcss for exposing context",
55
"exports": {
66
".": {
@@ -30,9 +30,9 @@
3030
],
3131
"scripts": {
3232
"build": "unbuild",
33-
"test": "vitest run",
33+
"test": "vitest run --coverage.enabled",
3434
"test:dev": "vitest",
35-
"cli": "node bin/tw-patch.js"
35+
"cli": "node bin/tw-patch.js install"
3636
},
3737
"keywords": [
3838
"tailwindcss",
@@ -49,9 +49,9 @@
4949
"@types/babel__traverse": "^7.20.1",
5050
"@types/resolve": "^1.20.2",
5151
"@types/semver": "^7.5.0",
52+
"dedent": "^1.5.1",
5253
"defu": "^6.1.2",
5354
"pkg-types": "^1.0.3",
54-
"postcss": "^8.4.27",
5555
"tailwindcss": "^3.3.3"
5656
},
5757
"dependencies": {
@@ -61,12 +61,20 @@
6161
"@babel/types": "^7.22.5",
6262
"c12": "^1.4.2",
6363
"cac": "^6.7.14",
64+
"postcss": "^8.4.27",
65+
"postcss-load-config": "^4.0.1",
6466
"resolve": "^1.22.4",
6567
"semver": "^7.5.4"
6668
},
6769
"homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
6870
"repository": {
6971
"type": "git",
7072
"url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git"
73+
},
74+
"bugs": {
75+
"url": "https://github.com/sonofmagic/tailwindcss-mangle/issues"
76+
},
77+
"directories": {
78+
"test": "test"
7179
}
72-
}
80+
}

packages/tailwindcss-patch/src/cli.ts

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
1-
import { createPatch, getPatchOptions } from './core'
2-
const opt = getPatchOptions()
3-
const patch = createPatch(opt)
4-
patch()
1+
import { createPatch, getPatchOptions, TailwindcssPatcher, getConfig } from './core'
2+
import cac from 'cac'
3+
import dedent from 'dedent'
4+
import path from 'node:path'
5+
import fs from 'node:fs/promises'
6+
7+
function init() {
8+
const cwd = process.cwd()
9+
return fs.writeFile(
10+
path.resolve(cwd, 'tailwindcss-patch.config.ts'),
11+
dedent`
12+
import { defineConfig } from 'tailwindcss-patch'
13+
14+
export default defineConfig({})
15+
`,
16+
'utf8'
17+
)
18+
}
19+
20+
const cli = cac()
21+
22+
cli.command('install', 'patch install').action(() => {
23+
const opt = getPatchOptions()
24+
const patch = createPatch(opt)
25+
patch()
26+
})
27+
28+
cli.command('init').action(async () => {
29+
await init()
30+
console.log('✨ tailwindcss-patch config initialized!')
31+
})
32+
33+
cli.command('extract').action(async () => {
34+
const { config } = await getConfig()
35+
if (config) {
36+
const twPatcher = new TailwindcssPatcher()
37+
const p = await twPatcher.extract(config)
38+
console.log('✨ tailwindcss-patch extract success! file path:\n' + p)
39+
}
40+
})
41+
42+
cli.help()
43+
44+
cli.parse()

0 commit comments

Comments
 (0)