@openwebf/webf 0.22.1 → 0.22.4

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/bin/webf.js +1 -0
  2. package/dist/IDLBlob.js +17 -0
  3. package/dist/analyzer.js +578 -0
  4. package/dist/analyzer_original.js +467 -0
  5. package/dist/commands.js +704 -0
  6. package/dist/dart.js +300 -0
  7. package/dist/declaration.js +63 -0
  8. package/dist/generator.js +466 -0
  9. package/dist/logger.js +103 -0
  10. package/dist/react.js +283 -0
  11. package/dist/utils.js +127 -0
  12. package/dist/vue.js +159 -0
  13. package/package.json +8 -1
  14. package/src/IDLBlob.ts +2 -2
  15. package/src/analyzer.ts +19 -1
  16. package/src/commands.ts +201 -22
  17. package/src/dart.ts +172 -11
  18. package/src/declaration.ts +5 -0
  19. package/src/generator.ts +82 -14
  20. package/src/react.ts +197 -62
  21. package/templates/class.dart.tpl +10 -4
  22. package/templates/gitignore.tpl +8 -1
  23. package/templates/react.component.tsx.tpl +78 -26
  24. package/templates/react.index.ts.tpl +0 -1
  25. package/templates/react.package.json.tpl +3 -0
  26. package/test/commands.test.ts +0 -5
  27. package/test/generator.test.ts +29 -8
  28. package/test/packageName.test.ts +231 -0
  29. package/test/react.test.ts +94 -9
  30. package/CLAUDE.md +0 -206
  31. package/README-zhCN.md +0 -256
  32. package/coverage/clover.xml +0 -1295
  33. package/coverage/coverage-final.json +0 -12
  34. package/coverage/lcov-report/IDLBlob.ts.html +0 -142
  35. package/coverage/lcov-report/analyzer.ts.html +0 -2158
  36. package/coverage/lcov-report/analyzer_original.ts.html +0 -1450
  37. package/coverage/lcov-report/base.css +0 -224
  38. package/coverage/lcov-report/block-navigation.js +0 -87
  39. package/coverage/lcov-report/commands.ts.html +0 -700
  40. package/coverage/lcov-report/dart.ts.html +0 -490
  41. package/coverage/lcov-report/declaration.ts.html +0 -337
  42. package/coverage/lcov-report/favicon.png +0 -0
  43. package/coverage/lcov-report/generator.ts.html +0 -1171
  44. package/coverage/lcov-report/index.html +0 -266
  45. package/coverage/lcov-report/logger.ts.html +0 -424
  46. package/coverage/lcov-report/prettify.css +0 -1
  47. package/coverage/lcov-report/prettify.js +0 -2
  48. package/coverage/lcov-report/react.ts.html +0 -619
  49. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  50. package/coverage/lcov-report/sorter.js +0 -196
  51. package/coverage/lcov-report/utils.ts.html +0 -466
  52. package/coverage/lcov-report/vue.ts.html +0 -613
  53. package/coverage/lcov.info +0 -2149
  54. package/global.d.ts +0 -2
  55. package/jest.config.js +0 -24
  56. package/templates/react.createComponent.tpl +0 -286
  57. package/tsconfig.json +0 -30
