-
Notifications
You must be signed in to change notification settings - Fork 15
feat(cli): add support for --separate-files flag to have separate component type files
#327
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
base: main
Are you sure you want to change the base?
feat(cli): add support for --separate-files flag to have separate component type files
#327
Conversation
--separate-files flag--separate-files for type generation
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.
Pull Request Overview
This PR adds support for generating separate TypeScript definition files per component using a new --separate-files flag in the types generate command. The default behavior remains unchanged, generating a single consolidated .d.ts file.
- Added
--separate-filesoption to enable per-component type file generation - Refactored type generation logic to support both single-file and separate-files modes
- Enhanced import scoping to include only required Storyblok types per file
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/cli/src/commands/types/generate/index.ts | Removed unused import and updated readComponentsFiles call with explicit options |
| packages/cli/src/commands/types/generate/actions.ts | Refactored generateTypes to support separate files mode with per-component import scoping |
| packages/cli/src/commands/types/generate/index.test.ts | Added test coverage for separate-files mode error handling |
| packages/cli/src/commands/types/generate/actions.test.ts | Added comprehensive test suite for separate-files functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
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.
Thank you for your contribution! I left a couple of comments. Additionally, as you suggested, it would be good if we show some info in the console when a user tries to generate types without running the components command with the same flag.
… not json separate
Yes, I added it now. Let me know what you think! |
--separate-files for type generation--separate-files flag
--separate-files flag--separate-files flag to have separate component type files
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.
I like the direction this PR is going! Yet in multiple places, it is still very visible that this feature was added at a later point.
E.g., there is const typedefString = await generateTypes where typedefString now can be an array.
I didn't invest too much thinking time into what that would mean for the code, but just as a general thought, I think it would be nice if there is only one part in the logic where --separate-files changes the behavior.
For example, by always dealing with an array of types and at the place where we save the types, deciding if we save this array in one or multiple files based on the config.
|
Hi @rydkvist, just following up if you had the chance to check the latest comments. There also seem to be some conflicts with the main branch. Let me know if I can help you with that |
I understand, let me revisit the code and see what I can do 👍🏼 |
|
Hi @alvarosabu and @maoberlehner, please have another look now. I hope it looks better now. Fixed a type discrepancy for Did some other type of clean-up on this PR, will verify that changes work locally before pushing an official PR into this repo. Let me know if you're interested on the PR though! |
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.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| import { readFileSync } from 'node:fs'; | ||
| import type { ComponentPropertySchema } from '../../../types/schemas'; | ||
| import type { TypesCommandOptions } from '../command'; | ||
| import type { ComponentsData } from 'src/commands/components'; |
Copilot
AI
Oct 22, 2025
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.
Import path should use relative path syntax '../../components' instead of absolute 'src/commands/components' to ensure proper module resolution.
| import type { ComponentsData } from 'src/commands/components'; | |
| import type { ComponentsData } from '../../../commands/components'; |
|
|
||
| expect(files[0].content).toContain('// This file was generated by the storyblok CLI.'); | ||
| expect(files[0].content).toContain('// DO NOT MODIFY THIS FILE BY HAND.'); | ||
| expect(files[0].name).toBe('Hero Section X'); |
Copilot
AI
Oct 22, 2025
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.
The expected filename 'Hero Section X' contains spaces and special characters which will not match the sanitized output from sanitizeFilename. The test should expect a sanitized version like 'Hero_Section_X' or similar based on the sanitization logic.
| expect(files[0].name).toBe('Hero Section X'); | |
| expect(files[0].name).toBe('Hero_Section_X'); |
Description
Introduce the optional
--separate-filesflag to thetypes generatecommand, giving users more flexibility in how type definitions are structured.What’s changed
--separate-filesoption totypes generate{filename}.d.tsfile{componentName}.d.tsfile per componentsanitizeFilenameutility to ensure safe filenamesNotes
Example (Separate files)
storyblok components pull --separate-files --space {spaceNumber} --path cms/.generated storyblok types --space {spaceNumber} generate --strict --sf --type-prefix CMS --path cms/.generatedExample (Single file)
storyblok components pull --space {spaceNumber} --path cms/.generated storyblok types --space {spaceNumber} generate --strict --type-prefix CMS --path cms/.generated