css2class 2.0.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.
Files changed (57) hide show
  1. package/API.md +1143 -0
  2. package/CHANGELOG.md +291 -0
  3. package/CONFIG.md +1096 -0
  4. package/CONTRIBUTING.md +571 -0
  5. package/MIGRATION.md +402 -0
  6. package/README.md +634 -0
  7. package/bin/class2css.js +380 -0
  8. package/class2css.config.js +124 -0
  9. package/common.css +3 -0
  10. package/configs/colors.config.js +62 -0
  11. package/configs/layout.config.js +110 -0
  12. package/configs/spacing.config.js +37 -0
  13. package/configs/typography.config.js +41 -0
  14. package/docs/.vitepress/config.mjs +65 -0
  15. package/docs/.vitepress/theme/custom.css +74 -0
  16. package/docs/.vitepress/theme/index.js +7 -0
  17. package/docs/guide/cli.md +97 -0
  18. package/docs/guide/concepts.md +63 -0
  19. package/docs/guide/config-template.md +365 -0
  20. package/docs/guide/config.md +275 -0
  21. package/docs/guide/faq.md +202 -0
  22. package/docs/guide/getting-started.md +83 -0
  23. package/docs/guide/important-and-static.md +67 -0
  24. package/docs/guide/incremental.md +162 -0
  25. package/docs/guide/rules-reference.md +354 -0
  26. package/docs/guide/units.md +57 -0
  27. package/docs/index.md +68 -0
  28. package/package.json +49 -0
  29. package/run.js +90 -0
  30. package/src/README.md +571 -0
  31. package/src/core/CacheManager.js +650 -0
  32. package/src/core/CompatibilityAdapter.js +264 -0
  33. package/src/core/ConfigManager.js +431 -0
  34. package/src/core/ConfigValidator.js +350 -0
  35. package/src/core/EventBus.js +77 -0
  36. package/src/core/FullScanManager.js +430 -0
  37. package/src/core/StateManager.js +631 -0
  38. package/src/docs/DocsServer.js +179 -0
  39. package/src/example.js +106 -0
  40. package/src/generators/DynamicClassGenerator.js +674 -0
  41. package/src/index.js +1046 -0
  42. package/src/parsers/ClassParser.js +572 -0
  43. package/src/parsers/ImportantParser.js +279 -0
  44. package/src/parsers/RegexCompiler.js +200 -0
  45. package/src/utils/ClassChangeTracker.js +366 -0
  46. package/src/utils/ConfigDiagnostics.js +673 -0
  47. package/src/utils/CssFormatter.js +261 -0
  48. package/src/utils/FileUtils.js +230 -0
  49. package/src/utils/Logger.js +150 -0
  50. package/src/utils/Throttle.js +172 -0
  51. package/src/utils/UnitProcessor.js +334 -0
  52. package/src/utils/WxssClassExtractor.js +137 -0
  53. package/src/watchers/ConfigWatcher.js +413 -0
  54. package/src/watchers/FileWatcher.js +133 -0
  55. package/src/writers/FileWriter.js +302 -0
  56. package/src/writers/UnifiedWriter.js +370 -0
  57. package/styles.config.js +250 -0
