Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic saving of types in files when the schema is changed #29

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

jclaveau
Copy link

@jclaveau jclaveau commented Jul 9, 2023

  • Add GENERATE_TYPES_SYNCED_TS_FILES="my-synced-types.d.ts, my-second-synced-types.d.ts" to your .env (support for several files is for not fully configured monorepos like in my case)
  • Create/udate/delete a collection, a field or a relation
  • The file(s) will be updated almost instantly

This PR required some refacto

  • Change the extebsion type to a bundle
  • Slice getCollections in 2 layers to be usable with data from a module (api) and from a hook (services)
  • I also added support for automatic extensions reloading of the server during dev

Out of scope (IMHO)

  • Python files

Remaining non blocking problem:

  • baseUrl is not taken in consideration with the recreated extension's (as a bundle one) tsconfig.json
  • I'm still not sure if I prefer to use nodemon or EXTENSIONS_AUTO_RELOAD="true", please tell me your feeling!

Hoping you'll have time for a review,
Thank you for your work!

jclaveau added 7 commits July 7, 2023 13:19
…es on creat/update/delete of collections, fields or relations

Add a hook saving types in files

List files to save to in an environment va

factorize data gathering between the admin module and the hook

closed maltejur#27
Example with Directus env var (may be faster but fuzzy log)

Example with nodemon (more readable but may be slower)

Add sample env.GENERATE_TYPES_SYNCED_TS_FILES to the dev project
Also adds a disclaimer to the generated types files

maltejur#27
@maltejur
Copy link
Owner

maltejur commented Jul 9, 2023

Hi, this looks great, thanks already! I am currently not at home, so it may take some days/a week until I can review this.

@jclaveau
Copy link
Author

Hi, this looks great, thanks already! I am currently not at home, so it may take some days/a week until I can review this.

No hurry, i'm using my fork with some other fixes meanwhile

@maltejur maltejur force-pushed the automatic_sync_ts_file branch from d5b7db6 to f79e32e Compare July 14, 2023 18:41
Copy link
Owner

@maltejur maltejur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have gone ahead and reformatted your pull request with prettier, that way we don't have stuff like using tabs for indentation in one place and spaces in a different one. Before submitting any new changes, could you also run prettier . -w first?

Another thing, when testing your changes with yarn dev:project, I am getting the following error when visiting the Directus interface:

Screenshot_20230714_202432

When I disable the extension through the following change, it works flawlessly again

--- a/dev.sh
+++ b/dev.sh
@@ -35,9 +35,6 @@ fi
 
 echo "-> Building and linking extension"
 
-(cd .. && yarn directus-extension link ./dev/extensions)
-(cd .. && yarn dev &)
-
 echo
 echo "-> Starting dev server"
 echo "   You can log in with:"

Could you try to figure out what is causing this?

@@ -40,3 +46,4 @@ echo " pw: admin"
echo

yarn directus start
# yarn dev:nodemon # using nodemon produces more readable log than EXTENSIONS_AUTO_RELOAD="true"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use nodemon then

Comment on lines +21 to +22
import generateOasTypes from "../../lib/generate-types/oas";
import languages from "../lib/languages";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular reason you turned these into relative imports?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants