-
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
feat: push components cmd #152
base: next
Are you sure you want to change the base?
Conversation
…SaveComponentsOptions - Deleted the `ComponentsSaveOptions` interface as it was no longer needed. - Removed the `space` property from the `SaveComponentsOptions` interface to simplify its structure. - This cleanup enhances code maintainability and reduces complexity in the components command.
- Added `@topcli/spinner` to implement async list of tasks - Extended error handling support for multiple operations and complex message stacks
- Implemented warning message when no components match filter criteria - Added specific message for separate files scenario - Temporarily replaced `pushComponent` with `fakePushComponent` for testing
- Implemented new actions for fetching and pushing component internal tags - Updated SpaceData and SpaceComponent interfaces to include internal tags - Enhanced component push process to handle internal tag synchronization - Added filesystem support for saving and reading internal tags - Updated error handling for new internal tag operations
- Added `upsertComponent` and `upsertComponentInternalTag` methods to handle component creation/update - Improved component push process to handle existing components and internal tags - Updated error handling to manage component name conflicts - Added new API error actions for update operations - Refined component push command to process internal tags sequentially
- Destructured `password` and `region` from state at the beginning of methods
- Implemented exponential backoff retry strategy for network requests - Added configurable max retries and base delay options - Improved error handling for rate limit and network errors - Created a delay utility function to support retry mechanism
…matting - Simplified and clarified conditional logic in component file reading functions - Added explicit continue statements and improved code formatting - Removed unused imports in components index file - Refined conditional checks in custom fetch utility
- Added support for pushing component groups, presets, and internal tags - Implemented upsert methods for component groups and presets - Improved error handling for resource conflicts and name collisions - Added recursive property removal utility for clean preset updates - Updated component push command to handle consolidated and separate file scenarios - Enhanced error messaging and spinner feedback for different resource types
- Split components module into separate pull, push, and core files - Created dedicated directories for pull and push actions - Moved constants, actions, and command implementations to respective modules - Simplified index file to export core functionality - Improved code organization and separation of concerns - Maintained existing functionality while enhancing code structure
- replace ora spinner with @topcli/spinner across multiple commands - Updated login, user, languages, and components commands to use @topcli/spinner - Added isVitest flag to conditionally disable spinner in test environments - Removed ora dependency from package.json - Standardized spinner initialization and usage across different commands - Improved spinner configuration with verbose option
- Applied consistent code style with semicolons across multiple test files - Cleaned up import and export statements - Improved code formatting and readability - Maintained existing test logic and coverage - Ensured uniform code style in TypeScript test files
…cture - Extracted tag handling logic into a separate `operations.ts` file - Commented out complex component and preset pushing code for future refinement - Replaced direct `program` import with `getProgram()` singleton method - Simplified push command by extracting tag handling to a dedicated function - Removed unused imports and simplified code structure
- Created test file for component push actions with mock server - Implemented tests for pushing, updating, and upserting components, groups, presets, and internal tags - Added test cases for successful API interactions and error handling - Utilized MSW for mocking HTTP requests and responses - Covered various scenarios including valid and invalid token authentication - Tested readComponentsFiles function with consolidated and separate file structures
- Created comprehensive test suite for `handleTags` function in push operations - Implemented test cases for successful and failed tag processing - Mocked external dependencies like spinner and actions module - Verified correct behavior of tag upsert with different scenarios
- Added `handleComponentGroups` function to process component groups with parent-child relationships - Implemented recursive group processing with UUID and ID mapping - Updated type definitions to support nullable parent references - Created comprehensive unit tests for group handling with various scenarios - Improved error handling and spinner feedback during group upsert operations
…sh command for consolidated files - Added `handleComponents` function to process components with mapped group UUIDs and tag IDs - Implemented comprehensive component and preset upsert logic - Enhanced error handling and spinner feedback during component processing - Created unit tests covering various component push scenarios - Integrated group and tag mapping into component push workflow
…cific filtering - Added new filtering functions `filterSpaceDataByPattern` and `filterSpaceDataByComponent` - Implemented flexible filtering for components using wildcard patterns and exact component names - Updated push command to support filtering components by name or pattern - Added comprehensive unit tests for new filtering functionality - Improved component processing with intelligent resource mapping - Updated VSCode launch configurations to support new filtering options
…tions - Removed unused type imports in operations test file - Simplified import statements for component-related types - Improved code readability by removing unnecessary type references
… and file structure - Updated pull command to maintain consistent `components/{spaceId}` folder structure - Improved path resolution for custom and default file paths - Added README.md with comprehensive documentation for component pull and push commands - Enhanced file path generation for separate and consolidated file modes - Ensured consistent file output regardless of custom path configuration - Updated related utility functions to support more flexible path handling
- Modified languages test to save files in a space-specific directory - Removed unnecessary console log in languages command index - Updated file path for consolidated languages file output
- Updated test cases for `resolvePath` function to correctly handle path and folder arguments - Ensured proper path resolution for both specified and default paths - Corrected expected path resolution in test assertions
…dling - Modified test cases to use space-specific directory structure for component files - Updated file path resolution in saveComponentsToFiles tests - Ensured consistent file output across different test scenarios - Refactored test setup to align with recent path handling improvements
…ing and path resolution - Modified test cases to use dynamic space-specific paths - Updated error assertion for file not found scenarios - Enhanced error object validation with more detailed error information - Refactored test setup to improve path flexibility and error handling
…ocessing logic - Modified test cases to reflect updated component upsert behavior - Removed schema field from mock component data - Added mock component groups to test data - Updated test expectations for component and preset processing - Adjusted test assertions for component upsert calls and error handling
…ist and dependency handling - Updated test scenarios for component group whitelisting - Modified test expectations for circular dependency detection - Adjusted test assertions for missing dependencies handling - Simplified component processing test steps
}, { | ||
path: undefined, | ||
separateFiles: false, | ||
}); | ||
expect(konsola.ok).toHaveBeenCalledWith(`Components downloaded successfully to ${chalk.hex(colorPalette.PRIMARY)(`.storyblok/components/12345/components.json`)}`); | ||
}); | ||
|
||
it('should fetch a component by name', async () => { | ||
/* it('should fetch a component by name', async () => { |
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.
@edodusi I just realized these are all commented out, don't remember why, let me check
- Uncommented and fixed test cases for component pull command - Updated test scenarios for fetching single and multiple components - Added tests for error handling and path configuration options - Corrected import and function references in test file - Ensured comprehensive coverage of pull command functionality
…itial tests for push command
…elists - Added test case for pushing components with group whitelist - Added test case for pushing components with component whitelist - Updated test scenarios to validate component filtering based on whitelist conditions - Expanded test coverage for component push command with different restriction types
- Implemented test cases for pushing specific components by name - Added test scenarios for filtering components using wildcard patterns - Introduced new filtering functions `filterSpaceDataByComponent` and `filterSpaceDataByPattern` - Expanded test coverage for component push command with name and filter options
- Removed console log statements from push command test - Simplified test setup by removing unnecessary spy and mock logging - Maintained core test logic for validating component push workflow
- Deleted unnecessary console.log statement in handleComponents method - Cleaned up verbose logging of internal state during component processing
…command - Refactored `readComponentsFiles` to use a more robust file reading approach - Added detailed error messaging for non-existing space directories - Implemented a generic `readJsonFile` utility function for consistent file parsing - Enhanced error handling for component file reading scenarios - Updated error messages to provide clearer guidance for users
- Removed unnecessary CommandError import from actions.ts - Cleaned up unused import in actions.test.ts - Simplified error handling imports
- Added a check to ensure component has a name before processing - Implemented a delay and spinner failure for components without a name - Improved error handling for missing component name scenario
- Ensured only tags with `object_type` of 'component' saved
|
||
### `--separate-files` | ||
|
||
[^1] Consolidated files are the default way to store components. They are a single file for each resource (components.json, groups.json, presets.json, tags.json). |
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.
hey @alvarosabu should this go into the repo?
- [ ] Pull components with nested groups | ||
- [ ] Pull components with multiple presets | ||
- [ ] Pull components with internal tags | ||
- [ ] Test verbose mode with --verbose flag |
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.
also this one, should it stay in the repo?
}; | ||
|
||
// Component preset actions | ||
// Component preset actions |
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.
repeated line
- [ ] Push components with presets | ||
- [ ] Push components with whitelists | ||
- [ ] Test custom path scenarios | ||
- [ ] Verify component updates vs creation |
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.
same as above
Components Push Command
The
storyblok components push
command allows you to push component schemas, groups, presets, and internal tags to a target Storyblok space. This is particularly useful for migrating components between spaces or deploying component changes across environments.Prerequisites
Before pushing components, ensure you have the necessary files in your
.storyblok/components/{spaceId}
directory. These files can be obtained using thestoryblok components pull
command. The file structure should match how you intend to push:Basic Usage
Architecture & Flow
The push command is organized in three main layers with a specific processing flow to ensure dependencies and references are handled correctly.
Command Structure
Processing Flow Examples
1. Simple Component Push
Flow:
Read Phase
Dependencies Phase
Component Phase
2. Component with Folders
Flow:
Group Hierarchy
Component Update
3. Component with Whitelists
If page.json has:
Flow:
Whitelist Processing
Update References
Key Architecture Points
Dependency Order
ID/UUID Mapping
Two-Pass System
Error Handling
This architecture ensures:
Command Options
--space <spaceId>
-s
--from <spaceId>
-f
--filter <pattern>
--fi
--separate-files
--sf
--path <path>
-p
--verbose
-v
Push Behavior
When pushing components, the command follows these rules:
Dependencies First: The command automatically handles dependencies in the correct order:
Smart Updates: When pushing a specific component or using a filter:
File Mode Matching:
--separate-files
, you should push with--separate-files
--separate-files
flagExamples
Manual Testing Checklist
Basic Push Operations
Dependency Handling
Filter and Source Options
File Mode Testing
Error Cases
Special Cases