{"id":15012561,"url":"https://github.com/microsoft/ts-gyb","last_synced_at":"2025-05-16T08:04:41.716Z","repository":{"id":40487833,"uuid":"317476745","full_name":"microsoft/ts-gyb","owner":"microsoft","description":"Generating native code interfaces from TypeScript","archived":false,"fork":false,"pushed_at":"2025-02-18T00:42:17.000Z","size":1178,"stargazers_count":135,"open_issues_count":16,"forks_count":17,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-15T00:08:50.869Z","etag":null,"topics":["code-generation","hybrid-app","javascriptcore","kotlin","swift","typescript","webview"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-01T08:37:54.000Z","updated_at":"2025-04-17T09:13:49.000Z","dependencies_parsed_at":"2024-06-19T02:56:13.669Z","dependency_job_id":"9cd1cceb-4d7a-4fef-932e-8181fec3f964","html_url":"https://github.com/microsoft/ts-gyb","commit_stats":{"total_commits":95,"total_committers":13,"mean_commits":"7.3076923076923075","dds":0.5894736842105264,"last_synced_commit":"d06874d009553325ec580443a10ea735048c646c"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fts-gyb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fts-gyb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fts-gyb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fts-gyb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microsoft","download_url":"https://codeload.github.com/microsoft/ts-gyb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254493378,"owners_count":22080126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generation","hybrid-app","javascriptcore","kotlin","swift","typescript","webview"],"created_at":"2024-09-24T19:42:50.590Z","updated_at":"2025-05-16T08:04:38.960Z","avatar_url":"https://github.com/microsoft.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","typescript"],"sub_categories":[],"readme":"# ts-gyb\n\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/microsoft/ts-gyb/default.yml)\n![npm](https://img.shields.io/npm/v/ts-gyb)\n\nts-gyb is a multi-purpose code generation tool based on TypeScript interfaces. It was initially designed for generating boilerplate interfacing code between web and mobile platforms in hybrid apps. With custom templates, it can generate code for any use from TypeScript.\n\nGYB: Generate Your Boilerplate. Inspired by [swift/gyb.py](https://github.com/apple/swift/blob/main/utils/gyb.py).\n\n## Features\n\n- Generate production ready and well documented code from TypeScript code\n- Support most of TypeScript syntax\n- Fully customizable template makes the generated code fit perfectly into any project\n\n## Installation\n\nTo use ts-gyb with an existing project managed by npm, it is recommended to install ts-gyb as a dev dependency:\n\n```shell\nnpm install --save-dev ts-gyb\n```\n\nYou can also install ts-gyb globally:\n\n```shell\nnpm install --global ts-gyb\n```\n\n## Get Started\n\n### 1. Define TypeScript interfaces\n\nTo generate code for a TypeScript interface, add the JSDoc tag `@shouldExport true` to documentation of the interface.\n\n```typescript\n/**\n * @shouldExport true\n */\ninterface EditorSelection {\n  getSelectionPath(): SelectionPath | null;\n\n  // Function can have only one argument and it must be an object\n  setSelection(args: { selectionPath: SelectionPath }): void;\n\n  // Destructuring assignment is allowed\n  setSelectionAtElement({ id, removeElement }: { id: string, removeElement?: boolean }): void;\n}\n```\n\nts-gyb only handles method members like `methodName(): ReturnType;`. If a method needs to take in parameters, it must define one object argument. The type of this object can either be an interface or an object literal. For more information on how to write interfaces for ts-gyb, please refer to [TypeScript Interface Guide](documentation/interface-guide.md).\n\n### 2. Provide templates\n\nts-gyb generates code from [mustache](http://mustache.github.io) templates. At least two templates are needed:\n\n- **Module template**: used to generate a file for every TypeScript interface\n- **Custom type template**: used to generate the file that hosts all TypeScript types found in method parameters or return types\n\nFor generating boilerplate interfacing code between web and mobile platforms, a good starting point is the [example templates](example-templates). You can copy the templates to your project and modify them according to your project's needs.\n\nPlease refer to [Template Guide](documentation/template-guide.md) for all available variables, and [mustache Manual](http://mustache.github.io/mustache.5.html) for mustache template syntax.\n\n### 3. Create a configuration file\n\nCreate a json configuration file in your project:\n\n```json\n{\n  \"parsing\": {\n    \"targets\": {\n      \"default\": {\n        \"source\": [\"path/to/interfaces.ts\"],\n        \"tsconfigPath\": \"path/to/tsconfigPath\"\n      }\n    }\n  },\n  \"rendering\": {\n    \"swift\": {\n      \"renders\": [\n        {\n          \"target\": \"default\",\n          \"templates\": \"path/to/module-interface.mustache\",\n          \"outputPath\": \"path/to/output/directory\"\n        }\n      ],\n      \"namedTypesTemplatePath\": \"path/to/named-types.mustache\",\n      \"namedTypesOutputPath\": \"path/to/output/directory/SharedTypes.swift\"\n    }\n  }\n}\n```\n\nAll paths are relative to the configuration file. For all supported options in the configuration file, please refer to [Configuration Reference](documentation/generated/interfaces/Configuration.md).\n\n### 4. Run ts-gyb\n\n```shell\nnpx ts-gyb --config path/to/config.json\n```\n\nOr if ts-gyb is installed globally:\n\n```shell\nts-gyb --config path/to/config.json\n```\n\nGenerated code can be found at the output directory specified in the configuration file.\n\n## Demos\n\n[mini-editor](demo/mini-editor) contains an iOS and an Android rich text editing app. Their editors are powered by the same TypeScript web project.\n\nThe web part provides some rich text formatting operations that can be invoked from native code (Kotlin/Swift). The operations are defined in [IEditor.ts](demo/mini-editor/web/src/editor/IEditor.ts). ts-gyb generates [EditorBridge.swift](demo/mini-editor/apple/MiniEditor/Generated/EditorBridge.swift) from that TypeScript interface.\n\n## Documentation\n\n- [TypeScript Interface Guide](documentation/interface-guide.md)\n- [Template Guide](documentation/template-guide.md)\n- [Configuration Reference](documentation/generated/interfaces/Configuration.md)\n\n## Contributing\n\nThis project welcomes contributions and suggestions. Most contributions require you to agree to a\nContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\nthe rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.\n\nWhen you submit a pull request, a CLA bot will automatically determine whether you need to provide\na CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions\nprovided by the bot. You will only need to do this once across all repos using our CLA.\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).\nFor more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or\ncontact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n\n## Trademarks\n\nThis project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft \ntrademarks or logos is subject to and must follow \n[Microsoft's Trademark \u0026 Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).\nUse of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.\nAny use of third-party trademarks or logos are subject to those third-party's policies.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fts-gyb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrosoft%2Fts-gyb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fts-gyb/lists"}