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
-
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
__imageshot
file 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, withfileName
indicating 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.fileName
by finding the last occurrence of a forward slash (/
) and usingsubstring
to get everything before this slash. This ensures the path to the directory containing the component is obtained.Construct the Imageshots Directory Path:
__imageshots
directory by appending__imageshots
to 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:
configurationName
andstory
to theimageshotDir
path.Output Format
Upon execution, the
nearestComponentImageshotPathFormatter
function 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.__imageshots
is the designated directory for storing imageshot files, placed directly next to the component's directory.chrome.desktop-playground.png
is the filename of the imageshot, which combines the configuration name (chrome.desktop
) and the story name (playground
), and appended with the.png
file extension.Return:
src/components/componentName/__imageshots/chrome.desktop-playground.png
CLI Configuration for Project Root Reference
To utilize the project's root directory for storing and referencing imageshot files instead of the default
./loki/reference
path, 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:Beta Was this translation helpful? Give feedback.
All reactions