@@ -0,0 +1,354 @@
1
+ # 规则参考(当前模板已内置)
2
+
3
+ 本页把仓库默认的 `class2css.config.js` 里**已经实现**的规则,按使用习惯(边距 / 宽高 / 文字 / 颜色 / 布局 / 自定义)整理成一份“像 Tailwind 一样可查”的参考。
4
+
5
+ :::tip 提示
6
+ 动态类的通用格式是:`<prefix>-<value>`。
7
+ 当前实现会把 **`value` 当成一段整体字符串**,因此 **`value` 里不要再包含 `-`**(例如不支持 `m--10` 这种负数写法)。
8
+ :::
9
+
10
+ ## 值(value)的写法
11
+
12
+ 对大多数动态类(例如 `m-10`、`w-100`):
13
+
14
+ - **纯数字**:会按 `unitConversion` 转换,并追加默认单位(如 `rpx`)
15
+ - **带单位**:保持你写的单位(如 `w-50px`、`top-10rpx`)
16
+ - **关键字**:保持原样(如 `w-auto`、`h-auto`)
17
+
18
+ :::warning 注意
19
+ 为了生成合法的 CSS,**不建议**在 class 名里直接出现 `%` 等特殊字符(选择器会变得难以匹配/需要转义)。
20
+ 推荐做法:用颜色 token(`bg-xxxx`)或写成带单位的安全值(`w-50px` / `w-10rpx`)。
21
+ :::
22
+
23
+ ---
24
+
25
+ ## 边距 / 内边距 / 间距(`atomicRules.spacing`)
26
+
27
+ ### Margin
28
+
29
+ - **`m-{n}`**:`margin`
30
+ - **`mt-{n}`**:`margin-top`
31
+ - **`mr-{n}`**:`margin-right`
32
+ - **`mb-{n}`**:`margin-bottom`
33
+ - **`ml-{n}`**:`margin-left`
34
+ - **`mx-{n}`**:`margin-left` + `margin-right`
35
+ - **`my-{n}`**:`margin-top` + `margin-bottom`
36
+
37
+ 示例:
38
+
39
+ ```html
40
+ <view class="m-10 mt-20 mx-12"></view>
41
+ ```
42
+
43
+ ### Padding
44
+
45
+ - **`p-{n}`**:`padding`
46
+ - **`pt-{n}`**:`padding-top`
47
+ - **`pr-{n}`**:`padding-right`
48
+ - **`pb-{n}`**:`padding-bottom`
49
+ - **`pl-{n}`**:`padding-left`
50
+ - **`px-{n}`**:`padding-left` + `padding-right`
51
+ - **`py-{n}`**:`padding-top` + `padding-bottom`
52
+
53
+ ### Gap
54
+
55
+ - **`gap-{n}`**:`gap`
56
+
57
+ ---
58
+
59
+ ## 宽高 / 尺寸(`atomicRules.sizing` + 静态类)
60
+
61
+ 动态:
62
+
63
+ - **`w-{n}`**:`width`
64
+ - **`h-{n}`**:`height`
65
+ - **`max-w-{n}`**:`max-width`
66
+ - **`max-h-{n}`**:`max-height`
67
+ - **`min-w-{n}`**:`min-width`
68
+ - **`min-h-{n}`**:`min-height`
69
+ - **`size-{n}`**:`width` + `height`(兼容写法)
70
+
71
+ 静态:
72
+
73
+ - **`w-full`**:`width: 100%`
74
+ - **`h-full`**:`height: 100%`
75
+ - **`w-screen`**:`width: 100vw`
76
+ - **`h-screen`**:`height: 100vh`
77
+
78
+ 示例:
79
+
80
+ ```html
81
+ <view class="w-100 h-200 max-w-600 min-h-300 w-full"></view>
82
+ ```
83
+
84
+ ---
85
+
86
+ ## 文字(字号/粗细/行高/字距/对齐/装饰)
87
+
88
+ ### 字号(`atomicRules.typography`)
89
+
90
+ - **`text-{n}`**:`font-size`
91
+ - **`text-size-{n}`**:`font-size`(更明确的别名,用来避免歧义)
92
+
93
+ ```html
94
+ <text class="text-14"></text>
95
+ <text class="text-size-16"></text>
96
+ ```
97
+
98
+ ### 字重(两种方式)
99
+
100
+ 动态(`atomicRules.typography`):
101
+
102
+ - **`font-{n}`**:`font-weight`(例如 `font-700`)
103
+
104
+ 静态(`baseClassName`):
105
+
106
+ - **`bold-thin`**(100)
107
+ - **`bold-extralight`**(200)
108
+ - **`bold-light`**(300)
109
+ - **`bold-normal`**(400)
110
+ - **`bold-medium`**(500)
111
+ - **`bold-semibold`**(600)
112
+ - **`bold-bold`**(700)
113
+ - **`bold-extrabold`**(800)
114
+ - **`bold-black`**(900)
115
+ - **`bold`**(`font-weight: bold;`)
116
+
117
+ ### 行高 / 字间距(`atomicRules.typography`)
118
+
119
+ - **`leading-{n}`**:`line-height`
120
+ - **`tracking-{n}`**:`letter-spacing`
121
+
122
+ :::tip
123
+ `leading` 默认是“无单位属性”,建议写成更明确的单位值(例如 `leading-24px` / `leading-32rpx`)。
124
+ :::
125
+
126
+ ### 文本对齐(静态)
127
+
128
+ - **`text-left`** / **`text-center`** / **`text-right`** / **`text-justify`**
129
+
130
+ ### 文本装饰/省略(静态)
131
+
132
+ - **`underline`**
133
+ - **`line-through`**
134
+ - **`ellipsis`**:`overflow: hidden; text-overflow: ellipsis; white-space: nowrap;`
135
+
136
+ ### 字体族(静态)
137
+
138
+ - **`font-runyuan`**:`font-family: 'HYRunYuan-BOLD';`
139
+
140
+ ---
141
+
142
+ ## 颜色(文字颜色/背景色/边框色)
143
+
144
+ 颜色来自 `baseClassName` 中的三类“颜色族”:
145
+
146
+ - **`color-{token}`**:`color`
147
+ - **`bg-{token}`**:`background-color`
148
+ - **`bcolor-{token}`**:`border-color`
149
+
150
+ 示例:
151
+
152
+ ```html
153
+ <text class="color-red"></text>
154
+ <view class="bg-fafafa bcolor-cc"></view>
155
+ ```
156
+
157
+ :::tip
158
+ 如果你在 `class2css.config.js` 里往颜色表里加了 `brand: '#12b7f5'`,那么你立刻就能用 `color-brand/bg-brand/bcolor-brand`。
159
+ :::
160
+
161
+ <details>
162
+ <summary>当前模板内置的颜色 token(展开查看)</summary>
163
+
164
+ - 466580
165
+ - 818182
166
+ - 595959
167
+ - 333333
168
+ - 666666
169
+ - 979797
170
+ - 777777
171
+ - 142640
172
+ - fafafa
173
+ - B3B3B3
174
+ - F9F9F9
175
+ - 9CA6B4
176
+ - 040404
177
+ - ECF5FF
178
+ - black07
179
+ - fffffe
180
+ - B10A32
181
+ - f4
182
+ - f4f4f4
183
+ - cc
184
+ - white
185
+ - black
186
+ - transparent
187
+ - slate
188
+ - gray
189
+ - gray1
190
+ - gray4
191
+ - zinc
192
+ - red
193
+ - orange
194
+ - amber
195
+ - yellow
196
+ - lime
197
+ - green
198
+ - emerald
199
+ - teal
200
+ - cyan
201
+ - sky
202
+ - blue
203
+ - indigo
204
+ - violet
205
+ - purple
206
+ - fuchsia
207
+ - pink
208
+ - rose
209
+
210
+ </details>
211
+
212
+ ---
213
+
214
+ ## 布局 / 显示(静态类)
215
+
216
+ ### Display
217
+
218
+ - **`block`**, **`inline`**, **`inline-block`**
219
+ - **`flex`**, **`inline-flex`**
220
+ - **`grid`**, **`inline-grid`**
221
+ - **`table`**
222
+ - **`hidden`**
223
+
224
+ ### Flexbox
225
+
226
+ - **`flex-row`**, **`flex-col`**
227
+ - **`flex-wrap`**, **`flex-nowrap`**
228
+ - **`items-start`**, **`items-center`**, **`items-end`**, **`items-stretch`**
229
+ - **`justify-start`**, **`justify-center`**, **`justify-end`**, **`justify-between`**, **`justify-around`**, **`justify-evenly`**
230
+ - **`flex-1`**, **`shrink-0`**
231
+ - **`flex-cen`**:`align-items: center; justify-content: center;`(注意:不包含 `display:flex`,通常配合 `flex` 一起用)
232
+
233
+ ### Grid
234
+
235
+ <details>
236
+ <summary>grid-cols(展开查看)</summary>
237
+
238
+ - `grid-cols-2`
239
+ - `grid-cols-3`
240
+ - `grid-cols-4`
241
+ - `grid-cols-5`
242
+ - `grid-cols-6`
243
+ - `grid-cols-7`
244
+ - `grid-cols-8`
245
+ - `grid-cols-9`
246
+ - `grid-cols-10`
247
+
248
+ </details>
249
+
250
+ ### 定位(静态 + 动态)
251
+
252
+ 静态:
253
+
254
+ - **`static`**, **`fixed`**, **`absolute`**, **`relative`**, **`sticky`**
255
+
256
+ 动态(`atomicRules.positioning`):
257
+
258
+ - **`top-{n}`**, **`right-{n}`**, **`bottom-{n}`**, **`left-{n}`**
259
+ - **`inset-{n}`**:四个方向
260
+ - **`inset-x-{n}`**:左右
261
+ - **`inset-y-{n}`**:上下
262
+
263
+ ### 溢出(静态)
264
+
265
+ - **`overflow-auto`**, **`overflow-hidden`**, **`overflow-visible`**, **`overflow-scroll`**
266
+ - **`overflow-x-auto`**, **`overflow-x-hidden`**, **`overflow-x-scroll`**
267
+ - **`overflow-y-auto`**, **`overflow-y-hidden`**, **`overflow-y-scroll`**
268
+
269
+ ### 光标(静态)
270
+
271
+ - **`cursor-auto`**, **`cursor-default`**, **`cursor-pointer`**, **`cursor-wait`**
272
+ - **`cursor-text`**, **`cursor-move`**, **`cursor-not-allowed`**
273
+
274
+ ### 盒模型(静态)
275
+
276
+ - **`box-border`**(`box-sizing: border-box`)
277
+ - **`box-content`**(`box-sizing: content-box`)
278
+
279
+ ---
280
+
281
+ ## 边框 / 圆角(`atomicRules.borders` + 静态类)
282
+
283
+ 动态:
284
+
285
+ - **`rounded-{n}`**:`border-radius`
286
+ - **`border-{n}`**:`border-width`
287
+ - **`bordert-{n}`** / **`borderr-{n}`** / **`borderb-{n}`** / **`borderl-{n}`**
288
+ - **`b_r-{n}`**:`border-radius`(兼容别名)
289
+
290
+ 静态:
291
+
292
+ - **`border-solid`**, **`border-dashed`**, **`border-dotted`**, **`border-none`**
293
+
294
+ ---
295
+
296
+ ## 效果(`atomicRules.effects`)
297
+
298
+ - **`opacity-{n}`**:`opacity`
299
+ - 推荐用 `0~100` 的整数:例如 `opacity-50` → `0.5`
300
+ - **`z-{n}`**:`z-index`
301
+ - **`transition-{n}`**:`transition`(默认单位 `ms`,并且不会乘 `unitConversion`)
302
+ - 例如 `transition-300` → `transition: 300ms`
303
+ - **`op-{n}`**:`opacity` 的别名
304
+
305
+ ---
306
+
307
+ ## Important(`importantFlags`)
308
+
309
+ 你可以给任意类名追加后缀生成 `!important`:
310
+
311
+ - `-i`:例如 `m-10-i`
312
+ - `_i`:例如 `m-10_i`
313
+
314
+ 详见 [Important 与静态类](./important-and-static.md)。
315
+
316
+ ---
317
+
318
+ ## 自定义:如何在这份配置上继续扩展
319
+
320
+ ### 1) 增加一条动态规则(推荐放在 `atomicRules`)
321
+
322
+ ```js
323
+ atomicRules: {
324
+ // ...
325
+ effects: {
326
+ // 例如:blur-4 → filter: blur(8rpx)
327
+ blur: { properties: ['filter'], defaultUnit: 'rpx' },
328
+ },
329
+ }
330
+ ```
331
+
332
+ ### 2) 增加一个静态类(推荐放在 `baseClassName`)
333
+
334
+ ```js
335
+ baseClassName: {
336
+ // ...
337
+ 'safe-area-bottom': 'padding-bottom: env(safe-area-inset-bottom);',
338
+ }
339
+ ```
340
+
341
+ ### 3) 增加一个颜色 token
342
+
343
+ ```js
344
+ baseColor: {
345
+ brand: '#12b7f5',
346
+ }
347
+ ```
348
+
349
+ 然后你就能使用:
350
+
351
+ - `color-brand`
352
+ - `bg-brand`
353
+ - `bcolor-brand`
354
+
@@ -0,0 +1,57 @@
1
+ # 单位与转换策略
2
+
3
+ 单位处理是 Class2CSS 最容易“踩坑”也最值得配置清楚的部分。本页用最短路径解释:**什么时候会乘以 `unitConversion`,什么时候会保持原值**。
4
+
5
+ ## 核心规则(当前版本)
6
+
7
+ - **写了单位**:保持你写的单位(例如 `w-50px` → `50px`,`top-10rpx` → `10rpx`)
8
+ - **没写单位且是数字**:按 `unitConversion` 换算,并追加默认单位(通常是 `baseUnit`)
9
+ - **部分属性天然无单位**:例如 `opacity`、`z-index`、`font-weight` 等会按“无单位”处理
10
+
11
+ :::tip
12
+ 如果你想知道“某个类到底会不会乘 `unitConversion`”,最稳的判断方式是:**它最终落到哪个 CSS 属性**。
13
+ 像 `opacity` / `z-index` 这种属性,即使写成 `opacity-50` 也不会加单位。
14
+ :::
15
+
16
+ ## 你需要记住的 2 个配置
17
+
18
+ ### baseUnit
19
+
20
+ 默认单位。例如微信小程序常用 `rpx`:
21
+
22
+ ```js
23
+ system: { baseUnit: 'rpx' }
24
+ ```
25
+
26
+ ### unitConversion
27
+
28
+ 转换比例(默认 `2`):当值是“纯数字”且需要单位时,会乘以比例。
29
+
30
+ \[
31
+ 输出值 = 输入值 \times unitConversion
32
+ \]
33
+
34
+ 例如 `m-10` 在 `unitConversion=2` 时生成 `20rpx`。
35
+
36
+ ## 常见例子
37
+
38
+ ```html
39
+ <view class="w-100 text-14 opacity-50 z-999"></view>
40
+ ```
41
+
42
+ 在一套典型配置下可能会生成:
43
+
44
+ - `w-100` → `width: 200rpx;`
45
+ - `text-14` → `font-size: 28rpx;`
46
+ - `opacity-50` → `opacity: 0.5;`
47
+ - `z-999` → `z-index: 999;`
48
+
49
+ :::warning 注意
50
+ `opacity` 的数值会做“百分比语义”处理:当值大于 1 时会除以 100(例如 `opacity-50` → `0.5`)。
51
+ :::
52
+
53
+ ## 下一步
54
+
55
+ - 了解类名解析整体:阅读 [类名语法与生成规则](./concepts.md)
56
+ - 查看所有配置项:阅读 [配置指南](./config.md)
57
+
package/docs/index.md ADDED
@@ -0,0 +1,68 @@
1
+ ---
2
+ home: true
3
+ title: Class2CSS
4
+ titleTemplate: false
5
+
6
+ hero:
7
+ name: Class2CSS
8
+ text: 面向微信小程序的原子化 CSS 生成器
9
+ tagline: 扫描 WXML/HTML 类名 → 生成 wxss/css。内置单位策略、配置校验、缓存与增量模式,让“写类名”变成稳定的工程能力。
10
+ actions:
11
+ - theme: brand
12
+ text: 开始使用
13
+ link: /guide/getting-started
14
+ - theme: alt
15
+ text: 查看配置
16
+ link: /guide/config
17
+
18
+ features:
19
+ - title: 类名即规则
20
+ details: 用 `m-10`、`w-100` 这类表达直接生成样式,避免手写重复 CSS,保持风格一致。
21
+ - title: 智能单位策略
22
+ details: 支持 rpx/px 等单位;可自动检测用户单位,并按属性设置默认单位与转换比例。
23
+ - title: 增量只增不删
24
+ details: 统一文件模式支持“只增不删”与 `appendDelta` 追加写入,兼顾性能与可控性。
25
+ - title: 配置诊断与兼容
26
+ details: 新旧配置无缝兼容;冲突检测、健康检查与建议,减少“配置写错但没发现”的成本。
27
+ ---
28
+
29
+ ## Quick start
30
+
31
+ 安装:
32
+
33
+ ```bash
34
+ npm install css2class --save-dev
35
+ ```
36
+
37
+ 创建 `class2css.config.js`(最小可用示例):
38
+
39
+ ```js
40
+ module.exports = {
41
+ system: { baseUnit: 'rpx', unitConversion: 2, cssFormat: 'compressed' },
42
+ output: { path: '../dist', fileName: 'styles.wxss' },
43
+ cssName: {
44
+ m: { classArr: ['margin'], unit: 'rpx' },
45
+ w: { classArr: ['width'], unit: 'rpx' },
46
+ h: { classArr: ['height'], unit: 'rpx' },
47
+ },
48
+ };
49
+ ```
50
+
51
+ 启动(监听模式):
52
+
53
+ ```bash
54
+ npm run start
55
+ ```
56
+
57
+ 在模板里使用类名:
58
+
59
+ ```html
60
+ <view class="m-10 w-100 h-200"></view>
61
+ ```
62
+
63
+ ## 下一步
64
+
65
+ - **从零跑通一次**:阅读 [快速开始](./guide/getting-started.md)
66
+ - **了解命令**:查看 [CLI](./guide/cli.md)
67
+ - **把配置写“正确且可维护”**:阅读 [配置指南](./guide/config.md)
68
+ - **大型项目优化**:了解 [增量模式(只增不删)](./guide/incremental.md)
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "css2class",
3
+ "version": "2.0.0",
4
+ "description": "Enterprise-grade Atomic CSS Generator for WeChat Mini Program",
5
+ "main": "src/index.js",
6
+ "bin": {
7
+ "class2css": "./bin/class2css.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node bin/class2css.js --docs",
11
+ "build": "node bin/class2css.js --no-watch",
12
+ "dev": "node bin/class2css.js --config ./class2css.config.js",
13
+ "docs:dev": "vitepress dev docs",
14
+ "test": "node src/example.js",
15
+ "help": "node bin/class2css.js --help",
16
+ "version": "node bin/class2css.js --version"
17
+ },
18
+ "keywords": [
19
+ "css",
20
+ "wechat",
21
+ "miniprogram",
22
+ "tailwind",
23
+ "utility",
24
+ "generator"
25
+ ],
26
+ "author": "CMViking",
27
+ "license": "MIT",
28
+ "dependencies": {
29
+ "chokidar": "^3.5.3"
30
+ },
31
+ "engines": {
32
+ "node": ">=14.0.0"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/wnagchi/css2class.git"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/wnagchi/css2class/issues"
40
+ },
41
+ "homepage": "https://github.com/wnagchi/css2class#readme",
42
+ "devDependencies": {
43
+ "eslint": "8.57.1",
44
+ "eslint-config-prettier": "10.1.8",
45
+ "eslint-plugin-prettier": "5.5.4",
46
+ "prettier": "3.6.2",
47
+ "vitepress": "^1.6.4"
48
+ }
49
+ }
package/run.js ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Class2CSS 快速启动脚本
5
+ * 使用方法: node run.js
6
+ */
7
+
8
+ const Class2CSS = require('./src/index');
9
+ const path = require('path');
10
+
11
+ async function run() {
12
+ try {
13
+ console.log('🚀 启动 Class2CSS 工具...');
14
+
15
+ // 创建 Class2CSS 实例
16
+ const class2css = new Class2CSS({
17
+ configPath: './class2css.config.js',
18
+ cacheSize: 1000,
19
+ logger: {
20
+ level: 'info',
21
+ enableDebug: true,
22
+ enableTimestamp: true,
23
+ },
24
+ });
25
+
26
+ // 获取事件总线
27
+ const eventBus = class2css.getEventBus();
28
+
29
+ // 监听事件
30
+ eventBus.on('class2css:started', () => {
31
+ console.log('✅ Class2CSS 启动成功');
32
+ });
33
+
34
+ eventBus.on('config:loaded', (config) => {
35
+ console.log('📋 配置文件加载成功');
36
+ });
37
+
38
+ eventBus.on('parser:completed', (stats) => {
39
+ console.log(`🔍 解析完成: 发现 ${stats.totalCount} 个类名`);
40
+ });
41
+
42
+ eventBus.on('generator:dynamic:completed', (stats) => {
43
+ console.log(`🎨 动态CSS生成完成: ${stats.generatedCount} 个类`);
44
+ });
45
+
46
+ eventBus.on('log:error', (data) => {
47
+ console.error('❌ 错误:', data);
48
+ });
49
+
50
+ // 启动工具
51
+ await class2css.start();
52
+
53
+ // 显示状态
54
+ console.log('\n📊 当前状态:');
55
+ const status = class2css.getStatus();
56
+ console.log(JSON.stringify(status, null, 2));
57
+
58
+ console.log('\n🎯 Class2CSS 正在监听文件变化...');
59
+ console.log('按 Ctrl+C 停止');
60
+
61
+ // 处理进程信号
62
+ process.on('SIGINT', async () => {
63
+ console.log('\n🛑 收到停止信号,正在关闭 Class2CSS...');
64
+ await class2css.stop();
65
+ process.exit(0);
66
+ });
67
+
68
+ process.on('SIGTERM', async () => {
69
+ console.log('\n🛑 收到终止信号,正在关闭 Class2CSS...');
70
+ await class2css.stop();
71
+ process.exit(0);
72
+ });
73
+ } catch (error) {
74
+ console.error('❌ 启动失败:', error.message);
75
+ if (error.stack) {
76
+ console.error(error.stack);
77
+ }
78
+ process.exit(1);
79
+ }
80
+ }
81
+
82
+ // 运行
83
+ if (require.main === module) {
84
+ run().catch((error) => {
85
+ console.error('❌ 未处理的错误:', error);
86
+ process.exit(1);
87
+ });
88
+ }
89
+
90
+ module.exports = { run };