forked from carbon-design-system/carbon-for-ibm-dotcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(storybook): script to use local styles in dev (carbon-design-sy…
…stem#10915) * chore(storybook): script to use local styles in dev * chore(yarn): using yarn start instead * chore(yarn): require fswatch for script
- Loading branch information
1 parent
75175c0
commit 36b824f
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
declare -a component_names | ||
|
||
if ! command -v fswatch &>/dev/null; then | ||
echo "fswatch required (https://github.com/emcrisostomo/fswatch)" | ||
exit 1 | ||
fi | ||
|
||
# Function to search and replace the string with proper escaping | ||
search_and_replace_string() { | ||
directory="$1" | ||
search_string="$2" | ||
replace_string="$3" | ||
|
||
# search for scss files under directory | ||
find "$directory" -type f -name "*.scss" ! -path "*/__stories__/*" | while read -r scss_file; do | ||
# search and replace the string in the file | ||
sed -i "" "s#$search_string#$replace_string#g" "$scss_file" | ||
echo "Replaced imports in $scss_file" | ||
done | ||
} | ||
|
||
# monitor for file changes under the `styles` directory | ||
fswatch -0 ../styles/ | while read -d "" changed_file | ||
do | ||
component=$(basename "$(dirname "$changed_file")") | ||
target_directory="src/components/$component" | ||
|
||
if [[ ! " ${component_names[@]} " =~ " ${component} " ]]; then | ||
component_names+=("$component") | ||
search_and_replace_string "$target_directory" "@carbon/ibmdotcom-styles/scss/components" "../../../../styles/scss/components" | ||
fi | ||
|
||
done | ||
|
||
cleanup() { | ||
echo "Reverting styles imports" | ||
search_and_replace_string "src/components" "../../../../styles/scss/components" "@carbon/ibmdotcom-styles/scss/components" | ||
} | ||
|
||
trap cleanup EXIT |