@react-native-windows/codegen 0.71.6 → 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 CHANGED
@@ -1,17 +1,25 @@
1
1
  # Change Log - @react-native-windows/codegen
2
2
 
3
- This log was last generated on Mon, 17 Jul 2023 15:14:30 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 16 Aug 2023 13:28:19 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 0.71.6
7
+ ## 0.71.7
8
8
 
9
- Mon, 17 Jul 2023 15:14:30 GMT
9
+ Wed, 16 Aug 2023 13:28:19 GMT
10
10
 
11
11
  ### Patches
12
12
 
13
- - Add cppStringType option to @rnw/codegen (#11833) (53799235+ZihanChen-MSFT@users.noreply.github.com)
13
+ - Add `separateDataFiles` to @rnw/cli and @rnw/codegen (53799235+ZihanChen-MSFT@users.noreply.github.com)
14
14
 
15
+ ## 0.71.6
16
+
17
+ Mon, 17 Jul 2023 15:14:58 GMT
18
+
19
+ ### Patches
20
+
21
+ - Add cppStringType option to @rnw/codegen (#11833) (53799235+ZihanChen-MSFT@users.noreply.github.com)
22
+
15
23
  ## 0.71.5
16
24
 
17
25
  Fri, 23 Jun 2023 18:19:56 GMT
@@ -66,6 +66,11 @@ const argv = yargs_1.default.options({
66
66
  describe: 'C++ string type in generated code, should be "std::string" or "std::wstring"',
67
67
  default: 'std::string',
68
68
  },
69
+ separateDataTypes: {
70
+ type: 'boolean',
71
+ describe: 'generate data types in a separate file',
72
+ default: false,
73
+ },
69
74
  }).argv;
70
75
  if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
71
76
  console.error('You must specify either --file or --files.');
@@ -1 +1 @@
1
- {"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kDAA0B;AAC1B,mCAAmD;AAEnD,MAAM,IAAI,GAAG,eAA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AAI,CAAC,KAAK,CAAC,EAAE;IAC5D,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,IACE,IAAI,CAAC,aAAa,KAAK,aAAa;IACpC,IAAI,CAAC,aAAa,KAAK,cAAc,EACrC;IACA,OAAO,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,yCAAyC;AACzC,yDAAyD;AACzD,iDAAiD;AACjD,MAAM,gBAAgB,GAAG,IAAA,kBAAU,EAAiB,IAAI,CAAC,CAAC;AAE1D,IAAI,IAAI,CAAC,IAAI,IAAI,gBAAgB,EAAE;IACjC,OAAO,CAAC,KAAK,CACX,kGAAkG,CACnG,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport {CodeGenOptions, 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 cppStringType: {\n choices: ['std::string', 'std::wstring'],\n describe:\n 'C++ string type in generated code, should be \"std::string\" or \"std::wstring\"',\n default: 'std::string',\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\nif (\n argv.cppStringType !== 'std::string' &&\n argv.cppStringType !== 'std::wstring'\n) {\n console.error('cppStringType should be \"std::string\" or \"std::wstring\".');\n process.exit(1);\n}\n\n// type casting is necessary here because\n// cppStringType does not become union of string literals\n// until yargs.options get improved in the future\nconst changesNecessary = runCodeGen(<CodeGenOptions>argv);\n\nif (argv.test && changesNecessary) {\n console.error(\n 'There is a change in the output of codegen. Rerun \"react-native codegen-windows\" to regenerate.',\n );\n process.exit(2);\n}\n"]}
1
+ {"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kDAA0B;AAC1B,mCAAmD;AAEnD,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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1D,IAAI,IAAI,CAAC,IAAI,IAAI,gBAAgB,EAAE;IACjC,OAAO,CAAC,KAAK,CACX,kGAAkG,CACnG,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport {CodeGenOptions, 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 cppStringType: {\n choices: ['std::string', 'std::wstring'],\n describe:\n 'C++ string type in generated code, should be \"std::string\" or \"std::wstring\"',\n default: 'std::string',\n },\n separateDataTypes: {\n type: 'boolean',\n describe: 'generate data types in a separate file',\n default: false,\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\nif (\n argv.cppStringType !== 'std::string' &&\n argv.cppStringType !== 'std::wstring'\n) {\n console.error('cppStringType should be \"std::string\" or \"std::wstring\".');\n process.exit(1);\n}\n\n// type casting is necessary here because\n// cppStringType does not become union of string literals\n// until yargs.options get improved in the future\nconst changesNecessary = runCodeGen(<CodeGenOptions>argv);\n\nif (argv.test && changesNecessary) {\n console.error(\n 'There is a change in the output of codegen. Rerun \"react-native codegen-windows\" to regenerate.',\n );\n process.exit(2);\n}\n"]}
@@ -9,4 +9,4 @@ import { CppCodegenOptions } from './ObjectTypes';
9
9
  export declare function createAliasMap(nativeModuleAliases: {
10
10
  [name: string]: NativeModuleObjectTypeAnnotation;
11
11
  }): AliasMap;
12
- export declare function generateAliases(aliases: AliasMap, options: CppCodegenOptions): string;
12
+ export declare function generateAliases(aliases: AliasMap, options: CppCodegenOptions): [string, string];
@@ -8,16 +8,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.generateAliases = exports.createAliasMap = void 0;
9
9
  const AliasManaging_1 = require("./AliasManaging");
10
10
  const ObjectTypes_1 = require("./ObjectTypes");
