Skip to content

Commit

Permalink
Fix generating structures for names that end with the word components
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Jul 19, 2023
1 parent d646c83 commit ee65b3c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

## Unreleased

* Fixed an edge case generating structures for component names that end with the word `components`

## v3.6.4 (July 18, 2023)

* Fixed `ENV_BOOKSHOP_LIVE` flag being undefined when live editing Astro components
Expand Down
2 changes: 1 addition & 1 deletion javascript-modules/generate/lib/structure-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const cascadeEntries = ([key,]) => {
}

const getComponentBase = (componentPath) => {
return componentPath.replace(/^.*components\//, '').split(".")[0];
return componentPath.replace(/^.*?components\//, '').split(".")[0];
}

const getComponentKey = (componentPath) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,32 @@ Feature: Bookshop Structure Generation
Then stderr should be empty
And stdout should contain "Added 1 structure from 1 Bookshop to 1 site."
Then I should see "site/public/_cloudcannon/info.json" containing the values:
| path | value |
| _structures.content_blocks.id_key | "_bookshop_name" |
| _structures.content_blocks.values.0.value._bookshop_name | "card" |
| _structures.content_blocks.values.0.value.card_text | "" |
| _structures.content_blocks.values.0.value.color | "Blue" |
| path | value |
| _structures.content_blocks.id_key | "_bookshop_name" |
| _structures.content_blocks.values.0.value._bookshop_name | "card" |
| _structures.content_blocks.values.0.value.card_text | "" |
| _structures.content_blocks.values.0.value.color | "Blue" |

Scenario: Generating structures for complex component keys
Given a component-lib/components/section/section--heading-and-components/section--heading-and-components.bookshop.yml file containing:
"""
spec:
structures:
- content_blocks
blueprint:
card_text: ""
color: Blue
"""
When I run "npm start" in the . directory
Then stderr should be empty
And stdout should contain "Added 1 structure from 1 Bookshop to 1 site."
Then I should see "site/public/_cloudcannon/info.json" containing the values:
| path | value |
| _structures.content_blocks.id_key | "_bookshop_name" |
| _structures.content_blocks.values.0.value._bookshop_name | "section/section--heading-and-components" |
| _structures.content_blocks.values.0.value.card_text | "" |
| _structures.content_blocks.values.0.value.color | "Blue" |

Scenario: Generating structures carries through extra fields
Given a component-lib/components/nested/card/card.bookshop.yml file containing:
Expand Down

0 comments on commit ee65b3c

Please sign in to comment.