@react-native-windows/codegen 0.0.0-canary.39 → 0.0.0-canary.40
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 +12 -4
- package/lib-commonjs/index.js +7 -7
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +28 -14
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
|
|
3
|
+
This log was last generated on Tue, 18 Oct 2022 05:11:29 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.40
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Tue, 18 Oct 2022 05:11:29 GMT
|
|
10
10
|
|
|
11
11
|
### Changes
|
|
12
12
|
|
|
13
|
-
-
|
|
13
|
+
- Use newer react-native-codegen generators (30809111+acoates-ms@users.noreply.github.com)
|
|
14
14
|
|
|
15
|
+
## 0.0.0-canary.39
|
|
16
|
+
|
|
17
|
+
Sat, 15 Oct 2022 05:12:00 GMT
|
|
18
|
+
|
|
19
|
+
### Changes
|
|
20
|
+
|
|
21
|
+
- Bump @react-native-windows/fs to v0.0.0-canary.7
|
|
22
|
+
|
|
15
23
|
## 0.0.0-canary.38
|
|
16
24
|
|
|
17
25
|
Fri, 07 Oct 2022 05:11:46 GMT
|
package/lib-commonjs/index.js
CHANGED
|
@@ -134,13 +134,13 @@ function generate({ libraryName, schema, outputDirectory, moduleSpecName, namesp
|
|
|
134
134
|
namespace,
|
|
135
135
|
methodonly,
|
|
136
136
|
});
|
|
137
|
-
const generatorPropsH = require('
|
|
138
|
-
const generatorPropsCPP = require('
|
|
139
|
-
const generatorShadowNodeH = require('
|
|
140
|
-
const generatorShadowNodeCPP = require('
|
|
141
|
-
const generatorComponentDescriptorH = require('
|
|
142
|
-
const generatorEventEmitterH = require('
|
|
143
|
-
const generatorEventEmitterCPP = require('
|
|
137
|
+
const generatorPropsH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GeneratePropsH')).generate;
|
|
138
|
+
const generatorPropsCPP = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GeneratePropsCPP')).generate;
|
|
139
|
+
const generatorShadowNodeH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateShadowNodeH')).generate;
|
|
140
|
+
const generatorShadowNodeCPP = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateShadowNodeCPP')).generate;
|
|
141
|
+
const generatorComponentDescriptorH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateComponentDescriptorH')).generate;
|
|
142
|
+
const generatorEventEmitterH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateEventEmitterH')).generate;
|
|
143
|
+
const generatorEventEmitterCPP = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateEventEmitterCpp')).generate;
|
|
144
144
|
normalizeFileMap(generateNM2(libraryName, schema, moduleSpecName), outputDirectory, generatedFiles);
|
|
145
145
|
if (ts) {
|
|
146
146
|
normalizeFileMap((0, GenerateTypeScript_1.generateTypeScript)(libraryName, schema, moduleSpecName), outputDirectory, generatedFiles);
|
|
@@ -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,MAAM,aAAa,GAAG,cAAI,CAAC,OAAO,CAChC,OAAO,CAAC,OAAO,CAAC,mCAAmC,EAAE,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yright (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 =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH').generate;\n const generatorPropsCPP =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP').generate;\n const generatorShadowNodeH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH').generate;\n const generatorShadowNodeCPP =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP').generate;\n const generatorComponentDescriptorH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH').generate;\n const generatorEventEmitterH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH').generate;\n const generatorEventEmitterCPP =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterCpp').generate;\n\n normalizeFileMap(\n generateNM2(libraryName, schema, moduleSpecName),\n outputDirectory,\n generatedFiles,\n );\n\n if (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,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,eA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ent":["/**\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"]}
|
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.40",
|
|
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/index.ts
CHANGED
|
@@ -208,20 +208,34 @@ export function generate(
|
|
|
208
208
|
methodonly,
|
|
209
209
|
});
|
|
210
210
|
|
|
211
|
-
const generatorPropsH =
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
211
|
+
const generatorPropsH = require(path.resolve(
|
|
212
|
+
rncodegenPath,
|
|
213
|
+
'lib/generators/components/GeneratePropsH',
|
|
214
|
+
)).generate;
|
|
215
|
+
const generatorPropsCPP = require(path.resolve(
|
|
216
|
+
rncodegenPath,
|
|
217
|
+
'lib/generators/components/GeneratePropsCPP',
|
|
218
|
+
)).generate;
|
|
219
|
+
const generatorShadowNodeH = require(path.resolve(
|
|
220
|
+
rncodegenPath,
|
|
221
|
+
'lib/generators/components/GenerateShadowNodeH',
|
|
222
|
+
)).generate;
|
|
223
|
+
const generatorShadowNodeCPP = require(path.resolve(
|
|
224
|
+
rncodegenPath,
|
|
225
|
+
'lib/generators/components/GenerateShadowNodeCPP',
|
|
226
|
+
)).generate;
|
|
227
|
+
const generatorComponentDescriptorH = require(path.resolve(
|
|
228
|
+
rncodegenPath,
|
|
229
|
+
'lib/generators/components/GenerateComponentDescriptorH',
|
|
230
|
+
)).generate;
|
|
231
|
+
const generatorEventEmitterH = require(path.resolve(
|
|
232
|
+
rncodegenPath,
|
|
233
|
+
'lib/generators/components/GenerateEventEmitterH',
|
|
234
|
+
)).generate;
|
|
235
|
+
const generatorEventEmitterCPP = require(path.resolve(
|
|
236
|
+
rncodegenPath,
|
|
237
|
+
'lib/generators/components/GenerateEventEmitterCpp',
|
|
238
|
+
)).generate;
|
|
225
239
|
|
|
226
240
|
normalizeFileMap(
|
|
227
241
|
generateNM2(libraryName, schema, moduleSpecName),
|