-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add command for Typescript typedefs generation #79
Conversation
Update 23 Feb 2024I refactored all the tests so that they could run with ESM. |
Update 28 Feb 2024I bumped the |
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.
This is HUGE, amazing refactor @Edo-San 🚀
Please take a look in this comment, it's very important.
Just to make a note:
This PR will generate a breaking change, it will be necessary to publish as V4.0.0
…s and no restrictions cases
Thank you @ademarCardoso Appreciate! 🤗 I wanted to ask you about the breaking changes, as I am probably missing something. Aside from the fact that with this new build step, there won't be the possibility to directly import anything from the CLI, as we won't be exposing all the CLI files anymore, do you see any other breaking changes? UPDATE 06/03/2024I rebased the PR on the updated master branch and fixed the conflicts related to the merged #81 PR |
Due to the amount of changes in the project, I thought it would be a breaking change, but I talked to other engineers and since the cli itself won't change the user's behavior, in other words, I don't think anything will break, so it's not a breaking change. |
@Edo-San I don't know if there is a QA on your team, but I would recommend that this PR be reviewed by one, to ensure that everything is working as it should. Carlos is an excellent QA and has experience with the CLI |
Pushed a fix for this one! Thanks again for pointing that out @carlosericciardi 🙏 |
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.
Awesome work!
@ademarCardoso Do you think we can merge it now that @carlosericciardi has reviewed it? You can merge it straight away if you want 🤗 |
Merging it as we good greenlight from @gustavomelki UPDATEReverted because a build step is missing on the CI |
🎉 This PR is included in version 3.28.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Pull request type
How to test this PR
I have set up an npm
dev
script that can be useful to conveniently run the build step and the CLI in a "pseudo-dev mode".pull-components
command)generate-typescript-typedefs
command providing the components JSON Schema via the--sourceFilePaths
flagCommand example
What is the new behavior?
The main purpose of this PR is to add a command to the CLI that would provide our users with first-party support for generating Typescript type definitions based on Storyblok component schemas. As we're dealing with Typescript, it was a good opportunity to open up Typescript adoption in the CLI as well, as it made working with Typescript MUCH easier.
Here's a list of the provided changes:
GenerateTypesFromJSONSchemas
class responsible for the whole rendering cycle of the Typescript type definitions file.unbuild
- required updating all import types to be ESM.vscode
settings to prevent automated formatting of existingjs
files while working onts
filesgenerate-typescript-typedefs
CLI command and task filetypes
README
file related to thegenerate-typescript-typedefs
commandTBD / Potential issues / Need hints
ISbStoryData
type from the samestoryblok
package, but there are some issues with exporting those types from this package, namely because some of them are also being imported from thestoryblok-js-client
. I'd assume that any user who is willing to use this new command is going to rely on thestoryblok-js-client
, at some point or another, so I guess the way to go is to somehow export thetypes
alongside thepackage.json
with@storyblok/js
orstoryblok-js-client
listed as dependencies so that we can be sure we're going to import types that are going to be available from our distributed types. I still have to find out how to do that properly :DPotential improvements
As I had the chance to dig further into the CLI repo, I have outlined some potential improvements, for both the
generate-typescript-typedefs
command and the whole repo:StoryblokProvidedPropertyTypes
and bloks (components) that can be created in Storyblok with the same name. I.e. a user can create a blok namedtable
, and the types will end up having twoTableStoryblok
types, one for the user's component and one for the Storyblok-providedTable
type.customFieldTypesParser
or aJSONSchemaToTSOptions
.scaffold
, that are not documented in the README file. Maybe we could benefit from some cleanup. That command in particular I think is related to the old Rendering Service.Other information
A new
build
step should be added to trigger thebuild
script.This work has been heavily inspired by dohomi's Storyblok generate ts. Thank you for your hard work and support! 🙏