@react-native-windows/codegen 0.66.1 → 0.68.0-preview.2
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 +126 -12
- package/bin.js +0 -0
- package/lib-commonjs/Cli.d.ts +7 -0
- package/lib-commonjs/Cli.js +199 -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 +24 -13
- package/src/Cli.ts +41 -33
- 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 +146 -41
- 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/CHANGELOG.json +0 -703
- package/jest.config.js +0 -1
- package/tsconfig.json +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,32 +1,146 @@
|
|
|
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, 14 Feb 2022 16:07:42 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## 0.
|
|
7
|
+
## 0.68.0-preview.2
|
|
8
8
|
|
|
9
|
-
Mon,
|
|
9
|
+
Mon, 14 Feb 2022 16:07:42 GMT
|
|
10
10
|
|
|
11
|
-
###
|
|
11
|
+
### Changes
|
|
12
12
|
|
|
13
|
-
-
|
|
13
|
+
- [0.68] Bump minimum Node version to 14 (jthysell@microsoft.com)
|
|
14
|
+
- Bump @react-native-windows/fs to v0.68.0-preview.2
|
|
14
15
|
|
|
15
|
-
## 0.
|
|
16
|
+
## 0.68.0-preview.1
|
|
16
17
|
|
|
17
|
-
Mon,
|
|
18
|
+
Mon, 07 Feb 2022 16:09:26 GMT
|
|
18
19
|
|
|
19
|
-
###
|
|
20
|
+
### Changes
|
|
21
|
+
|
|
22
|
+
- Promote 0.68 to preview (ngerlem@microsoft.com)
|
|
23
|
+
- Move @react-native-windows/fs to promoteRelease scheme (ngerlem@microsoft.com)
|
|
24
|
+
- Bump @react-native-windows/fs to v0.68.0-preview.1
|
|
25
|
+
|
|
26
|
+
## 0.0.0-canary.23
|
|
27
|
+
|
|
28
|
+
Sat, 29 Jan 2022 06:08:58 GMT
|
|
29
|
+
|
|
30
|
+
### Changes
|
|
31
|
+
|
|
32
|
+
- Add document for turbo module codegen (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
33
|
+
|
|
34
|
+
## 0.0.0-canary.22
|
|
35
|
+
|
|
36
|
+
Fri, 03 Dec 2021 06:12:10 GMT
|
|
37
|
+
|
|
38
|
+
### Changes
|
|
39
|
+
|
|
40
|
+
- Integrate 11/11 (34109996+chiaramooney@users.noreply.github.com)
|
|
41
|
+
- Bump @react-native-windows/fs to v1.0.1
|
|
42
|
+
- Bump @rnw-scripts/eslint-config to v1.1.10
|
|
43
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.2.5
|
|
44
|
+
- Bump @rnw-scripts/just-task to v2.2.2
|
|
45
|
+
|
|
46
|
+
## 0.0.0-canary.21
|
|
47
|
+
|
|
48
|
+
Thu, 18 Nov 2021 06:11:20 GMT
|
|
49
|
+
|
|
50
|
+
### Changes
|
|
51
|
+
|
|
52
|
+
- Use '@react-native-windows/fs' (ngerlem@microsoft.com)
|
|
53
|
+
- Bump @react-native-windows/fs to v1.0.0
|
|
54
|
+
- Bump @rnw-scripts/eslint-config to v1.1.9
|
|
55
|
+
|
|
56
|
+
## 0.0.0-canary.20
|
|
57
|
+
|
|
58
|
+
Thu, 04 Nov 2021 05:07:29 GMT
|
|
59
|
+
|
|
60
|
+
### Changes
|
|
61
|
+
|
|
62
|
+
- Codegen prints `::React::JSValue` instead of `React::JSValue` (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
63
|
+
|
|
64
|
+
## 0.0.0-canary.20
|
|
65
|
+
|
|
66
|
+
Thu, 04 Nov 2021 05:07:08 GMT
|
|
67
|
+
|
|
68
|
+
### Changes
|
|
69
|
+
|
|
70
|
+
- Codegen prints `::React::JSValue` instead of `React::JSValue` (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
71
|
+
|
|
72
|
+
## 0.0.0-canary.19
|
|
73
|
+
|
|
74
|
+
Sat, 23 Oct 2021 05:06:49 GMT
|
|
75
|
+
|
|
76
|
+
### Changes
|
|
77
|
+
|
|
78
|
+
- Only generate component files if a component is specified (30809111+acoates-ms@users.noreply.github.com)
|
|
20
79
|
|
|
21
|
-
|
|
80
|
+
## 0.0.0-canary.18
|
|
22
81
|
|
|
23
|
-
|
|
82
|
+
Fri, 22 Oct 2021 05:06:46 GMT
|
|
83
|
+
|
|
84
|
+
### Changes
|
|
85
|
+
|
|
86
|
+
- Built files not included in published package (30809111+acoates-ms@users.noreply.github.com)
|
|
87
|
+
|
|
88
|
+
## 0.0.0-canary.17
|
|
89
|
+
|
|
90
|
+
Thu, 21 Oct 2021 05:08:01 GMT
|
|
91
|
+
|
|
92
|
+
### Changes
|
|
93
|
+
|
|
94
|
+
- Update to typescript 4 (30809111+acoates-ms@users.noreply.github.com)
|
|
95
|
+
|
|
96
|
+
## 0.0.0-canary.16
|
|
97
|
+
|
|
98
|
+
Wed, 29 Sep 2021 05:06:54 GMT
|
|
99
|
+
|
|
100
|
+
### Changes
|
|
101
|
+
|
|
102
|
+
- Check constants in generated turbo module specs (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
103
|
+
|
|
104
|
+
## 0.0.0-canary.15
|
|
105
|
+
|
|
106
|
+
Wed, 15 Sep 2021 05:07:04 GMT
|
|
107
|
+
|
|
108
|
+
### Changes
|
|
109
|
+
|
|
110
|
+
- Generate anonymous objects in correct order for turbo module (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
111
|
+
|
|
112
|
+
## 0.0.0-canary.14
|
|
113
|
+
|
|
114
|
+
Fri, 10 Sep 2021 05:07:31 GMT
|
|
115
|
+
|
|
116
|
+
### Changes
|
|
117
|
+
|
|
118
|
+
- Generate `std::vector<T>` for array types in turbo modules (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
119
|
+
|
|
120
|
+
## 0.0.0-canary.13
|
|
121
|
+
|
|
122
|
+
Thu, 09 Sep 2021 05:07:46 GMT
|
|
123
|
+
|
|
124
|
+
### Changes
|
|
125
|
+
|
|
126
|
+
- Bump to 0.66-based react-native-tscodegen (ngerlem@microsoft.com)
|
|
127
|
+
- Generate nullable type for turbo module (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
128
|
+
|
|
129
|
+
## 0.0.0-canary.12
|
|
130
|
+
|
|
131
|
+
Wed, 08 Sep 2021 05:08:53 GMT
|
|
132
|
+
|
|
133
|
+
### Patches
|
|
24
134
|
|
|
25
|
-
|
|
135
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.2.4 (ngerlem@microsoft.com)
|
|
136
|
+
- Bump @rnw-scripts/just-task to v2.2.1 (ngerlem@microsoft.com)
|
|
137
|
+
- Bump @rnw-scripts/ts-config to v2.0.1 (ngerlem@microsoft.com)
|
|
138
|
+
- Bump @rnw-scripts/eslint-config to v1.1.8 (ngerlem@microsoft.com)
|
|
26
139
|
|
|
27
140
|
### Changes
|
|
28
141
|
|
|
29
|
-
-
|
|
142
|
+
- Set consistent node requirements on our packages (ngerlem@microsoft.com)
|
|
143
|
+
- Match Alert module with NativeDialogManagerWindowsSpec.h (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
30
144
|
|
|
31
145
|
## 0.0.0-canary.11
|
|
32
146
|
|
package/bin.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,199 @@
|
|
|
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
|
+
// @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()]
|
|
82
|
+
.map((_) => path_1.default.normalize(_))
|
|
83
|
+
.sort();
|
|
84
|
+
if (allExistingFiles.length !== allGeneratedFiles.length ||
|
|
85
|
+
!allExistingFiles.every((val, index) => val === allGeneratedFiles[index]))
|
|
86
|
+
return true;
|
|
87
|
+
for (const [fileName, contents] of map) {
|
|
88
|
+
if (!fs_1.default.existsSync(fileName)) {
|
|
89
|
+
hasChanges = true;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const currentContents = fs_1.default.readFileSync(fileName, 'utf8');
|
|
93
|
+
if (currentContents !== contents) {
|
|
94
|
+
console.error(`- ${fileName} has changed`);
|
|
95
|
+
hasChanges = true;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return hasChanges;
|
|
100
|
+
}
|
|
101
|
+
function writeMapToFiles(map, outputDir) {
|
|
102
|
+
let success = true;
|
|
103
|
+
// This ensures that we delete any generated files from modules that have been deleted
|
|
104
|
+
const allExistingFiles = globby_1.default.sync(`${outputDir}/**`);
|
|
105
|
+
allExistingFiles.forEach((existingFile) => {
|
|
106
|
+
if (!map.has(path_1.default.normalize(existingFile))) {
|
|
107
|
+
fs_1.default.unlinkSync(existingFile);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
for (const [fileName, contents] of map) {
|
|
111
|
+
try {
|
|
112
|
+
fs_1.default.mkdirSync(path_1.default.dirname(fileName), { recursive: true });
|
|
113
|
+
if (fs_1.default.existsSync(fileName)) {
|
|
114
|
+
const currentContents = fs_1.default.readFileSync(fileName, 'utf8');
|
|
115
|
+
// Don't update the files if there are no changes as this breaks incremental builds
|
|
116
|
+
if (currentContents === contents) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
fs_1.default.writeFileSync(fileName, contents);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
success = false;
|
|
124
|
+
console.error(`Failed to write ${fileName} to ${fileName}`, error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return success;
|
|
128
|
+
}
|
|
129
|
+
function parseFlowFile(filename) {
|
|
130
|
+
try {
|
|
131
|
+
return (0, flow_1.parseFile)(filename);
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
if (e instanceof Error) {
|
|
135
|
+
e.message = `(${filename}): ${e.message}`;
|
|
136
|
+
}
|
|
137
|
+
throw e;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function combineSchemas(files) {
|
|
141
|
+
return files.reduce((merged, filename) => {
|
|
142
|
+
const contents = fs_1.default.readFileSync(filename, 'utf8');
|
|
143
|
+
if (contents &&
|
|
144
|
+
(/export\s+default\s+\(?codegenNativeComponent</.test(contents) ||
|
|
145
|
+
contents.includes('extends TurboModule'))) {
|
|
146
|
+
const schema = parseFlowFile(filename);
|
|
147
|
+
merged.modules = { ...merged.modules, ...schema.modules };
|
|
148
|
+
}
|
|
149
|
+
return merged;
|
|
150
|
+
}, { modules: {} });
|
|
151
|
+
}
|
|
152
|
+
function generate({ libraryName, schema, outputDirectory, moduleSpecName }, { /*generators,*/ test }) {
|
|
153
|
+
schemaValidator_1.default.validate(schema);
|
|
154
|
+
const componentOutputdir = path_1.default.join(outputDirectory, 'react/components', libraryName);
|
|
155
|
+
const generatedFiles = new Map();
|
|
156
|
+
generatedFiles.set(path_1.default.join(outputDirectory, '.clang-format'), 'DisableFormat: true\nSortIncludes: false');
|
|
157
|
+
const generateNM2 = (0, GenerateNM2_1.createNM2Generator)({ namespace: argv.namespace });
|
|
158
|
+
const generatorPropsH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH').generate;
|
|
159
|
+
const generatorPropsCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP').generate;
|
|
160
|
+
const generatorShadowNodeH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH').generate;
|
|
161
|
+
const generatorShadowNodeCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP').generate;
|
|
162
|
+
const generatorComponentDescriptorH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH').generate;
|
|
163
|
+
const generatorEventEmitterH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH').generate;
|
|
164
|
+
normalizeFileMap(generateNM2(libraryName, schema, moduleSpecName), outputDirectory, generatedFiles);
|
|
165
|
+
if (Object.keys(schema.modules).some((moduleName) => schema.modules[moduleName].type === 'Component')) {
|
|
166
|
+
const componentGenerators = [
|
|
167
|
+
generatorPropsH,
|
|
168
|
+
generatorPropsCPP,
|
|
169
|
+
generatorShadowNodeH,
|
|
170
|
+
generatorShadowNodeCPP,
|
|
171
|
+
generatorComponentDescriptorH,
|
|
172
|
+
generatorEventEmitterH,
|
|
173
|
+
];
|
|
174
|
+
componentGenerators.forEach((generator) => {
|
|
175
|
+
const generated = generator(libraryName, schema, moduleSpecName);
|
|
176
|
+
normalizeFileMap(generated, componentOutputdir, generatedFiles);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
if (test === true) {
|
|
180
|
+
return checkFilesForChanges(generatedFiles, outputDirectory);
|
|
181
|
+
}
|
|
182
|
+
return writeMapToFiles(generatedFiles, outputDirectory);
|
|
183
|
+
}
|
|
184
|
+
if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
|
|
185
|
+
console.error('You must specify either --file or --files.');
|
|
186
|
+
process.exit(1);
|
|
187
|
+
}
|
|
188
|
+
let schema;
|
|
189
|
+
if (argv.file) {
|
|
190
|
+
schema = parseFlowFile(argv.file);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
schema = combineSchemas(globby_1.default.sync(argv.files));
|
|
194
|
+
}
|
|
195
|
+
const libraryName = argv.libraryName;
|
|
196
|
+
const moduleSpecName = 'moduleSpecName';
|
|
197
|
+
const outputDirectory = 'codegen';
|
|
198
|
+
generate({ libraryName, schema, outputDirectory, moduleSpecName }, { generators: [], test: false });
|
|
199
|
+
//# 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,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,QA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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,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 '@react-native-windows/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()]\n .map((_) => path.normalize(_))\n .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 =\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\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;
|
|
@@ -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,OAAiB,EACjB,aAAqB,EACrB,MAAc;IAEd,OAAO,IAAI,CAAC,UAAU;SACnB,GAAG,CAAC,CAAC,IAA0D,EAAE,EAAE;QAClE,IAAI,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC;QACnC,IAAI,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,wBAAwB,EAAE;YAC/D,QAAQ,GAAG,EAAC,IAAI,EAAE,wBAAwB,EAAE,cAAc,EAAE,QAAQ,EAAC,CAAC;SACvE;QACD,MAAM,KAAK,GAAG,GAAG,MAAM,eAAe,IAAI,CAAC,IAAI,GAAG,CAAC;QACnD,MAAM,MAAM,GAAG,GAAG,MAAM,GAAG,IAAA,4BAAc,EACvC,QAAQ,EACR,OAAO,EACP,GAAG,aAAa,IAAI,IAAI,CAAC,IAAI,EAAE,CAChC,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC;QAClB,OAAO,GAAG,KAAK,KAAK,MAAM,EAAE,CAAC;IAC/B,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,SAAgB,cAAc,CAAC,mBAE9B;IACC,MAAM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AAC;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"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
* @format
|
|
5
|
+
*/
|
|
6
|
+
import { NativeModuleObjectTypeAnnotation } from 'react-native-tscodegen';
|
|
7
|
+
export declare function setPreferredModuleName(moduleName: string): void;
|
|
8
|
+
export declare function getAliasCppName(typeName: string): string;
|
|
9
|
+
export interface AliasMap {
|
|
10
|
+
types: {
|
|
11
|
+
[name: string]: NativeModuleObjectTypeAnnotation | undefined;
|
|
12
|
+
};
|
|
13
|
+
jobs: string[];
|
|
14
|
+
}
|
|
15
|
+
export declare function getAnonymousAliasCppName(aliases: AliasMap, baseAliasName: string, objectType: NativeModuleObjectTypeAnnotation): string;
|
|
@@ -0,0 +1,49 @@
|
|
|
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.getAnonymousAliasCppName = exports.getAliasCppName = exports.setPreferredModuleName = void 0;
|
|
9
|
+
let preferredModuleName = '';
|
|
10
|
+
function setPreferredModuleName(moduleName) {
|
|
11
|
+
preferredModuleName = moduleName;
|
|
12
|
+
}
|
|
13
|
+
exports.setPreferredModuleName = setPreferredModuleName;
|
|
14
|
+
function getAliasCppName(typeName) {
|
|
15
|
+
return `${preferredModuleName}Spec_${typeName}`;
|
|
16
|
+
}
|
|
17
|
+
exports.getAliasCppName = getAliasCppName;
|
|
18
|
+
const ExtendedObjectKey = '$RNW-TURBOMODULE-ALIAS';
|
|
19
|
+
function recordAnonymouseAlias(aliases, baseAliasName, extended) {
|
|
20
|
+
extended[ExtendedObjectKey] = baseAliasName;
|
|
21
|
+
aliases.types[baseAliasName] = extended;
|
|
22
|
+
aliases.jobs.push(baseAliasName);
|
|
23
|
+
return baseAliasName;
|
|
24
|
+
}
|
|
25
|
+
function getAnonymousAliasCppName(aliases, baseAliasName, objectType) {
|
|
26
|
+
// someone found an anonymous object literal type
|
|
27
|
+
// if the ExtendedObjectKey flag has been set
|
|
28
|
+
// then it is a known one
|
|
29
|
+
// this happens because method signatures are generate twice in spec and error messages
|
|
30
|
+
const extended = objectType;
|
|
31
|
+
const key = extended[ExtendedObjectKey];
|
|
32
|
+
if (key !== undefined) {
|
|
33
|
+
return getAliasCppName(key);
|
|
34
|
+
}
|
|
35
|
+
// if the ExtendedObjectKey flag has not been set
|
|
36
|
+
// it means it is a unknown one
|
|
37
|
+
// associate the name with this object literal type and return
|
|
38
|
+
if (aliases.types[baseAliasName] === undefined) {
|
|
39
|
+
return getAliasCppName(recordAnonymouseAlias(aliases, baseAliasName, extended));
|
|
40
|
+
}
|
|
41
|
+
// sometimes names could be anonymous
|
|
42
|
+
let index = 2;
|
|
43
|
+
while (aliases.types[`${baseAliasName}${index}`] !== undefined) {
|
|
44
|
+
index++;
|
|
45
|
+
}
|
|
46
|
+
return getAliasCppName(recordAnonymouseAlias(aliases, `${baseAliasName}${index}`, extended));
|
|
47
|
+
}
|
|
48
|
+
exports.getAnonymousAliasCppName = getAnonymousAliasCppName;
|
|
49
|
+
//# sourceMappingURL=AliasManaging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AliasManaging.js","sourceRoot":"","sources":["../../src/generators/AliasManaging.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAIb,IAAI,mBAAmB,GAAW,EAAE,CAAC;AAErC,SAAgB,sBAAsB,CAAC,UAAkB;IACvD,mBAAmB,GAAG,UAAU,CAAC;AACnC,CAAC;AAFD,wDAEC;AAED,SAAgB,eAAe,CAAC,QAAgB;IAC9C,OAAO,GAAG,mBAAmB,QAAQ,QAAQ,EAAE,CAAC;AAClD,CAAC;AAFD,0CAEC;AAOD,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAKnD,SAAS,qBAAqB,CAC5B,OAAiB,EACjB,aAAqB,EACrB,QAAwB;IAExB,QAAQ,CAAC,iBAAiB,CAAC,GAAG,aAAa,CAAC;IAC5C,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACjC,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAgB,wBAAwB,CACtC,OAAiB,EACjB,aAAqB,EACrB,UAA4C;IAE5C,iDAAiD;IACjD,6CAA6C;IAC7C,yBAAyB;IACzB,uFAAuF;IACvF,MAAM,QAAQ,GAAmB,UAAU,CAAC;IAC5C,MAAM,GAAG,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACxC,IAAI,GAAG,KAAK,SAAS,EAAE;QACrB,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;KAC7B;IAED,iDAAiD;IACjD,+BAA+B;IAC/B,8DAA8D;IAC9D,IAAI,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,SAAS,EAAE;QAC9C,OAAO,eAAe,CACpB,qBAAqB,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,CACxD,CAAC;KACH;IAED,qCAAqC;IACrC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,aAAa,GAAG,KAAK,EAAE,CAAC,KAAK,SAAS,EAAE;QAC9D,KAAK,EAAE,CAAC;KACT;IAED,OAAO,eAAe,CACpB,qBAAqB,CAAC,OAAO,EAAE,GAAG,aAAa,GAAG,KAAK,EAAE,EAAE,QAAQ,CAAC,CACrE,CAAC;AACJ,CAAC;AAjCD,4DAiCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {NativeModuleObjectTypeAnnotation} from 'react-native-tscodegen';\n\nlet preferredModuleName: string = '';\n\nexport function setPreferredModuleName(moduleName: string): void {\n preferredModuleName = moduleName;\n}\n\nexport function getAliasCppName(typeName: string): string {\n return `${preferredModuleName}Spec_${typeName}`;\n}\n\nexport interface AliasMap {\n types: {[name: string]: NativeModuleObjectTypeAnnotation | undefined};\n jobs: string[];\n}\n\nconst ExtendedObjectKey = '$RNW-TURBOMODULE-ALIAS';\ninterface ExtendedObject extends NativeModuleObjectTypeAnnotation {\n '$RNW-TURBOMODULE-ALIAS'?: string;\n}\n\nfunction recordAnonymouseAlias(\n aliases: AliasMap,\n baseAliasName: string,\n extended: ExtendedObject,\n): string {\n extended[ExtendedObjectKey] = baseAliasName;\n aliases.types[baseAliasName] = extended;\n aliases.jobs.push(baseAliasName);\n return baseAliasName;\n}\n\nexport function getAnonymousAliasCppName(\n aliases: AliasMap,\n baseAliasName: string,\n objectType: NativeModuleObjectTypeAnnotation,\n): string {\n // someone found an anonymous object literal type\n // if the ExtendedObjectKey flag has been set\n // then it is a known one\n // this happens because method signatures are generate twice in spec and error messages\n const extended = <ExtendedObject>objectType;\n const key = extended[ExtendedObjectKey];\n if (key !== undefined) {\n return getAliasCppName(key);\n }\n\n // if the ExtendedObjectKey flag has not been set\n // it means it is a unknown one\n // associate the name with this object literal type and return\n if (aliases.types[baseAliasName] === undefined) {\n return getAliasCppName(\n recordAnonymouseAlias(aliases, baseAliasName, extended),\n );\n }\n\n // sometimes names could be anonymous\n let index = 2;\n while (aliases.types[`${baseAliasName}${index}`] !== undefined) {\n index++;\n }\n\n return getAliasCppName(\n recordAnonymouseAlias(aliases, `${baseAliasName}${index}`, extended),\n );\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
* @format
|
|
5
|
+
*/
|
|
6
|
+
import { SchemaType } from 'react-native-tscodegen';
|
|
7
|
+
declare type FilesOutput = Map<string, string>;
|
|
8
|
+
export declare function createNM2Generator({ namespace }: {
|
|
9
|
+
namespace: string;
|
|
10
|
+
}): (_libraryName: string, schema: SchemaType, _moduleSpecName: string) => FilesOutput;
|
|
11
|
+
export {};
|