package/README-zhCN.md DELETED
@@ -1,256 +0,0 @@
1
- # WebF CLI
2
-
3
- 一个用于生成 Flutter 类和 Vue/React 组件声明文件的命令行工具。
4
-
5
- ## 安装
6
-
7
- ```bash
8
- npm install -g @openwebf/webf
9
- ```
10
-
11
- ## 使用方法
12
-
13
- WebF CLI 提供三个主要命令:
14
-
15
- ### 1. 初始化类型定义
16
-
17
- 在项目中初始化 WebF 类型定义:
18
-
19
- ```bash
20
- webf init <目标目录>
21
- ```
22
-
23
- 这将在指定目录中创建必要的类型定义文件。
24
-
25
- ### 2. 创建新项目
26
-
27
- 创建一个新的 Vue 或 React 项目:
28
-
29
- ```bash
30
- webf create <目标目录> --framework <框架> --package-name <包名>
31
- ```
32
-
33
- 选项:
34
- - `--framework`:选择 'vue' 或 'react'
35
- - `--package-name`:指定包名
36
-
37
- 示例:
38
- ```bash
39
- webf create my-webf-app --framework react --package-name @myorg/my-webf-app
40
- ```
41
-
42
- ### 3. 生成代码
43
-
44
- 生成 Flutter 类和组件声明文件:
45
-
46
- ```bash
47
- webf generate <目标路径> --flutter-package-src <Flutter源码路径> --framework <框架>
48
- ```
49
-
50
- 选项:
51
- - `--flutter-package-src`:Flutter 包源码路径
52
- - `--framework`:选择 'vue' 或 'react'
53
-
54
- 示例:
55
- ```bash
56
- webf generate ./src --flutter-package-src ./flutter_package --framework react
57
- ```
58
-
59
- ## 实现细节
60
-
61
- ### 类型系统
62
-
63
- CLI 使用复杂的类型系统来处理各种数据类型:
64
-
65
- - 基本类型:
66
- - `string`(DOM 字符串)
67
- - `number`(整数/浮点数)
68
- - `boolean`(布尔值)
69
- - `any`(任意类型)
70
- - `void`(空类型)
71
- - `null`(空值)
72
- - `undefined`(未定义)
73
-
74
- - 复杂类型:
75
- - 数组:`Type[]`
76
- - 函数:`Function`
77
- - Promise:`Promise<Type>`
78
- - 自定义事件:`CustomEvent`
79
- - 布局依赖类型:`DependentsOnLayout<Type>`
80
-
81
- ### 命名约定和文件结构
82
-
83
- #### 接口命名模式
84
-
85
- CLI 遵循特定的接口命名模式:
86
-
87
- 1. **组件接口**:
88
- - 属性接口:`{组件名称}Properties`
89
- - 事件接口:`{组件名称}Events`
90
- - 示例:`ButtonProperties`、`ButtonEvents`
91
-
92
- 2. **生成的文件名**:
93
- - React 组件:`{组件名称}.tsx`
94
- - Vue 组件:`{组件名称}.vue`
95
- - Flutter 类:`{组件名称}.dart`
96
- - 类型定义:`{组件名称}.d.ts`
97
-
98
- 3. **名称转换**:
99
- - 组件名称提取:
100
- - 从 `{名称}Properties` → `{名称}`
101
- - 从 `{名称}Events` → `{名称}`
102
- - 示例:`ButtonProperties` → `Button`
103
-
104
- #### 生成的组件名称
105
-
106
- 1. **React 组件**:
107
- - 标签名:`<{组件名称} />`
108
- - 文件名:`{组件名称}.tsx`
109
- - 示例:`ButtonProperties` → `<Button />` 在 `button.tsx` 中
110
-
111
- 2. **Vue 组件**:
112
- - 标签名:`<{组件名称}-component />`
113
- - 文件名:`{组件名称}.vue`
114
- - 示例:`ButtonProperties` → `<button-component />` 在 `button.vue` 中
115
-
116
- 3. **Flutter 类**:
117
- - 类名:`{组件名称}`
118
- - 文件名:`{组件名称}.dart`
119
- - 示例:`ButtonProperties` → `Button` 类在 `button.dart` 中
120
-
121
- #### 类型定义文件
122
-
123
- 1. **文件位置**:
124
- - React:`src/components/{组件名称}.d.ts`
125
- - Vue:`src/components/{组件名称}.d.ts`
126
- - Flutter:`lib/src/{组件名称}.dart`
127
-
128
- 2. **接口结构**:
129
- ```typescript
130
- interface {组件名称}Properties {
131
- // 属性
132
- }
133
-
134
- interface {组件名称}Events {
135
- // 事件
136
- }
137
- ```
138
-
139
- 3. **组件注册**:
140
- - React:在 `index.ts` 中导出
141
- - Vue:在组件声明文件中注册
142
- - Flutter:在库文件中导出
143
-
144
- ### 组件生成
145
-
146
- #### React 组件
147
- - 生成带有适当类型定义的 TypeScript React 组件
148
- - 处理带有正确事件类型的事件绑定
149
- - 支持带有基于 Promise 返回类型的异步方法
150
- - 将事件名称转换为 React 约定(如 `onClick`、`onChange`)
151
-
152
- #### Vue 组件
153
- - 生成 Vue 组件类型声明
154
- - 支持 Vue 的事件系统
155
- - 使用适当的 TypeScript 类型处理属性和事件
156
- - 生成组件注册代码
157
-
158
- #### Flutter 类
159
- - 生成带有适当类型映射的 Dart 类
160
- - 使用正确的参数类型处理方法声明
161
- - 支持异步操作
162
- - 生成适当的事件处理器类型
163
-
164
- ### 类型分析
165
-
166
- CLI 使用 TypeScript 的编译器 API 来分析和处理类型定义:
167
-
168
- 1. 解析 TypeScript 接口声明
169
- 2. 分析类关系和继承
170
- 3. 处理方法签名和参数类型
171
- 4. 处理联合类型和复杂类型表达式
172
- 5. 为每个目标平台生成适当的类型映射
173
-
174
- ### 代码生成约定
175
-
176
- 1. **命名约定**:
177
- - 属性:camelCase
178
- - 事件:带 'on' 前缀的 camelCase
179
- - 方法:camelCase
180
- - 类:PascalCase
181
-
182
- 2. **类型映射**:
183
- - TypeScript → Dart:
184
- - `string` → `String`
185
- - `number` → `int`/`double`
186
- - `boolean` → `bool`
187
- - `any` → `dynamic`
188
- - `void` → `void`
189
-
190
- - TypeScript → React/Vue:
191
- - `string` → `string`
192
- - `number` → `number`
193
- - `boolean` → `boolean`
194
- - `any` → `any`
195
- - `void` → `void`
196
-
197
- 3. **事件处理**:
198
- - React:`EventHandler<SyntheticEvent<Element>>`
199
- - Vue:`Event`/`CustomEvent`
200
- - Flutter:`EventHandler<Event>`
201
-
202
- ## 项目结构
203
-
204
- 运行命令后,您的项目将具有以下结构:
205
-
206
- ### React 项目
207
- ```
208
- my-webf-app/
209
- ├── src/
210
- │ ├── components/
211
- │ │ ├── button.tsx
212
- │ │ ├── button.d.ts
213
- │ │ └── index.ts
214
- │ ├── utils/
215
- │ │ └── createComponent.ts
216
- │ └── index.ts
217
- ├── package.json
218
- ├── tsconfig.json
219
- └── tsup.config.ts
220
- ```
221
-
222
- ### Vue 项目
223
- ```
224
- my-webf-app/
225
- ├── src/
226
- │ ├── components/
227
- │ │ ├── button.vue
228
- │ │ └── button.d.ts
229
- ├── package.json
230
- └── tsconfig.json
231
- ```
232
-
233
- ## 依赖项
234
-
235
- CLI 会自动为所选框架安装必要的依赖项:
236
- - React:React 及相关类型定义
237
- - Vue:Vue 及相关类型定义
238
-
239
- ## 开发
240
-
241
- ### 从源码构建
242
-
243
- ```bash
244
- npm install
245
- npm run build
246
- ```
247
-
248
- ### 测试
249
-
250
- ```bash
251
- npm test
252
- ```
253
-
254
- ## 许可证
255
-
256
- ISC