Generate react-native turbo modules using TypeScript
Перейти к файлу
Zihan Chen (MSFT) 9075dd7f02
Update README.md
2023-05-16 11:09:22 -07:00
.github/workflows Try enforcing a specific node version on the CI (#62) 2022-11-29 16:57:20 -08:00
packages applying package updates 2022-12-13 22:32:30 +00:00
react-native@455ca8cfaf Catch up facebook/react-native/packages/react-native-codegen on 2022-12-13 (#66) 2022-12-13 14:27:20 -08:00
.gitignore ... 2019-10-14 17:08:28 -07:00
.gitmodules Submodule facebook/react-native 2019-08-05 16:13:05 -07:00
CODE_OF_CONDUCT.md Initial commit 2019-08-20 16:41:45 -07:00
LICENSE Update LICENSE 2019-08-29 14:28:55 -07:00
README.md Update README.md 2023-05-16 11:09:22 -07:00
SECURITY.md Initial commit 2019-08-20 16:41:48 -07:00
lerna.json Move repo to use yarn workspaces and lerna 2019-08-22 16:03:49 -07:00
package.json Catch up react-native-codegen 0.72 (#60) 2022-11-15 16:14:59 -08:00
yarn.lock Bump decode-uri-component from 0.2.0 to 0.2.2 (#64) 2022-12-20 01:45:11 -08:00

README.md

react-native-tscodegen

All works are ported to react-native, this project has stopped developing.

TypeScript Code Generation for React Native Turbo Module

  • Index
    • Contributing
    • Building this repo
    • Packages
    • Deploying
    • Development

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Building this repo

yarn
yarn build
yarn test

Packages

@react-native-ts-codegen/tslint-shared

This is the shared tslint configuration for all other packages.

RN-TSCodegen

This is the TypeScript code generation for TurboModule in react native.

There are two important exported functions:

  • typeScriptToCodeSchema function:
    • fileName argument: Full path to a TypeScript source file, a module name.
    • moduleName argument: The module name. It is not reflected in generated files.
    • targetName argument (optional): It will be used in the entry header file, if this TypeScript source file registers a native module.
    • Output: A SchemaType data structure.
  • generator.generate function
    • options argument:
      • libraryName property: A string that becomes part of type names in generated files.
      • schema property: Result from typeScriptToCodeSchema
      • outputDirectory property: Full path to a folder to write files. Multiple files will be generated and most of the file names are hard-coded.
      • moduleSpecName property: Name of the entry header file, no file extension.
    • config arguments:
      • generators property: An array that is or a subset of ['descriptors', 'events', 'props', 'tests', 'shadow-nodes', 'modules'] to control what files are generated.

RN-TSCodegen-Test

This package contains all test cases for RN-TSCodegen, with unit test code.

@react-native-ts-codegen/minimum-flow-parser

This is a Flow parser, just enough to convert necessary files to TypeScript for this repo.

update-test-files

Get generated files sync to facebook/react-native

Deploying

You are welcome to use cli tool react-native-tscodegen instead of calling functions in build scripts by yourself if possible. Basically, just add react-native-tscodegen ./react-native-tscodegen.json to npm scripts, after getting react-native-tscodegen.json prepared. The file name is not important.

{
    "libraryName": "PlaygroundModule",
    "outputDirectory": "./lib/cpp-generated",
    "moduleSpecName": "PlaygroundModuleSpec",
    "generators": [
        "descriptors",
        "events",
        "props",
        "tests",
        "shadow-nodes",
        "modules"
    ],
    "inputFile": "./src/turboModule.ts"
}

libraryName and moduleSpecName control file names and some generated C++ class names. generators controls what files get generated. After the cli tool is successfully executed, files will be created under outputDirectory.

Development

Sync react-native after pull

git submodule update

Sync react-native to a new version

pushd react-native
git fetch
git checkout <VERSION-NAME>
popd
git status

Works to do after updating react-native

yarn
yarn build
pushd packages\update-test-files
npm run start
popd
git status

Fixing test case codegen

cls & pushd packages\update-test-files & npm run build & cd ..\RN-TSCodegen-Test & npm run build & popd

Fixing compiler

cls & pushd packages\RN-TSCodegen & npm run build & cd ..\RN-TSCodegen-Test & npm run build & npm run test & popd