11
- function translateObjectBody(type, aliases, baseAliasName, prefix, options) {
11
+ function translateObjectMembersDefinition(type, aliases, baseAliasName, prefix, options) {
12
12
  return type.properties
13
13
  .map((prop) => {
14
14
  let propType = prop.typeAnnotation;
15
15
  if (prop.optional && propType.type !== 'NullableTypeAnnotation') {
16
16
  propType = { type: 'NullableTypeAnnotation', typeAnnotation: propType };
17
17
  }
18
- const first = `${prefix}REACT_FIELD(${prop.name})`;
19
- const second = `${prefix}${(0, ObjectTypes_1.translateField)(propType, aliases, `${baseAliasName}_${prop.name}`, options)} ${prop.name};`;
20
- return `${first}\n${second}`;
18
+ return `${prefix}${(0, ObjectTypes_1.translateField)(propType, aliases, `${baseAliasName}_${prop.name}`, options)} ${prop.name};`;
19
+ })
20
+ .join('\n');
21
+ }
22
+ function translateObjectMembersReflection(type, aliasCppName, prefix) {
23
+ return type.properties
24
+ .map((prop) => {
25
+ return `${prefix}{L"${prop.name}", &${aliasCppName}::${prop.name}},`;
21
26
  })
22
27
  .join('\n');
23
28
  }
@@ -30,13 +35,22 @@ function createAliasMap(nativeModuleAliases) {
30
35
  }
31
36
  exports.createAliasMap = createAliasMap;
32
37
  function generateSingleAlias(aliases, aliasName, aliasCode, options) {
38
+ const aliasCppName = (0, AliasManaging_1.getAliasCppName)(aliasName);
33
39
  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, ' ', options)}
40
+ const definition = `
41
+ struct ${aliasCppName} {
42
+ ${translateObjectMembersDefinition(aliasType, aliases, aliasName, ' ', options)}
38
43
  };
39
44
  `;
45
+ const reflection = `
46
+ inline winrt::Microsoft::ReactNative::FieldMap GetStructInfo(${aliasCppName}*) noexcept {
47
+ winrt::Microsoft::ReactNative::FieldMap fieldMap {
48
+ ${translateObjectMembersReflection(aliasType, aliasCppName, ' ')}
49
+ };
50
+ return fieldMap;
51
+ }
52
+ `;
53
+ aliasCode[aliasName] = { definition, reflection };
40
54
  }
41
55
  function generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options) {
42
56
  // retrieve and clean all ungenerated aliases
@@ -62,11 +76,13 @@ function generateAliases(aliases, options) {
62
76
  const aliasOrder = [];
63
77
  generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options);
64
78
  // aliasOrder now has the correct order of C++ struct code
65
- let traversedAliasedStructs = '';
79
+ let customTypes = '';
80
+ let customReflection = '';
66
81
  for (const aliasName of aliasOrder) {
67
- traversedAliasedStructs = `${traversedAliasedStructs}${aliasCode[aliasName]}`;
82
+ customTypes = `${customTypes}${aliasCode[aliasName].definition}`;
83
+ customReflection = `${customReflection}${aliasCode[aliasName].reflection}`;
68
84
  }
69
- return traversedAliasedStructs;
85
+ return [customTypes, customReflection];
70
86
  }
71
87
  exports.generateAliases = generateAliases;
72
88
  //# sourceMappingURL=AliasGen.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AliasGen.js","source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AC,SAAS,CAAC,EAAE,CAAC;KAC/E;IACD,OAAO,uBAAuB,CAAC;AACjC,CAAC;AAdD,0CAcC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleBaseTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NamedShape,\n Nullable,\n} from 'react-native-tscodegen';\nimport {AliasMap, getAliasCppName} from './AliasManaging';\nimport {CppCodegenOptions, translateField} from './ObjectTypes';\n\nfunction translateObjectBody(\n type: NativeModuleObjectTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n prefix: string,\n options: CppCodegenOptions,\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 options,\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 options: CppCodegenOptions,\n): void {\n const aliasType = <NativeModuleObjectTypeAnnotation>aliases.types[aliasName];\n aliasCode[aliasName] = `\nREACT_STRUCT(${getAliasCppName(aliasName)})\nstruct ${getAliasCppName(aliasName)} {\n${translateObjectBody(aliasType, aliases, aliasName, ' ', options)}\n};\n`;\n}\n\nfunction generateNestedAliasesInCorrectOrder(\n aliases: AliasMap,\n aliasCode: AliasCodeMap,\n aliasOrder: string[],\n options: CppCodegenOptions,\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, options);\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(\n aliases,\n aliasCode,\n aliasOrder,\n options,\n );\n // all referenced C++ structs are generated\n // put the current one following them\n aliasOrder.push(aliasName);\n }\n}\n\nexport function generateAliases(\n aliases: AliasMap,\n options: CppCodegenOptions,\n): string {\n const aliasCode: AliasCodeMap = {};\n const aliasOrder: string[] = [];\n generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options);\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"]}
