Code Monkey home page Code Monkey logo

frappe-types's Introduction

Frappe Typescript Type Generator

Typescript type definition generator for Frappe DocTypes.



Usage

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.

Screenshot 2023-01-12 at 2 30 31 PM

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.


Features

  1. Supports most Frappe field types
  2. Runs automatically whenever you save/update a DocType
  3. Adds JSDoc comments for every field in the interface
  4. Support CLI command to run type generation on existing DocTypes without having to update them.

CLI Command

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 .

  1. 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
  1. 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.

  1. --app - the app name included in Type Generation Settings doctype and where you want to save type files.
  2. --doctype - the doctype name for which you want to generate types.
  3. --module - the module name for which you want to generate types.
  4. --generate_child_tables - if you want to generate types for child tables of the doctype (default=False).
  5. --custom_fields - if you want to generate types for custom fields of the doctype (Default=False).

Example

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

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
image

Where can you use this?

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.


What features will we add next?

  1. Looking at how to improve speed so that DocType saving does not take a lot of time.

Maintainers

Maintainer GitHub Social
Nikhil Kothari nikkothari22 @nik_kothari22
Sumit Jain sumitjain236 @sumit_jain

License

MIT

frappe-types's People

Contributors

nagariahussain avatar nikkothari22 avatar sumitjain236 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.