-
Notifications
You must be signed in to change notification settings - Fork 17
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
docs: revised generating typescript interfaces section #4504
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -404,14 +404,50 @@ Open the index.html file, add update the message with the name of your app. In a | |
|
||
By this point, you should have enough to view your app. Run the `yarn dev` command to start the dev server. The app will be served at [http://localhost:5173](http://localhost:5173). | ||
|
||
### Generate typescript types for an app | ||
### Generating interfaces and types for use in MOLGENIS fontend apps | ||
|
||
To generate the typescript interfaces for a given schema, run: | ||
`./gradlew generateTypes --args=[schemaName] [full-path+file-name]` | ||
Throughout the EMX2 frontend, we use typescript for stronger typing and validation in our frontend components. To make things easier for developers, we've include a command for autogenerating typescript interfaces and types from an EMX2 schema. This process is outlined in the steps below. | ||
|
||
for example on unix: `./gradlew generateTypes --args='catalogue /Users/john/Code/emx2/molgenis-emx2/apps/nuxt3-ssr/interfaces/generated/types.ts'` | ||
" | ||
or on windows: `.\gradlew generateTypes --args='"catalogue" "C:\Users\john\Code\emx2\molgenis-emx2\apps\nuxt3-ssr\interfaces\generated\types.ts"' ` | ||
#### 1. Start a local EMX2 instance | ||
|
||
The first param is the schema name, second param is the full path to the file the interfaces get generated into. | ||
Note that the file is either created or overridden, and that the folder must already exist. | ||
Start your local molgenis instance using gradlew. (Note: Postgres will also need to be started.) In the root `molgenis-emx2` directory, run the following command. | ||
|
||
```terminal | ||
./gradlew run | ||
``` | ||
|
||
#### 2. Import your schema | ||
|
||
Once your instance is live - | ||
|
||
1. Navigate to the local emx2 instance at [http://localhost:8080/](http://localhost:8080/) | ||
2. Sign in as admin or as another user that can create databases | ||
3. Create a new database (e.g., `My new database`) | ||
4. Import your EMX2 file into the new database | ||
|
||
Comment on lines
+415
to
+427
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not have to use this run command of create an new database to generate the types |
||
#### 3. Generate the interfaces and types | ||
|
||
In your application folder (`apps/*`), create a directory to store the types (e.g., "types", "interfaces", etc.). The command is `generateTypes`. The syntax to generate the file is described below. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does not have to be in the apps folder |
||
|
||
```terminal | ||
./gradlew generateTypes --args=[schemaName] [full-path+file-name] | ||
``` | ||
|
||
##### Definitions | ||
|
||
- `schemaName`: the name of the schema you would like to use to generate types and interfaces | ||
- `full-path+file-name`: the full system path to the output file. (Note: the command will throw an error if the output directory does not exist.) | ||
|
||
##### Notes | ||
|
||
Any changes made to this file will be overwritten when the command is run again. If you would like to keep these changes, we recommend saving them in a new file. | ||
|
||
Depending on your operating system, there are some slight differences in the way it should be written. For example, if you wanted to generate types for a schema called `MySchema`, here's how it would be written. | ||
|
||
```terminal | ||
# unix | ||
./gradlew generateTypes --args='MySchema /Users/john/Code/emx2/molgenis-emx2/apps/nuxt3-ssr/interfaces/generated/types.ts' | ||
|
||
# windows | ||
.\gradlew generateTypes --args='"MySchema" "C:\Users\john\Code\emx2\molgenis-emx2\apps\nuxt3-ssr\interfaces\generated\types.ts"' | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
somewhat verbose, prefer more direct style of current doc