1
+ {"version":3,"file":"AliasGen.js","sourceRoot":"","sources":["../../src/generators/AliasGen.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAQb,mDAA0D;AAC1D,+CAAgE;AAEhE,SAAS,gCAAgC,CACvC,IAAsC,EACtC,OAAiB,EACjB,aAAqB,EACrB,MAAc,EACd,OAA0B;IAE1B,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,EAA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SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;KAC5E;IACD,OAAO,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;AACzC,CAAC;AAhBD,0CAgBC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleBaseTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NamedShape,\n Nullable,\n} from 'react-native-tscodegen';\nimport {AliasMap, getAliasCppName} from './AliasManaging';\nimport {CppCodegenOptions, translateField} from './ObjectTypes';\n\nfunction translateObjectMembersDefinition(\n type: NativeModuleObjectTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n prefix: string,\n options: CppCodegenOptions,\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 return `${prefix}${translateField(\n propType,\n aliases,\n `${baseAliasName}_${prop.name}`,\n options,\n )} ${prop.name};`;\n })\n .join('\\n');\n}\n\nfunction translateObjectMembersReflection(\n type: NativeModuleObjectTypeAnnotation,\n aliasCppName: string,\n prefix: string,\n) {\n return type.properties\n .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {\n return `${prefix}{L\"${prop.name}\", &${aliasCppName}::${prop.name}},`;\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 AliasCode {\n definition: string;\n reflection: string;\n}\n\ninterface AliasCodeMap {\n [name: string]: AliasCode;\n}\n\nfunction generateSingleAlias(\n aliases: AliasMap,\n aliasName: string,\n aliasCode: AliasCodeMap,\n options: CppCodegenOptions,\n): void {\n const aliasCppName = getAliasCppName(aliasName);\n const aliasType = <NativeModuleObjectTypeAnnotation>aliases.types[aliasName];\n const definition = `\nstruct ${aliasCppName} {\n${translateObjectMembersDefinition(\n aliasType,\n aliases,\n aliasName,\n ' ',\n options,\n)}\n};\n`;\n const reflection = `\ninline winrt::Microsoft::ReactNative::FieldMap GetStructInfo(${aliasCppName}*) noexcept {\n winrt::Microsoft::ReactNative::FieldMap fieldMap {\n${translateObjectMembersReflection(aliasType, aliasCppName, ' ')}\n };\n return fieldMap;\n}\n`;\n aliasCode[aliasName] = {definition, reflection};\n}\n\nfunction generateNestedAliasesInCorrectOrder(\n aliases: AliasMap,\n aliasCode: AliasCodeMap,\n aliasOrder: string[],\n options: CppCodegenOptions,\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, options);\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(\n aliases,\n aliasCode,\n aliasOrder,\n options,\n );\n // all referenced C++ structs are generated\n // put the current one following them\n aliasOrder.push(aliasName);\n }\n}\n\nexport function generateAliases(\n aliases: AliasMap,\n options: CppCodegenOptions,\n): [string, string] {\n const aliasCode: AliasCodeMap = {};\n const aliasOrder: string[] = [];\n generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options);\n\n // aliasOrder now has the correct order of C++ struct code\n let customTypes = '';\n let customReflection = '';\n for (const aliasName of aliasOrder) {\n customTypes = `${customTypes}${aliasCode[aliasName].definition}`;\n customReflection = `${customReflection}${aliasCode[aliasName].reflection}`;\n }\n return [customTypes, customReflection];\n}\n"]}
@@ -7,8 +7,9 @@ import type { SchemaType } from 'react-native-tscodegen';
7
7
  import type { CppStringTypes } from './ObjectTypes';
8
8
  export type { CppStringTypes } from './ObjectTypes';
9
9
  type FilesOutput = Map<string, string>;
