Skip to content

Instantly share code, notes, and snippets.

@Dragod
Created February 21, 2020 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dragod/b7b53a55ff0839b3047782958cdcc160 to your computer and use it in GitHub Desktop.
Save Dragod/b7b53a55ff0839b3047782958cdcc160 to your computer and use it in GitHub Desktop.
Add a check to build default skin
#!/usr/bin/env bash
# Sass build only skin colors
# Use: type "colors" in bash console, or npm run colors,
# make sure eithe .bashrc or npm scripts are set up for this to work
# No Color
white='\e[1;37m'
# Red
red='\e[0;31m'
# Green
green='\e[32m'
# Light purple
light_purple='\e[1;35m'
#normal
normal='\e[m'
# Create an array from an external configuration file (grunt-config.json) for main.css path
readarray -t pathName < <(grep '"' grunt-config.json | cut -d '"' -f4)
#Removing last value of the path array so it doesn't show the assets path
unset 'pathName[${#pathname[@]}-1]'
# Creating a new array from grunt-config.json for the assests path only
readarray -t assetsPath < <(grep '"' grunt-config.json | cut -d '"' -f4)
# Get last element of the array to get the right path for assets
assets=${assetsPath[-1]}
# Print bulid messages, evaluate build sass and evaluate task elapsed time
function build()
{
# Print the path of main css
printf "\n${light_purple}→${normal} Override @import in main.css with $brand, path: ${pathName[@]} ${NC}\n\n"
#Override the main.css
echo "@import url(\"../css/app.css\"); @import url(\"../assets/$brand/css/$brand.css\");" >${pathName[@]}/main.css
# Build sass and stamp times of the compiled task at the end
STARTTIME=$(date +%s)
eval "grunt colors-1 --skin=$brand"
ENDTIME=$(date +%s)
printf "\nColors compile time: ⌚ ${red} $(($ENDTIME - $STARTTIME)) seconds${normal}\n\n"
}
function colors()
{
printf "\n################ [${light_purple}Sass:${normal} Building brand skin colors] ################\n\n"
# Ask if I should build default skin (ioc) or pick your own brand
read -p "Would you like to print default skin (ioc)? y/n: " answer
if [ $answer == "y" ]; then
# Print the path of main css
printf "\n${light_purple}→${normal} Override @import in main.css with IOC, path: ${pathName[@]} ${NC}\n\n"
#Override the main.css
echo "@import url(\"../css/app.css\"); @import url(\"../assets/ioc/css/ioc.css\");" >${pathName[@]}/main.css
# Build sass and stamp times of the compiled task at the end
STARTTIME=$(date +%s)
eval "grunt colors-1 --skin=ioc"
ENDTIME=$(date +%s)
printf "\nColors compile time: ⌚ ${red} $(($ENDTIME - $STARTTIME)) seconds${normal}\n\n"
elif [ $answer == "n" ]; then
# Read the brand name from command line
read -p "Type brand name: " brand
# Setup the assets directory based on your grunt-config.json to create the "css" folder if doesn't exsist yet
directory=$assets'/'$brand'/'css
# Exit the script if the brand name is left blank
if [[ -z "$brand" ]]; then
printf '%s\n' "No brand entered, will now exit..."
return
# If the directory exsist, build colors
elif [[ -d "$directory" ]]; then
printf "\nDirectory exist, task start!\n"
build
else
# If css directory does not exsist create one with the brand name the user just typed in then build
printf "\n${red}✗${normal} The css directory of the brand ${brand} in: ${directory}, does not exsist...\n"
# Set the directory path
newDirectory=$assets'/'$brand'/'css
# Create the new directory
mkdir -p -- "$newDirectory";
printf "\n${green}✓${normal} New css directory created for ${brand} brand in: "${newDirectory}
printf "\n"
build
fi
printf "###############################################################"
else
echo "Closing, no valid parameter passed, either y or n..."
fi
}
# Run the script calling the function
colors
printf "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment