@react-native-windows/codegen 0.66.1 → 0.67.1
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.
- package/CHANGELOG.json +204 -16
- package/CHANGELOG.md +99 -10
- package/lib-commonjs/Cli.d.ts +7 -0
- package/lib-commonjs/Cli.js +203 -0
- package/lib-commonjs/Cli.js.map +1 -0
- package/lib-commonjs/generators/AliasGen.d.ts +11 -0
- package/lib-commonjs/generators/AliasGen.js +72 -0
- package/lib-commonjs/generators/AliasGen.js.map +1 -0
- package/lib-commonjs/generators/AliasManaging.d.ts +15 -0
- package/lib-commonjs/generators/AliasManaging.js +49 -0
- package/lib-commonjs/generators/AliasManaging.js.map +1 -0
- package/lib-commonjs/generators/GenerateNM2.d.ts +11 -0
- package/lib-commonjs/generators/GenerateNM2.js +94 -0
- package/lib-commonjs/generators/GenerateNM2.js.map +1 -0
- package/lib-commonjs/generators/ObjectTypes.d.ts +8 -0
- package/lib-commonjs/generators/ObjectTypes.js +53 -0
- package/lib-commonjs/generators/ObjectTypes.js.map +1 -0
- package/lib-commonjs/generators/ParamTypes.d.ts +11 -0
- package/lib-commonjs/generators/ParamTypes.js +114 -0
- package/lib-commonjs/generators/ParamTypes.js.map +1 -0
- package/lib-commonjs/generators/ReturnTypes.d.ts +9 -0
- package/lib-commonjs/generators/ReturnTypes.js +63 -0
- package/lib-commonjs/generators/ReturnTypes.js.map +1 -0
- package/lib-commonjs/generators/ValidateConstants.d.ts +8 -0
- package/lib-commonjs/generators/ValidateConstants.js +38 -0
- package/lib-commonjs/generators/ValidateConstants.js.map +1 -0
- package/lib-commonjs/generators/ValidateMethods.d.ts +8 -0
- package/lib-commonjs/generators/ValidateMethods.js +70 -0
- package/lib-commonjs/generators/ValidateMethods.js.map +1 -0
- package/package.json +20 -10
- package/src/Cli.ts +23 -17
- package/src/generators/AliasGen.ts +105 -0
- package/src/generators/AliasManaging.ts +75 -0
- package/src/generators/GenerateNM2.ts +38 -122
- package/src/generators/ObjectTypes.ts +24 -39
- package/src/generators/ParamTypes.ts +144 -39
- package/src/generators/ReturnTypes.ts +29 -10
- package/src/generators/ValidateConstants.ts +50 -0
- package/src/generators/ValidateMethods.ts +135 -0
- package/.eslintrc.js +0 -4
- package/.vscode/launch.json +0 -23
- package/jest.config.js +0 -1
- package/tsconfig.json +0 -5
package/CHANGELOG.json
CHANGED
|
@@ -2,45 +2,233 @@
|
|
|
2
2
|
"name": "@react-native-windows/codegen",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "Mon,
|
|
6
|
-
"tag": "@react-native-windows/codegen_v0.
|
|
7
|
-
"version": "0.
|
|
5
|
+
"date": "Mon, 04 Apr 2022 15:12:54 GMT",
|
|
6
|
+
"tag": "@react-native-windows/codegen_v0.67.1",
|
|
7
|
+
"version": "0.67.1",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "34109996+chiaramooney@users.noreply.github.com",
|
|
12
|
+
"package": "@react-native-windows/codegen",
|
|
13
|
+
"commit": "f4f970be35618e9942c5c96e6c15c88f8426c91c",
|
|
14
|
+
"comment": "Promote 0.67 to legacy"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Mon, 24 Jan 2022 16:13:22 GMT",
|
|
21
|
+
"tag": "@react-native-windows/codegen_v0.67.0",
|
|
22
|
+
"version": "0.67.0",
|
|
8
23
|
"comments": {
|
|
9
24
|
"patch": [
|
|
10
25
|
{
|
|
11
|
-
"comment": "Promote 0.66 to legacy",
|
|
12
26
|
"author": "ngerlem@microsoft.com",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
27
|
+
"package": "@react-native-windows/codegen",
|
|
28
|
+
"commit": "not available",
|
|
29
|
+
"comment": "Promote 0.67 to latest"
|
|
15
30
|
}
|
|
16
31
|
]
|
|
17
32
|
}
|
|
18
33
|
},
|
|
19
34
|
{
|
|
20
|
-
"date": "Mon,
|
|
21
|
-
"tag": "@react-native-windows/codegen_v0.
|
|
22
|
-
"version": "0.
|
|
35
|
+
"date": "Mon, 24 Jan 2022 16:12:32 GMT",
|
|
36
|
+
"tag": "@react-native-windows/codegen_v0.67.0",
|
|
37
|
+
"version": "0.67.0",
|
|
23
38
|
"comments": {
|
|
24
39
|
"patch": [
|
|
25
40
|
{
|
|
26
|
-
"comment": "Promote 0.66 to latest",
|
|
27
41
|
"author": "ngerlem@microsoft.com",
|
|
28
|
-
"
|
|
42
|
+
"package": "@react-native-windows/codegen",
|
|
43
|
+
"commit": "56818ebc599aa084aa9ffc949691f1be71da169a",
|
|
44
|
+
"comment": "Promote 0.67 to latest"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"date": "Mon, 25 Oct 2021 15:07:48 GMT",
|
|
51
|
+
"tag": "@react-native-windows/codegen_v0.67.0-preview.1",
|
|
52
|
+
"version": "0.67.0-preview.1",
|
|
53
|
+
"comments": {
|
|
54
|
+
"prerelease": [
|
|
55
|
+
{
|
|
56
|
+
"author": "ngerlem@microsoft.com",
|
|
57
|
+
"package": "@react-native-windows/codegen",
|
|
58
|
+
"commit": "not available",
|
|
59
|
+
"comment": "Promote 0.67 to preview"
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"date": "Mon, 25 Oct 2021 15:07:19 GMT",
|
|
66
|
+
"tag": "@react-native-windows/codegen_v0.67.0-preview.1",
|
|
67
|
+
"version": "0.67.0-preview.1",
|
|
68
|
+
"comments": {
|
|
69
|
+
"prerelease": [
|
|
70
|
+
{
|
|
71
|
+
"author": "ngerlem@microsoft.com",
|
|
72
|
+
"package": "@react-native-windows/codegen",
|
|
73
|
+
"commit": "5ca0feb9bccbf395aa8297f97a1a8832971d4f2e",
|
|
74
|
+
"comment": "Promote 0.67 to preview"
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"date": "Sat, 23 Oct 2021 05:06:49 GMT",
|
|
81
|
+
"tag": "@react-native-windows/codegen_v0.0.0-canary.19",
|
|
82
|
+
"version": "0.0.0-canary.19",
|
|
83
|
+
"comments": {
|
|
84
|
+
"prerelease": [
|
|
85
|
+
{
|
|
86
|
+
"author": "30809111+acoates-ms@users.noreply.github.com",
|
|
87
|
+
"package": "@react-native-windows/codegen",
|
|
88
|
+
"commit": "c39ba3f4e8eac73445eec4d405a0209ccf2df1bf",
|
|
89
|
+
"comment": "Only generate component files if a component is specified"
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"date": "Fri, 22 Oct 2021 05:06:46 GMT",
|
|
96
|
+
"tag": "@react-native-windows/codegen_v0.0.0-canary.18",
|
|
97
|
+
"version": "0.0.0-canary.18",
|
|
98
|
+
"comments": {
|
|
99
|
+
"prerelease": [
|
|
100
|
+
{
|
|
101
|
+
"author": "30809111+acoates-ms@users.noreply.github.com",
|
|
102
|
+
"package": "@react-native-windows/codegen",
|
|
103
|
+
"comment": "Built files not included in published package",
|
|
104
|
+
"commit": "e8d09f86fce740a0c16b6f6f9fd876d2122cfc74"
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"date": "Thu, 21 Oct 2021 05:08:01 GMT",
|
|
111
|
+
"tag": "@react-native-windows/codegen_v0.0.0-canary.17",
|
|
112
|
+
"version": "0.0.0-canary.17",
|
|
113
|
+
"comments": {
|
|
114
|
+
"prerelease": [
|
|
115
|
+
{
|
|
116
|
+
"author": "30809111+acoates-ms@users.noreply.github.com",
|
|
117
|
+
"package": "@react-native-windows/codegen",
|
|
118
|
+
"comment": "Update to typescript 4",
|
|
119
|
+
"commit": "8a0ffecdcf5e68d950f20380fdf62295edb352b6"
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"date": "Wed, 29 Sep 2021 05:06:54 GMT",
|
|
126
|
+
"tag": "@react-native-windows/codegen_v0.0.0-canary.16",
|
|
127
|
+
"version": "0.0.0-canary.16",
|
|
128
|
+
"comments": {
|
|
129
|
+
"prerelease": [
|
|
130
|
+
{
|
|
131
|
+
"comment": "Check constants in generated turbo module specs",
|
|
132
|
+
"author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
|
|
133
|
+
"commit": "6238240df45549967e66f7fcfa411c67007eade3",
|
|
134
|
+
"package": "@react-native-windows/codegen"
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"date": "Wed, 15 Sep 2021 05:07:04 GMT",
|
|
141
|
+
"tag": "@react-native-windows/codegen_v0.0.0-canary.15",
|
|
142
|
+
"version": "0.0.0-canary.15",
|
|
143
|
+
"comments": {
|
|
144
|
+
"prerelease": [
|
|
145
|
+
{
|
|
146
|
+
"comment": "Generate anonymous objects in correct order for turbo module",
|
|
147
|
+
"author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
|
|
148
|
+
"commit": "df2e77140ebe63c91039226a83f4d2e49e4af408",
|
|
149
|
+
"package": "@react-native-windows/codegen"
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"date": "Fri, 10 Sep 2021 05:07:31 GMT",
|
|
156
|
+
"tag": "@react-native-windows/codegen_v0.0.0-canary.14",
|
|
157
|
+
"version": "0.0.0-canary.14",
|
|
158
|
+
"comments": {
|
|
159
|
+
"prerelease": [
|
|
160
|
+
{
|
|
161
|
+
"comment": "Generate `std::vector<T>` for array types in turbo modules",
|
|
162
|
+
"author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
|
|
163
|
+
"commit": "42d0853c684f0e9f9c9f1f7fa34cbf4ca3810edc",
|
|
29
164
|
"package": "@react-native-windows/codegen"
|
|
30
165
|
}
|
|
31
166
|
]
|
|
32
167
|
}
|
|
33
168
|
},
|
|
34
169
|
{
|
|
35
|
-
"date": "
|
|
36
|
-
"tag": "@react-native-windows/codegen_v0.
|
|
37
|
-
"version": "0.
|
|
170
|
+
"date": "Thu, 09 Sep 2021 05:07:46 GMT",
|
|
171
|
+
"tag": "@react-native-windows/codegen_v0.0.0-canary.13",
|
|
172
|
+
"version": "0.0.0-canary.13",
|
|
38
173
|
"comments": {
|
|
39
174
|
"prerelease": [
|
|
40
175
|
{
|
|
41
|
-
"comment": "
|
|
176
|
+
"comment": "Bump to 0.66-based react-native-tscodegen",
|
|
177
|
+
"author": "ngerlem@microsoft.com",
|
|
178
|
+
"commit": "6e2dd6a4334285633e4f939be8184d911d34707a",
|
|
179
|
+
"package": "@react-native-windows/codegen"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"comment": "Generate nullable type for turbo module",
|
|
183
|
+
"author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
|
|
184
|
+
"commit": "66a9f86f24f862c9e9e611ad435f68daddb4e04e",
|
|
185
|
+
"package": "@react-native-windows/codegen"
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"date": "Wed, 08 Sep 2021 05:08:53 GMT",
|
|
192
|
+
"tag": "@react-native-windows/codegen_v0.0.0-canary.12",
|
|
193
|
+
"version": "0.0.0-canary.12",
|
|
194
|
+
"comments": {
|
|
195
|
+
"prerelease": [
|
|
196
|
+
{
|
|
197
|
+
"comment": "Set consistent node requirements on our packages",
|
|
198
|
+
"author": "ngerlem@microsoft.com",
|
|
199
|
+
"commit": "2974ea0ab58b546264b8d9a4a7c12ceeb0a02851",
|
|
200
|
+
"package": "@react-native-windows/codegen"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"comment": "Match Alert module with NativeDialogManagerWindowsSpec.h",
|
|
204
|
+
"author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
|
|
205
|
+
"commit": "d085526651bb421f97b536a753365c7375b74828",
|
|
206
|
+
"package": "@react-native-windows/codegen"
|
|
207
|
+
}
|
|
208
|
+
],
|
|
209
|
+
"patch": [
|
|
210
|
+
{
|
|
211
|
+
"comment": "Bump @rnw-scripts/jest-unittest-config to v1.2.4",
|
|
212
|
+
"author": "ngerlem@microsoft.com",
|
|
213
|
+
"commit": "2974ea0ab58b546264b8d9a4a7c12ceeb0a02851",
|
|
214
|
+
"package": "@react-native-windows/codegen"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"comment": "Bump @rnw-scripts/just-task to v2.2.1",
|
|
218
|
+
"author": "ngerlem@microsoft.com",
|
|
219
|
+
"commit": "2974ea0ab58b546264b8d9a4a7c12ceeb0a02851",
|
|
220
|
+
"package": "@react-native-windows/codegen"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"comment": "Bump @rnw-scripts/ts-config to v2.0.1",
|
|
224
|
+
"author": "ngerlem@microsoft.com",
|
|
225
|
+
"commit": "2974ea0ab58b546264b8d9a4a7c12ceeb0a02851",
|
|
226
|
+
"package": "@react-native-windows/codegen"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"comment": "Bump @rnw-scripts/eslint-config to v1.1.8",
|
|
42
230
|
"author": "ngerlem@microsoft.com",
|
|
43
|
-
"commit": "
|
|
231
|
+
"commit": "2974ea0ab58b546264b8d9a4a7c12ceeb0a02851",
|
|
44
232
|
"package": "@react-native-windows/codegen"
|
|
45
233
|
}
|
|
46
234
|
]
|
package/CHANGELOG.md
CHANGED
|
@@ -1,32 +1,121 @@
|
|
|
1
1
|
# Change Log - @react-native-windows/codegen
|
|
2
2
|
|
|
3
|
-
This log was last generated on Mon,
|
|
3
|
+
This log was last generated on Mon, 04 Apr 2022 15:12:54 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## 0.
|
|
7
|
+
## 0.67.1
|
|
8
8
|
|
|
9
|
-
Mon,
|
|
9
|
+
Mon, 04 Apr 2022 15:12:54 GMT
|
|
10
10
|
|
|
11
11
|
### Patches
|
|
12
12
|
|
|
13
|
-
- Promote 0.
|
|
13
|
+
- Promote 0.67 to legacy (34109996+chiaramooney@users.noreply.github.com)
|
|
14
14
|
|
|
15
|
-
## 0.
|
|
15
|
+
## 0.67.0
|
|
16
16
|
|
|
17
|
-
Mon,
|
|
17
|
+
Mon, 24 Jan 2022 16:13:22 GMT
|
|
18
18
|
|
|
19
19
|
### Patches
|
|
20
20
|
|
|
21
|
-
- Promote 0.
|
|
21
|
+
- Promote 0.67 to latest (ngerlem@microsoft.com)
|
|
22
22
|
|
|
23
|
-
## 0.
|
|
23
|
+
## 0.67.0
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Mon, 24 Jan 2022 16:12:32 GMT
|
|
26
|
+
|
|
27
|
+
### Patches
|
|
28
|
+
|
|
29
|
+
- Promote 0.67 to latest (ngerlem@microsoft.com)
|
|
30
|
+
|
|
31
|
+
## 0.67.0-preview.1
|
|
32
|
+
|
|
33
|
+
Mon, 25 Oct 2021 15:07:48 GMT
|
|
34
|
+
|
|
35
|
+
### Changes
|
|
36
|
+
|
|
37
|
+
- Promote 0.67 to preview (ngerlem@microsoft.com)
|
|
38
|
+
|
|
39
|
+
## 0.67.0-preview.1
|
|
40
|
+
|
|
41
|
+
Mon, 25 Oct 2021 15:07:19 GMT
|
|
42
|
+
|
|
43
|
+
### Changes
|
|
44
|
+
|
|
45
|
+
- Promote 0.67 to preview (ngerlem@microsoft.com)
|
|
46
|
+
|
|
47
|
+
## 0.0.0-canary.19
|
|
48
|
+
|
|
49
|
+
Sat, 23 Oct 2021 05:06:49 GMT
|
|
50
|
+
|
|
51
|
+
### Changes
|
|
52
|
+
|
|
53
|
+
- Only generate component files if a component is specified (30809111+acoates-ms@users.noreply.github.com)
|
|
54
|
+
|
|
55
|
+
## 0.0.0-canary.18
|
|
56
|
+
|
|
57
|
+
Fri, 22 Oct 2021 05:06:46 GMT
|
|
58
|
+
|
|
59
|
+
### Changes
|
|
60
|
+
|
|
61
|
+
- Built files not included in published package (30809111+acoates-ms@users.noreply.github.com)
|
|
62
|
+
|
|
63
|
+
## 0.0.0-canary.17
|
|
64
|
+
|
|
65
|
+
Thu, 21 Oct 2021 05:08:01 GMT
|
|
66
|
+
|
|
67
|
+
### Changes
|
|
68
|
+
|
|
69
|
+
- Update to typescript 4 (30809111+acoates-ms@users.noreply.github.com)
|
|
70
|
+
|
|
71
|
+
## 0.0.0-canary.16
|
|
72
|
+
|
|
73
|
+
Wed, 29 Sep 2021 05:06:54 GMT
|
|
74
|
+
|
|
75
|
+
### Changes
|
|
76
|
+
|
|
77
|
+
- Check constants in generated turbo module specs (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
78
|
+
|
|
79
|
+
## 0.0.0-canary.15
|
|
80
|
+
|
|
81
|
+
Wed, 15 Sep 2021 05:07:04 GMT
|
|
82
|
+
|
|
83
|
+
### Changes
|
|
84
|
+
|
|
85
|
+
- Generate anonymous objects in correct order for turbo module (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
86
|
+
|
|
87
|
+
## 0.0.0-canary.14
|
|
88
|
+
|
|
89
|
+
Fri, 10 Sep 2021 05:07:31 GMT
|
|
90
|
+
|
|
91
|
+
### Changes
|
|
92
|
+
|
|
93
|
+
- Generate `std::vector<T>` for array types in turbo modules (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
94
|
+
|
|
95
|
+
## 0.0.0-canary.13
|
|
96
|
+
|
|
97
|
+
Thu, 09 Sep 2021 05:07:46 GMT
|
|
98
|
+
|
|
99
|
+
### Changes
|
|
100
|
+
|
|
101
|
+
- Bump to 0.66-based react-native-tscodegen (ngerlem@microsoft.com)
|
|
102
|
+
- Generate nullable type for turbo module (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
103
|
+
|
|
104
|
+
## 0.0.0-canary.12
|
|
105
|
+
|
|
106
|
+
Wed, 08 Sep 2021 05:08:53 GMT
|
|
107
|
+
|
|
108
|
+
### Patches
|
|
109
|
+
|
|
110
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.2.4 (ngerlem@microsoft.com)
|
|
111
|
+
- Bump @rnw-scripts/just-task to v2.2.1 (ngerlem@microsoft.com)
|
|
112
|
+
- Bump @rnw-scripts/ts-config to v2.0.1 (ngerlem@microsoft.com)
|
|
113
|
+
- Bump @rnw-scripts/eslint-config to v1.1.8 (ngerlem@microsoft.com)
|
|
26
114
|
|
|
27
115
|
### Changes
|
|
28
116
|
|
|
29
|
-
-
|
|
117
|
+
- Set consistent node requirements on our packages (ngerlem@microsoft.com)
|
|
118
|
+
- Match Alert module with NativeDialogManagerWindowsSpec.h (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
30
119
|
|
|
31
120
|
## 0.0.0-canary.11
|
|
32
121
|
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*
|
|
6
|
+
* @format
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const fs_1 = __importDefault(require("fs"));
|
|
15
|
+
const globby_1 = __importDefault(require("globby"));
|
|
16
|
+
const GenerateNM2_1 = require("./generators/GenerateNM2");
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const flow_1 = require("react-native-tscodegen/lib/rncodegen/src/parsers/flow");
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const schemaValidator_1 = __importDefault(require("react-native-tscodegen/lib/rncodegen/src/schemaValidator"));
|
|
21
|
+
const argv = yargs_1.default.options({
|
|
22
|
+
file: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
describe: 'file which contains spec',
|
|
25
|
+
},
|
|
26
|
+
files: {
|
|
27
|
+
type: 'array',
|
|
28
|
+
describe: 'glob patterns for files which contains specs',
|
|
29
|
+
},
|
|
30
|
+
test: {
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
describe: 'Verify that the generated output is unchanged',
|
|
33
|
+
},
|
|
34
|
+
namespace: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
describe: 'C++/C# Namespace to put generated native modules in',
|
|
37
|
+
default: 'MyNamespace',
|
|
38
|
+
},
|
|
39
|
+
libraryName: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
required: true,
|
|
42
|
+
describe: 'Used for part of the path generated within the codegen dir',
|
|
43
|
+
},
|
|
44
|
+
}).argv;
|
|
45
|
+
/*
|
|
46
|
+
const GENERATORS = {
|
|
47
|
+
descriptors: [generateComponentDescriptorH.generate],
|
|
48
|
+
events: [
|
|
49
|
+
generateEventEmitterCpp.generate,
|
|
50
|
+
generateEventEmitterH.generate,
|
|
51
|
+
generateModuleHObjCpp.generate,
|
|
52
|
+
generateModuleMm.generate,
|
|
53
|
+
],
|
|
54
|
+
props: [
|
|
55
|
+
generateComponentHObjCpp.generate,
|
|
56
|
+
generatePropsCpp.generate,
|
|
57
|
+
generatePropsH.generate,
|
|
58
|
+
generatePropsJavaInterface.generate,
|
|
59
|
+
generatePropsJavaDelegate.generate,
|
|
60
|
+
],
|
|
61
|
+
modules: [generateModuleCpp.generate, generateModuleH.generate],
|
|
62
|
+
tests: [generateTests.generate],
|
|
63
|
+
'shadow-nodes': [
|
|
64
|
+
generateShadowNodeCpp.generate,
|
|
65
|
+
generateShadowNodeH.generate,
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
*/
|
|
69
|
+
function normalizeFileMap(map, outputDir, outMap) {
|
|
70
|
+
for (const [fileName, contents] of map) {
|
|
71
|
+
const location = path_1.default.join(outputDir, fileName);
|
|
72
|
+
outMap.set(path_1.default.normalize(location), contents);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function checkFilesForChanges(map, outputDir) {
|
|
76
|
+
let hasChanges = false;
|
|
77
|
+
const allExistingFiles = globby_1.default
|
|
78
|
+
.sync(`${outputDir}/**`)
|
|
79
|
+
.map(_ => path_1.default.normalize(_))
|
|
80
|
+
.sort();
|
|
81
|
+
const allGeneratedFiles = [...map.keys()].map(_ => path_1.default.normalize(_)).sort();
|
|
82
|
+
if (allExistingFiles.length !== allGeneratedFiles.length ||
|
|
83
|
+
!allExistingFiles.every((val, index) => val === allGeneratedFiles[index]))
|
|
84
|
+
return true;
|
|
85
|
+
for (const [fileName, contents] of map) {
|
|
86
|
+
if (!fs_1.default.existsSync(fileName)) {
|
|
87
|
+
hasChanges = true;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const currentContents = fs_1.default.readFileSync(fileName, 'utf8');
|
|
91
|
+
if (currentContents !== contents) {
|
|
92
|
+
console.error(`- ${fileName} has changed`);
|
|
93
|
+
hasChanges = true;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return hasChanges;
|
|
98
|
+
}
|
|
99
|
+
function writeMapToFiles(map, outputDir) {
|
|
100
|
+
let success = true;
|
|
101
|
+
// This ensures that we delete any generated files from modules that have been deleted
|
|
102
|
+
const allExistingFiles = globby_1.default.sync(`${outputDir}/**`);
|
|
103
|
+
allExistingFiles.forEach(existingFile => {
|
|
104
|
+
if (!map.has(path_1.default.normalize(existingFile))) {
|
|
105
|
+
fs_1.default.unlinkSync(existingFile);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
for (const [fileName, contents] of map) {
|
|
109
|
+
try {
|
|
110
|
+
fs_1.default.mkdirSync(path_1.default.dirname(fileName), { recursive: true });
|
|
111
|
+
if (fs_1.default.existsSync(fileName)) {
|
|
112
|
+
const currentContents = fs_1.default.readFileSync(fileName, 'utf8');
|
|
113
|
+
// Don't update the files if there are no changes as this breaks incremental builds
|
|
114
|
+
if (currentContents === contents) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
fs_1.default.writeFileSync(fileName, contents);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
success = false;
|
|
122
|
+
console.error(`Failed to write ${fileName} to ${fileName}`, error);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return success;
|
|
126
|
+
}
|
|
127
|
+
function parseFlowFile(filename) {
|
|
128
|
+
try {
|
|
129
|
+
return (0, flow_1.parseFile)(filename);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
if (e instanceof Error) {
|
|
133
|
+
e.message = `(${filename}): ${e.message}`;
|
|
134
|
+
}
|
|
135
|
+
throw e;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function combineSchemas(files) {
|
|
139
|
+
return files.reduce((merged, filename) => {
|
|
140
|
+
const contents = fs_1.default.readFileSync(filename, 'utf8');
|
|
141
|
+
if (contents &&
|
|
142
|
+
(/export\s+default\s+\(?codegenNativeComponent</.test(contents) ||
|
|
143
|
+
contents.includes('extends TurboModule'))) {
|
|
144
|
+
const schema = parseFlowFile(filename);
|
|
145
|
+
merged.modules = { ...merged.modules, ...schema.modules };
|
|
146
|
+
}
|
|
147
|
+
return merged;
|
|
148
|
+
}, { modules: {} });
|
|
149
|
+
}
|
|
150
|
+
function generate({ libraryName, schema, outputDirectory, moduleSpecName }, { /*generators,*/ test }) {
|
|
151
|
+
schemaValidator_1.default.validate(schema);
|
|
152
|
+
const componentOutputdir = path_1.default.join(outputDirectory, 'react/components', libraryName);
|
|
153
|
+
const generatedFiles = new Map();
|
|
154
|
+
generatedFiles.set(path_1.default.join(outputDirectory, '.clang-format'), 'DisableFormat: true\nSortIncludes: false');
|
|
155
|
+
const generateNM2 = (0, GenerateNM2_1.createNM2Generator)({ namespace: argv.namespace });
|
|
156
|
+
const generatorPropsH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH')
|
|
157
|
+
.generate;
|
|
158
|
+
const generatorPropsCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP')
|
|
159
|
+
.generate;
|
|
160
|
+
const generatorShadowNodeH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH')
|
|
161
|
+
.generate;
|
|
162
|
+
const generatorShadowNodeCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP')
|
|
163
|
+
.generate;
|
|
164
|
+
const generatorComponentDescriptorH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH')
|
|
165
|
+
.generate;
|
|
166
|
+
const generatorEventEmitterH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH')
|
|
167
|
+
.generate;
|
|
168
|
+
normalizeFileMap(generateNM2(libraryName, schema, moduleSpecName), outputDirectory, generatedFiles);
|
|
169
|
+
if (Object.keys(schema.modules).some(moduleName => schema.modules[moduleName].type === 'Component')) {
|
|
170
|
+
const componentGenerators = [
|
|
171
|
+
generatorPropsH,
|
|
172
|
+
generatorPropsCPP,
|
|
173
|
+
generatorShadowNodeH,
|
|
174
|
+
generatorShadowNodeCPP,
|
|
175
|
+
generatorComponentDescriptorH,
|
|
176
|
+
generatorEventEmitterH,
|
|
177
|
+
];
|
|
178
|
+
componentGenerators.forEach(generator => {
|
|
179
|
+
const generated = generator(libraryName, schema, moduleSpecName);
|
|
180
|
+
normalizeFileMap(generated, componentOutputdir, generatedFiles);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (test === true) {
|
|
184
|
+
return checkFilesForChanges(generatedFiles, outputDirectory);
|
|
185
|
+
}
|
|
186
|
+
return writeMapToFiles(generatedFiles, outputDirectory);
|
|
187
|
+
}
|
|
188
|
+
if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
|
|
189
|
+
console.error('You must specify either --file or --files.');
|
|
190
|
+
process.exit(1);
|
|
191
|
+
}
|
|
192
|
+
let schema;
|
|
193
|
+
if (argv.file) {
|
|
194
|
+
schema = parseFlowFile(argv.file);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
schema = combineSchemas(globby_1.default.sync(argv.files));
|
|
198
|
+
}
|
|
199
|
+
const libraryName = argv.libraryName;
|
|
200
|
+
const moduleSpecName = 'moduleSpecName';
|
|
201
|
+
const outputDirectory = 'codegen';
|
|
202
|
+
generate({ libraryName, schema, outputDirectory, moduleSpecName }, { generators: [], test: false });
|
|
203
|
+
//# sourceMappingURL=Cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kDAA0B;AAC1B,gDAAwB;AACxB,4CAAoB;AACpB,oDAA4B;AAC5B,0DAA4D;AAC5D,aAAa;AACb,gFAAgF;AAChF,aAAa;AACb,+GAAuF;AAEvF,MAAM,IAAI,GAAG,eAAK,CAAC,OAAO,CAAC;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,0BAA0B;KACrC;IACD,KAAK,EAAE;QACL,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,8CAA8C;KACzD;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,+CAA+C;KAC1D;IACD,SAAS,EAAE;QACT,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,qDAAqD;QAC/D,OAAO,EAAE,aAAa;KACvB;IACD,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,4DAA4D;KACvE;CACF,CAAC,CAAC,I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C;QAClE,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,IAAI,KAAK,IAAI,EAAE;QACjB,OAAO,oBAAoB,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;KAC9D;IAED,OAAO,eAAe,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;AAC1D,CAAC;AAED,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;IAC5D,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,IAAI,MAAkB,CAAC;AACvB,IAAI,IAAI,CAAC,IAAI,EAAE;IACb,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;CACnC;KAAM;IACL,MAAM,GAAG,cAAc,CAAC,gBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAiB,CAAC,CAAC,CAAC;CAC9D;AAED,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;AACrC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AACxC,MAAM,eAAe,GAAG,SAAS,CAAC;AAClC,QAAQ,CACN,EAAC,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAC,EACtD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAC,CAC9B,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport path from 'path';\nimport fs from 'fs';\nimport globby from 'globby';\nimport {createNM2Generator} from './generators/GenerateNM2';\n// @ts-ignore\nimport {parseFile} from 'react-native-tscodegen/lib/rncodegen/src/parsers/flow';\n// @ts-ignore\nimport schemaValidator from 'react-native-tscodegen/lib/rncodegen/src/schemaValidator';\n\nconst argv = yargs.options({\n file: {\n type: 'string',\n describe: 'file which contains spec',\n },\n files: {\n type: 'array',\n describe: 'glob patterns for files which contains specs',\n },\n test: {\n type: 'boolean',\n describe: 'Verify that the generated output is unchanged',\n },\n namespace: {\n type: 'string',\n describe: 'C++/C# Namespace to put generated native modules in',\n default: 'MyNamespace',\n },\n libraryName: {\n type: 'string',\n required: true,\n describe: 'Used for part of the path generated within the codegen dir',\n },\n}).argv;\n\nimport {SchemaType} from 'react-native-tscodegen';\n\ninterface Options {\n libraryName: string;\n schema: SchemaType;\n outputDirectory: string;\n moduleSpecName: string;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\n}\n\n/*\nconst GENERATORS = {\n descriptors: [generateComponentDescriptorH.generate],\n events: [\n generateEventEmitterCpp.generate,\n generateEventEmitterH.generate,\n generateModuleHObjCpp.generate,\n generateModuleMm.generate,\n ],\n props: [\n generateComponentHObjCpp.generate,\n generatePropsCpp.generate,\n generatePropsH.generate,\n generatePropsJavaInterface.generate,\n generatePropsJavaDelegate.generate,\n ],\n modules: [generateModuleCpp.generate, generateModuleH.generate],\n tests: [generateTests.generate],\n 'shadow-nodes': [\n generateShadowNodeCpp.generate,\n generateShadowNodeH.generate,\n ],\n};\n*/\n\nfunction normalizeFileMap(\n map: Map<string, string>,\n outputDir: string,\n outMap: Map<string, string>,\n): void {\n for (const [fileName, contents] of map) {\n const location = path.join(outputDir, fileName);\n outMap.set(path.normalize(location), contents);\n }\n}\n\nfunction checkFilesForChanges(\n map: Map<string, string>,\n outputDir: string,\n): boolean {\n let hasChanges = false;\n\n const allExistingFiles = globby\n .sync(`${outputDir}/**`)\n .map(_ => path.normalize(_))\n .sort();\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n\n if (\n allExistingFiles.length !== allGeneratedFiles.length ||\n !allExistingFiles.every((val, index) => val === allGeneratedFiles[index])\n )\n return true;\n\n for (const [fileName, contents] of map) {\n if (!fs.existsSync(fileName)) {\n hasChanges = true;\n continue;\n }\n\n const currentContents = fs.readFileSync(fileName, 'utf8');\n if (currentContents !== contents) {\n console.error(`- ${fileName} has changed`);\n hasChanges = true;\n continue;\n }\n }\n\n return hasChanges;\n}\n\nfunction writeMapToFiles(map: Map<string, string>, outputDir: string) {\n let success = true;\n\n // This ensures that we delete any generated files from modules that have been deleted\n const allExistingFiles = globby.sync(`${outputDir}/**`);\n allExistingFiles.forEach(existingFile => {\n if (!map.has(path.normalize(existingFile))) {\n fs.unlinkSync(existingFile);\n }\n });\n\n for (const [fileName, contents] of map) {\n try {\n fs.mkdirSync(path.dirname(fileName), {recursive: true});\n\n if (fs.existsSync(fileName)) {\n const currentContents = fs.readFileSync(fileName, 'utf8');\n // Don't update the files if there are no changes as this breaks incremental builds\n if (currentContents === contents) {\n continue;\n }\n }\n\n fs.writeFileSync(fileName, contents);\n } catch (error) {\n success = false;\n console.error(`Failed to write ${fileName} to ${fileName}`, error);\n }\n }\n\n return success;\n}\n\nfunction parseFlowFile(filename: string): SchemaType {\n try {\n return parseFile(filename);\n } catch (e) {\n if (e instanceof Error) {\n e.message = `(${filename}): ${e.message}`;\n }\n throw e;\n }\n}\n\nfunction combineSchemas(files: string[]): SchemaType {\n return files.reduce(\n (merged, filename) => {\n const contents = fs.readFileSync(filename, 'utf8');\n if (\n contents &&\n (/export\\s+default\\s+\\(?codegenNativeComponent</.test(contents) ||\n contents.includes('extends TurboModule'))\n ) {\n const schema = parseFlowFile(filename);\n merged.modules = {...merged.modules, ...schema.modules};\n }\n return merged;\n },\n {modules: {}},\n );\n}\n\nfunction generate(\n {libraryName, schema, outputDirectory, moduleSpecName}: Options,\n {/*generators,*/ test}: Config,\n): boolean {\n schemaValidator.validate(schema);\n\n const componentOutputdir = path.join(\n outputDirectory,\n 'react/components',\n libraryName,\n );\n\n const generatedFiles = new Map<string, string>();\n\n generatedFiles.set(\n path.join(outputDirectory, '.clang-format'),\n 'DisableFormat: true\\nSortIncludes: false',\n );\n\n const generateNM2 = createNM2Generator({namespace: argv.namespace});\n const generatorPropsH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH')\n .generate;\n const generatorPropsCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP')\n .generate;\n const generatorShadowNodeH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH')\n .generate;\n const generatorShadowNodeCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP')\n .generate;\n const generatorComponentDescriptorH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH')\n .generate;\n const generatorEventEmitterH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH')\n .generate;\n\n normalizeFileMap(\n generateNM2(libraryName, schema, moduleSpecName),\n outputDirectory,\n generatedFiles,\n );\n\n if (\n Object.keys(schema.modules).some(\n moduleName => schema.modules[moduleName].type === 'Component',\n )\n ) {\n const componentGenerators = [\n generatorPropsH,\n generatorPropsCPP,\n generatorShadowNodeH,\n generatorShadowNodeCPP,\n generatorComponentDescriptorH,\n generatorEventEmitterH,\n ];\n\n componentGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, componentOutputdir, generatedFiles);\n });\n }\n\n if (test === true) {\n return checkFilesForChanges(generatedFiles, outputDirectory);\n }\n\n return writeMapToFiles(generatedFiles, outputDirectory);\n}\n\nif ((argv.file && argv.files) || (!argv.file && !argv.files)) {\n console.error('You must specify either --file or --files.');\n process.exit(1);\n}\n\nlet schema: SchemaType;\nif (argv.file) {\n schema = parseFlowFile(argv.file);\n} else {\n schema = combineSchemas(globby.sync(argv.files as string[]));\n}\n\nconst libraryName = argv.libraryName;\nconst moduleSpecName = 'moduleSpecName';\nconst outputDirectory = 'codegen';\ngenerate(\n {libraryName, schema, outputDirectory, moduleSpecName},\n {generators: [], test: false},\n);\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
* @format
|
|
5
|
+
*/
|
|
6
|
+
import { NativeModuleObjectTypeAnnotation } from 'react-native-tscodegen';
|
|
7
|
+
import { AliasMap } from './AliasManaging';
|
|
8
|
+
export declare function createAliasMap(nativeModuleAliases: {
|
|
9
|
+
[name: string]: NativeModuleObjectTypeAnnotation;
|
|
10
|
+
}): AliasMap;
|
|
11
|
+
export declare function generateAliases(aliases: AliasMap): string;
|