https://github.com/bryanbill/dartify
Generate Dart JS interop bindings from TypeScript declaration files, with modular output and grouped (barrel) exports.
https://github.com/bryanbill/dartify
dart interop typescript
Last synced: about 1 month ago
JSON representation
Generate Dart JS interop bindings from TypeScript declaration files, with modular output and grouped (barrel) exports.
- Host: GitHub
- URL: https://github.com/bryanbill/dartify
- Owner: bryanbill
- Created: 2025-07-04T10:31:20.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2025-07-04T10:34:49.000Z (12 months ago)
- Last Synced: 2025-09-27T05:41:36.801Z (9 months ago)
- Topics: dart, interop, typescript
- Language: TypeScript
- Homepage:
- Size: 50.8 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
dartify
TypeScript-to-Dart Interop Generator
Generate Dart JS interop bindings from TypeScript declaration files, with modular output and grouped (barrel) exports.
---
## Features
- **Converts TypeScript `.d.ts` files to Dart JS interop code**
- **Modular, DRY, and production-ready codebase**
- **CLI usage via `npx` or local install**
- **Grouped export (barrel) file generation per folder and at output root**
- **Jest-based test suite for all modules**
- **ESM/Node compatibility**
- **In-code API documentation**
---
## Installation
You can use dartify directly with `npx` (no install required):
```sh
npx dartify
```
Or install locally/globally:
```sh
npm install -g dartify
# or
npm install --save-dev dartify
```
---
## Usage
### CLI
```sh
npx dartify
```
### Example
```sh
npx dartify example/types/ example/interops/
```
This will generate Dart files for each TypeScript declaration, grouped by folder, with `.dart` barrel files in each output folder and at the output root.
---
## How It Works
1. **Parses TypeScript declaration files** using the TypeScript compiler API.
2. **Maps TypeScript types to Dart JS interop types** (e.g., `string` → `JSString`).
3. **Generates Dart files** for classes, functions, and type aliases.
4. **Creates grouped export (barrel) files** per folder and at the output root.
5. **Ensures all output is modular and ready for Dart consumption.**
---
## Project Structure
- `src/cli.ts` — CLI entrypoint
- `src/generator/` — Modular generator logic:
- `barrel.ts` — Barrel (grouped export) file generation
- `dartWriter.ts` — Dart file writing utilities
- `fileUtils.ts` — File system helpers
- `generateClass.ts` — Class code generation
- `generateFunction.ts` — Function code generation
- `generateNode.ts` — AST traversal and code generation
- `generateTypeAlias.ts` — Type alias code generation
- `mapType.ts` — TypeScript-to-Dart type mapping
- `typeMap.ts` — Type name to file path mapping
- `src/__tests__/` — Jest test files for all modules
- `package.json`, `tsconfig.json`, `jest.config.js` — Configuration
---
## Development
### Build
```sh
npm run build
```
### Test
```sh
npm test
```
### Local CLI Development
```sh
npm run build
npm link
dartify
```
---
## API Documentation
All modules and functions are documented with JSDoc-style comments. See the source files in `src/generator/` for details.
---
## License
MIT