Repository navigation
Store imageshots beside corresponding components with root directory configuration #502
ReihaneB
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I created a function that allows you to use imageshots as close as possible to their respective components:
Imageshot Path Formatter Explanation
This code snippet is designed to generate a formatted file path for storing imageshot files related to specific components in a development environment. Its primary purpose is to ensure that imageshot files are organized neatly in a directory named
__imageshots, located in the same directory as the component it represents. Below is a detailed breakdown of the code:Path Formatter Function (
nearestComponentImageshotPathFormatter)This function formats a path for storing an
__imageshotfile related to a specific component story, taking an object with three properties:story: The name of the story or component (ex: playground)parameters: Contains various parameters, withfileNameindicating the path to the component file.configurationName: Represents a specific configuration for which the imageshot is taken (ex: chrome.desktop)Steps Performed
Extract the Component Directory:
parameters.fileNameby finding the last occurrence of a forward slash (/) and usingsubstringto get everything before this slash. This ensures the path to the directory containing the component is obtained.Construct the Imageshots Directory Path:
__imageshotsdirectory by appending__imageshotsto the directory path obtained in the previous step. This creates a dedicated place next to each component for storing its imageshots, making the structure organized and easily navigable.Generate the Full Path for the Imageshot File:
configurationNameandstoryto theimageshotDirpath.Output Format
Upon execution, the
nearestComponentImageshotPathFormatterfunction returns a string that represents the full path of the imageshot file, formatted and organized according to the specified naming conventions and directory structure. The returned string follows this format:This output example demonstrates how the function constructs the path:
src/components/componentName/is the directory of the component.__imageshotsis the designated directory for storing imageshot files, placed directly next to the component's directory.chrome.desktop-playground.pngis the filename of the imageshot, which combines the configuration name (chrome.desktop) and the story name (playground), and appended with the.pngfile extension.Return:
src/components/componentName/__imageshots/chrome.desktop-playground.pngCLI Configuration for Project Root Reference
To utilize the project's root directory for storing and referencing imageshot files instead of the default
./loki/referencepath, the Loki command-line interface (CLI) commands need to be configured with the--reference .option. This modification directs Loki to use the root of the project as the base reference directory for imageshot comparison, creation, and updates. Here are the modified CLI commands incorporating this option:All reactions