@react-native-windows/codegen 0.71.5 → 0.71.7
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 +21 -5
- package/lib-commonjs/Cli.js +23 -1
- package/lib-commonjs/Cli.js.map +1 -1
- package/lib-commonjs/generators/AliasGen.d.ts +2 -1
- package/lib-commonjs/generators/AliasGen.js +33 -17
- package/lib-commonjs/generators/AliasGen.js.map +1 -1
- package/lib-commonjs/generators/GenerateNM2.d.ts +5 -2
- package/lib-commonjs/generators/GenerateNM2.js +68 -20
- package/lib-commonjs/generators/GenerateNM2.js.map +1 -1
- package/lib-commonjs/generators/ObjectTypes.d.ts +6 -2
- package/lib-commonjs/generators/ObjectTypes.js +9 -9
- package/lib-commonjs/generators/ObjectTypes.js.map +1 -1
- package/lib-commonjs/generators/ParamTypes.d.ts +3 -2
- package/lib-commonjs/generators/ParamTypes.js +27 -27
- package/lib-commonjs/generators/ParamTypes.js.map +1 -1
- package/lib-commonjs/generators/ReturnTypes.d.ts +3 -2
- package/lib-commonjs/generators/ReturnTypes.js +7 -7
- package/lib-commonjs/generators/ReturnTypes.js.map +1 -1
- package/lib-commonjs/generators/ValidateMethods.d.ts +2 -1
- package/lib-commonjs/generators/ValidateMethods.js +15 -15
- package/lib-commonjs/generators/ValidateMethods.js.map +1 -1
- package/lib-commonjs/index.d.ts +11 -13
- package/lib-commonjs/index.js +8 -4
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Cli.ts +31 -2
- package/src/generators/AliasGen.ts +61 -17
- package/src/generators/GenerateNM2.ts +86 -17
- package/src/generators/ObjectTypes.ts +15 -3
- package/src/generators/ParamTypes.ts +43 -9
- package/src/generators/ReturnTypes.ts +18 -3
- package/src/generators/ValidateMethods.ts +32 -4
- package/src/index.ts +23 -14
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
NativeModuleSchema,
|
|
13
13
|
} from 'react-native-tscodegen';
|
|
14
14
|
import {AliasMap} from './AliasManaging';
|
|
15
|
+
import type {CppCodegenOptions} from './ObjectTypes';
|
|
15
16
|
import {translateArgs, translateSpecArgs} from './ParamTypes';
|
|
16
17
|
import {translateImplReturnType, translateSpecReturnType} from './ReturnTypes';
|
|
17
18
|
|
|
@@ -27,8 +28,9 @@ function getPossibleMethodSignatures(
|
|
|
27
28
|
funcType: NativeModuleFunctionTypeAnnotation,
|
|
28
29
|
aliases: AliasMap,
|
|
29
30
|
baseAliasName: string,
|
|
31
|
+
options: CppCodegenOptions,
|
|
30
32
|
): string[] {
|
|
31
|
-
const args = translateArgs(funcType.params, aliases, baseAliasName);
|
|
33
|
+
const args = translateArgs(funcType.params, aliases, baseAliasName, options);
|
|
32
34
|
if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {
|
|
33
35
|
if (funcType.returnTypeAnnotation.elementType) {
|
|
34
36
|
args.push(
|
|
@@ -36,6 +38,7 @@ function getPossibleMethodSignatures(
|
|
|
36
38
|
funcType.returnTypeAnnotation.elementType,
|
|
37
39
|
aliases,
|
|
38
40
|
baseAliasName,
|
|
41
|
+
options,
|
|
39
42
|
)}> &&result`,
|
|
40
43
|
);
|
|
41
44
|
} else {
|
|
@@ -50,6 +53,7 @@ function getPossibleMethodSignatures(
|
|
|
50
53
|
funcType.returnTypeAnnotation,
|
|
51
54
|
aliases,
|
|
52
55
|
baseAliasName,
|
|
56
|
+
options,
|
|
53
57
|
)} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;
|
|
54
58
|
|
|
55
59
|
const staticsig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${
|
|
@@ -58,6 +62,7 @@ function getPossibleMethodSignatures(
|
|
|
58
62
|
funcType.returnTypeAnnotation,
|
|
59
63
|
aliases,
|
|
60
64
|
baseAliasName,
|
|
65
|
+
options,
|
|
61
66
|
)} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;
|
|
62
67
|
|
|
63
68
|
return [sig, staticsig];
|
|
@@ -68,8 +73,15 @@ function translatePossibleMethodSignatures(
|
|
|
68
73
|
funcType: NativeModuleFunctionTypeAnnotation,
|
|
69
74
|
aliases: AliasMap,
|
|
70
75
|
baseAliasName: string,
|
|
76
|
+
options: CppCodegenOptions,
|
|
71
77
|
): string {
|
|
72
|
-
return getPossibleMethodSignatures(
|
|
78
|
+
return getPossibleMethodSignatures(
|
|
79
|
+
prop,
|
|
80
|
+
funcType,
|
|
81
|
+
aliases,
|
|
82
|
+
baseAliasName,
|
|
83
|
+
options,
|
|
84
|
+
)
|
|
73
85
|
.map(sig => `" ${sig}\\n"`)
|
|
74
86
|
.join('\n ');
|
|
75
87
|
}
|
|
@@ -78,6 +90,7 @@ function renderProperties(
|
|
|
78
90
|
properties: ReadonlyArray<NativeModulePropertyShape>,
|
|
79
91
|
aliases: AliasMap,
|
|
80
92
|
tuple: boolean,
|
|
93
|
+
options: CppCodegenOptions,
|
|
81
94
|
): string {
|
|
82
95
|
// TODO: generate code for constants
|
|
83
96
|
return properties
|
|
@@ -95,12 +108,14 @@ function renderProperties(
|
|
|
95
108
|
funcType.params,
|
|
96
109
|
aliases,
|
|
97
110
|
propAliasName,
|
|
111
|
+
options,
|
|
98
112
|
);
|
|
99
113
|
|
|
100
114
|
const translatedReturnParam = translateSpecReturnType(
|
|
101
115
|
funcType.returnTypeAnnotation,
|
|
102
116
|
aliases,
|
|
103
117
|
propAliasName,
|
|
118
|
+
options,
|
|
104
119
|
);
|
|
105
120
|
|
|
106
121
|
if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {
|
|
@@ -110,6 +125,7 @@ function renderProperties(
|
|
|
110
125
|
funcType.returnTypeAnnotation.elementType,
|
|
111
126
|
aliases,
|
|
112
127
|
propAliasName,
|
|
128
|
+
options,
|
|
113
129
|
)}>`,
|
|
114
130
|
);
|
|
115
131
|
} else {
|
|
@@ -132,6 +148,7 @@ function renderProperties(
|
|
|
132
148
|
funcType,
|
|
133
149
|
aliases,
|
|
134
150
|
propAliasName,
|
|
151
|
+
options,
|
|
135
152
|
)});`;
|
|
136
153
|
}
|
|
137
154
|
})
|
|
@@ -141,9 +158,20 @@ function renderProperties(
|
|
|
141
158
|
export function generateValidateMethods(
|
|
142
159
|
nativeModule: NativeModuleSchema,
|
|
143
160
|
aliases: AliasMap,
|
|
161
|
+
options: CppCodegenOptions,
|
|
144
162
|
): [string, string] {
|
|
145
163
|
const properties = nativeModule.spec.properties;
|
|
146
|
-
const traversedProperties = renderProperties(
|
|
147
|
-
|
|
164
|
+
const traversedProperties = renderProperties(
|
|
165
|
+
properties,
|
|
166
|
+
aliases,
|
|
167
|
+
false,
|
|
168
|
+
options,
|
|
169
|
+
);
|
|
170
|
+
const traversedPropertyTuples = renderProperties(
|
|
171
|
+
properties,
|
|
172
|
+
aliases,
|
|
173
|
+
true,
|
|
174
|
+
options,
|
|
175
|
+
);
|
|
148
176
|
return [traversedPropertyTuples, traversedProperties];
|
|
149
177
|
}
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import fs from '@react-native-windows/fs';
|
|
10
10
|
import globby from 'globby';
|
|
11
|
+
import type {CppStringTypes} from './generators/GenerateNM2';
|
|
11
12
|
import {createNM2Generator} from './generators/GenerateNM2';
|
|
12
13
|
import {
|
|
13
14
|
generateTypeScript,
|
|
@@ -15,7 +16,9 @@ import {
|
|
|
15
16
|
} from './generators/GenerateTypeScript';
|
|
16
17
|
import type {SchemaType} from 'react-native-tscodegen';
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
export type {CppStringTypes} from './generators/GenerateNM2';
|
|
20
|
+
|
|
21
|
+
// Load @react-native/codegen from react-native
|
|
19
22
|
const rnPath = path.dirname(require.resolve('react-native/package.json'));
|
|
20
23
|
const rncodegenPath = path.dirname(
|
|
21
24
|
require.resolve('react-native-codegen/package.json', {paths: [rnPath]}),
|
|
@@ -31,15 +34,20 @@ const schemaValidator = require(path.resolve(
|
|
|
31
34
|
'lib/SchemaValidator',
|
|
32
35
|
));
|
|
33
36
|
|
|
34
|
-
interface
|
|
37
|
+
export interface SharedOptions {
|
|
35
38
|
libraryName: string;
|
|
36
39
|
methodOnly: boolean;
|
|
37
40
|
modulesCxx: boolean;
|
|
38
|
-
moduleSpecName: string;
|
|
39
41
|
modulesTypeScriptTypes: boolean;
|
|
40
42
|
modulesWindows: boolean;
|
|
41
43
|
namespace: string;
|
|
42
44
|
outputDirectory: string;
|
|
45
|
+
cppStringType: CppStringTypes;
|
|
46
|
+
separateDataTypes: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface Options extends SharedOptions {
|
|
50
|
+
moduleSpecName: string;
|
|
43
51
|
schema: SchemaType;
|
|
44
52
|
}
|
|
45
53
|
|
|
@@ -183,11 +191,13 @@ export function generate(
|
|
|
183
191
|
libraryName,
|
|
184
192
|
methodOnly,
|
|
185
193
|
modulesCxx,
|
|
186
|
-
moduleSpecName,
|
|
187
194
|
modulesTypeScriptTypes,
|
|
188
195
|
modulesWindows,
|
|
189
196
|
namespace,
|
|
190
197
|
outputDirectory,
|
|
198
|
+
cppStringType,
|
|
199
|
+
separateDataTypes,
|
|
200
|
+
moduleSpecName,
|
|
191
201
|
schema,
|
|
192
202
|
}: Options,
|
|
193
203
|
{/*generators,*/ test}: Config,
|
|
@@ -210,6 +220,8 @@ export function generate(
|
|
|
210
220
|
const generateNM2 = createNM2Generator({
|
|
211
221
|
methodOnly,
|
|
212
222
|
namespace,
|
|
223
|
+
cppStringType,
|
|
224
|
+
separateDataTypes,
|
|
213
225
|
});
|
|
214
226
|
|
|
215
227
|
const generateJsiModuleH = require(path.resolve(
|
|
@@ -315,18 +327,11 @@ export function generate(
|
|
|
315
327
|
return writeMapToFiles(generatedFiles, outputDirectory);
|
|
316
328
|
}
|
|
317
329
|
|
|
318
|
-
export
|
|
330
|
+
export interface CodeGenOptions extends SharedOptions {
|
|
319
331
|
file?: string;
|
|
320
332
|
files?: string[];
|
|
321
|
-
libraryName: string;
|
|
322
|
-
methodOnly: boolean;
|
|
323
|
-
modulesCxx: boolean;
|
|
324
|
-
modulesTypeScriptTypes: boolean;
|
|
325
|
-
modulesWindows: boolean;
|
|
326
|
-
namespace: string;
|
|
327
|
-
outputDirectory: string;
|
|
328
333
|
test: boolean;
|
|
329
|
-
}
|
|
334
|
+
}
|
|
330
335
|
|
|
331
336
|
export function runCodeGen(options: CodeGenOptions): boolean {
|
|
332
337
|
if (!options.file && !options.files)
|
|
@@ -345,17 +350,21 @@ export function runCodeGen(options: CodeGenOptions): boolean {
|
|
|
345
350
|
modulesWindows,
|
|
346
351
|
namespace,
|
|
347
352
|
outputDirectory,
|
|
353
|
+
cppStringType,
|
|
354
|
+
separateDataTypes,
|
|
348
355
|
} = options;
|
|
349
356
|
return generate(
|
|
350
357
|
{
|
|
351
358
|
libraryName,
|
|
352
359
|
methodOnly,
|
|
353
360
|
modulesCxx,
|
|
354
|
-
moduleSpecName,
|
|
355
361
|
modulesTypeScriptTypes,
|
|
356
362
|
modulesWindows,
|
|
357
363
|
namespace,
|
|
358
364
|
outputDirectory,
|
|
365
|
+
cppStringType,
|
|
366
|
+
separateDataTypes,
|
|
367
|
+
moduleSpecName,
|
|
359
368
|
schema,
|
|
360
369
|
},
|
|
361
370
|
{generators: [], test: options.test},
|