Skip to content

Instantly share code, notes, and snippets.

@kikoseijo
Created December 23, 2017 02:56
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 kikoseijo/04114b316c14e6bdac142e3c12e2f899 to your computer and use it in GitHub Desktop.
Save kikoseijo/04114b316c14e6bdac142e3c12e2f899 to your computer and use it in GitHub Desktop.
NPM - Bash and jobs
#!/bin/sh
JOB="$1"
LOCAL_PATH="xx"
DEV_PATH="x"
DIST_PATH="x"
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
blue=`tput setaf 4`
magenta=`tput setaf 5`
cyan=`tput setaf 6`
white=`tput setaf 7`
redBg=`tput setab 1`
greenBg=`tput setab 2`
yellowBg=`tput setab 3`
blueBg=`tput setab 4`
magentaBg=`tput setab 5`
cyanBg=`tput setab 6`
whiteBg=`tput setab 7`
reset=`tput sgr0`
kPrintError () {
echo "${reset}$1${reset}"
}
kPrintWarning () {
echo "${yellow}$1${reset}"
}
kPrintSuccess () {
echo "${green}$1${reset}"
}
kPrintPrompt () {
echo "${magenta}$1${reset}"
}
kPrintInit () {
echo "${green} ✔︎ ${greenBg}${white}$1${reset}"
}
copyDistToFolder () {
kPrintSuccess "Publishing content from ${blue}./dist/*${reset} to ${blue}$1${reset}"
cp -R ./dist/* $1
kPrintSuccess "Done publish all to distribution"
}
if [ $JOB == "dev" ]; then
kPrintInit "Init-dev"
rm -rf $DEV_PATH
ln -s $LOCAL_PATH $DEV_PATH
ls -la "$DEV_PATH/../"
kPrintInit "Job done success - Happy days!"
fi
if [ $JOB == "dist_setup" ]; then
kPrintInit "Preparing distribution folder"
rm -rf $DIST_PATH
mkdir $DIST_PATH
kPrintSuccess "distribution folder ($DIST_PATH) its ready"
ls -la "$DIST_PATH/../"
kPrintInit "Job done success - Happy days!"
fi
if [ $JOB == "prod" ]; then
kPrintInit "Excuting npm run production"
npm run production
kPrintSuccess "Production assets build succesfully"
copyDistToFolder $DIST_PATH
kPrintInit "Job done success - Happy days!"
fi
if [ $JOB == "git" ]; then
kPrintInit "Init GIT Job"
rm -rf $DEV_PATH # remove develpment linked folder
mkdir $DEV_PATH # remove develpment linked folder
copyDistToFolder $DEV_PATH
kPrintSuccess "Commiting to GIT"
kPrintPrompt "Type the commit message"
read commitMsg
cd $DEV_PATH
cd ..
git add .
git commit -m "$commitMsg"
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
kPrintSuccess "files commited, pushing to remote branch $branch"
git push -u origin $branch
kPrintInit "Job done success - Happy days!"
fi
if [ $JOB == "publish" ]; then
kPrintInit "Excuting npm run production"
npm run production
kPrintSuccess "Production assets build succesfully"
kPrintSuccess "Publishing to clients Wordpress folder"
cp -R ./dist/css/* "$DIST_PATH/css/"
cp -R ./dist/js/* "$DIST_PATH/js/"
kPrintInit "Job done success - Happy days!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment