@react-native-windows/codegen 0.71.1 → 0.71.3

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,18 +1,35 @@
1
1
  # Change Log - @react-native-windows/codegen
2
2
 
3
- This log was last generated on Mon, 13 Feb 2023 16:15:13 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 13 Apr 2023 20:50:07 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 0.71.1
7
+ ## 0.71.3
8
8
 
9
- Mon, 13 Feb 2023 16:15:13 GMT
9
+ Thu, 13 Apr 2023 20:50:07 GMT
10
10
 
11
11
  ### Patches
12
12
 
13
- - Bump typescript version (30809111+acoates-ms@users.noreply.github.com)
14
- - Bump @react-native-windows/fs to v0.71.1
13
+ - Fix RNW not being detected on case-sensitive file systems (4123478+tido64@users.noreply.github.com)
15
14
 
15
+ ## 0.71.2
16
+
17
+ Mon, 27 Feb 2023 16:15:26 GMT
18
+
19
+ ### Patches
20
+
21
+ - Move `@typescript-eslint/eslint-plugin` to `devDependencies` so they don't get installed by consumers (4123478+tido64@users.noreply.github.com)
22
+ - Bump @react-native-windows/fs to v0.71.2
23
+
24
+ ## 0.71.1
25
+
26
+ Mon, 13 Feb 2023 16:16:02 GMT
27
+
28
+ ### Patches
29
+
30
+ - Bump typescript version (30809111+acoates-ms@users.noreply.github.com)
31
+ - Bump @react-native-windows/fs to v0.71.1
32
+
16
33
  ## 0.71.0
17
34
 
18
35
  Mon, 23 Jan 2023 16:16:57 GMT
@@ -20,7 +20,7 @@ const rnPath = path_1.default.dirname(require.resolve('react-native/package.json
20
20
  const rncodegenPath = path_1.default.dirname(require.resolve('react-native-codegen/package.json', { paths: [rnPath] }));
21
21
  const FlowParser = require(path_1.default.resolve(rncodegenPath, 'lib/parsers/flow'));
22
22
  const TypeScriptParser = require(path_1.default.resolve(rncodegenPath, 'lib/parsers/typescript'));
23
- const schemaValidator = require(path_1.default.resolve(rncodegenPath, 'lib/schemaValidator'));
23
+ const schemaValidator = require(path_1.default.resolve(rncodegenPath, 'lib/SchemaValidator'));
24
24
  function normalizeFileMap(map, outputDir, outMap) {
25
25
  for (const [fileName, contents] of map) {
26
26
  const location = path_1.default.join(outputDir, fileName);
@@ -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,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;AAmBH,SAAS,gBAAgB,CACvB,GAAwB,EACxB,SAAiB,EACjB,MAA2B;IAE3B,KAAK,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,GAAG,EAAE;QACtC,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAChD,MAAM,CAAC,GAAG,CAAC,cAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,C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CAAC,OAAO,CAAC,IAAI,CAAC;QACzB,CAAC,CAAC,cAAc,CAAC,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAM,CAAC,CAAC,CAAC;IAEhD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACxC,MAAM,cAAc,GAAG,gBAAgB,CAAC;IACxC,MAAM,EACJ,UAAU,EACV,UAAU,EACV,sBAAsB,EACtB,cAAc,EACd,SAAS,EACT,eAAe,GAChB,GAAG,OAAO,CAAC;IACZ,OAAO,QAAQ,CACb;QACE,WAAW;QACX,UAAU;QACV,UAAU;QACV,cAAc;QACd,sBAAsB;QACtB,cAAc;QACd,SAAS;QACT,eAAe;QACf,MAAM;KACP,EACD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAC,CACrC,CAAC;AACJ,CAAC;AAhCD,gCAgCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport path from 'path';\nimport fs from '@react-native-windows/fs';\nimport globby from 'globby';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {\n generateTypeScript,\n setOptionalTurboModule,\n} from './generators/GenerateTypeScript';\nimport type {SchemaType} from 'react-native-tscodegen';\n\n// Load react-native-codegen from react-native\nconst rnPath = path.dirname(require.resolve('react-native/package.json'));\nconst rncodegenPath = path.dirname(\n require.resolve('react-native-codegen/package.json', {paths: [rnPath]}),\n);\nconst FlowParser = require(path.resolve(rncodegenPath, 'lib/parsers/flow'));\nconst TypeScriptParser = require(path.resolve(\n rncodegenPath,\n 'lib/parsers/typescript',\n));\n\nconst schemaValidator = require(path.resolve(\n rncodegenPath,\n 'lib/schemaValidator',\n));\n\ninterface Options {\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n moduleSpecName: string;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n namespace: string;\n outputDirectory: string;\n schema: SchemaType;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\n}\n\nfunction normalizeFileMap(\n map: Map<string, string>,\n outputDir: string,\n outMap: Map<string, string>,\n): void {\n for (const [fileName, contents] of map) {\n const location = path.join(outputDir, fileName);\n outMap.set(path.normalize(location), contents);\n }\n}\n\nfunction checkFilesForChanges(\n map: Map<string, string>,\n outputDir: string,\n): boolean {\n let hasChanges = false;\n\n const allExistingFiles = globby\n .sync(`${outputDir}/**`)\n .map(_ => path.normalize(_))\n .sort();\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n\n if (\n allExistingFiles.length !== allGeneratedFiles.length ||\n !allExistingFiles.every((val, index) => val === allGeneratedFiles[index])\n )\n return true;\n\n for (const [fileName, contents] of map) {\n if (!fs.existsSync(fileName)) {\n hasChanges = true;\n continue;\n }\n\n const currentContents = fs.readFileSync(fileName, 'utf8');\n if (currentContents !== contents) {\n console.log(`- ${fileName} has changed`);\n hasChanges = true;\n continue;\n }\n }\n\n return hasChanges;\n}\n\nfunction writeMapToFiles(map: Map<string, string>, outputDir: string) {\n let success = true;\n\n // This ensures that we delete any generated files from modules that have been deleted\n const allExistingFiles = globby.sync(`${outputDir}/**`);\n allExistingFiles.forEach(existingFile => {\n if (!map.has(path.normalize(existingFile))) {\n fs.unlinkSync(existingFile);\n }\n });\n\n for (const [fileName, contents] of map) {\n try {\n fs.mkdirSync(path.dirname(fileName), {recursive: true});\n\n if (fs.existsSync(fileName)) {\n const currentContents = fs.readFileSync(fileName, 'utf8');\n // Don't update the files if there are no changes as this breaks incremental builds\n if (currentContents === contents) {\n continue;\n }\n }\n\n fs.writeFileSync(fileName, contents);\n } catch (error) {\n success = false;\n console.error(`Failed to write ${fileName} to ${fileName}`, error);\n }\n }\n\n return success;\n}\n\nexport function parseFile(filename: string): SchemaType {\n try {\n const isTypeScript =\n path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';\n 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"]}
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,CAC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,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,IAAI,KAAK,IAAI,EAAE;QACjB,OAAO,oBAAoB,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;KAC9D;IAED,OAAO,eAAe,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;AAC1D,CAAC;AAvID,4BAuIC;AAeD,SAAgB,UAAU,CAAC,OAAuB;IAChD,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK;QACjC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI;QACzB,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;QACzB,CAAC,CAAC,cAAc,CAAC,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAM,CAAC,CAAC,CAAC;IAEhD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACxC,MAAM,cAAc,GAAG,gBAAgB,CAAC;IACxC,MAAM,EACJ,UAAU,EACV,UAAU,EACV,sBAAsB,EACtB,cAAc,EACd,SAAS,EACT,eAAe,GAChB,GAAG,OAAO,CAAC;IACZ,OAAO,QAAQ,CACb;QACE,WAAW;QACX,UAAU;QACV,UAAU;QACV,cAAc;QACd,sBAAsB;QACtB,cAAc;QACd,SAAS;QACT,eAAe;QACf,MAAM;KACP,EACD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAC,CACrC,CAAC;AACJ,CAAC;AAhCD,gCAgCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport path from 'path';\nimport fs from '@react-native-windows/fs';\nimport globby from 'globby';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {\n generateTypeScript,\n setOptionalTurboModule,\n} from './generators/GenerateTypeScript';\nimport type {SchemaType} from 'react-native-tscodegen';\n\n// Load react-native-codegen from react-native\nconst rnPath = path.dirname(require.resolve('react-native/package.json'));\nconst rncodegenPath = path.dirname(\n require.resolve('react-native-codegen/package.json', {paths: [rnPath]}),\n);\nconst FlowParser = require(path.resolve(rncodegenPath, 'lib/parsers/flow'));\nconst TypeScriptParser = require(path.resolve(\n rncodegenPath,\n 'lib/parsers/typescript',\n));\n\nconst schemaValidator = require(path.resolve(\n rncodegenPath,\n 'lib/SchemaValidator',\n));\n\ninterface Options {\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n moduleSpecName: string;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n namespace: string;\n outputDirectory: string;\n schema: SchemaType;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\n}\n\nfunction normalizeFileMap(\n map: Map<string, string>,\n outputDir: string,\n outMap: Map<string, string>,\n): void {\n for (const [fileName, contents] of map) {\n const location = path.join(outputDir, fileName);\n outMap.set(path.normalize(location), contents);\n }\n}\n\nfunction checkFilesForChanges(\n map: Map<string, string>,\n outputDir: string,\n): boolean {\n let hasChanges = false;\n\n const allExistingFiles = globby\n .sync(`${outputDir}/**`)\n .map(_ => path.normalize(_))\n .sort();\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n\n if (\n allExistingFiles.length !== allGeneratedFiles.length ||\n !allExistingFiles.every((val, index) => val === allGeneratedFiles[index])\n )\n return true;\n\n for (const [fileName, contents] of map) {\n if (!fs.existsSync(fileName)) {\n hasChanges = true;\n continue;\n }\n\n const currentContents = fs.readFileSync(fileName, 'utf8');\n if (currentContents !== contents) {\n console.log(`- ${fileName} has changed`);\n hasChanges = true;\n continue;\n }\n }\n\n return hasChanges;\n}\n\nfunction writeMapToFiles(map: Map<string, string>, outputDir: string) {\n let success = true;\n\n // This ensures that we delete any generated files from modules that have been deleted\n const allExistingFiles = globby.sync(`${outputDir}/**`);\n allExistingFiles.forEach(existingFile => {\n if (!map.has(path.normalize(existingFile))) {\n fs.unlinkSync(existingFile);\n }\n });\n\n for (const [fileName, contents] of map) {\n try {\n fs.mkdirSync(path.dirname(fileName), {recursive: true});\n\n if (fs.existsSync(fileName)) {\n const currentContents = fs.readFileSync(fileName, 'utf8');\n // Don't update the files if there are no changes as this breaks incremental builds\n if (currentContents === contents) {\n continue;\n }\n }\n\n fs.writeFileSync(fileName, contents);\n } catch (error) {\n success = false;\n console.error(`Failed to write ${fileName} to ${fileName}`, error);\n }\n }\n\n return success;\n}\n\nexport function parseFile(filename: string): SchemaType {\n try {\n const isTypeScript =\n path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';\n 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.71.1",
3
+ "version": "0.71.3",
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,9 +18,7 @@
18
18
  "react-native-windows-codegen": "./bin.js"
19
19
  },
20
20
  "dependencies": {
21
- "@react-native-windows/fs": "0.71.1",
22
- "@typescript-eslint/eslint-plugin": "^5.30.5",
23
- "@typescript-eslint/parser": "^5.30.5",
21
+ "@react-native-windows/fs": "0.71.2",
24
22
  "chalk": "^4.1.0",
25
23
  "globby": "^11.0.4",
26
24
  "mustache": "^4.0.1",
@@ -36,6 +34,8 @@
36
34
  "@types/jest": "^29.2.2",
37
35
  "@types/node": "^14.14.22",
38
36
  "@types/yargs": "16.0.0",
37
+ "@typescript-eslint/eslint-plugin": "^5.30.5",
38
+ "@typescript-eslint/parser": "^5.30.5",
39
39
  "babel-jest": "^29.3.0",
40
40
  "eslint": "^8.19.0",
41
41
  "jest": "^29.2.1",
package/src/index.ts CHANGED
@@ -28,7 +28,7 @@ const TypeScriptParser = require(path.resolve(
28
28
 
29
29
  const schemaValidator = require(path.resolve(
30
30
  rncodegenPath,
31
- 'lib/schemaValidator',
31
+ 'lib/SchemaValidator',
32
32
  ));
33
33
 
34
34
  interface Options {