Skip to content

Instantly share code, notes, and snippets.

@wbotelhos
Created March 17, 2022 01:20
Show Gist options
  • Save wbotelhos/8d9de0d7193471db69e86b72a4e45ba6 to your computer and use it in GitHub Desktop.
Save wbotelhos/8d9de0d7193471db69e86b72a4e45ba6 to your computer and use it in GitHub Desktop.
Convert SASS to SCSS
#!/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