@react-native-windows/codegen 0.0.0-canary.42 → 0.0.0-canary.44
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 +24 -7
- package/lib-commonjs/Cli.js +13 -3
- package/lib-commonjs/Cli.js.map +1 -1
- package/lib-commonjs/generators/GenerateNM2.d.ts +2 -2
- package/lib-commonjs/generators/GenerateNM2.js +2 -2
- package/lib-commonjs/generators/GenerateNM2.js.map +1 -1
- package/lib-commonjs/index.d.ts +12 -8
- package/lib-commonjs/index.js +30 -16
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +3 -3
- package/src/Cli.ts +13 -3
- package/src/generators/GenerateNM2.ts +3 -3
- package/src/index.ts +66 -34
package/CHANGELOG.md
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
# Change Log - @react-native-windows/codegen
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 21 Nov 2022 06:15:02 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.44
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Mon, 21 Nov 2022 06:15:02 GMT
|
|
10
10
|
|
|
11
11
|
### Changes
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
- Bump @react-native-windows/fs to v0.0.0-canary.9
|
|
15
|
-
- Bump @rnw-scripts/jest-unittest-config to v1.4.1
|
|
16
|
-
- Bump @rnw-scripts/just-task to v2.3.1
|
|
13
|
+
- Enable ability to codegen JSI C++ TurboModule specs (30809111+acoates-ms@users.noreply.github.com)
|
|
17
14
|
|
|
15
|
+
## 0.0.0-canary.43
|
|
16
|
+
|
|
17
|
+
Wed, 16 Nov 2022 06:16:01 GMT
|
|
18
|
+
|
|
19
|
+
### Changes
|
|
20
|
+
|
|
21
|
+
- Bump @react-native-windows/fs to v0.0.0-canary.10
|
|
22
|
+
- Bump @rnw-scripts/just-task to v2.3.2
|
|
23
|
+
|
|
24
|
+
## 0.0.0-canary.42
|
|
25
|
+
|
|
26
|
+
Sat, 12 Nov 2022 06:17:21 GMT
|
|
27
|
+
|
|
28
|
+
### Changes
|
|
29
|
+
|
|
30
|
+
- Integrate 10/10 (34109996+chiaramooney@users.noreply.github.com)
|
|
31
|
+
- Bump @react-native-windows/fs to v0.0.0-canary.9
|
|
32
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.4.1
|
|
33
|
+
- Bump @rnw-scripts/just-task to v2.3.1
|
|
34
|
+
|
|
18
35
|
## 0.0.0-canary.41
|
|
19
36
|
|
|
20
37
|
Thu, 10 Nov 2022 06:17:10 GMT
|
package/lib-commonjs/Cli.js
CHANGED
|
@@ -21,17 +21,27 @@ const argv = yargs_1.default.options({
|
|
|
21
21
|
array: true,
|
|
22
22
|
describe: 'glob patterns for files which contains specs',
|
|
23
23
|
},
|
|
24
|
-
|
|
24
|
+
modulesTypeScriptTypes: {
|
|
25
25
|
type: 'boolean',
|
|
26
26
|
describe: 'generate turbo module definition files in TypeScript',
|
|
27
27
|
default: false,
|
|
28
28
|
},
|
|
29
|
-
|
|
29
|
+
modulesCxx: {
|
|
30
|
+
type: 'boolean',
|
|
31
|
+
describe: 'generate C++ JSI turbo module spec files',
|
|
32
|
+
default: false,
|
|
33
|
+
},
|
|
34
|
+
modulesWindows: {
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
describe: 'generate turbo module spec files for REACT_MODULE',
|
|
37
|
+
default: false,
|
|
38
|
+
},
|
|
39
|
+
methodOnly: {
|
|
30
40
|
type: 'boolean',
|
|
31
41
|
describe: 'generate only method metadata in C++ turbo module spec',
|
|
32
42
|
default: false,
|
|
33
43
|
},
|
|
34
|
-
|
|
44
|
+
outputDirectory: {
|
|
35
45
|
type: 'string',
|
|
36
46
|
describe: 'output directory',
|
|
37
47
|
default: 'codegen',
|
package/lib-commonjs/Cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kDAA0B;AAC1B,mCAAmC;AAEnC,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,QAAQ;QACd,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,8CAA8C;KACzD;IACD,
|
|
1
|
+
{"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kDAA0B;AAC1B,mCAAmC;AAEnC,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,QAAQ;QACd,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,8CAA8C;KACzD;IACD,sBAAsB,EAAE;QACtB,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,sDAAsD;QAChE,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE;QACV,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,0CAA0C;QACpD,OAAO,EAAE,KAAK;KACf;IACD,cAAc,EAAE;QACd,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,mDAAmD;QAC7D,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE;QACV,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,wDAAwD;QAClE,OAAO,EAAE,KAAK;KACf;IACD,eAAe,EAAE;QACf,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,kBAAkB;QAC5B,OAAO,EAAE,SAAS;KACnB;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,+CAA+C;QACzD,OAAO,EAAE,KAAK;KACf;IACD,SAAS,EAAE;QACT,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,qDAAqD;QAC/D,OAAO,EAAE,aAAa;KACvB;IACD,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,4DAA4D;KACvE;CACF,CAAC,CAAC,IAAI,CAAC;AAER,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,IAAA,kBAAU,EAAC,IAAI,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport {runCodeGen} from './index';\n\nconst argv = yargs.options({\n file: {\n type: 'string',\n describe: 'file which contains spec',\n },\n files: {\n type: 'string',\n array: true,\n describe: 'glob patterns for files which contains specs',\n },\n modulesTypeScriptTypes: {\n type: 'boolean',\n describe: 'generate turbo module definition files in TypeScript',\n default: false,\n },\n modulesCxx: {\n type: 'boolean',\n describe: 'generate C++ JSI turbo module spec files',\n default: false,\n },\n modulesWindows: {\n type: 'boolean',\n describe: 'generate turbo module spec files for REACT_MODULE',\n default: false,\n },\n methodOnly: {\n type: 'boolean',\n describe: 'generate only method metadata in C++ turbo module spec',\n default: false,\n },\n outputDirectory: {\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 default: false,\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\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\nrunCodeGen(argv);\n"]}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { SchemaType } from 'react-native-tscodegen';
|
|
7
7
|
declare type FilesOutput = Map<string, string>;
|
|
8
|
-
export declare function createNM2Generator({
|
|
8
|
+
export declare function createNM2Generator({ methodOnly, namespace, }: {
|
|
9
|
+
methodOnly: boolean;
|
|
9
10
|
namespace: string;
|
|
10
|
-
methodonly: boolean;
|
|
11
11
|
}): (_libraryName: string, schema: SchemaType, _moduleSpecName: string) => FilesOutput;
|
|
12
12
|
export {};
|
|
@@ -38,7 +38,7 @@ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
|
|
|
38
38
|
|
|
39
39
|
} // namespace ::_NAMESPACE_::
|
|
40
40
|
`;
|
|
41
|
-
function createNM2Generator({
|
|
41
|
+
function createNM2Generator({ methodOnly, namespace, }) {
|
|
42
42
|
return (_libraryName, schema, _moduleSpecName) => {
|
|
43
43
|
const files = new Map();
|
|
44
44
|
for (const moduleName of Object.keys(schema.modules)) {
|
|
@@ -65,7 +65,7 @@ ${methods[0]}
|
|
|
65
65
|
let errors = methods[1];
|
|
66
66
|
// prepare constants
|
|
67
67
|
const constants = (0, ValidateConstants_1.generateValidateConstants)(nativeModule, aliases);
|
|
68
|
-
if (constants !== undefined && !
|
|
68
|
+
if (constants !== undefined && !methodOnly) {
|
|
69
69
|
tuples = `
|
|
70
70
|
static constexpr auto constants = std::tuple{
|
|
71
71
|
${constants[0]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateNM2.js","sourceRoot":"","sources":["../../src/generators/GenerateNM2.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY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GAAG,IAAA,yCAAuB,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;gBAC/D,IAAI,MAAM,GAAG;;EAEnB,OAAO,CAAC,CAAC,CAAC;KACP,CAAC;gBACE,IAAI,MAAM,GAAG;wFACmE,CAAC;gBACjF,IAAI,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;gBAExB,oBAAoB;gBACpB,MAAM,SAAS,GAAG,IAAA,6CAAyB,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;gBACnE,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,UAAU,EAAE;oBAC1C,MAAM,GAAG;;EAEjB,SAAS,CAAC,CAAC,CAAC;MACR,MAAM,EAAE,CAAC;oBACL,MAAM,GAAG;6FAC0E,MAAM,EAAE,CAAC;oBAC5F,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC;;EAEhC,MAAM,EAAE,CAAC;iBACF;gBAED,4BAA4B;gBAC5B,MAAM,uBAAuB,GAAG,IAAA,0BAAe,EAAC,OAAO,CAAC,CAAC;gBAEzD,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,UAAU,EACtC,cAAc;qBACX,OAAO,CAAC,+BAA+B,EAAE,uBAAuB,CAAC;qBACjE,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;qBAC5D,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;qBAC5D,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC;qBAC/C,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC;qBAClD,OAAO,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAC1C,CAAC;aACH;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAxED,gDAwEC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {SchemaType} from 'react-native-tscodegen';\nimport {AliasMap, setPreferredModuleName} from './AliasManaging';\nimport {createAliasMap, generateAliases} from './AliasGen';\nimport {generateValidateConstants} from './ValidateConstants';\nimport {generateValidateMethods} from './ValidateMethods';\n\ntype FilesOutput = Map<string, string>;\n\nconst moduleTemplate = `\n/*\n * This file is auto-generated from a NativeModule spec file in js.\n *\n * This is a C++ Spec class that should be used with MakeTurboModuleProvider to register native modules\n * in a way that also verifies at compile time that the native module matches the interface required\n * by the TurboModule JS spec.\n */\n#pragma once\n\n#include \"NativeModules.h\"\n#include <tuple>\n\nnamespace ::_NAMESPACE_:: {\n::_MODULE_ALIASED_STRUCTS_::\nstruct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {\n::_MODULE_MEMBERS_TUPLES_::\n\n template <class TModule>\n static constexpr void ValidateModule() noexcept {\n::_MODULE_MEMBERS_CHECKS_::\n\n::_MODULE_MEMBERS_ERRORS_::\n }\n};\n\n} // namespace ::_NAMESPACE_::\n`;\n\nexport function createNM2Generator({\n methodOnly,\n namespace,\n}: {\n methodOnly: boolean;\n namespace: string;\n}) {\n return (\n _libraryName: string,\n schema: SchemaType,\n _moduleSpecName: string,\n ): FilesOutput => {\n const files = new Map<string, string>();\n\n for (const moduleName of Object.keys(schema.modules)) {\n const nativeModule = schema.modules[moduleName];\n // from 0.65 facebook's react-native-codegen\n // the module name has the Native prefix comparing to 0.63\n // when reading files we provided\n const preferredModuleName = moduleName.startsWith('Native')\n ? moduleName.substr(6)\n : moduleName;\n setPreferredModuleName(preferredModuleName);\n\n if (nativeModule.type === 'NativeModule') {\n console.log(`Generating Native${preferredModuleName}Spec.g.h`);\n\n // copy all explicit to a map\n const aliases: AliasMap = createAliasMap(nativeModule.aliases);\n\n // prepare methods\n const methods = generateValidateMethods(nativeModule, aliases);\n let tuples = `\n static constexpr auto methods = std::tuple{\n${methods[0]}\n };`;\n let checks = `\n constexpr auto methodCheckResults = CheckMethods<TModule, ::_MODULE_NAME_::Spec>();`;\n let errors = methods[1];\n\n // prepare constants\n const constants = generateValidateConstants(nativeModule, aliases);\n if (constants !== undefined && !methodOnly) {\n tuples = `\n static constexpr auto constants = std::tuple{\n${constants[0]}\n };${tuples}`;\n checks = `\n constexpr auto constantCheckResults = CheckConstants<TModule, ::_MODULE_NAME_::Spec>();${checks}`;\n errors = `${constants[1]}\n\n${errors}`;\n }\n\n // generate code for structs\n const traversedAliasedStructs = generateAliases(aliases);\n\n files.set(\n `Native${preferredModuleName}Spec.g.h`,\n moduleTemplate\n .replace(/::_MODULE_ALIASED_STRUCTS_::/g, traversedAliasedStructs)\n .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))\n .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))\n .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)\n .replace(/::_MODULE_NAME_::/g, preferredModuleName)\n .replace(/::_NAMESPACE_::/g, namespace),\n );\n }\n }\n\n return files;\n };\n}\n"]}
|
package/lib-commonjs/index.d.ts
CHANGED
|
@@ -7,12 +7,14 @@
|
|
|
7
7
|
import type { SchemaType } from 'react-native-tscodegen';
|
|
8
8
|
interface Options {
|
|
9
9
|
libraryName: string;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
methodOnly: boolean;
|
|
11
|
+
modulesCxx: boolean;
|
|
12
12
|
moduleSpecName: string;
|
|
13
|
+
modulesTypeScriptTypes: boolean;
|
|
14
|
+
modulesWindows: boolean;
|
|
13
15
|
namespace: string;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
outputDirectory: string;
|
|
17
|
+
schema: SchemaType;
|
|
16
18
|
}
|
|
17
19
|
interface Config {
|
|
18
20
|
generators: any[];
|
|
@@ -20,15 +22,17 @@ interface Config {
|
|
|
20
22
|
}
|
|
21
23
|
export declare function parseFile(filename: string): SchemaType;
|
|
22
24
|
export declare function combineSchemas(files: string[]): SchemaType;
|
|
23
|
-
export declare function generate({ libraryName,
|
|
25
|
+
export declare function generate({ libraryName, methodOnly, modulesCxx, moduleSpecName, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, schema, }: Options, { /*generators,*/ test }: Config): boolean;
|
|
24
26
|
export declare type CodeGenOptions = {
|
|
25
27
|
file?: string;
|
|
26
28
|
files?: string[];
|
|
27
29
|
libraryName: string;
|
|
28
|
-
|
|
30
|
+
methodOnly: boolean;
|
|
31
|
+
modulesCxx: boolean;
|
|
32
|
+
modulesTypeScriptTypes: boolean;
|
|
33
|
+
modulesWindows: boolean;
|
|
29
34
|
namespace: string;
|
|
30
|
-
|
|
31
|
-
ts: boolean;
|
|
35
|
+
outputDirectory: string;
|
|
32
36
|
test: boolean;
|
|
33
37
|
};
|
|
34
38
|
export declare function runCodeGen(options: CodeGenOptions): boolean;
|
package/lib-commonjs/index.js
CHANGED
|
@@ -125,15 +125,17 @@ function combineSchemas(files) {
|
|
|
125
125
|
}, { modules: {} });
|
|
126
126
|
}
|
|
127
127
|
exports.combineSchemas = combineSchemas;
|
|
128
|
-
function generate({ libraryName,
|
|
128
|
+
function generate({ libraryName, methodOnly, modulesCxx, moduleSpecName, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, schema, }, { /*generators,*/ test }) {
|
|
129
129
|
schemaValidator.validate(schema);
|
|
130
130
|
const componentOutputdir = path_1.default.join(outputDirectory, 'react/components', libraryName);
|
|
131
131
|
const generatedFiles = new Map();
|
|
132
132
|
generatedFiles.set(path_1.default.join(outputDirectory, '.clang-format'), 'DisableFormat: true\nSortIncludes: false');
|
|
133
133
|
const generateNM2 = (0, GenerateNM2_1.createNM2Generator)({
|
|
134
|
+
methodOnly,
|
|
134
135
|
namespace,
|
|
135
|
-
methodonly,
|
|
136
136
|
});
|
|
137
|
+
const generateJsiModuleH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/modules/GenerateModuleH')).generate;
|
|
138
|
+
const generateJsiModuleCpp = require(path_1.default.resolve(rncodegenPath, 'lib/generators/modules/GenerateModuleCpp')).generate;
|
|
137
139
|
const generatorPropsH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GeneratePropsH')).generate;
|
|
138
140
|
const generatorPropsCPP = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GeneratePropsCPP')).generate;
|
|
139
141
|
const generatorShadowNodeH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateShadowNodeH')).generate;
|
|
@@ -141,19 +143,30 @@ function generate({ libraryName, schema, outputDirectory, moduleSpecName, namesp
|
|
|
141
143
|
const generatorComponentDescriptorH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateComponentDescriptorH')).generate;
|
|
142
144
|
const generatorEventEmitterH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateEventEmitterH')).generate;
|
|
143
145
|
const generatorEventEmitterCPP = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateEventEmitterCpp')).generate;
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
|
|
146
|
+
const moduleGenerators = [];
|
|
147
|
+
if (modulesWindows) {
|
|
148
|
+
moduleGenerators.push(generateNM2);
|
|
147
149
|
}
|
|
150
|
+
if (modulesCxx) {
|
|
151
|
+
moduleGenerators.push(generateJsiModuleH);
|
|
152
|
+
moduleGenerators.push(generateJsiModuleCpp);
|
|
153
|
+
}
|
|
154
|
+
if (modulesTypeScriptTypes) {
|
|
155
|
+
moduleGenerators.push(GenerateTypeScript_1.generateTypeScript);
|
|
156
|
+
}
|
|
157
|
+
moduleGenerators.forEach(generator => {
|
|
158
|
+
const generated = generator(libraryName, schema, moduleSpecName);
|
|
159
|
+
normalizeFileMap(generated, outputDirectory, generatedFiles);
|
|
160
|
+
});
|
|
148
161
|
if (Object.keys(schema.modules).some(moduleName => schema.modules[moduleName].type === 'Component')) {
|
|
149
162
|
const componentGenerators = [
|
|
150
|
-
generatorPropsH,
|
|
151
|
-
generatorPropsCPP,
|
|
152
|
-
generatorShadowNodeH,
|
|
153
|
-
generatorShadowNodeCPP,
|
|
154
163
|
generatorComponentDescriptorH,
|
|
155
|
-
generatorEventEmitterH,
|
|
156
164
|
generatorEventEmitterCPP,
|
|
165
|
+
generatorEventEmitterH,
|
|
166
|
+
generatorPropsCPP,
|
|
167
|
+
generatorPropsH,
|
|
168
|
+
generatorShadowNodeCPP,
|
|
169
|
+
generatorShadowNodeH,
|
|
157
170
|
];
|
|
158
171
|
componentGenerators.forEach(generator => {
|
|
159
172
|
const generated = generator(libraryName, schema, moduleSpecName);
|
|
@@ -174,16 +187,17 @@ function runCodeGen(options) {
|
|
|
174
187
|
: combineSchemas(globby_1.default.sync(options.files));
|
|
175
188
|
const libraryName = options.libraryName;
|
|
176
189
|
const moduleSpecName = 'moduleSpecName';
|
|
177
|
-
const outputDirectory = options
|
|
178
|
-
const { namespace, methodonly, ts } = options;
|
|
190
|
+
const { methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, } = options;
|
|
179
191
|
return generate({
|
|
180
192
|
libraryName,
|
|
181
|
-
|
|
182
|
-
|
|
193
|
+
methodOnly,
|
|
194
|
+
modulesCxx,
|
|
183
195
|
moduleSpecName,
|
|
196
|
+
modulesTypeScriptTypes,
|
|
197
|
+
modulesWindows,
|
|
184
198
|
namespace,
|
|
185
|
-
|
|
186
|
-
|
|
199
|
+
outputDirectory,
|
|
200
|
+
schema,
|
|
187
201
|
}, { generators: [], test: options.test });
|
|
188
202
|
}
|
|
189
203
|
exports.runCodeGen = runCodeGen;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,gDAAwB;AACxB,kEAA0C;AAC1C,oDAA4B;AAC5B,0DAA4D;AAC5D,wEAGyC;AAGzC,8CAA8C;AAC9C,MAAM,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC;AAC1E,MAA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B,CAAC;IACxC,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IACvC,MAAM,EAAC,SAAS,EAAE,UAAU,EAAE,EAAE,EAAC,GAAG,OAAO,CAAC;IAC5C,OAAO,QAAQ,CACb;QACE,WAAW;QACX,MAAM;QACN,eAAe;QACf,cAAc;QACd,SAAS;QACT,UAAU;QACV,EAAE;KACH,EACD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAC,CACrC,CAAC;AACJ,CAAC;AAxBD,gCAwBC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\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';\nimport type {SchemaType} from 'react-native-tscodegen';\n\n// Load react-native-codegen from react-native\nconst rnPath = path.dirname(require.resolve('react-native/package.json'));\nconst rncodegenPath = path.dirname(\n require.resolve('react-native-codegen/package.json', {paths: [rnPath]}),\n);\nconst FlowParser = require(path.resolve(rncodegenPath, 'lib/parsers/flow'));\nconst TypeScriptParser = require(path.resolve(\n rncodegenPath,\n 'lib/parsers/typescript',\n));\n\nconst schemaValidator = require(path.resolve(\n rncodegenPath,\n 'lib/schemaValidator',\n));\n\ninterface Options {\n libraryName: string;\n schema: SchemaType;\n outputDirectory: string;\n moduleSpecName: string;\n namespace: string;\n methodonly: boolean;\n ts: boolean;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\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.log(`- ${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\nexport function parseFile(filename: string): SchemaType {\n try {\n const isTypeScript =\n path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';\n\n const schema = isTypeScript\n ? TypeScriptParser.parseFile(filename)\n : FlowParser.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\nexport function 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 = parseFile(filename);\n merged.modules = {...merged.modules, ...schema.modules};\n }\n return merged;\n },\n {modules: {}},\n );\n}\n\nexport function generate(\n {\n libraryName,\n schema,\n outputDirectory,\n moduleSpecName,\n namespace,\n methodonly,\n ts,\n }: 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({\n namespace,\n methodonly,\n });\n\n const generatorPropsH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsH',\n )).generate;\n const generatorPropsCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsCPP',\n )).generate;\n const generatorShadowNodeH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeH',\n )).generate;\n const generatorShadowNodeCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeCPP',\n )).generate;\n const generatorComponentDescriptorH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateComponentDescriptorH',\n )).generate;\n const generatorEventEmitterH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterH',\n )).generate;\n const generatorEventEmitterCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterCpp',\n )).generate;\n\n normalizeFileMap(\n generateNM2(libraryName, schema, moduleSpecName),\n outputDirectory,\n generatedFiles,\n );\n\n if (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\nexport type CodeGenOptions = {\n file?: string;\n files?: string[];\n libraryName: string;\n outdir: string;\n namespace: string;\n methodonly: boolean;\n ts: boolean;\n test: boolean;\n};\n\nexport function runCodeGen(options: CodeGenOptions): boolean {\n if (!options.file && !options.files)\n throw new Error('Must specify file or files option');\n\n const schema = options.file\n ? parseFile(options.file)\n : combineSchemas(globby.sync(options.files!));\n\n const libraryName = options.libraryName;\n const moduleSpecName = 'moduleSpecName';\n const outputDirectory = options.outdir;\n const {namespace, methodonly, ts} = options;\n return generate(\n {\n libraryName,\n schema,\n outputDirectory,\n moduleSpecName,\n namespace,\n methodonly,\n ts,\n },\n {generators: [], test: options.test},\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,gDAAwB;AACxB,kEAA0C;AAC1C,oDAA4B;AAC5B,0DAA4D;AAC5D,wEAGyC;AAGzC,8CAA8C;AAC9C,MAAM,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAA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AC,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;AA7HD,4BA6HC;AAeD,SAAgB,UAAU,CAAC,OAAuB;IAChD,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK;QACjC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI;QACzB,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;QACzB,CAAC,CAAC,cAAc,CAAC,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAM,CAAC,CAAC,CAAC;IAEhD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACxC,MAAM,cAAc,GAAG,gBAAgB,CAAC;IACxC,MAAM,EACJ,UAAU,EACV,UAAU,EACV,sBAAsB,EACtB,cAAc,EACd,SAAS,EACT,eAAe,GAChB,GAAG,OAAO,CAAC;IACZ,OAAO,QAAQ,CACb;QACE,WAAW;QACX,UAAU;QACV,UAAU;QACV,cAAc;QACd,sBAAsB;QACtB,cAAc;QACd,SAAS;QACT,eAAe;QACf,MAAM;KACP,EACD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAC,CACrC,CAAC;AACJ,CAAC;AAhCD,gCAgCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\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';\nimport type {SchemaType} from 'react-native-tscodegen';\n\n// Load react-native-codegen from react-native\nconst rnPath = path.dirname(require.resolve('react-native/package.json'));\nconst rncodegenPath = path.dirname(\n require.resolve('react-native-codegen/package.json', {paths: [rnPath]}),\n);\nconst FlowParser = require(path.resolve(rncodegenPath, 'lib/parsers/flow'));\nconst TypeScriptParser = require(path.resolve(\n rncodegenPath,\n 'lib/parsers/typescript',\n));\n\nconst schemaValidator = require(path.resolve(\n rncodegenPath,\n 'lib/schemaValidator',\n));\n\ninterface Options {\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n moduleSpecName: string;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n namespace: string;\n outputDirectory: string;\n schema: SchemaType;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\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.log(`- ${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\nexport function parseFile(filename: string): SchemaType {\n try {\n const isTypeScript =\n path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';\n\n const schema = isTypeScript\n ? TypeScriptParser.parseFile(filename)\n : FlowParser.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\nexport function 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 = parseFile(filename);\n merged.modules = {...merged.modules, ...schema.modules};\n }\n return merged;\n },\n {modules: {}},\n );\n}\n\nexport function generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n moduleSpecName,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n schema,\n }: 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({\n methodOnly,\n namespace,\n });\n\n const generateJsiModuleH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleH',\n )).generate;\n const generateJsiModuleCpp = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleCpp',\n )).generate;\n const generatorPropsH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsH',\n )).generate;\n const generatorPropsCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsCPP',\n )).generate;\n const generatorShadowNodeH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeH',\n )).generate;\n const generatorShadowNodeCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeCPP',\n )).generate;\n const generatorComponentDescriptorH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateComponentDescriptorH',\n )).generate;\n const generatorEventEmitterH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterH',\n )).generate;\n const generatorEventEmitterCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterCpp',\n )).generate;\n\n const moduleGenerators = [];\n\n if (modulesWindows) {\n moduleGenerators.push(generateNM2);\n }\n\n if (modulesCxx) {\n moduleGenerators.push(generateJsiModuleH);\n moduleGenerators.push(generateJsiModuleCpp);\n }\n\n if (modulesTypeScriptTypes) {\n moduleGenerators.push(generateTypeScript);\n }\n\n moduleGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, outputDirectory, generatedFiles);\n });\n\n if (\n Object.keys(schema.modules).some(\n moduleName => schema.modules[moduleName].type === 'Component',\n )\n ) {\n const componentGenerators = [\n generatorComponentDescriptorH,\n generatorEventEmitterCPP,\n generatorEventEmitterH,\n generatorPropsCPP,\n generatorPropsH,\n generatorShadowNodeCPP,\n generatorShadowNodeH,\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\nexport type CodeGenOptions = {\n file?: string;\n files?: string[];\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n namespace: string;\n outputDirectory: string;\n test: boolean;\n};\n\nexport function runCodeGen(options: CodeGenOptions): boolean {\n if (!options.file && !options.files)\n throw new Error('Must specify file or files option');\n\n const schema = options.file\n ? parseFile(options.file)\n : combineSchemas(globby.sync(options.files!));\n\n const libraryName = options.libraryName;\n const moduleSpecName = 'moduleSpecName';\n const {\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n } = options;\n return generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n moduleSpecName,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n schema,\n },\n {generators: [], test: options.test},\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-windows/codegen",
|
|
3
|
-
"version": "0.0.0-canary.
|
|
3
|
+
"version": "0.0.0-canary.44",
|
|
4
4
|
"description": "Generators for react-native-codegen targeting react-native-windows",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"repository": "https://github.com/microsoft/react-native-windows",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"react-native-windows-codegen": "./bin.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@react-native-windows/fs": "^0.0.0-canary.
|
|
21
|
+
"@react-native-windows/fs": "^0.0.0-canary.10",
|
|
22
22
|
"@typescript-eslint/eslint-plugin": "^5.30.5",
|
|
23
23
|
"@typescript-eslint/parser": "^5.30.5",
|
|
24
24
|
"chalk": "^4.1.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@rnw-scripts/eslint-config": "1.1.14",
|
|
32
32
|
"@rnw-scripts/jest-unittest-config": "1.4.1",
|
|
33
|
-
"@rnw-scripts/just-task": "2.3.
|
|
33
|
+
"@rnw-scripts/just-task": "2.3.2",
|
|
34
34
|
"@rnw-scripts/ts-config": "2.0.2",
|
|
35
35
|
"@types/chalk": "^2.2.0",
|
|
36
36
|
"@types/jest": "^29.2.2",
|
package/src/Cli.ts
CHANGED
|
@@ -18,17 +18,27 @@ const argv = yargs.options({
|
|
|
18
18
|
array: true,
|
|
19
19
|
describe: 'glob patterns for files which contains specs',
|
|
20
20
|
},
|
|
21
|
-
|
|
21
|
+
modulesTypeScriptTypes: {
|
|
22
22
|
type: 'boolean',
|
|
23
23
|
describe: 'generate turbo module definition files in TypeScript',
|
|
24
24
|
default: false,
|
|
25
25
|
},
|
|
26
|
-
|
|
26
|
+
modulesCxx: {
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
describe: 'generate C++ JSI turbo module spec files',
|
|
29
|
+
default: false,
|
|
30
|
+
},
|
|
31
|
+
modulesWindows: {
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
describe: 'generate turbo module spec files for REACT_MODULE',
|
|
34
|
+
default: false,
|
|
35
|
+
},
|
|
36
|
+
methodOnly: {
|
|
27
37
|
type: 'boolean',
|
|
28
38
|
describe: 'generate only method metadata in C++ turbo module spec',
|
|
29
39
|
default: false,
|
|
30
40
|
},
|
|
31
|
-
|
|
41
|
+
outputDirectory: {
|
|
32
42
|
type: 'string',
|
|
33
43
|
describe: 'output directory',
|
|
34
44
|
default: 'codegen',
|
|
@@ -44,11 +44,11 @@ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
|
|
|
44
44
|
`;
|
|
45
45
|
|
|
46
46
|
export function createNM2Generator({
|
|
47
|
+
methodOnly,
|
|
47
48
|
namespace,
|
|
48
|
-
methodonly,
|
|
49
49
|
}: {
|
|
50
|
+
methodOnly: boolean;
|
|
50
51
|
namespace: string;
|
|
51
|
-
methodonly: boolean;
|
|
52
52
|
}) {
|
|
53
53
|
return (
|
|
54
54
|
_libraryName: string,
|
|
@@ -85,7 +85,7 @@ ${methods[0]}
|
|
|
85
85
|
|
|
86
86
|
// prepare constants
|
|
87
87
|
const constants = generateValidateConstants(nativeModule, aliases);
|
|
88
|
-
if (constants !== undefined && !
|
|
88
|
+
if (constants !== undefined && !methodOnly) {
|
|
89
89
|
tuples = `
|
|
90
90
|
static constexpr auto constants = std::tuple{
|
|
91
91
|
${constants[0]}
|
package/src/index.ts
CHANGED
|
@@ -33,12 +33,14 @@ const schemaValidator = require(path.resolve(
|
|
|
33
33
|
|
|
34
34
|
interface Options {
|
|
35
35
|
libraryName: string;
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
methodOnly: boolean;
|
|
37
|
+
modulesCxx: boolean;
|
|
38
38
|
moduleSpecName: string;
|
|
39
|
+
modulesTypeScriptTypes: boolean;
|
|
40
|
+
modulesWindows: boolean;
|
|
39
41
|
namespace: string;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
outputDirectory: string;
|
|
43
|
+
schema: SchemaType;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
interface Config {
|
|
@@ -179,12 +181,14 @@ export function combineSchemas(files: string[]): SchemaType {
|
|
|
179
181
|
export function generate(
|
|
180
182
|
{
|
|
181
183
|
libraryName,
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
methodOnly,
|
|
185
|
+
modulesCxx,
|
|
184
186
|
moduleSpecName,
|
|
187
|
+
modulesTypeScriptTypes,
|
|
188
|
+
modulesWindows,
|
|
185
189
|
namespace,
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
outputDirectory,
|
|
191
|
+
schema,
|
|
188
192
|
}: Options,
|
|
189
193
|
{/*generators,*/ test}: Config,
|
|
190
194
|
): boolean {
|
|
@@ -204,10 +208,18 @@ export function generate(
|
|
|
204
208
|
);
|
|
205
209
|
|
|
206
210
|
const generateNM2 = createNM2Generator({
|
|
211
|
+
methodOnly,
|
|
207
212
|
namespace,
|
|
208
|
-
methodonly,
|
|
209
213
|
});
|
|
210
214
|
|
|
215
|
+
const generateJsiModuleH = require(path.resolve(
|
|
216
|
+
rncodegenPath,
|
|
217
|
+
'lib/generators/modules/GenerateModuleH',
|
|
218
|
+
)).generate;
|
|
219
|
+
const generateJsiModuleCpp = require(path.resolve(
|
|
220
|
+
rncodegenPath,
|
|
221
|
+
'lib/generators/modules/GenerateModuleCpp',
|
|
222
|
+
)).generate;
|
|
211
223
|
const generatorPropsH = require(path.resolve(
|
|
212
224
|
rncodegenPath,
|
|
213
225
|
'lib/generators/components/GeneratePropsH',
|
|
@@ -237,33 +249,43 @@ export function generate(
|
|
|
237
249
|
'lib/generators/components/GenerateEventEmitterCpp',
|
|
238
250
|
)).generate;
|
|
239
251
|
|
|
240
|
-
|
|
241
|
-
generateNM2(libraryName, schema, moduleSpecName),
|
|
242
|
-
outputDirectory,
|
|
243
|
-
generatedFiles,
|
|
244
|
-
);
|
|
252
|
+
const moduleGenerators = [];
|
|
245
253
|
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
generateTypeScript(libraryName, schema, moduleSpecName),
|
|
249
|
-
outputDirectory,
|
|
250
|
-
generatedFiles,
|
|
251
|
-
);
|
|
254
|
+
if (modulesWindows) {
|
|
255
|
+
moduleGenerators.push(generateNM2);
|
|
252
256
|
}
|
|
253
257
|
|
|
258
|
+
if (modulesCxx) {
|
|
259
|
+
moduleGenerators.push(generateJsiModuleH);
|
|
260
|
+
moduleGenerators.push(generateJsiModuleCpp);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (modulesTypeScriptTypes) {
|
|
264
|
+
moduleGenerators.push(generateTypeScript);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
moduleGenerators.forEach(generator => {
|
|
268
|
+
const generated: Map<string, string> = generator(
|
|
269
|
+
libraryName,
|
|
270
|
+
schema,
|
|
271
|
+
moduleSpecName,
|
|
272
|
+
);
|
|
273
|
+
normalizeFileMap(generated, outputDirectory, generatedFiles);
|
|
274
|
+
});
|
|
275
|
+
|
|
254
276
|
if (
|
|
255
277
|
Object.keys(schema.modules).some(
|
|
256
278
|
moduleName => schema.modules[moduleName].type === 'Component',
|
|
257
279
|
)
|
|
258
280
|
) {
|
|
259
281
|
const componentGenerators = [
|
|
260
|
-
generatorPropsH,
|
|
261
|
-
generatorPropsCPP,
|
|
262
|
-
generatorShadowNodeH,
|
|
263
|
-
generatorShadowNodeCPP,
|
|
264
282
|
generatorComponentDescriptorH,
|
|
265
|
-
generatorEventEmitterH,
|
|
266
283
|
generatorEventEmitterCPP,
|
|
284
|
+
generatorEventEmitterH,
|
|
285
|
+
generatorPropsCPP,
|
|
286
|
+
generatorPropsH,
|
|
287
|
+
generatorShadowNodeCPP,
|
|
288
|
+
generatorShadowNodeH,
|
|
267
289
|
];
|
|
268
290
|
|
|
269
291
|
componentGenerators.forEach(generator => {
|
|
@@ -287,10 +309,12 @@ export type CodeGenOptions = {
|
|
|
287
309
|
file?: string;
|
|
288
310
|
files?: string[];
|
|
289
311
|
libraryName: string;
|
|
290
|
-
|
|
312
|
+
methodOnly: boolean;
|
|
313
|
+
modulesCxx: boolean;
|
|
314
|
+
modulesTypeScriptTypes: boolean;
|
|
315
|
+
modulesWindows: boolean;
|
|
291
316
|
namespace: string;
|
|
292
|
-
|
|
293
|
-
ts: boolean;
|
|
317
|
+
outputDirectory: string;
|
|
294
318
|
test: boolean;
|
|
295
319
|
};
|
|
296
320
|
|
|
@@ -304,17 +328,25 @@ export function runCodeGen(options: CodeGenOptions): boolean {
|
|
|
304
328
|
|
|
305
329
|
const libraryName = options.libraryName;
|
|
306
330
|
const moduleSpecName = 'moduleSpecName';
|
|
307
|
-
const
|
|
308
|
-
|
|
331
|
+
const {
|
|
332
|
+
methodOnly,
|
|
333
|
+
modulesCxx,
|
|
334
|
+
modulesTypeScriptTypes,
|
|
335
|
+
modulesWindows,
|
|
336
|
+
namespace,
|
|
337
|
+
outputDirectory,
|
|
338
|
+
} = options;
|
|
309
339
|
return generate(
|
|
310
340
|
{
|
|
311
341
|
libraryName,
|
|
312
|
-
|
|
313
|
-
|
|
342
|
+
methodOnly,
|
|
343
|
+
modulesCxx,
|
|
314
344
|
moduleSpecName,
|
|
345
|
+
modulesTypeScriptTypes,
|
|
346
|
+
modulesWindows,
|
|
315
347
|
namespace,
|
|
316
|
-
|
|
317
|
-
|
|
348
|
+
outputDirectory,
|
|
349
|
+
schema,
|
|
318
350
|
},
|
|
319
351
|
{generators: [], test: options.test},
|
|
320
352
|
);
|