Typescript type definition generator for Frappe DocTypes.
To use the app, install it on your local development bench:
$ bench get-app https://github.com/The-Commit-Company/frappe-types
$ bench --site mysite.test install-app frappe_types
After installing the app, search for "Type Generation Settings" in Desk using the Awesomebar. You need to add the app name and path where you want to save your Typescript type definition files. frappe-types will only run on those app whose app name and path are added in these settings.
That's it.
Now whenever you create or update any DocType on your local machine, the app will generate .ts
files under at the following path: app/src/types/<module_def>/<doctype_name>.ts
.
- Supports most Frappe field types
- Runs automatically whenever you save/update a DocType
- Adds JSDoc comments for every field in the interface
- Support CLI command to run type generation on existing DocTypes without having to update them.
You can also run the type generation command from the bench CLI. This will generate types for all DocTypes in the system. This CLI Command works for all frappe-bench apps, and can generate types of any DocType .
- Generate types for DocType.
$ bench --site <site_name> generate-types-for-doctype --app <app_name> --doctype <doctype_name> [--generate_child_tables] [--custom_fields]
# or just Answer the prompts
$ bench --site <site_name> generate-types-for-doctype
- Generate types for Module.
$ bench --site <site_name> generate-types-for-module --app <app_name> --module <module_name> [--generate_child_tables]
# or just Answer the prompts
$ bench --site <site_name> generate-types-for-module
Note: No need to mention --site <site_name> if current site is same site where module/doctype existed app installed in that site.
--app
- the app name included inType Generation Settings
doctype and where you want to save type files.--doctype
- the doctype name for which you want to generate types.--module
- the module name for which you want to generate types.--generate_child_tables
- if you want to generate types for child tables of the doctype (default=False).--custom_fields
- if you want to generate types for custom fields of the doctype (Default=False).
Let's say you create a DocType in a module called "Project Management" called "Projects" and Child Table called "Project User Table" with the following fields:
![image](https://private-user-images.githubusercontent.com/59503001/240828536-60718378-c1e7-4b65-86eb-5e320ab3a5ca.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIwNzE4OTEsIm5iZiI6MTcyMjA3MTU5MSwicGF0aCI6Ii81OTUwMzAwMS8yNDA4Mjg1MzYtNjA3MTgzNzgtYzFlNy00YjY1LTg2ZWItNWUzMjBhYjNhNWNhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI3VDA5MTMxMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU1ZmNlNDBlY2Y0YWEyN2ZlYzZjZGYwZGMyMGFkMzdhZTBhMTExZjBjZWU5MzAzMTY5MTI0OTZkN2MxYTQ5MTYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.2i6PDGOqYaiiWaI50SE6Oe0sxSkzMRb2Y0yE9rsMq5Q)
The app will automatically create a file called Projects.ts
and ProjectUserTable.ts
at the path <your_app_folder>/types/ProjectManagement
like this:
(Notice that spaces in the Module and DocType names will be removed)
![image](https://private-user-images.githubusercontent.com/59503001/240827250-c67b6f11-66b3-4c72-8217-bb1afab95c02.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIwNzE4OTEsIm5iZiI6MTcyMjA3MTU5MSwicGF0aCI6Ii81OTUwMzAwMS8yNDA4MjcyNTAtYzY3YjZmMTEtNjZiMy00YzcyLTgyMTctYmIxYWZhYjk1YzAyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzd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)
If you are developing custom Frappe apps with a Frappe backend and a frontend single-page app using React/Vue/other frameworks, you can use this app to generate TypeScript definitions to be used in your frontend app.
- Looking at how to improve speed so that DocType saving does not take a lot of time.
Maintainer | GitHub | Social |
---|---|---|
Nikhil Kothari | nikkothari22 | @nik_kothari22 |
Sumit Jain | sumitjain236 | @sumit_jain |
MIT