Created
April 26, 2019 10:33
-
-
Save Dragod/1bf154e54abdb5868c1e6fff843f0a0a to your computer and use it in GitHub Desktop.
Build colors for a specific skin in sd-unity
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
#!/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" | |
# 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 "###############################################################" | |
} | |
# 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