Created
March 17, 2022 01:20
-
-
Save wbotelhos/8d9de0d7193471db69e86b72a4e45ba6 to your computer and use it in GitHub Desktop.
Convert SASS to SCSS
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
#!/bin/bash | |
convert() { | |
file=$1 | |
target=${file//.sass/.scss} | |
paths_with_file=$(echo $file | tr '/' "\n" | wc -l | tr -d ' ') | |
paths_number=$(($paths_with_file - 4)) # app assets stylesheets ... filename.sass | |
backtracks='' | |
for _i in $(seq ${paths_number}); do | |
backtracks="../${backtracks}" | |
done | |
imports=( | |
'functions/_get_color.sass' | |
) | |
ignores=( | |
'app/assets/stylesheets/functions/_get_color.sass' | |
) | |
all_imports='' | |
for import in ${imports[@]}; do | |
new_import="@import '${backtracks}${import}'" >> $file | |
all_imports="${all_imports}\n${new_import}" | |
done | |
echo -e "${all_imports}\n\n$(cat ${file})" > $file | |
./node_modules/sass/sass.js ${file}:${target} --no-source-map --load-path=node_modules | |
} | |
find app/assets/stylesheets -name '*.sass' -print0 | while read -d $'\0' file; do | |
echo $file | |
if printf '%s\n' "${ignores[@]}" | grep -Fxq ${file}; then | |
echo "File ${file} ignored." | |
else | |
convert $file | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment