@react-native-windows/codegen 0.65.0 → 0.67.0-preview.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.
Files changed (43) hide show
  1. package/CHANGELOG.json +305 -10
  2. package/CHANGELOG.md +121 -8
  3. package/lib-commonjs/Cli.d.ts +7 -0
  4. package/lib-commonjs/Cli.js +203 -0
  5. package/lib-commonjs/Cli.js.map +1 -0
  6. package/lib-commonjs/generators/AliasGen.d.ts +11 -0
  7. package/lib-commonjs/generators/AliasGen.js +72 -0
  8. package/lib-commonjs/generators/AliasGen.js.map +1 -0
  9. package/lib-commonjs/generators/AliasManaging.d.ts +15 -0
  10. package/lib-commonjs/generators/AliasManaging.js +49 -0
  11. package/lib-commonjs/generators/AliasManaging.js.map +1 -0
  12. package/lib-commonjs/generators/GenerateNM2.d.ts +11 -0
  13. package/lib-commonjs/generators/GenerateNM2.js +94 -0
  14. package/lib-commonjs/generators/GenerateNM2.js.map +1 -0
  15. package/lib-commonjs/generators/ObjectTypes.d.ts +8 -0
  16. package/lib-commonjs/generators/ObjectTypes.js +53 -0
  17. package/lib-commonjs/generators/ObjectTypes.js.map +1 -0
  18. package/lib-commonjs/generators/ParamTypes.d.ts +11 -0
  19. package/lib-commonjs/generators/ParamTypes.js +114 -0
  20. package/lib-commonjs/generators/ParamTypes.js.map +1 -0
  21. package/lib-commonjs/generators/ReturnTypes.d.ts +9 -0
  22. package/lib-commonjs/generators/ReturnTypes.js +63 -0
  23. package/lib-commonjs/generators/ReturnTypes.js.map +1 -0
  24. package/lib-commonjs/generators/ValidateConstants.d.ts +8 -0
  25. package/lib-commonjs/generators/ValidateConstants.js +38 -0
  26. package/lib-commonjs/generators/ValidateConstants.js.map +1 -0
  27. package/lib-commonjs/generators/ValidateMethods.d.ts +8 -0
  28. package/lib-commonjs/generators/ValidateMethods.js +70 -0
  29. package/lib-commonjs/generators/ValidateMethods.js.map +1 -0
  30. package/package.json +21 -11
  31. package/src/Cli.ts +102 -54
  32. package/src/generators/AliasGen.ts +105 -0
  33. package/src/generators/AliasManaging.ts +75 -0
  34. package/src/generators/GenerateNM2.ts +58 -290
  35. package/src/generators/ObjectTypes.ts +70 -0
  36. package/src/generators/ParamTypes.ts +220 -0
  37. package/src/generators/ReturnTypes.ts +92 -0
  38. package/src/generators/ValidateConstants.ts +50 -0
  39. package/src/generators/ValidateMethods.ts +135 -0
  40. package/.eslintrc.js +0 -4
  41. package/.vscode/launch.json +0 -23
  42. package/jest.config.js +0 -1
  43. package/tsconfig.json +0 -5
package/CHANGELOG.json CHANGED
@@ -2,30 +2,325 @@
2
2
  "name": "@react-native-windows/codegen",
