• Blogs (9)
    • 📱 236 - 992 - 3846

      đź“§ jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • bash color-display grunt script

    Blogs20152015-01-29


    bash color-display grunt script

    Here I wrote a script to restart an node-express server to initialize Angular app. It uses grunt, git, nohup to manage the node-server, easily to extend.

    #!/bin/bash
    cd ~/working_directory/
    if [ $# -ne 0 ]
    then
      if [ $1 = "full" ]; then
        echo -en "33[1m33[31mgit pull from github repository ...  33[0m"
        # do 'git pull'
        echo "33[1m33[31mDone. 33[0m"
      else
        echo "Usage: `basename (full)` to execute full installation and restart."
      fi
    fi
    
    # If `grunt node` is already running, stop it first.
    pid=`ps -ef | grep node | grep server.js | grep -v grep | wc -l`
    if [ $pid -ne 0 ];then
      pkill node
    fi
    
    # clean-up temp dir
    echo -en "33[1m33[31m1. BOWER CACHE CLEAN ...... 33[0m"
    bower cache clean
    echo -e "33[1m33[31mDone.33[0m"
    
    echo -ne "33[1m33[31m2. NPM CACHE CLEAN ...... 33[0m"
    npm cache clean
    echo -e "33[1m33[31mDone.33[0m"
    
    echo -ne "33[1m33[31m3. GRUNT JSHINT ...... 33[0m"
    grunt jshint
    echo -e "33[1m33[31mDone.33[0m"
    
    echo -en "33[1m33[31m4. GRUNT TEST ...... 33[0m"
    grunt test
    echo -e "33[1m33[31mDone.33[0m"
    
    echo -en "33[1m33[31m5. GRUNT SERVE ...... 33[0m"
    nohup grunt serve &
    echo -e "33[1m33[31mDone. See nohup.out for details. 33[0m"
    
    tail -f nohup.out