@react-native-windows/codegen 0.0.0-canary.3 → 0.0.0-canary.32
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.md +283 -6
- package/bin.js +0 -0
- package/lib-commonjs/Cli.d.ts +7 -0
- package/lib-commonjs/Cli.js +231 -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/GenerateTypeScript.d.ts +11 -0
- package/lib-commonjs/generators/GenerateTypeScript.js +166 -0
- package/lib-commonjs/generators/GenerateTypeScript.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 +28 -16
- package/src/Cli.ts +172 -35
- package/src/generators/AliasGen.ts +105 -0
- package/src/generators/AliasManaging.ts +75 -0
- package/src/generators/GenerateNM2.ts +62 -296
- package/src/generators/GenerateTypeScript.ts +247 -0
- package/src/generators/ObjectTypes.ts +70 -0
- package/src/generators/ParamTypes.ts +220 -0
- package/src/generators/ReturnTypes.ts +92 -0
- 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/CHANGELOG.json +0 -447
- package/jest.config.js +0 -1
- package/tsconfig.json +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,295 @@
|
|
|
1
1
|
# Change Log - @react-native-windows/codegen
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 27 Apr 2022 05:09:11 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## 0.0.0-canary.
|
|
7
|
+
## 0.0.0-canary.32
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Wed, 27 Apr 2022 05:09:11 GMT
|
|
10
10
|
|
|
11
|
-
###
|
|
11
|
+
### Changes
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
- Bump @
|
|
13
|
+
- Merge (34109996+chiaramooney@users.noreply.github.com)
|
|
14
|
+
- Bump @react-native-windows/fs to v0.0.0-canary.3
|
|
15
|
+
- Bump @rnw-scripts/eslint-config to v1.1.12
|
|
15
16
|
|
|
17
|
+
## 0.0.0-canary.31
|
|
18
|
+
|
|
19
|
+
Mon, 25 Apr 2022 22:50:30 GMT
|
|
20
|
+
|
|
21
|
+
### Changes
|
|
22
|
+
|
|
23
|
+
- Update globby of @react-native-windows/codegen to remove glob-parent 3.x dependency (dannyvv@microsoft.com)
|
|
24
|
+
|
|
25
|
+
## 0.0.0-canary.30
|
|
26
|
+
|
|
27
|
+
Tue, 12 Apr 2022 05:10:38 GMT
|
|
28
|
+
|
|
29
|
+
### Changes
|
|
30
|
+
|
|
31
|
+
- Fix Overrides (34109996+chiaramooney@users.noreply.github.com)
|
|
32
|
+
- Bump @react-native-windows/fs to v0.0.0-canary.2
|
|
33
|
+
|
|
34
|
+
## 0.0.0-canary.29
|
|
35
|
+
|
|
36
|
+
Fri, 01 Apr 2022 05:09:56 GMT
|
|
37
|
+
|
|
38
|
+
### Changes
|
|
39
|
+
|
|
40
|
+
- Fix publish after promotion to preview (ngerlem@microsoft.com)
|
|
41
|
+
- Bump @react-native-windows/fs to v0.0.0-canary.1
|
|
42
|
+
|
|
43
|
+
## 0.0.0-canary.28
|
|
44
|
+
|
|
45
|
+
Wed, 09 Mar 2022 06:09:07 GMT
|
|
46
|
+
|
|
47
|
+
### Changes
|
|
48
|
+
|
|
49
|
+
- Fix turbo module codegen to generate correct import statement and registration (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
50
|
+
|
|
51
|
+
## 0.0.0-canary.27
|
|
52
|
+
|
|
53
|
+
Fri, 04 Mar 2022 06:09:13 GMT
|
|
54
|
+
|
|
55
|
+
### Changes
|
|
56
|
+
|
|
57
|
+
- Generate fabric eventemitter.cpp (acoates@microsoft.com)
|
|
58
|
+
|
|
59
|
+
## 0.0.0-canary.26
|
|
60
|
+
|
|
61
|
+
Thu, 24 Feb 2022 06:07:47 GMT
|
|
62
|
+
|
|
63
|
+
### Changes
|
|
64
|
+
|
|
65
|
+
- Add TypeScript turbo module definition as new codegen traget (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
66
|
+
|
|
67
|
+
## 0.0.0-canary.25
|
|
68
|
+
|
|
69
|
+
Wed, 09 Feb 2022 06:09:36 GMT
|
|
70
|
+
|
|
71
|
+
### Changes
|
|
72
|
+
|
|
73
|
+
- Bump minimum Node version to 14 (jthysell@microsoft.com)
|
|
74
|
+
- Bump @react-native-windows/fs to v1.0.2
|
|
75
|
+
- Bump @rnw-scripts/eslint-config to v1.1.11
|
|
76
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.2.6
|
|
77
|
+
- Bump @rnw-scripts/just-task to v2.2.3
|
|
78
|
+
- Bump @rnw-scripts/ts-config to v2.0.2
|
|
79
|
+
|
|
80
|
+
## 0.0.0-canary.24
|
|
81
|
+
|
|
82
|
+
Tue, 08 Feb 2022 18:21:23 GMT
|
|
83
|
+
|
|
84
|
+
### Changes
|
|
85
|
+
|
|
86
|
+
- Fix TurboModule codegen document (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
87
|
+
|
|
88
|
+
## 0.0.0-canary.23
|
|
89
|
+
|
|
90
|
+
Sat, 29 Jan 2022 06:08:58 GMT
|
|
91
|
+
|
|
92
|
+
### Changes
|
|
93
|
+
|
|
94
|
+
- Add document for turbo module codegen (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
95
|
+
|
|
96
|
+
## 0.0.0-canary.22
|
|
97
|
+
|
|
98
|
+
Fri, 03 Dec 2021 06:12:10 GMT
|
|
99
|
+
|
|
100
|
+
### Changes
|
|
101
|
+
|
|
102
|
+
- Integrate 11/11 (34109996+chiaramooney@users.noreply.github.com)
|
|
103
|
+
- Bump @react-native-windows/fs to v1.0.1
|
|
104
|
+
- Bump @rnw-scripts/eslint-config to v1.1.10
|
|
105
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.2.5
|
|
106
|
+
- Bump @rnw-scripts/just-task to v2.2.2
|
|
107
|
+
|
|
108
|
+
## 0.0.0-canary.21
|
|
109
|
+
|
|
110
|
+
Thu, 18 Nov 2021 06:11:20 GMT
|
|
111
|
+
|
|
112
|
+
### Changes
|
|
113
|
+
|
|
114
|
+
- Use '@react-native-windows/fs' (ngerlem@microsoft.com)
|
|
115
|
+
- Bump @react-native-windows/fs to v1.0.0
|
|
116
|
+
- Bump @rnw-scripts/eslint-config to v1.1.9
|
|
117
|
+
|
|
118
|
+
## 0.0.0-canary.20
|
|
119
|
+
|
|
120
|
+
Thu, 04 Nov 2021 05:07:29 GMT
|
|
121
|
+
|
|
122
|
+
### Changes
|
|
123
|
+
|
|
124
|
+
- Codegen prints `::React::JSValue` instead of `React::JSValue` (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
125
|
+
|
|
126
|
+
## 0.0.0-canary.20
|
|
127
|
+
|
|
128
|
+
Thu, 04 Nov 2021 05:07:08 GMT
|
|
129
|
+
|
|
130
|
+
### Changes
|
|
131
|
+
|
|
132
|
+
- Codegen prints `::React::JSValue` instead of `React::JSValue` (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
133
|
+
|
|
134
|
+
## 0.0.0-canary.19
|
|
135
|
+
|
|
136
|
+
Sat, 23 Oct 2021 05:06:49 GMT
|
|
137
|
+
|
|
138
|
+
### Changes
|
|
139
|
+
|
|
140
|
+
- Only generate component files if a component is specified (30809111+acoates-ms@users.noreply.github.com)
|
|
141
|
+
|
|
142
|
+
## 0.0.0-canary.18
|
|
143
|
+
|
|
144
|
+
Fri, 22 Oct 2021 05:06:46 GMT
|
|
145
|
+
|
|
146
|
+
### Changes
|
|
147
|
+
|
|
148
|
+
- Built files not included in published package (30809111+acoates-ms@users.noreply.github.com)
|
|
149
|
+
|
|
150
|
+
## 0.0.0-canary.17
|
|
151
|
+
|
|
152
|
+
Thu, 21 Oct 2021 05:08:01 GMT
|
|
153
|
+
|
|
154
|
+
### Changes
|
|
155
|
+
|
|
156
|
+
- Update to typescript 4 (30809111+acoates-ms@users.noreply.github.com)
|
|
157
|
+
|
|
158
|
+
## 0.0.0-canary.16
|
|
159
|
+
|
|
160
|
+
Wed, 29 Sep 2021 05:06:54 GMT
|
|
161
|
+
|
|
162
|
+
### Changes
|
|
163
|
+
|
|
164
|
+
- Check constants in generated turbo module specs (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
165
|
+
|
|
166
|
+
## 0.0.0-canary.15
|
|
167
|
+
|
|
168
|
+
Wed, 15 Sep 2021 05:07:04 GMT
|
|
169
|
+
|
|
170
|
+
### Changes
|
|
171
|
+
|
|
172
|
+
- Generate anonymous objects in correct order for turbo module (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
173
|
+
|
|
174
|
+
## 0.0.0-canary.14
|
|
175
|
+
|
|
176
|
+
Fri, 10 Sep 2021 05:07:31 GMT
|
|
177
|
+
|
|
178
|
+
### Changes
|
|
179
|
+
|
|
180
|
+
- Generate `std::vector<T>` for array types in turbo modules (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
181
|
+
|
|
182
|
+
## 0.0.0-canary.13
|
|
183
|
+
|
|
184
|
+
Thu, 09 Sep 2021 05:07:46 GMT
|
|
185
|
+
|
|
186
|
+
### Changes
|
|
187
|
+
|
|
188
|
+
- Bump to 0.66-based react-native-tscodegen (ngerlem@microsoft.com)
|
|
189
|
+
- Generate nullable type for turbo module (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
190
|
+
|
|
191
|
+
## 0.0.0-canary.12
|
|
192
|
+
|
|
193
|
+
Wed, 08 Sep 2021 05:08:53 GMT
|
|
194
|
+
|
|
195
|
+
### Patches
|
|
196
|
+
|
|
197
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.2.4 (ngerlem@microsoft.com)
|
|
198
|
+
- Bump @rnw-scripts/just-task to v2.2.1 (ngerlem@microsoft.com)
|
|
199
|
+
- Bump @rnw-scripts/ts-config to v2.0.1 (ngerlem@microsoft.com)
|
|
200
|
+
- Bump @rnw-scripts/eslint-config to v1.1.8 (ngerlem@microsoft.com)
|
|
201
|
+
|
|
202
|
+
### Changes
|
|
203
|
+
|
|
204
|
+
- Set consistent node requirements on our packages (ngerlem@microsoft.com)
|
|
205
|
+
- Match Alert module with NativeDialogManagerWindowsSpec.h (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
206
|
+
|
|
207
|
+
## 0.0.0-canary.11
|
|
208
|
+
|
|
209
|
+
Fri, 03 Sep 2021 05:06:04 GMT
|
|
210
|
+
|
|
211
|
+
### Changes
|
|
212
|
+
|
|
213
|
+
- Generate aliased struct for turbo module (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
214
|
+
|
|
215
|
+
## 0.0.0-canary.10
|
|
216
|
+
|
|
217
|
+
Thu, 05 Aug 2021 05:07:20 GMT
|
|
218
|
+
|
|
219
|
+
### Changes
|
|
220
|
+
|
|
221
|
+
- Do not write codegen files if the contents have not changed, as this breaks incremental builds (30809111+acoates-ms@users.noreply.github.com)
|
|
222
|
+
|
|
223
|
+
## 0.0.0-canary.9
|
|
224
|
+
|
|
225
|
+
Fri, 11 Jun 2021 05:08:55 GMT
|
|
226
|
+
|
|
227
|
+
### Patches
|
|
228
|
+
|
|
229
|
+
- Bump @rnw-scripts/just-task to v2.2.0 (ngerlem@microsoft.com)
|
|
230
|
+
|
|
231
|
+
## 0.0.0-canary.8
|
|
232
|
+
|
|
233
|
+
Wed, 09 Jun 2021 05:10:07 GMT
|
|
234
|
+
|
|
235
|
+
### Patches
|
|
236
|
+
|
|
237
|
+
- Bump @rnw-scripts/just-task to v2.1.3 (igklemen@microsoft.com)
|
|
238
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.2.3 (igklemen@microsoft.com)
|
|
239
|
+
|
|
240
|
+
## 0.0.0-canary.7
|
|
241
|
+
|
|
242
|
+
Thu, 03 Jun 2021 05:09:47 GMT
|
|
243
|
+
|
|
244
|
+
### Patches
|
|
245
|
+
|
|
246
|
+
- Bump @rnw-scripts/just-task to v2.1.2 (ngerlem@microsoft.com)
|
|
247
|
+
- Bump @rnw-scripts/ts-config to v2.0.0 (ngerlem@microsoft.com)
|
|
248
|
+
- Bump @rnw-scripts/eslint-config to v1.1.7 (ngerlem@microsoft.com)
|
|
249
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.2.2 (ngerlem@microsoft.com)
|
|
250
|
+
|
|
251
|
+
### Changes
|
|
252
|
+
|
|
253
|
+
- Enable esModuleInterop Repo Wide (ngerlem@microsoft.com)
|
|
254
|
+
|
|
255
|
+
## 0.0.0-canary.6
|
|
256
|
+
|
|
257
|
+
Fri, 21 May 2021 05:17:18 GMT
|
|
258
|
+
|
|
259
|
+
### Patches
|
|
260
|
+
|
|
261
|
+
- Bump @rnw-scripts/just-task to v2.1.1 (ngerlem@microsoft.com)
|
|
262
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.2.1 (ngerlem@microsoft.com)
|
|
263
|
+
|
|
264
|
+
### Changes
|
|
265
|
+
|
|
266
|
+
- Integrate Apr 28 (base of 0.65) Nightly RN Build (ngerlem@microsoft.com)
|
|
267
|
+
|
|
268
|
+
## 0.0.0-canary.5
|
|
269
|
+
|
|
270
|
+
Thu, 13 May 2021 05:11:48 GMT
|
|
271
|
+
|
|
272
|
+
### Changes
|
|
273
|
+
|
|
274
|
+
- Hook up view component codegen (30809111+acoates-ms@users.noreply.github.com)
|
|
275
|
+
|
|
276
|
+
## 0.0.0-canary.4
|
|
277
|
+
|
|
278
|
+
Thu, 04 Mar 2021 05:05:53 GMT
|
|
279
|
+
|
|
280
|
+
### Changes
|
|
281
|
+
|
|
282
|
+
- Update yargs version used and patch y18n version 4.0.0 to 4.0.1 as used by detox of transitive dependencies to address https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-7774 (dannyvv@microsoft.com)
|
|
283
|
+
|
|
284
|
+
## 0.0.0-canary.3
|
|
285
|
+
|
|
286
|
+
Thu, 11 Feb 2021 05:08:29 GMT
|
|
287
|
+
|
|
288
|
+
### Patches
|
|
289
|
+
|
|
290
|
+
- Bump @rnw-scripts/just-task to v2.1.0 (ngerlem@microsoft.com)
|
|
291
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.2.0 (ngerlem@microsoft.com)
|
|
292
|
+
|
|
16
293
|
## 0.0.0-canary.2
|
|
17
294
|
|
|
18
295
|
Tue, 09 Feb 2021 05:07:37 GMT
|
package/bin.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,231 @@
|
|
|
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("@react-native-windows/fs"));
|
|
15
|
+
const globby_1 = __importDefault(require("globby"));
|
|
16
|
+
const GenerateNM2_1 = require("./generators/GenerateNM2");
|
|
17
|
+
const GenerateTypeScript_1 = require("./generators/GenerateTypeScript");
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
const flow_1 = require("react-native-tscodegen/lib/rncodegen/src/parsers/flow");
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
const schemaValidator_1 = __importDefault(require("react-native-tscodegen/lib/rncodegen/src/schemaValidator"));
|
|
22
|
+
const argv = yargs_1.default.options({
|
|
23
|
+
file: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
describe: 'file which contains spec',
|
|
26
|
+
},
|
|
27
|
+
files: {
|
|
28
|
+
type: 'array',
|
|
29
|
+
describe: 'glob patterns for files which contains specs',
|
|
30
|
+
},
|
|
31
|
+
ts: {
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
describe: 'generate turbo module definition files in TypeScript',
|
|
34
|
+
default: false,
|
|
35
|
+
},
|
|
36
|
+
outdir: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
describe: 'output directory',
|
|
39
|
+
default: 'codegen',
|
|
40
|
+
},
|
|
41
|
+
test: {
|
|
42
|
+
type: 'boolean',
|
|
43
|
+
describe: 'Verify that the generated output is unchanged',
|
|
44
|
+
},
|
|
45
|
+
namespace: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
describe: 'C++/C# Namespace to put generated native modules in',
|
|
48
|
+
default: 'MyNamespace',
|
|
49
|
+
},
|
|
50
|
+
libraryName: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
required: true,
|
|
53
|
+
describe: 'Used for part of the path generated within the codegen dir',
|
|
54
|
+
},
|
|
55
|
+
}).argv;
|
|
56
|
+
/*
|
|
57
|
+
const GENERATORS = {
|
|
58
|
+
descriptors: [generateComponentDescriptorH.generate],
|
|
59
|
+
events: [
|
|
60
|
+
generateEventEmitterCpp.generate,
|
|
61
|
+
generateEventEmitterH.generate,
|
|
62
|
+
generateModuleHObjCpp.generate,
|
|
63
|
+
generateModuleMm.generate,
|
|
64
|
+
],
|
|
65
|
+
props: [
|
|
66
|
+
generateComponentHObjCpp.generate,
|
|
67
|
+
generatePropsCpp.generate,
|
|
68
|
+
generatePropsH.generate,
|
|
69
|
+
generatePropsJavaInterface.generate,
|
|
70
|
+
generatePropsJavaDelegate.generate,
|
|
71
|
+
],
|
|
72
|
+
modules: [generateModuleCpp.generate, generateModuleH.generate],
|
|
73
|
+
tests: [generateTests.generate],
|
|
74
|
+
'shadow-nodes': [
|
|
75
|
+
generateShadowNodeCpp.generate,
|
|
76
|
+
generateShadowNodeH.generate,
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
*/
|
|
80
|
+
function normalizeFileMap(map, outputDir, outMap) {
|
|
81
|
+
for (const [fileName, contents] of map) {
|
|
82
|
+
const location = path_1.default.join(outputDir, fileName);
|
|
83
|
+
outMap.set(path_1.default.normalize(location), contents);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function checkFilesForChanges(map, outputDir) {
|
|
87
|
+
let hasChanges = false;
|
|
88
|
+
const allExistingFiles = globby_1.default
|
|
89
|
+
.sync(`${outputDir}/**`)
|
|
90
|
+
.map(_ => path_1.default.normalize(_))
|
|
91
|
+
.sort();
|
|
92
|
+
const allGeneratedFiles = [...map.keys()].map(_ => path_1.default.normalize(_)).sort();
|
|
93
|
+
if (allExistingFiles.length !== allGeneratedFiles.length ||
|
|
94
|
+
!allExistingFiles.every((val, index) => val === allGeneratedFiles[index]))
|
|
95
|
+
return true;
|
|
96
|
+
for (const [fileName, contents] of map) {
|
|
97
|
+
if (!fs_1.default.existsSync(fileName)) {
|
|
98
|
+
hasChanges = true;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const currentContents = fs_1.default.readFileSync(fileName, 'utf8');
|
|
102
|
+
if (currentContents !== contents) {
|
|
103
|
+
console.error(`- ${fileName} has changed`);
|
|
104
|
+
hasChanges = true;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return hasChanges;
|
|
109
|
+
}
|
|
110
|
+
function writeMapToFiles(map, outputDir) {
|
|
111
|
+
let success = true;
|
|
112
|
+
// This ensures that we delete any generated files from modules that have been deleted
|
|
113
|
+
const allExistingFiles = globby_1.default.sync(`${outputDir}/**`);
|
|
114
|
+
allExistingFiles.forEach(existingFile => {
|
|
115
|
+
if (!map.has(path_1.default.normalize(existingFile))) {
|
|
116
|
+
fs_1.default.unlinkSync(existingFile);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
for (const [fileName, contents] of map) {
|
|
120
|
+
try {
|
|
121
|
+
fs_1.default.mkdirSync(path_1.default.dirname(fileName), { recursive: true });
|
|
122
|
+
if (fs_1.default.existsSync(fileName)) {
|
|
123
|
+
const currentContents = fs_1.default.readFileSync(fileName, 'utf8');
|
|
124
|
+
// Don't update the files if there are no changes as this breaks incremental builds
|
|
125
|
+
if (currentContents === contents) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
fs_1.default.writeFileSync(fileName, contents);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
success = false;
|
|
133
|
+
console.error(`Failed to write ${fileName} to ${fileName}`, error);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return success;
|
|
137
|
+
}
|
|
138
|
+
function parseFlowFile(filename) {
|
|
139
|
+
try {
|
|
140
|
+
const schema = (0, flow_1.parseFile)(filename);
|
|
141
|
+
// there will be at most one turbo module per file
|
|
142
|
+
const moduleName = Object.keys(schema.modules)[0];
|
|
143
|
+
if (moduleName) {
|
|
144
|
+
const spec = schema.modules[moduleName];
|
|
145
|
+
if (spec.type === 'NativeModule') {
|
|
146
|
+
const contents = fs_1.default.readFileSync(filename, 'utf8');
|
|
147
|
+
if (contents) {
|
|
148
|
+
// This is a temporary implementation until such information is added to the schema in facebook/react-native
|
|
149
|
+
if (contents.includes('TurboModuleRegistry.get<')) {
|
|
150
|
+
(0, GenerateTypeScript_1.setOptionalTurboModule)(spec, true);
|
|
151
|
+
}
|
|
152
|
+
else if (contents.includes('TurboModuleRegistry.getEnforcing<')) {
|
|
153
|
+
(0, GenerateTypeScript_1.setOptionalTurboModule)(spec, false);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return schema;
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
if (e instanceof Error) {
|
|
162
|
+
e.message = `(${filename}): ${e.message}`;
|
|
163
|
+
}
|
|
164
|
+
throw e;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function combineSchemas(files) {
|
|
168
|
+
return files.reduce((merged, filename) => {
|
|
169
|
+
const contents = fs_1.default.readFileSync(filename, 'utf8');
|
|
170
|
+
if (contents &&
|
|
171
|
+
(/export\s+default\s+\(?codegenNativeComponent</.test(contents) ||
|
|
172
|
+
contents.includes('extends TurboModule'))) {
|
|
173
|
+
const schema = parseFlowFile(filename);
|
|
174
|
+
merged.modules = { ...merged.modules, ...schema.modules };
|
|
175
|
+
}
|
|
176
|
+
return merged;
|
|
177
|
+
}, { modules: {} });
|
|
178
|
+
}
|
|
179
|
+
function generate({ libraryName, schema, outputDirectory, moduleSpecName }, { /*generators,*/ test }) {
|
|
180
|
+
schemaValidator_1.default.validate(schema);
|
|
181
|
+
const componentOutputdir = path_1.default.join(outputDirectory, 'react/components', libraryName);
|
|
182
|
+
const generatedFiles = new Map();
|
|
183
|
+
generatedFiles.set(path_1.default.join(outputDirectory, '.clang-format'), 'DisableFormat: true\nSortIncludes: false');
|
|
184
|
+
const generateNM2 = (0, GenerateNM2_1.createNM2Generator)({ namespace: argv.namespace });
|
|
185
|
+
const generatorPropsH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH').generate;
|
|
186
|
+
const generatorPropsCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP').generate;
|
|
187
|
+
const generatorShadowNodeH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH').generate;
|
|
188
|
+
const generatorShadowNodeCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP').generate;
|
|
189
|
+
const generatorComponentDescriptorH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH').generate;
|
|
190
|
+
const generatorEventEmitterH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH').generate;
|
|
191
|
+
const generatorEventEmitterCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterCpp').generate;
|
|
192
|
+
normalizeFileMap(generateNM2(libraryName, schema, moduleSpecName), outputDirectory, generatedFiles);
|
|
193
|
+
if (argv.ts) {
|
|
194
|
+
normalizeFileMap((0, GenerateTypeScript_1.generateTypeScript)(libraryName, schema, moduleSpecName), outputDirectory, generatedFiles);
|
|
195
|
+
}
|
|
196
|
+
if (Object.keys(schema.modules).some(moduleName => schema.modules[moduleName].type === 'Component')) {
|
|
197
|
+
const componentGenerators = [
|
|
198
|
+
generatorPropsH,
|
|
199
|
+
generatorPropsCPP,
|
|
200
|
+
generatorShadowNodeH,
|
|
201
|
+
generatorShadowNodeCPP,
|
|
202
|
+
generatorComponentDescriptorH,
|
|
203
|
+
generatorEventEmitterH,
|
|
204
|
+
generatorEventEmitterCPP,
|
|
205
|
+
];
|
|
206
|
+
componentGenerators.forEach(generator => {
|
|
207
|
+
const generated = generator(libraryName, schema, moduleSpecName);
|
|
208
|
+
normalizeFileMap(generated, componentOutputdir, generatedFiles);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
if (test === true) {
|
|
212
|
+
return checkFilesForChanges(generatedFiles, outputDirectory);
|
|
213
|
+
}
|
|
214
|
+
return writeMapToFiles(generatedFiles, outputDirectory);
|
|
215
|
+
}
|
|
216
|
+
if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
|
|
217
|
+
console.error('You must specify either --file or --files.');
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
let schema;
|
|
221
|
+
if (argv.file) {
|
|
222
|
+
schema = parseFlowFile(argv.file);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
schema = combineSchemas(globby_1.default.sync(argv.files));
|
|
226
|
+
}
|
|
227
|
+
const libraryName = argv.libraryName;
|
|
228
|
+
const moduleSpecName = 'moduleSpecName';
|
|
229
|
+
const outputDirectory = argv.outdir;
|
|
230
|
+
generate({ libraryName, schema, outputDirectory, moduleSpecName }, { generators: [], test: false });
|
|
231
|
+
//# 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,kEAA0C;AAC1C,oDAA4B;AAC5B,0DAA4D;AAC5D,wEAGyC;AACzC,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,EAAE,EAAE;QACF,IAAI,EAA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M,SAAS,GAAwB,SAAS,CAC9C,WAAW,EACX,MAAM,EACN,cAAc,CACf,CAAC;YACF,gBAAgB,CAAC,SAAS,EAAE,kBAAkB,EAAE,cAAc,CAAC,CAAC;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,IAAI,CAAC,MAAM,CAAC;AACpC,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 '@react-native-windows/fs';\nimport globby from 'globby';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {\n generateTypeScript,\n setOptionalTurboModule,\n} from './generators/GenerateTypeScript';\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 ts: {\n type: 'boolean',\n describe: 'generate turbo module definition files in TypeScript',\n default: false,\n },\n outdir: {\n type: 'string',\n describe: 'output directory',\n default: 'codegen',\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 const schema = parseFile(filename);\n // there will be at most one turbo module per file\n const moduleName = Object.keys(schema.modules)[0];\n if (moduleName) {\n const spec = schema.modules[moduleName];\n if (spec.type === 'NativeModule') {\n const contents = fs.readFileSync(filename, 'utf8');\n if (contents) {\n // This is a temporary implementation until such information is added to the schema in facebook/react-native\n if (contents.includes('TurboModuleRegistry.get<')) {\n setOptionalTurboModule(spec, true);\n } else if (contents.includes('TurboModuleRegistry.getEnforcing<')) {\n setOptionalTurboModule(spec, false);\n }\n }\n }\n }\n return schema;\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\n const generatorPropsH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH').generate;\n const generatorPropsCPP =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP').generate;\n const generatorShadowNodeH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH').generate;\n const generatorShadowNodeCPP =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP').generate;\n const generatorComponentDescriptorH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH').generate;\n const generatorEventEmitterH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH').generate;\n const generatorEventEmitterCPP =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterCpp').generate;\n\n normalizeFileMap(\n generateNM2(libraryName, schema, moduleSpecName),\n outputDirectory,\n generatedFiles,\n );\n\n if (argv.ts) {\n normalizeFileMap(\n generateTypeScript(libraryName, schema, moduleSpecName),\n outputDirectory,\n generatedFiles,\n );\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 generatorEventEmitterCPP,\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 = argv.outdir;\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;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
* @format
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.generateAliases = exports.createAliasMap = void 0;
|
|
9
|
+
const AliasManaging_1 = require("./AliasManaging");
|
|
10
|
+
const ObjectTypes_1 = require("./ObjectTypes");
|
|
11
|
+
function translateObjectBody(type, aliases, baseAliasName, prefix) {
|
|
12
|
+
return type.properties
|
|
13
|
+
.map((prop) => {
|
|
14
|
+
let propType = prop.typeAnnotation;
|
|
15
|
+
if (prop.optional && propType.type !== 'NullableTypeAnnotation') {
|
|
16
|
+
propType = { type: 'NullableTypeAnnotation', typeAnnotation: propType };
|
|
17
|
+
}
|
|
18
|
+
const first = `${prefix}REACT_FIELD(${prop.name})`;
|
|
19
|
+
const second = `${prefix}${(0, ObjectTypes_1.translateField)(propType, aliases, `${baseAliasName}_${prop.name}`)} ${prop.name};`;
|
|
20
|
+
return `${first}\n${second}`;
|
|
21
|
+
})
|
|
22
|
+
.join('\n');
|
|
23
|
+
}
|
|
24
|
+
function createAliasMap(nativeModuleAliases) {
|
|
25
|
+
const aliases = { types: {}, jobs: Object.keys(nativeModuleAliases) };
|
|
26
|
+
for (const aliasName of aliases.jobs) {
|
|
27
|
+
aliases.types[aliasName] = nativeModuleAliases[aliasName];
|
|
28
|
+
}
|
|
29
|
+
return aliases;
|
|
30
|
+
}
|
|
31
|
+
exports.createAliasMap = createAliasMap;
|
|
32
|
+
function generateSingleAlias(aliases, aliasName, aliasCode) {
|
|
33
|
+
const aliasType = aliases.types[aliasName];
|
|
34
|
+
aliasCode[aliasName] = `
|
|
35
|
+
REACT_STRUCT(${(0, AliasManaging_1.getAliasCppName)(aliasName)})
|
|
36
|
+
struct ${(0, AliasManaging_1.getAliasCppName)(aliasName)} {
|
|
37
|
+
${translateObjectBody(aliasType, aliases, aliasName, ' ')}
|
|
38
|
+
};
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
function generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder) {
|
|
42
|
+
// retrieve and clean all ungenerated aliases
|
|
43
|
+
const jobs = aliases.jobs;
|
|
44
|
+
aliases.jobs = [];
|
|
45
|
+
// generate each one in its found order
|
|
46
|
+
for (const aliasName of jobs) {
|
|
47
|
+
// generate a new struct and all fields will be examined
|
|
48
|
+
// new anonymous objects could be found
|
|
49
|
+
// they will be stored in aliases.jobs
|
|
50
|
+
generateSingleAlias(aliases, aliasName, aliasCode);
|
|
51
|
+
// nested C++ structs must be put before the current C++ struct
|
|
52
|
+
// as they will be used in the current C++ struct
|
|
53
|
+
// the order will be perfectly and easily ensured by doing this recursively
|
|
54
|
+
generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder);
|
|
55
|
+
// all referenced C++ structs are generated
|
|
56
|
+
// put the current one following them
|
|
57
|
+
aliasOrder.push(aliasName);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function generateAliases(aliases) {
|
|
61
|
+
const aliasCode = {};
|
|
62
|
+
const aliasOrder = [];
|
|
63
|
+
generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder);
|
|
64
|
+
// aliasOrder now has the correct order of C++ struct code
|
|
65
|
+
let traversedAliasedStructs = '';
|
|
66
|
+
for (const aliasName of aliasOrder) {
|
|
67
|
+
traversedAliasedStructs = `${traversedAliasedStructs}${aliasCode[aliasName]}`;
|
|
68
|
+
}
|
|
69
|
+
return traversedAliasedStructs;
|
|
70
|
+
}
|
|
71
|
+
exports.generateAliases = generateAliases;
|
|
72
|
+
//# sourceMappingURL=AliasGen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AliasGen.js","sourceRoot":"","sources":["../../src/generators/AliasGen.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAQb,mDAA0D;AAC1D,+CAA6C;AAE7C,SAAS,mBAAmB,CAC1B,IAAsC,EACtC,O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Ae,EAAC,SAAS,CAAC;EACjC,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC;;CAE3D,CAAC;AACF,CAAC;AAED,SAAS,mCAAmC,CAC1C,OAAiB,EACjB,SAAuB,EACvB,UAAoB;IAEpB,6CAA6C;IAC7C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC1B,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC;IAElB,uCAAuC;IACvC,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE;QAC5B,wDAAwD;QACxD,uCAAuC;QACvC,sCAAsC;QACtC,mBAAmB,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;QACnD,+DAA+D;QAC/D,iDAAiD;QACjD,2EAA2E;QAC3E,mCAAmC,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;QACpE,2CAA2C;QAC3C,qCAAqC;QACrC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KAC5B;AACH,CAAC;AAED,SAAgB,eAAe,CAAC,OAAiB;IAC/C,MAAM,SAAS,GAAiB,EAAE,CAAC;IACnC,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,mCAAmC,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IAEpE,0DAA0D;IAC1D,IAAI,uBAAuB,GAAG,EAAE,CAAC;IACjC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;QAClC,uBAAuB,GAAG,GAAG,uBAAuB,GAAG,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;KAC/E;IACD,OAAO,uBAAuB,CAAC;AACjC,CAAC;AAXD,0CAWC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {\n NativeModuleBaseTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NamedShape,\n Nullable,\n} from 'react-native-tscodegen';\nimport {AliasMap, getAliasCppName} from './AliasManaging';\nimport {translateField} from './ObjectTypes';\n\nfunction translateObjectBody(\n type: NativeModuleObjectTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n prefix: string,\n) {\n return type.properties\n .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {\n let propType = prop.typeAnnotation;\n if (prop.optional && propType.type !== 'NullableTypeAnnotation') {\n propType = {type: 'NullableTypeAnnotation', typeAnnotation: propType};\n }\n const first = `${prefix}REACT_FIELD(${prop.name})`;\n const second = `${prefix}${translateField(\n propType,\n aliases,\n `${baseAliasName}_${prop.name}`,\n )} ${prop.name};`;\n return `${first}\\n${second}`;\n })\n .join('\\n');\n}\n\nexport function createAliasMap(nativeModuleAliases: {\n [name: string]: NativeModuleObjectTypeAnnotation;\n}): AliasMap {\n const aliases: AliasMap = {types: {}, jobs: Object.keys(nativeModuleAliases)};\n for (const aliasName of aliases.jobs) {\n aliases.types[aliasName] = nativeModuleAliases[aliasName];\n }\n return aliases;\n}\n\ninterface AliasCodeMap {\n [name: string]: string;\n}\n\nfunction generateSingleAlias(\n aliases: AliasMap,\n aliasName: string,\n aliasCode: AliasCodeMap,\n): void {\n const aliasType = <NativeModuleObjectTypeAnnotation>aliases.types[aliasName];\n aliasCode[aliasName] = `\nREACT_STRUCT(${getAliasCppName(aliasName)})\nstruct ${getAliasCppName(aliasName)} {\n${translateObjectBody(aliasType, aliases, aliasName, ' ')}\n};\n`;\n}\n\nfunction generateNestedAliasesInCorrectOrder(\n aliases: AliasMap,\n aliasCode: AliasCodeMap,\n aliasOrder: string[],\n): void {\n // retrieve and clean all ungenerated aliases\n const jobs = aliases.jobs;\n aliases.jobs = [];\n\n // generate each one in its found order\n for (const aliasName of jobs) {\n // generate a new struct and all fields will be examined\n // new anonymous objects could be found\n // they will be stored in aliases.jobs\n generateSingleAlias(aliases, aliasName, aliasCode);\n // nested C++ structs must be put before the current C++ struct\n // as they will be used in the current C++ struct\n // the order will be perfectly and easily ensured by doing this recursively\n generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder);\n // all referenced C++ structs are generated\n // put the current one following them\n aliasOrder.push(aliasName);\n }\n}\n\nexport function generateAliases(aliases: AliasMap): string {\n const aliasCode: AliasCodeMap = {};\n const aliasOrder: string[] = [];\n generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder);\n\n // aliasOrder now has the correct order of C++ struct code\n let traversedAliasedStructs = '';\n for (const aliasName of aliasOrder) {\n traversedAliasedStructs = `${traversedAliasedStructs}${aliasCode[aliasName]}`;\n }\n return traversedAliasedStructs;\n}\n"]}
|