10
- export declare function createNM2Generator({ methodOnly, namespace, cppStringType, }: {
10
+ export declare function createNM2Generator({ methodOnly, namespace, cppStringType, separateDataTypes, }: {
11
11
  methodOnly: boolean;
12
12
  namespace: string;
13
13
  cppStringType: CppStringTypes;
14
+ separateDataTypes: boolean;
14
15
  }): (_libraryName: string, schema: SchemaType, _moduleSpecName: string) => FilesOutput;
@@ -10,21 +10,15 @@ const AliasManaging_1 = require("./AliasManaging");
10
10
  const AliasGen_1 = require("./AliasGen");
11
11
  const ValidateConstants_1 = require("./ValidateConstants");
12
12
  const ValidateMethods_1 = require("./ValidateMethods");
13
- const moduleTemplate = `
14
- /*
13
+ const headerTemplate = `/*
15
14
  * This file is auto-generated from a NativeModule spec file in js.
16
15
  *
17
16
  * This is a C++ Spec class that should be used with MakeTurboModuleProvider to register native modules
18
17
  * in a way that also verifies at compile time that the native module matches the interface required
19
18
  * by the TurboModule JS spec.
20
19
  */
21
- #pragma once
22
-
23
- #include "NativeModules.h"
24
- #include <tuple>
25
-
26
- namespace ::_NAMESPACE_:: {
27
- ::_MODULE_ALIASED_STRUCTS_::
20
+ #pragma once`;
21
+ const specTemplate = `::_MODULE_CUSTPM_TYPES_REFLECTION_::
28
22
  struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
29
23
  ::_MODULE_MEMBERS_TUPLES_::
30
24
 
@@ -33,12 +27,46 @@ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
33
27
  ::_MODULE_MEMBERS_CHECKS_::
34
28
 
35
29
  ::_MODULE_MEMBERS_ERRORS_::
36
- }
30
+ }`;
31
+ const typeOnlyTemplate = `
32
+ ${headerTemplate}
33
+
34
+ #include <string>
35
+ #include <optional>
36
+ #include <functional>
37
+ #include <vector>
38
+
39
+ namespace ::_NAMESPACE_:: {
40
+ ::_MODULE_CUSTPM_TYPES_::
41
+ } // namespace ::_NAMESPACE_::
42
+ `;
43
+ const moduleOnlyTemplate = `
44
+ ${headerTemplate}
45
+
46
+ ::_TYPE_DEFINITION_INCLUDE_::
47
+ #include <NativeModules.h>
48
+ #include <tuple>
49
+
50
+ namespace ::_NAMESPACE_:: {
51
+ ${specTemplate}
37
52
  };
38
53
 
39
54
  } // namespace ::_NAMESPACE_::
40
55
  `;
41
- function createNM2Generator({ methodOnly, namespace, cppStringType, }) {
56
+ const allInOneTemplate = `
57
+ ${headerTemplate}
58
+
59
+ #include <NativeModules.h>
60
+ #include <tuple>
61
+
62
+ namespace ::_NAMESPACE_:: {
63
+ ::_MODULE_CUSTPM_TYPES_::
64
+ ${specTemplate}
65
+ };
66
+
67
+ } // namespace ::_NAMESPACE_::
68
+ `;
69
+ function createNM2Generator({ methodOnly, namespace, cppStringType, separateDataTypes, }) {
42
70
  return (_libraryName, schema, _moduleSpecName) => {
43
71
  const files = new Map();
44
72
  for (const moduleName of Object.keys(schema.modules)) {
@@ -79,16 +107,32 @@ ${constants[0]}
79
107
  ${errors}`;
80
108
  }
81
109
  // generate code for structs
82
- const traversedAliasedStructs = (0, AliasGen_1.generateAliases)(aliases, {
110
+ const [customTypes, customReflection] = (0, AliasGen_1.generateAliases)(aliases, {
83
111
  cppStringType,
84
112
  });
85
- files.set(`Native${preferredModuleName}Spec.g.h`, moduleTemplate
86
- .replace(/::_MODULE_ALIASED_STRUCTS_::/g, traversedAliasedStructs)
87
- .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
88
- .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
89
- .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
90
- .replace(/::_MODULE_NAME_::/g, preferredModuleName)
91
- .replace(/::_NAMESPACE_::/g, namespace));
113
+ const customTypesExist = customTypes !== '';
114
+ const replaceContent = function (template) {
115
+ return template
116
+ .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)
117
+ .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)
118
+ .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
119
+ .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
120
+ .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
121
+ .replace(/::_MODULE_NAME_::/g, preferredModuleName)
122
+ .replace(/::_TYPE_DEFINITION_INCLUDE_::/g, customTypesExist
123
+ ? `// #include "Native${preferredModuleName}DataTypes.g.h" before this file to use the generated type definition`
124
+ : '')
125
+ .replace(/::_NAMESPACE_::/g, namespace);
126
+ };
127
+ if (separateDataTypes) {
128
+ if (customTypesExist) {
129
+ files.set(`Native${preferredModuleName}DataTypes.g.h`, replaceContent(typeOnlyTemplate));
130
+ }
131
+ files.set(`Native${preferredModuleName}Spec.g.h`, replaceContent(moduleOnlyTemplate));
132
+ }
133
+ else {
134
+ files.set(`Native${preferredModuleName}Spec.g.h`, replaceContent(allInOneTemplate));
135
+ }
92
136
  }
93
137
  }
94
138
  return files;
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateNM2.js","sourceRoot":"","sources":["../../src/generators/GenerateNM2.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAGb,mDAAiE;AACjE,yCAA2D;AAC3D,2DAA8D;AAC9D,uDAA0D;AAO1D,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BtB,CAAC;AAEF,SAAgB,kBAAkB,CAAC,EACjC,UAAU,EACV,SAAS,EACT,aAAa,GAKd;IACC,OAAO,CACL,YAAoB,EACpB,MAAkB,EAClB,eAAuB,EACV,EAAE;QACf,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;QAExC,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;YACpD,MAAM,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,CAAC;gBAEH,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;AA9ED,gDA8EC","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';\nimport type {CppStringTypes} from './ObjectTypes';\n\nexport type {CppStringTypes} from './ObjectTypes';\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 cppStringType,\n}: {\n methodOnly: boolean;\n namespace: string;\n cppStringType: CppStringTypes;\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 cppStringType,\n });\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 cppStringType,\n });\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"]}
1
+ {"version":3,"file":"GenerateNM2.js","sourceRoot":"","sources":["../../src/generators/GenerateNM2.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAGb,mDAAiE;AACjE,yCAA2D;AAC3D,2DAA8D;AAC9D,uDAA0D;AAO1D,MAAM,cAAc,GAAG;;;;;;;aAOV,CAAC;AAEd,MAAM,YAAY,GAAG;;;;;;;;;IASjB,CAAC;AAEL,MAAM,gBAAgB,GAAG;EACvB,cAAc;;;;;;;;;;CAUf,CAAC;AAEF,MAAM,kBAAkB,GAAG;EACzB,cAAc;;;;;;;EAOd,YAAY;;;;CAIb,CAAC;AAEF,MAAM,gBAAgB,GAAG;EACvB,cAAc;;;;;;;EAOd,YAAY;;;;CAIb,CAAC;AAEF,SAAgB,kBAAkB,CAAC,EACjC,UAAU,EACV,SAAS,EACT,aAAa,EACb,iBAAiB,GAMlB;IACC,OAAO,CACL,YAAoB,EACpB,MAAkB,EAClB,eAAuB,EACV,EAAE;QACf,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;QAExC,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;YACpD,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAChD,4CAA4C;YAC5C,0DAA0D;YAC1D,iCAAiC;YACjC,MAAM,mBAAmB,GAAG,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC;gBACzD,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;gBACtB,CAAC,CAAC,UAAU,CAAC;YACf,IAAA,sCAAsB,EAAC,mBAAmB,CAAC,CAAC;YAE5C,IAAI,YAAY,CAAC,IAAI,KAAK,cAAc,EAAE;gBACxC,OAAO,CAAC,GAAG,CA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,CAAC,CAAC,CAAC;yBAC5D,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC;yBAC/C,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC;yBAClD,OAAO,CACN,gCAAgC,EAChC,gBAAgB;wBACd,CAAC,CAAC,sBAAsB,mBAAmB,sEAAsE;wBACjH,CAAC,CAAC,EAAE,CACP;yBACA,OAAO,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;gBAC5C,CAAC,CAAC;gBAEF,IAAI,iBAAiB,EAAE;oBACrB,IAAI,gBAAgB,EAAE;wBACpB,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,eAAe,EAC3C,cAAc,CAAC,gBAAgB,CAAC,CACjC,CAAC;qBACH;oBACD,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,UAAU,EACtC,cAAc,CAAC,kBAAkB,CAAC,CACnC,CAAC;iBACH;qBAAM;oBACL,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,UAAU,EACtC,cAAc,CAAC,gBAAgB,CAAC,CACjC,CAAC;iBACH;aACF;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AA1GD,gDA0GC","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';\nimport type {CppStringTypes} from './ObjectTypes';\n\nexport type {CppStringTypes} from './ObjectTypes';\n\ntype FilesOutput = Map<string, string>;\n\nconst headerTemplate = `/*\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\nconst specTemplate = `::_MODULE_CUSTPM_TYPES_REFLECTION_::\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\nconst typeOnlyTemplate = `\n${headerTemplate}\n\n#include <string>\n#include <optional>\n#include <functional>\n#include <vector>\n\nnamespace ::_NAMESPACE_:: {\n::_MODULE_CUSTPM_TYPES_::\n} // namespace ::_NAMESPACE_::\n`;\n\nconst moduleOnlyTemplate = `\n${headerTemplate}\n\n::_TYPE_DEFINITION_INCLUDE_::\n#include <NativeModules.h>\n#include <tuple>\n\nnamespace ::_NAMESPACE_:: {\n${specTemplate}\n};\n\n} // namespace ::_NAMESPACE_::\n`;\n\nconst allInOneTemplate = `\n${headerTemplate}\n\n#include <NativeModules.h>\n#include <tuple>\n\nnamespace ::_NAMESPACE_:: {\n::_MODULE_CUSTPM_TYPES_::\n${specTemplate}\n};\n\n} // namespace ::_NAMESPACE_::\n`;\n\nexport function createNM2Generator({\n methodOnly,\n namespace,\n cppStringType,\n separateDataTypes,\n}: {\n methodOnly: boolean;\n namespace: string;\n cppStringType: CppStringTypes;\n separateDataTypes: boolean;\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 cppStringType,\n });\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 [customTypes, customReflection] = generateAliases(aliases, {\n cppStringType,\n });\n\n const customTypesExist = customTypes !== '';\n\n const replaceContent = function (template: string): string {\n return template\n .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)\n .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)\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(\n /::_TYPE_DEFINITION_INCLUDE_::/g,\n customTypesExist\n ? `// #include \"Native${preferredModuleName}DataTypes.g.h\" before this file to use the generated type definition`\n : '',\n )\n .replace(/::_NAMESPACE_::/g, namespace);\n };\n\n if (separateDataTypes) {\n if (customTypesExist) {\n files.set(\n `Native${preferredModuleName}DataTypes.g.h`,\n replaceContent(typeOnlyTemplate),\n );\n }\n files.set(\n `Native${preferredModuleName}Spec.g.h`,\n replaceContent(moduleOnlyTemplate),\n );\n } else {\n files.set(\n `Native${preferredModuleName}Spec.g.h`,\n replaceContent(allInOneTemplate),\n );\n }\n }\n }\n\n return files;\n };\n}\n"]}
@@ -16,6 +16,7 @@ export interface SharedOptions {
16
16
  namespace: string;
17
17
  outputDirectory: string;
18
18
  cppStringType: CppStringTypes;
19
+ separateDataTypes: boolean;
19
20
  }
20
21
  interface Options extends SharedOptions {
21
22
  moduleSpecName: string;
@@ -27,7 +28,7 @@ interface Config {
27
28
  }
28
29
  export declare function parseFile(filename: string): SchemaType;
29
30
  export declare function combineSchemas(files: string[]): SchemaType;
30
- export declare function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, moduleSpecName, schema, }: Options, { /*generators,*/ test }: Config): boolean;
31
+ export declare function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, separateDataTypes, moduleSpecName, schema, }: Options, { /*generators,*/ test }: Config): boolean;
31
32
  export interface CodeGenOptions extends SharedOptions {
32
33
  file?: string;
33
34
  files?: string[];
@@ -126,7 +126,7 @@ function combineSchemas(files) {
126
126
  }, { modules: {} });
