@react-native-windows/codegen 0.0.0-canary.44 → 0.0.0-canary.45
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 +16 -4
- package/lib-commonjs/index.js +7 -2
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +13 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
# Change Log - @react-native-windows/codegen
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 02 Dec 2022 06:17:25 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.45
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Fri, 02 Dec 2022 06:17:25 GMT
|
|
10
10
|
|
|
11
11
|
### Changes
|
|
12
12
|
|
|
13
|
-
-
|
|
13
|
+
- Integrate 10/10 (34109996+chiaramooney@users.noreply.github.com)
|
|
14
|
+
- Bump codegen version (30809111+acoates-ms@users.noreply.github.com)
|
|
15
|
+
- Bump @react-native-windows/fs to v0.0.0-canary.11
|
|
16
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.4.2
|
|
17
|
+
- Bump @rnw-scripts/just-task to v2.3.3
|
|
14
18
|
|
|
19
|
+
## 0.0.0-canary.44
|
|
20
|
+
|
|
21
|
+
Mon, 21 Nov 2022 06:15:36 GMT
|
|
22
|
+
|
|
23
|
+
### Changes
|
|
24
|
+
|
|
25
|
+
- Enable ability to codegen JSI C++ TurboModule specs (30809111+acoates-ms@users.noreply.github.com)
|
|
26
|
+
|
|
15
27
|
## 0.0.0-canary.43
|
|
16
28
|
|
|
17
29
|
Wed, 16 Nov 2022 06:16:01 GMT
|
package/lib-commonjs/index.js
CHANGED
|
@@ -82,9 +82,10 @@ function writeMapToFiles(map, outputDir) {
|
|
|
82
82
|
function parseFile(filename) {
|
|
83
83
|
try {
|
|
84
84
|
const isTypeScript = path_1.default.extname(filename) === '.ts' || path_1.default.extname(filename) === '.tsx';
|
|
85
|
+
const contents = fs_1.default.readFileSync(filename, 'utf8');
|
|
85
86
|
const schema = isTypeScript
|
|
86
|
-
? TypeScriptParser.
|
|
87
|
-
: FlowParser.
|
|
87
|
+
? TypeScriptParser.parseString(contents, filename)
|
|
88
|
+
: FlowParser.parseString(contents, filename);
|
|
88
89
|
// there will be at most one turbo module per file
|
|
89
90
|
const moduleName = Object.keys(schema.modules)[0];
|
|
90
91
|
if (moduleName) {
|
|
@@ -143,6 +144,8 @@ function generate({ libraryName, methodOnly, modulesCxx, moduleSpecName, modules
|
|
|
143
144
|
const generatorComponentDescriptorH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateComponentDescriptorH')).generate;
|
|
144
145
|
const generatorEventEmitterH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateEventEmitterH')).generate;
|
|
145
146
|
const generatorEventEmitterCPP = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateEventEmitterCpp')).generate;
|
|
147
|
+
const generatorStateCPP = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateStateCpp')).generate;
|
|
148
|
+
const generatorStateH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/components/GenerateStateH')).generate;
|
|
146
149
|
const moduleGenerators = [];
|
|
147
150
|
if (modulesWindows) {
|
|
148
151
|
moduleGenerators.push(generateNM2);
|
|
@@ -167,6 +170,8 @@ function generate({ libraryName, methodOnly, modulesCxx, moduleSpecName, modules
|
|
|
167
170
|
generatorPropsH,
|
|
168
171
|
generatorShadowNodeCPP,
|
|
169
172
|
generatorShadowNodeH,
|
|
173
|
+
generatorStateCPP,
|
|
174
|
+
generatorStateH,
|
|
170
175
|
];
|
|
171
176
|
componentGenerators.forEach(generator => {
|
|
172
177
|
const generated = generator(libraryName, schema, moduleSpecName);
|
|
@@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gCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport path from 'path';\nimport fs from '@react-native-windows/fs';\nimport globby from 'globby';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {\n generateTypeScript,\n setOptionalTurboModule,\n} from './generators/GenerateTypeScript';\nimport type {SchemaType} from 'react-native-tscodegen';\n\n// Load react-native-codegen from react-native\nconst rnPath = path.dirname(require.resolve('react-native/package.json'));\nconst rncodegenPath = path.dirname(\n require.resolve('react-native-codegen/package.json', {paths: [rnPath]}),\n);\nconst FlowParser = require(path.resolve(rncodegenPath, 'lib/parsers/flow'));\nconst TypeScriptParser = require(path.resolve(\n rncodegenPath,\n 'lib/parsers/typescript',\n));\n\nconst schemaValidator = require(path.resolve(\n rncodegenPath,\n 'lib/schemaValidator',\n));\n\ninterface Options {\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n moduleSpecName: string;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n namespace: string;\n outputDirectory: string;\n schema: SchemaType;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\n}\n\nfunction normalizeFileMap(\n map: Map<string, string>,\n outputDir: string,\n outMap: Map<string, string>,\n): void {\n for (const [fileName, contents] of map) {\n const location = path.join(outputDir, fileName);\n outMap.set(path.normalize(location), contents);\n }\n}\n\nfunction checkFilesForChanges(\n map: Map<string, string>,\n outputDir: string,\n): boolean {\n let hasChanges = false;\n\n const allExistingFiles = globby\n .sync(`${outputDir}/**`)\n .map(_ => path.normalize(_))\n .sort();\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n\n if (\n allExistingFiles.length !== allGeneratedFiles.length ||\n !allExistingFiles.every((val, index) => val === allGeneratedFiles[index])\n )\n return true;\n\n for (const [fileName, contents] of map) {\n if (!fs.existsSync(fileName)) {\n hasChanges = true;\n continue;\n }\n\n const currentContents = fs.readFileSync(fileName, 'utf8');\n if (currentContents !== contents) {\n console.log(`- ${fileName} has changed`);\n hasChanges = true;\n continue;\n }\n }\n\n return hasChanges;\n}\n\nfunction writeMapToFiles(map: Map<string, string>, outputDir: string) {\n let success = true;\n\n // This ensures that we delete any generated files from modules that have been deleted\n const allExistingFiles = globby.sync(`${outputDir}/**`);\n allExistingFiles.forEach(existingFile => {\n if (!map.has(path.normalize(existingFile))) {\n fs.unlinkSync(existingFile);\n }\n });\n\n for (const [fileName, contents] of map) {\n try {\n fs.mkdirSync(path.dirname(fileName), {recursive: true});\n\n if (fs.existsSync(fileName)) {\n const currentContents = fs.readFileSync(fileName, 'utf8');\n // Don't update the files if there are no changes as this breaks incremental builds\n if (currentContents === contents) {\n continue;\n }\n }\n\n fs.writeFileSync(fileName, contents);\n } catch (error) {\n success = false;\n console.error(`Failed to write ${fileName} to ${fileName}`, error);\n }\n }\n\n return success;\n}\n\nexport function parseFile(filename: string): SchemaType {\n try {\n const isTypeScript =\n path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';\n\n const schema = isTypeScript\n ? TypeScriptParser.parseFile(filename)\n : FlowParser.parseFile(filename);\n // there will be at most one turbo module per file\n const moduleName = Object.keys(schema.modules)[0];\n if (moduleName) {\n const spec = schema.modules[moduleName];\n if (spec.type === 'NativeModule') {\n const contents = fs.readFileSync(filename, 'utf8');\n if (contents) {\n // This is a temporary implementation until such information is added to the schema in facebook/react-native\n if (contents.includes('TurboModuleRegistry.get<')) {\n setOptionalTurboModule(spec, true);\n } else if (contents.includes('TurboModuleRegistry.getEnforcing<')) {\n setOptionalTurboModule(spec, false);\n }\n }\n }\n }\n return schema;\n } catch (e) {\n if (e instanceof Error) {\n e.message = `(${filename}): ${e.message}`;\n }\n throw e;\n }\n}\n\nexport function combineSchemas(files: string[]): SchemaType {\n return files.reduce(\n (merged, filename) => {\n const contents = fs.readFileSync(filename, 'utf8');\n if (\n contents &&\n (/export\\s+default\\s+\\(?codegenNativeComponent</.test(contents) ||\n contents.includes('extends TurboModule'))\n ) {\n const schema = parseFile(filename);\n merged.modules = {...merged.modules, ...schema.modules};\n }\n return merged;\n },\n {modules: {}},\n );\n}\n\nexport function generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n moduleSpecName,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n schema,\n }: Options,\n {/*generators,*/ test}: Config,\n): boolean {\n schemaValidator.validate(schema);\n\n const componentOutputdir = path.join(\n outputDirectory,\n 'react/components',\n libraryName,\n );\n\n const generatedFiles = new Map<string, string>();\n\n generatedFiles.set(\n path.join(outputDirectory, '.clang-format'),\n 'DisableFormat: true\\nSortIncludes: false',\n );\n\n const generateNM2 = createNM2Generator({\n methodOnly,\n namespace,\n });\n\n const generateJsiModuleH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleH',\n )).generate;\n const generateJsiModuleCpp = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleCpp',\n )).generate;\n const generatorPropsH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsH',\n )).generate;\n const generatorPropsCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsCPP',\n )).generate;\n const generatorShadowNodeH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeH',\n )).generate;\n const generatorShadowNodeCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeCPP',\n )).generate;\n const generatorComponentDescriptorH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateComponentDescriptorH',\n )).generate;\n const generatorEventEmitterH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterH',\n )).generate;\n const generatorEventEmitterCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterCpp',\n )).generate;\n\n const moduleGenerators = [];\n\n if (modulesWindows) {\n moduleGenerators.push(generateNM2);\n }\n\n if (modulesCxx) {\n moduleGenerators.push(generateJsiModuleH);\n moduleGenerators.push(generateJsiModuleCpp);\n }\n\n if (modulesTypeScriptTypes) {\n moduleGenerators.push(generateTypeScript);\n }\n\n moduleGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, outputDirectory, generatedFiles);\n });\n\n if (\n Object.keys(schema.modules).some(\n moduleName => schema.modules[moduleName].type === 'Component',\n )\n ) {\n const componentGenerators = [\n generatorComponentDescriptorH,\n generatorEventEmitterCPP,\n generatorEventEmitterH,\n generatorPropsCPP,\n generatorPropsH,\n generatorShadowNodeCPP,\n generatorShadowNodeH,\n ];\n\n componentGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, componentOutputdir, generatedFiles);\n });\n }\n\n if (test === true) {\n return checkFilesForChanges(generatedFiles, outputDirectory);\n }\n\n return writeMapToFiles(generatedFiles, outputDirectory);\n}\n\nexport type CodeGenOptions = {\n file?: string;\n files?: string[];\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n namespace: string;\n outputDirectory: string;\n test: boolean;\n};\n\nexport function runCodeGen(options: CodeGenOptions): boolean {\n if (!options.file && !options.files)\n throw new Error('Must specify file or files option');\n\n const schema = options.file\n ? parseFile(options.file)\n : combineSchemas(globby.sync(options.files!));\n\n const libraryName = options.libraryName;\n const moduleSpecName = 'moduleSpecName';\n const {\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n } = options;\n return generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n moduleSpecName,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n schema,\n },\n {generators: [], test: options.test},\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AA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GAAG,OAAO,CAAC;IACZ,OAAO,QAAQ,CACb;QACE,WAAW;QACX,UAAU;QACV,UAAU;QACV,cAAc;QACd,sBAAsB;QACtB,cAAc;QACd,SAAS;QACT,eAAe;QACf,MAAM;KACP,EACD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAC,CACrC,CAAC;AACJ,CAAC;AAhCD,gCAgCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport path from 'path';\nimport fs from '@react-native-windows/fs';\nimport globby from 'globby';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {\n generateTypeScript,\n setOptionalTurboModule,\n} from './generators/GenerateTypeScript';\nimport type {SchemaType} from 'react-native-tscodegen';\n\n// Load react-native-codegen from react-native\nconst rnPath = path.dirname(require.resolve('react-native/package.json'));\nconst rncodegenPath = path.dirname(\n require.resolve('react-native-codegen/package.json', {paths: [rnPath]}),\n);\nconst FlowParser = require(path.resolve(rncodegenPath, 'lib/parsers/flow'));\nconst TypeScriptParser = require(path.resolve(\n rncodegenPath,\n 'lib/parsers/typescript',\n));\n\nconst schemaValidator = require(path.resolve(\n rncodegenPath,\n 'lib/schemaValidator',\n));\n\ninterface Options {\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n moduleSpecName: string;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n namespace: string;\n outputDirectory: string;\n schema: SchemaType;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\n}\n\nfunction normalizeFileMap(\n map: Map<string, string>,\n outputDir: string,\n outMap: Map<string, string>,\n): void {\n for (const [fileName, contents] of map) {\n const location = path.join(outputDir, fileName);\n outMap.set(path.normalize(location), contents);\n }\n}\n\nfunction checkFilesForChanges(\n map: Map<string, string>,\n outputDir: string,\n): boolean {\n let hasChanges = false;\n\n const allExistingFiles = globby\n .sync(`${outputDir}/**`)\n .map(_ => path.normalize(_))\n .sort();\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n\n if (\n allExistingFiles.length !== allGeneratedFiles.length ||\n !allExistingFiles.every((val, index) => val === allGeneratedFiles[index])\n )\n return true;\n\n for (const [fileName, contents] of map) {\n if (!fs.existsSync(fileName)) {\n hasChanges = true;\n continue;\n }\n\n const currentContents = fs.readFileSync(fileName, 'utf8');\n if (currentContents !== contents) {\n console.log(`- ${fileName} has changed`);\n hasChanges = true;\n continue;\n }\n }\n\n return hasChanges;\n}\n\nfunction writeMapToFiles(map: Map<string, string>, outputDir: string) {\n let success = true;\n\n // This ensures that we delete any generated files from modules that have been deleted\n const allExistingFiles = globby.sync(`${outputDir}/**`);\n allExistingFiles.forEach(existingFile => {\n if (!map.has(path.normalize(existingFile))) {\n fs.unlinkSync(existingFile);\n }\n });\n\n for (const [fileName, contents] of map) {\n try {\n fs.mkdirSync(path.dirname(fileName), {recursive: true});\n\n if (fs.existsSync(fileName)) {\n const currentContents = fs.readFileSync(fileName, 'utf8');\n // Don't update the files if there are no changes as this breaks incremental builds\n if (currentContents === contents) {\n continue;\n }\n }\n\n fs.writeFileSync(fileName, contents);\n } catch (error) {\n success = false;\n console.error(`Failed to write ${fileName} to ${fileName}`, error);\n }\n }\n\n return success;\n}\n\nexport function parseFile(filename: string): SchemaType {\n try {\n const isTypeScript =\n path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';\n 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 moduleSpecName,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n schema,\n }: Options,\n {/*generators,*/ test}: Config,\n): boolean {\n schemaValidator.validate(schema);\n\n const componentOutputdir = path.join(\n outputDirectory,\n 'react/components',\n libraryName,\n );\n\n const generatedFiles = new Map<string, string>();\n\n generatedFiles.set(\n path.join(outputDirectory, '.clang-format'),\n 'DisableFormat: true\\nSortIncludes: false',\n );\n\n const generateNM2 = createNM2Generator({\n methodOnly,\n namespace,\n });\n\n const generateJsiModuleH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleH',\n )).generate;\n const generateJsiModuleCpp = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleCpp',\n )).generate;\n const generatorPropsH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsH',\n )).generate;\n const generatorPropsCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsCPP',\n )).generate;\n const generatorShadowNodeH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeH',\n )).generate;\n const generatorShadowNodeCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeCPP',\n )).generate;\n const generatorComponentDescriptorH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateComponentDescriptorH',\n )).generate;\n const generatorEventEmitterH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterH',\n )).generate;\n const generatorEventEmitterCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterCpp',\n )).generate;\n 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 type CodeGenOptions = {\n file?: string;\n files?: string[];\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n namespace: string;\n outputDirectory: string;\n test: boolean;\n};\n\nexport function runCodeGen(options: CodeGenOptions): boolean {\n if (!options.file && !options.files)\n throw new Error('Must specify file or files option');\n\n const schema = options.file\n ? parseFile(options.file)\n : combineSchemas(globby.sync(options.files!));\n\n const libraryName = options.libraryName;\n const moduleSpecName = 'moduleSpecName';\n const {\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n } = options;\n return generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n moduleSpecName,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n schema,\n },\n {generators: [], test: options.test},\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-windows/codegen",
|
|
3
|
-
"version": "0.0.0-canary.
|
|
3
|
+
"version": "0.0.0-canary.45",
|
|
4
4
|
"description": "Generators for react-native-codegen targeting react-native-windows",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"repository": "https://github.com/microsoft/react-native-windows",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"react-native-windows-codegen": "./bin.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@react-native-windows/fs": "^0.0.0-canary.
|
|
21
|
+
"@react-native-windows/fs": "^0.0.0-canary.11",
|
|
22
22
|
"@typescript-eslint/eslint-plugin": "^5.30.5",
|
|
23
23
|
"@typescript-eslint/parser": "^5.30.5",
|
|
24
24
|
"chalk": "^4.1.0",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@rnw-scripts/eslint-config": "1.1.14",
|
|
32
|
-
"@rnw-scripts/jest-unittest-config": "1.4.
|
|
33
|
-
"@rnw-scripts/just-task": "2.3.
|
|
32
|
+
"@rnw-scripts/jest-unittest-config": "1.4.2",
|
|
33
|
+
"@rnw-scripts/just-task": "2.3.3",
|
|
34
34
|
"@rnw-scripts/ts-config": "2.0.2",
|
|
35
35
|
"@types/chalk": "^2.2.0",
|
|
36
36
|
"@types/jest": "^29.2.2",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@types/yargs": "16.0.0",
|
|
39
39
|
"babel-jest": "^29.3.0",
|
|
40
40
|
"eslint": "^8.19.0",
|
|
41
|
-
"jest": "^29.
|
|
41
|
+
"jest": "^29.2.1",
|
|
42
42
|
"prettier": "^2.4.1",
|
|
43
43
|
"react-native-tscodegen": "0.68.4",
|
|
44
44
|
"typescript": "^4.4.4"
|
package/src/index.ts
CHANGED
|
@@ -131,10 +131,10 @@ export function parseFile(filename: string): SchemaType {
|
|
|
131
131
|
try {
|
|
132
132
|
const isTypeScript =
|
|
133
133
|
path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
|
|
134
|
-
|
|
134
|
+
const contents = fs.readFileSync(filename, 'utf8');
|
|
135
135
|
const schema = isTypeScript
|
|
136
|
-
? TypeScriptParser.
|
|
137
|
-
: FlowParser.
|
|
136
|
+
? TypeScriptParser.parseString(contents, filename)
|
|
137
|
+
: FlowParser.parseString(contents, filename);
|
|
138
138
|
// there will be at most one turbo module per file
|
|
139
139
|
const moduleName = Object.keys(schema.modules)[0];
|
|
140
140
|
if (moduleName) {
|
|
@@ -248,6 +248,14 @@ export function generate(
|
|
|
248
248
|
rncodegenPath,
|
|
249
249
|
'lib/generators/components/GenerateEventEmitterCpp',
|
|
250
250
|
)).generate;
|
|
251
|
+
const generatorStateCPP = require(path.resolve(
|
|
252
|
+
rncodegenPath,
|
|
253
|
+
'lib/generators/components/GenerateStateCpp',
|
|
254
|
+
)).generate;
|
|
255
|
+
const generatorStateH = require(path.resolve(
|
|
256
|
+
rncodegenPath,
|
|
257
|
+
'lib/generators/components/GenerateStateH',
|
|
258
|
+
)).generate;
|
|
251
259
|
|
|
252
260
|
const moduleGenerators = [];
|
|
253
261
|
|
|
@@ -286,6 +294,8 @@ export function generate(
|
|
|
286
294
|
generatorPropsH,
|
|
287
295
|
generatorShadowNodeCPP,
|
|
288
296
|
generatorShadowNodeH,
|
|
297
|
+
generatorStateCPP,
|
|
298
|
+
generatorStateH,
|
|
289
299
|
];
|
|
290
300
|
|
|
291
301
|
componentGenerators.forEach(generator => {
|