3
3
  "entries": [
4
4
  {
5
- "date": "Mon, 23 Aug 2021 15:08:33 GMT",
6
- "tag": "@react-native-windows/codegen_v0.65.0",
7
- "version": "0.65.0",
5
+ "date": "Mon, 25 Oct 2021 15:07:19 GMT",
6
+ "tag": "@react-native-windows/codegen_v0.67.0-preview.1",
7
+ "version": "0.67.0-preview.1",
8
8
  "comments": {
9
+ "prerelease": [
10
+ {
11
+ "author": "ngerlem@microsoft.com",
12
+ "package": "@react-native-windows/codegen",
13
+ "commit": "5ca0feb9bccbf395aa8297f97a1a8832971d4f2e",
14
+ "comment": "Promote 0.67 to preview"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Sat, 23 Oct 2021 05:06:49 GMT",
21
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.19",
22
+ "version": "0.0.0-canary.19",
23
+ "comments": {
24
+ "prerelease": [
25
+ {
26
+ "author": "30809111+acoates-ms@users.noreply.github.com",
27
+ "package": "@react-native-windows/codegen",
28
+ "commit": "c39ba3f4e8eac73445eec4d405a0209ccf2df1bf",
29
+ "comment": "Only generate component files if a component is specified"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Fri, 22 Oct 2021 05:06:46 GMT",
36
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.18",
37
+ "version": "0.0.0-canary.18",
38
+ "comments": {
39
+ "prerelease": [
40
+ {
41
+ "author": "30809111+acoates-ms@users.noreply.github.com",
42
+ "package": "@react-native-windows/codegen",
43
+ "comment": "Built files not included in published package",
44
+ "commit": "e8d09f86fce740a0c16b6f6f9fd876d2122cfc74"
45
+ }
46
+ ]
47
+ }
48
+ },
49
+ {
50
+ "date": "Thu, 21 Oct 2021 05:08:01 GMT",
51
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.17",
52
+ "version": "0.0.0-canary.17",
53
+ "comments": {
54
+ "prerelease": [
55
+ {
56
+ "author": "30809111+acoates-ms@users.noreply.github.com",
57
+ "package": "@react-native-windows/codegen",
58
+ "comment": "Update to typescript 4",
59
+ "commit": "8a0ffecdcf5e68d950f20380fdf62295edb352b6"
60
+ }
61
+ ]
62
+ }
63
+ },
64
+ {
65
+ "date": "Wed, 29 Sep 2021 05:06:54 GMT",
66
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.16",
67
+ "version": "0.0.0-canary.16",
68
+ "comments": {
69
+ "prerelease": [
70
+ {
71
+ "comment": "Check constants in generated turbo module specs",
72
+ "author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
73
+ "commit": "6238240df45549967e66f7fcfa411c67007eade3",
74
+ "package": "@react-native-windows/codegen"
75
+ }
76
+ ]
77
+ }
78
+ },
79
+ {
80
+ "date": "Wed, 15 Sep 2021 05:07:04 GMT",
81
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.15",
82
+ "version": "0.0.0-canary.15",
83
+ "comments": {
84
+ "prerelease": [
85
+ {
86
+ "comment": "Generate anonymous objects in correct order for turbo module",
87
+ "author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
88
+ "commit": "df2e77140ebe63c91039226a83f4d2e49e4af408",
89
+ "package": "@react-native-windows/codegen"
90
+ }
91
+ ]
92
+ }
93
+ },
94
+ {
95
+ "date": "Fri, 10 Sep 2021 05:07:31 GMT",
96
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.14",
97
+ "version": "0.0.0-canary.14",
98
+ "comments": {
99
+ "prerelease": [
100
+ {
101
+ "comment": "Generate `std::vector<T>` for array types in turbo modules",
102
+ "author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
103
+ "commit": "42d0853c684f0e9f9c9f1f7fa34cbf4ca3810edc",
104
+ "package": "@react-native-windows/codegen"
105
+ }
106
+ ]
107
+ }
108
+ },
109
+ {
110
+ "date": "Thu, 09 Sep 2021 05:07:46 GMT",
111
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.13",
112
+ "version": "0.0.0-canary.13",
113
+ "comments": {
114
+ "prerelease": [
115
+ {
116
+ "comment": "Bump to 0.66-based react-native-tscodegen",
117
+ "author": "ngerlem@microsoft.com",
118
+ "commit": "6e2dd6a4334285633e4f939be8184d911d34707a",
119
+ "package": "@react-native-windows/codegen"
120
+ },
121
+ {
122
+ "comment": "Generate nullable type for turbo module",
123
+ "author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
124
+ "commit": "66a9f86f24f862c9e9e611ad435f68daddb4e04e",
125
+ "package": "@react-native-windows/codegen"
126
+ }
127
+ ]
128
+ }
129
+ },
130
+ {
131
+ "date": "Wed, 08 Sep 2021 05:08:53 GMT",
132
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.12",
133
+ "version": "0.0.0-canary.12",
134
+ "comments": {
135
+ "prerelease": [
136
+ {
137
+ "comment": "Set consistent node requirements on our packages",
138
+ "author": "ngerlem@microsoft.com",
139
+ "commit": "2974ea0ab58b546264b8d9a4a7c12ceeb0a02851",
140
+ "package": "@react-native-windows/codegen"
141
+ },
142
+ {
143
+ "comment": "Match Alert module with NativeDialogManagerWindowsSpec.h",
144
+ "author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
145
+ "commit": "d085526651bb421f97b536a753365c7375b74828",
146
+ "package": "@react-native-windows/codegen"
147
+ }
148
+ ],
9
149
  "patch": [
10
150
  {
11
- "comment": "Promote 0.65 to latest",
151
+ "comment": "Bump @rnw-scripts/jest-unittest-config to v1.2.4",
12
152
  "author": "ngerlem@microsoft.com",
13
- "commit": "6b2df206699d51f2be4595391735344a2f53af01",
153
+ "commit": "2974ea0ab58b546264b8d9a4a7c12ceeb0a02851",
154
+ "package": "@react-native-windows/codegen"
155
+ },
156
+ {
157
+ "comment": "Bump @rnw-scripts/just-task to v2.2.1",
158
+ "author": "ngerlem@microsoft.com",
159
+ "commit": "2974ea0ab58b546264b8d9a4a7c12ceeb0a02851",
160
+ "package": "@react-native-windows/codegen"
161
+ },
162
+ {
163
+ "comment": "Bump @rnw-scripts/ts-config to v2.0.1",
164
+ "author": "ngerlem@microsoft.com",
165
+ "commit": "2974ea0ab58b546264b8d9a4a7c12ceeb0a02851",
166
+ "package": "@react-native-windows/codegen"
167
+ },
168
+ {
169
+ "comment": "Bump @rnw-scripts/eslint-config to v1.1.8",
170
+ "author": "ngerlem@microsoft.com",
171
+ "commit": "2974ea0ab58b546264b8d9a4a7c12ceeb0a02851",
172
+ "package": "@react-native-windows/codegen"
173
+ }
174
+ ]
175
+ }
176
+ },
177
+ {
178
+ "date": "Fri, 03 Sep 2021 05:06:04 GMT",
179
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.11",
180
+ "version": "0.0.0-canary.11",
181
+ "comments": {
182
+ "prerelease": [
183
+ {
184
+ "comment": "Generate aliased struct for turbo module",
185
+ "author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
186
+ "commit": "b23b6bd01813b9d4ab843f397b7611e3e22d8508",
187
+ "package": "@react-native-windows/codegen"
188
+ }
189
+ ]
190
+ }
191
+ },
192
+ {
193
+ "date": "Thu, 02 Sep 2021 05:08:16 GMT",
194
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.10",
195
+ "version": "0.0.0-canary.10",
196
+ "comments": {
197
+ "none": [
198
+ {
199
+ "comment": "Remove path patch in rnw-codegen",
200
+ "author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
201
+ "commit": "6cd806bb2486db76195edd47e949f6a9424fc6cb",
14
202
  "package": "@react-native-windows/codegen"
15
203
  }
16
204
  ]
17
205
  }
18
206
  },
19
207
  {
20
- "date": "Mon, 31 May 2021 15:23:18 GMT",
21
- "tag": "@react-native-windows/codegen_v0.65.0-preview.1",
22
- "version": "0.65.0-preview.1",
208
+ "date": "Fri, 27 Aug 2021 05:06:34 GMT",
209
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.10",
210
+ "version": "0.0.0-canary.10",
211
+ "comments": {
212
+ "none": [
213
+ {
214
+ "comment": "Bump react-native-tscodegen to catch up react-native 0.65",
215
+ "author": "53799235+ZihanChen-MSFT@users.noreply.github.com",
216
+ "commit": "420edbedb4cbe4b40f2541e466f98bd9e177e26a",
217
+ "package": "@react-native-windows/codegen"
218
+ }
219
+ ]
220
+ }
221
+ },
222
+ {
223
+ "date": "Thu, 05 Aug 2021 05:07:20 GMT",
224
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.10",
225
+ "version": "0.0.0-canary.10",
23
226
  "comments": {
24
227
  "prerelease": [
25
228
  {
26
- "comment": "Promote 0.65 to preview",
229
+ "comment": "Do not write codegen files if the contents have not changed, as this breaks incremental builds",
230
+ "author": "30809111+acoates-ms@users.noreply.github.com",
231
+ "commit": "3b92733ab97670e6eb2d944f65ff341994e80517",
232
+ "package": "@react-native-windows/codegen"
233
+ }
234
+ ]
235
+ }
236
+ },
237
+ {
238
+ "date": "Sat, 24 Jul 2021 05:05:52 GMT",
239
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.9",
240
+ "version": "0.0.0-canary.9",
241
+ "comments": {
242
+ "none": [
243
+ {
244
+ "comment": "Replace @rnw-scripts/jest-out-of-tree-resolver with @rnx-kit/jest-resolver",
245
+ "author": "4123478+tido64@users.noreply.github.com",
246
+ "commit": "a311022ebc0c1d8070d7e54312197f486c470d33",
247
+ "package": "@react-native-windows/codegen"
248
+ }
249
+ ]
250
+ }
251
+ },
252
+ {
253
+ "date": "Fri, 11 Jun 2021 05:08:55 GMT",
254
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.9",
255
+ "version": "0.0.0-canary.9",
256
+ "comments": {
257
+ "patch": [
258
+ {
259
+ "comment": "Bump @rnw-scripts/just-task to v2.2.0",
260
+ "author": "ngerlem@microsoft.com",
261
+ "commit": "3d7c8d8fcf14a3cbda83a93c85b0bcf1e4e4f829",
262
+ "package": "@react-native-windows/codegen"
263
+ }
264
+ ]
265
+ }
266
+ },
267
+ {
268
+ "date": "Wed, 09 Jun 2021 05:10:07 GMT",
269
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.8",
270
+ "version": "0.0.0-canary.8",
271
+ "comments": {
272
+ "patch": [
273
+ {
274
+ "comment": "Bump @rnw-scripts/just-task to v2.1.3",
275
+ "author": "igklemen@microsoft.com",
276
+ "commit": "2ba41a4f087cc3bf16cbe799575923fc7a626009",
277
+ "package": "@react-native-windows/codegen"
278
+ },
279
+ {
280
+ "comment": "Bump @rnw-scripts/jest-unittest-config to v1.2.3",
281
+ "author": "igklemen@microsoft.com",
282
+ "commit": "2ba41a4f087cc3bf16cbe799575923fc7a626009",
283
+ "package": "@react-native-windows/codegen"
284
+ }
285
+ ]
286
+ }
287
+ },
288
+ {
289
+ "date": "Thu, 03 Jun 2021 05:09:47 GMT",
290
+ "tag": "@react-native-windows/codegen_v0.0.0-canary.7",
291
+ "version": "0.0.0-canary.7",
292
+ "comments": {
293
+ "prerelease": [
294
+ {
295
+ "comment": "Enable esModuleInterop Repo Wide",
296
+ "author": "ngerlem@microsoft.com",
297
+ "commit": "6c871e6ba27888804c776e5deeefbc7064e181d0",
298
+ "package": "@react-native-windows/codegen"
299
+ }
300
+ ],
301
+ "patch": [
302
+ {
303
+ "comment": "Bump @rnw-scripts/just-task to v2.1.2",
304
+ "author": "ngerlem@microsoft.com",
305
+ "commit": "b481f0a4ea68a8100860eb061902b715fca6652e",
306
+ "package": "@react-native-windows/codegen"
307
+ },
308
+ {
309
+ "comment": "Bump @rnw-scripts/ts-config to v2.0.0",
310
+ "author": "ngerlem@microsoft.com",
311
+ "commit": "6c871e6ba27888804c776e5deeefbc7064e181d0",
312
+ "package": "@react-native-windows/codegen"
313
+ },
314
+ {
315
+ "comment": "Bump @rnw-scripts/eslint-config to v1.1.7",
316
+ "author": "ngerlem@microsoft.com",
317
+ "commit": "b481f0a4ea68a8100860eb061902b715fca6652e",
318
+ "package": "@react-native-windows/codegen"
319
+ },
320
+ {
321
+ "comment": "Bump @rnw-scripts/jest-unittest-config to v1.2.2",
27
322
  "author": "ngerlem@microsoft.com",
28
- "commit": "3d6d7f00b51a68c7ab7c3b3e50cdb2be8b17929f",
323
+ "commit": "b481f0a4ea68a8100860eb061902b715fca6652e",
29
324
  "package": "@react-native-windows/codegen"
30
325
  }
31
326
  ]
package/CHANGELOG.md CHANGED
@@ -1,24 +1,137 @@
1
1
  # Change Log - @react-native-windows/codegen
2
2
 
3
- This log was last generated on Mon, 23 Aug 2021 15:08:33 GMT and should not be manually modified.
3
+ This log was last generated on Mon, 25 Oct 2021 15:07:19 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 0.65.0
7
+ ## 0.67.0-preview.1
8
8
 
9
- Mon, 23 Aug 2021 15:08:33 GMT
9
+ Mon, 25 Oct 2021 15:07:19 GMT
10
10
 
11
- ### Patches
11
+ ### Changes
12
12
 
13
- - Promote 0.65 to latest (ngerlem@microsoft.com)
13
+ - Promote 0.67 to preview (ngerlem@microsoft.com)
14
14
 
15
- ## 0.65.0-preview.1
15
+ ## 0.0.0-canary.19
16
16
 
17
- Mon, 31 May 2021 15:23:18 GMT
17
+ Sat, 23 Oct 2021 05:06:49 GMT
18
18
 
19
19
  ### Changes
20
20
 
21
- - Promote 0.65 to preview (ngerlem@microsoft.com)
21
+ - Only generate component files if a component is specified (30809111+acoates-ms@users.noreply.github.com)
22
+
23
+ ## 0.0.0-canary.18
24
+
25
+ Fri, 22 Oct 2021 05:06:46 GMT
26
+
27
+ ### Changes
28
+
29
+ - Built files not included in published package (30809111+acoates-ms@users.noreply.github.com)
30
+
31
+ ## 0.0.0-canary.17
32
+
33
+ Thu, 21 Oct 2021 05:08:01 GMT
34
+
35
+ ### Changes
36
+
37
+ - Update to typescript 4 (30809111+acoates-ms@users.noreply.github.com)
38
+
39
+ ## 0.0.0-canary.16
40
+
41
+ Wed, 29 Sep 2021 05:06:54 GMT
42
+
43
+ ### Changes
44
+
45
+ - Check constants in generated turbo module specs (53799235+ZihanChen-MSFT@users.noreply.github.com)
46
+
47
+ ## 0.0.0-canary.15
48
+
49
+ Wed, 15 Sep 2021 05:07:04 GMT
50
+
51
+ ### Changes
52
+
53
+ - Generate anonymous objects in correct order for turbo module (53799235+ZihanChen-MSFT@users.noreply.github.com)
54
+
55
+ ## 0.0.0-canary.14
56
+
57
+ Fri, 10 Sep 2021 05:07:31 GMT
58
+
59
+ ### Changes
60
+
61
+ - Generate `std::vector<T>` for array types in turbo modules (53799235+ZihanChen-MSFT@users.noreply.github.com)
62
+
63
+ ## 0.0.0-canary.13
64
+
65
+ Thu, 09 Sep 2021 05:07:46 GMT
66
+
67
+ ### Changes
68
+
69
+ - Bump to 0.66-based react-native-tscodegen (ngerlem@microsoft.com)
70
+ - Generate nullable type for turbo module (53799235+ZihanChen-MSFT@users.noreply.github.com)
71
+
72
+ ## 0.0.0-canary.12
73
+
74
+ Wed, 08 Sep 2021 05:08:53 GMT
75
+
76
+ ### Patches
77
+
78
+ - Bump @rnw-scripts/jest-unittest-config to v1.2.4 (ngerlem@microsoft.com)
79
+ - Bump @rnw-scripts/just-task to v2.2.1 (ngerlem@microsoft.com)
80
+ - Bump @rnw-scripts/ts-config to v2.0.1 (ngerlem@microsoft.com)
81
+ - Bump @rnw-scripts/eslint-config to v1.1.8 (ngerlem@microsoft.com)
82
+
83
+ ### Changes
84
+
85
+ - Set consistent node requirements on our packages (ngerlem@microsoft.com)
86
+ - Match Alert module with NativeDialogManagerWindowsSpec.h (53799235+ZihanChen-MSFT@users.noreply.github.com)
87
+
88
+ ## 0.0.0-canary.11
89
+
90
+ Fri, 03 Sep 2021 05:06:04 GMT
91
+
92
+ ### Changes
93
+
94
+ - Generate aliased struct for turbo module (53799235+ZihanChen-MSFT@users.noreply.github.com)
95
+
96
+ ## 0.0.0-canary.10
97
+
98
+ Thu, 05 Aug 2021 05:07:20 GMT
99
+
100
+ ### Changes
101
+
102
+ - Do not write codegen files if the contents have not changed, as this breaks incremental builds (30809111+acoates-ms@users.noreply.github.com)
103
+
104
+ ## 0.0.0-canary.9
105
+
106
+ Fri, 11 Jun 2021 05:08:55 GMT
107
+
108
+ ### Patches
109
+
110
+ - Bump @rnw-scripts/just-task to v2.2.0 (ngerlem@microsoft.com)
111
+
112
+ ## 0.0.0-canary.8
113
+
114
+ Wed, 09 Jun 2021 05:10:07 GMT
115
+
116
+ ### Patches
117
+
118
+ - Bump @rnw-scripts/just-task to v2.1.3 (igklemen@microsoft.com)
119
+ - Bump @rnw-scripts/jest-unittest-config to v1.2.3 (igklemen@microsoft.com)
120
+
121
+ ## 0.0.0-canary.7
122
+
123
+ Thu, 03 Jun 2021 05:09:47 GMT
124
+
125
+ ### Patches
126
+
127
+ - Bump @rnw-scripts/just-task to v2.1.2 (ngerlem@microsoft.com)
128
+ - Bump @rnw-scripts/ts-config to v2.0.0 (ngerlem@microsoft.com)
129
+ - Bump @rnw-scripts/eslint-config to v1.1.7 (ngerlem@microsoft.com)
130
+ - Bump @rnw-scripts/jest-unittest-config to v1.2.2 (ngerlem@microsoft.com)
131
+
132
+ ### Changes
133
+
134
+ - Enable esModuleInterop Repo Wide (ngerlem@microsoft.com)
22
135
 
23
136
  ## 0.0.0-canary.6
24
137
 
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ *
5
+ * @format
6
+ */
7
+ export {};
@@ -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