127
127
  }
128
128
  exports.combineSchemas = combineSchemas;
129
- function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, moduleSpecName, schema, }, { /*generators,*/ test }) {
129
+ function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, separateDataTypes, moduleSpecName, schema, }, { /*generators,*/ test }) {
130
130
  schemaValidator.validate(schema);
131
131
  const componentOutputdir = path_1.default.join(outputDirectory, 'react/components', libraryName);
132
132
  const generatedFiles = new Map();
@@ -135,6 +135,7 @@ function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes,
135
135
  methodOnly,
136
136
  namespace,
137
137
  cppStringType,
138
+ separateDataTypes,
138
139
  });
139
140
  const generateJsiModuleH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/modules/GenerateModuleH')).generate;
140
141
  const generateJsiModuleCpp = require(path_1.default.resolve(rncodegenPath, 'lib/generators/modules/GenerateModuleCpp')).generate;
@@ -193,7 +194,7 @@ function runCodeGen(options) {
193
194
  : combineSchemas(globby_1.default.sync(options.files));
194
195
  const libraryName = options.libraryName;
195
196
  const moduleSpecName = 'moduleSpecName';
196
- const { methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, } = options;
197
+ const { methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, separateDataTypes, } = options;
197
198
  return generate({
198
199
  libraryName,
199
200
  methodOnly,
@@ -203,6 +204,7 @@ function runCodeGen(options) {
203
204
  namespace,
204
205
  outputDirectory,
205
206
  cppStringType,
207
+ separateDataTypes,
206
208
  moduleSpecName,
207
209
  schema,
208
210
  }, { generators: [], test: options.test });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,gDAAwB;AACxB,kEAA0C;AAC1C,oDAA4B;AAE5B,0DAA4D;AAC5D,wEAGyC;AAKzC,+CAA+C;AAC/C,MAAM,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC;AAC1E,MAAM,aAAa,GAAG,cAAI,CAAC,OAAO,CAChC,OAAO,CAAC,OAAO,CAAC,mCAAmC,EAAE,EAAC,KAAK,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC,CACxE,CAAC;AACF,MAAM,UAAU,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAC5E,MAAM,gBAAgB,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAC3C,aAAa,EACb,wBAAwB,CACzB,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAC1C,aAAa,EACb,qBAAqB,CACtB,CAAC,CAAC;AAuBH,SAAS,gBAAgB,CACvB,GAAwB,EACxB,SAAiB,EACjB,MAA2B;IAE3B,KAAK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AC;AAC1D,CAAC;AAzID,4BAyIC;AAQD,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,EACf,aAAa,GACd,GAAG,OAAO,CAAC;IACZ,OAAO,QAAQ,CACb;QACE,WAAW;QACX,UAAU;QACV,UAAU;QACV,sBAAsB;QACtB,cAAc;QACd,SAAS;QACT,eAAe;QACf,aAAa;QACb,cAAc;QACd,MAAM;KACP,EACD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAC,CACrC,CAAC;AACJ,CAAC;AAlCD,gCAkCC","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 type {CppStringTypes} from './generators/GenerateNM2';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {\n generateTypeScript,\n setOptionalTurboModule,\n} from './generators/GenerateTypeScript';\nimport type {SchemaType} from 'react-native-tscodegen';\n\nexport type {CppStringTypes} from './generators/GenerateNM2';\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\nexport interface SharedOptions {\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n namespace: string;\n outputDirectory: string;\n cppStringType: CppStringTypes;\n}\n\ninterface Options extends SharedOptions {\n moduleSpecName: 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 const contents = fs.readFileSync(filename, 'utf8');\n const schema = isTypeScript\n ? TypeScriptParser.parseString(contents, filename)\n : FlowParser.parseString(contents, 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 modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n cppStringType,\n moduleSpecName,\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 cppStringType,\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 const generatorStateCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateStateCpp',\n )).generate;\n const generatorStateH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateStateH',\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 generatorStateCPP,\n generatorStateH,\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 interface CodeGenOptions extends SharedOptions {\n file?: string;\n files?: 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 cppStringType,\n } = options;\n return generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n cppStringType,\n moduleSpecName,\n schema,\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;AAE5B,0DAA4D;AAC5D,wEAGyC;AAKzC,+CAA+C;AAC/C,MAAM,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC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B;QACtB,cAAc;QACd,SAAS;QACT,eAAe;QACf,aAAa;QACb,iBAAiB;QACjB,cAAc;QACd,MAAM;KACP,EACD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAC,CACrC,CAAC;AACJ,CAAC;AApCD,gCAoCC","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 type {CppStringTypes} from './generators/GenerateNM2';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {\n generateTypeScript,\n setOptionalTurboModule,\n} from './generators/GenerateTypeScript';\nimport type {SchemaType} from 'react-native-tscodegen';\n\nexport type {CppStringTypes} from './generators/GenerateNM2';\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\nexport interface SharedOptions {\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n namespace: string;\n outputDirectory: string;\n cppStringType: CppStringTypes;\n separateDataTypes: boolean;\n}\n\ninterface Options extends SharedOptions {\n moduleSpecName: 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 const contents = fs.readFileSync(filename, 'utf8');\n const schema = isTypeScript\n ? TypeScriptParser.parseString(contents, filename)\n : FlowParser.parseString(contents, 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 modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n cppStringType,\n separateDataTypes,\n moduleSpecName,\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 cppStringType,\n separateDataTypes,\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 const generatorStateCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateStateCpp',\n )).generate;\n const generatorStateH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateStateH',\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 generatorStateCPP,\n generatorStateH,\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 interface CodeGenOptions extends SharedOptions {\n file?: string;\n files?: 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 cppStringType,\n separateDataTypes,\n } = options;\n return generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n cppStringType,\n separateDataTypes,\n moduleSpecName,\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.71.6",
3
+ "version": "0.71.7",
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",
package/src/Cli.ts CHANGED
@@ -64,6 +64,11 @@ const argv = yargs.options({
64
64
  'C++ string type in generated code, should be "std::string" or "std::wstring"',
65
65
  default: 'std::string',
66
66
  },
67
+ separateDataTypes: {
68
+ type: 'boolean',
69
+ describe: 'generate data types in a separate file',
70
+ default: false,
71
+ },
67
72
  }).argv;
68
73
 
69
74
  if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
@@ -15,7 +15,7 @@ import type {
15
15
  import {AliasMap, getAliasCppName} from './AliasManaging';
16
16
  import {CppCodegenOptions, translateField} from './ObjectTypes';
17
17
 
18
- function translateObjectBody(
18
+ function translateObjectMembersDefinition(
19
19
  type: NativeModuleObjectTypeAnnotation,
20
20
  aliases: AliasMap,
21
21
  baseAliasName: string,
@@ -28,14 +28,24 @@ function translateObjectBody(
28
28
  if (prop.optional && propType.type !== 'NullableTypeAnnotation') {
29
29
  propType = {type: 'NullableTypeAnnotation', typeAnnotation: propType};
30
30
  }
31
- const first = `${prefix}REACT_FIELD(${prop.name})`;
32
- const second = `${prefix}${translateField(
31
+ return `${prefix}${translateField(
33
32
  propType,
34
33
  aliases,
35
34
  `${baseAliasName}_${prop.name}`,
36
35
  options,
37
36
  )} ${prop.name};`;
38
- return `${first}\n${second}`;
37
+ })
38
+ .join('\n');
39
+ }
40
+
41
+ function translateObjectMembersReflection(
42
+ type: NativeModuleObjectTypeAnnotation,
43
+ aliasCppName: string,
44
+ prefix: string,
45
+ ) {
46
+ return type.properties
47
+ .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {
48
+ return `${prefix}{L"${prop.name}", &${aliasCppName}::${prop.name}},`;
39
49
  })
40
50
  .join('\n');
41
51
  }
@@ -50,8 +60,13 @@ export function createAliasMap(nativeModuleAliases: {
50
60
  return aliases;
51
61
  }
52
62
 
63
+ interface AliasCode {
64
+ definition: string;
65
+ reflection: string;
66
+ }
67
+
53
68
  interface AliasCodeMap {
54
- [name: string]: string;
69
+ [name: string]: AliasCode;
55
70
  }
56
71
 
57
72
  function generateSingleAlias(
@@ -60,13 +75,28 @@ function generateSingleAlias(
60
75
  aliasCode: AliasCodeMap,
61
76
  options: CppCodegenOptions,
62
77
  ): void {
78
+ const aliasCppName = getAliasCppName(aliasName);
63
79
  const aliasType = <NativeModuleObjectTypeAnnotation>aliases.types[aliasName];
64
- aliasCode[aliasName] = `
65
- REACT_STRUCT(${getAliasCppName(aliasName)})
66
- struct ${getAliasCppName(aliasName)} {
67
- ${translateObjectBody(aliasType, aliases, aliasName, ' ', options)}
80
+ const definition = `
81
+ struct ${aliasCppName} {
82
+ ${translateObjectMembersDefinition(
83
+ aliasType,
84
+ aliases,
85
+ aliasName,
86
+ ' ',
87
+ options,
88
+ )}
68
89
  };
69
90
  `;
91
+ const reflection = `
92
+ inline winrt::Microsoft::ReactNative::FieldMap GetStructInfo(${aliasCppName}*) noexcept {
93
+ winrt::Microsoft::ReactNative::FieldMap fieldMap {
94
+ ${translateObjectMembersReflection(aliasType, aliasCppName, ' ')}
95
+ };
96
+ return fieldMap;
97
+ }
98
+ `;
99
+ aliasCode[aliasName] = {definition, reflection};
70
100
  }
71
101
 
72
102
  function generateNestedAliasesInCorrectOrder(
@@ -103,15 +133,17 @@ function generateNestedAliasesInCorrectOrder(
103
133
  export function generateAliases(
104
134
  aliases: AliasMap,
105
135
  options: CppCodegenOptions,
106
- ): string {
136
+ ): [string, string] {
107
137
  const aliasCode: AliasCodeMap = {};
108
138
  const aliasOrder: string[] = [];
109
139
  generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options);
110
140
 
111
141
  // aliasOrder now has the correct order of C++ struct code
112
- let traversedAliasedStructs = '';
142
+ let customTypes = '';
143
+ let customReflection = '';
113
144
  for (const aliasName of aliasOrder) {
114
- traversedAliasedStructs = `${traversedAliasedStructs}${aliasCode[aliasName]}`;
145
+ customTypes = `${customTypes}${aliasCode[aliasName].definition}`;
146
+ customReflection = `${customReflection}${aliasCode[aliasName].reflection}`;
115
147
  }
116
- return traversedAliasedStructs;
148
+ return [customTypes, customReflection];
117
149
  }
@@ -17,21 +17,16 @@ export type {CppStringTypes} from './ObjectTypes';
17
17
 
18
18
  type FilesOutput = Map<string, string>;
19
19
 
20
- const moduleTemplate = `
21
- /*
20
+ const headerTemplate = `/*
22
21
  * This file is auto-generated from a NativeModule spec file in js.
23
22
  *
24
23
  * This is a C++ Spec class that should be used with MakeTurboModuleProvider to register native modules
25
24
  * in a way that also verifies at compile time that the native module matches the interface required
26
25
  * by the TurboModule JS spec.
27
26
  */
28
- #pragma once
27
+ #pragma once`;
29
28
 
30
- #include "NativeModules.h"
31
- #include <tuple>
32
-
33
- namespace ::_NAMESPACE_:: {
34
- ::_MODULE_ALIASED_STRUCTS_::
29
+ const specTemplate = `::_MODULE_CUSTPM_TYPES_REFLECTION_::
35
30
  struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
36
31
  ::_MODULE_MEMBERS_TUPLES_::
37
32
 
@@ -40,7 +35,44 @@ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
40
35
  ::_MODULE_MEMBERS_CHECKS_::
41
36
 
42
37
  ::_MODULE_MEMBERS_ERRORS_::
43
- }
38
+ }`;
39
+
40
+ const typeOnlyTemplate = `
41
+ ${headerTemplate}
42
+
43
+ #include <string>
44
+ #include <optional>
45
+ #include <functional>
46
+ #include <vector>
47
+
48
+ namespace ::_NAMESPACE_:: {
49
+ ::_MODULE_CUSTPM_TYPES_::
50
+ } // namespace ::_NAMESPACE_::
51
+ `;
52
+
53
+ const moduleOnlyTemplate = `
54
+ ${headerTemplate}
55
+
56
+ ::_TYPE_DEFINITION_INCLUDE_::
57
+ #include <NativeModules.h>
58
+ #include <tuple>
59
+
60
+ namespace ::_NAMESPACE_:: {
61
+ ${specTemplate}
62
+ };
63
+
64
+ } // namespace ::_NAMESPACE_::
65
+ `;
66
+
67
+ const allInOneTemplate = `
68
+ ${headerTemplate}
69
+
70
+ #include <NativeModules.h>
71
+ #include <tuple>
72
+
73
+ namespace ::_NAMESPACE_:: {
74
+ ::_MODULE_CUSTPM_TYPES_::
75
+ ${specTemplate}
44
76
  };
45
77
 
46
78
  } // namespace ::_NAMESPACE_::
@@ -50,10 +82,12 @@ export function createNM2Generator({
50
82
  methodOnly,
51
83
  namespace,
52
84
  cppStringType,
85
+ separateDataTypes,
53
86
  }: {
54
87
  methodOnly: boolean;
55
88
  namespace: string;
56
89
  cppStringType: CppStringTypes;
90
+ separateDataTypes: boolean;
57
91
  }) {
58
92
  return (
59
93
  _libraryName: string,
@@ -105,20 +139,46 @@ ${errors}`;
105
139
  }
106
140
 
107
141
  // generate code for structs
108
- const traversedAliasedStructs = generateAliases(aliases, {
142
+ const [customTypes, customReflection] = generateAliases(aliases, {
109
143
  cppStringType,
110
144
  });
111
145
 
112
- files.set(
113
- `Native${preferredModuleName}Spec.g.h`,
114
- moduleTemplate
115
- .replace(/::_MODULE_ALIASED_STRUCTS_::/g, traversedAliasedStructs)
146
+ const customTypesExist = customTypes !== '';
147
+
148
+ const replaceContent = function (template: string): string {
149
+ return template
150
+ .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)
151
+ .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)
116
152
  .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
117
153
  .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
118
154
  .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
119
155
  .replace(/::_MODULE_NAME_::/g, preferredModuleName)
120
- .replace(/::_NAMESPACE_::/g, namespace),
121
- );
156
+ .replace(
157
+ /::_TYPE_DEFINITION_INCLUDE_::/g,
158
+ customTypesExist
159
+ ? `// #include "Native${preferredModuleName}DataTypes.g.h" before this file to use the generated type definition`
160
+ : '',
161
+ )
162
+ .replace(/::_NAMESPACE_::/g, namespace);
163
+ };
164
+
165
+ if (separateDataTypes) {
166
+ if (customTypesExist) {
167
+ files.set(
168
+ `Native${preferredModuleName}DataTypes.g.h`,
169
+ replaceContent(typeOnlyTemplate),
170
+ );
171
+ }
172
+ files.set(
173
+ `Native${preferredModuleName}Spec.g.h`,
174
+ replaceContent(moduleOnlyTemplate),
175
+ );
176
+ } else {
177
+ files.set(
178
+ `Native${preferredModuleName}Spec.g.h`,
179
+ replaceContent(allInOneTemplate),
180
+ );
181
+ }
122
182
  }
123
183
  }
124
184
 
package/src/index.ts CHANGED
@@ -43,6 +43,7 @@ export interface SharedOptions {
43
43
  namespace: string;
44
44
  outputDirectory: string;
45
45
  cppStringType: CppStringTypes;
46
+ separateDataTypes: boolean;
46
47
  }
47
48
 
48
49
  interface Options extends SharedOptions {
@@ -195,6 +196,7 @@ export function generate(
195
196
  namespace,
196
197
  outputDirectory,
197
198
  cppStringType,
199
+ separateDataTypes,
198
200
  moduleSpecName,
199
201
  schema,
200
202
  }: Options,
@@ -219,6 +221,7 @@ export function generate(
219
221
  methodOnly,
220
222
  namespace,
221
223
  cppStringType,
224
+ separateDataTypes,
222
225
  });
223
226
 
224
227
  const generateJsiModuleH = require(path.resolve(
@@ -348,6 +351,7 @@ export function runCodeGen(options: CodeGenOptions): boolean {
348
351
  namespace,
349
352
  outputDirectory,
350
353
  cppStringType,
354
+ separateDataTypes,
351
355
  } = options;
352
356
  return generate(
353
357
  {
@@ -359,6 +363,7 @@ export function runCodeGen(options: CodeGenOptions): boolean {
359
363
  namespace,
360
364
  outputDirectory,
361
365
  cppStringType,
366
+ separateDataTypes,
362
367
  moduleSpecName,
363
368
  schema,
364
369
  },