build/build.sh
changeset 352 d8a8c57f36c4
parent 346 4cd0f8c936ed
child 367 e0fb97c1e9c6
equal deleted inserted replaced
351:c69dcc3b0524 352:d8a8c57f36c4
       
     1 #!/usr/bin/env bash
       
     2 
       
     3 set -e
       
     4 ## option --prod/--dev
       
     5 
       
     6 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
       
     7 
       
     8 VAGRANT_STARTED=false
       
     9 
       
    10 green="\x1B[0;32m" # '\e[1;32m' is too bright for white bg.
       
    11 blue="\x1B[1;34m"
       
    12 endColor="\x1B[0m"
       
    13 
       
    14 function echoblue() {
       
    15     echo -e "${blue}$1${endColor}"
       
    16 }
       
    17 
       
    18 function install() {
       
    19     pushd "$DIR"
       
    20 
       
    21     echoblue "---> preparing bo client"
       
    22     pushd ../server/bo_client
       
    23     npm install
       
    24     ./node_modules/.bin/bower install
       
    25     popd
       
    26     echoblue "---> preparing bo client done"
       
    27 
       
    28     echoblue "---> preparing back"
       
    29     pushd ../server/src
       
    30     php composer.phar install
       
    31     npm install
       
    32     ./node_modules/.bin/bower install
       
    33     popd
       
    34     echoblue "---> preparing back done"
       
    35 
       
    36     echoblue "---> preparing app-client"
       
    37     pushd ../cms/app-client
       
    38     npm install
       
    39     ./node_modules/.bin/bower install
       
    40     popd
       
    41     echoblue "---> preparing app-client done"
       
    42 
       
    43     echoblue "---> preparing module"
       
    44     pushd ../cms
       
    45     npm install
       
    46 
       
    47 
       
    48     echoblue "---> checking vagrant"
       
    49     if vagrant status | grep -q "running"; then
       
    50         echoblue "---> starting vagrant"
       
    51         vagrant up
       
    52         VAGRANT_STARTED=true
       
    53     fi
       
    54 
       
    55     echoblue "---> done"
       
    56 
       
    57     popd
       
    58 
       
    59 }
       
    60 
       
    61 function usage() {
       
    62     cat <<EOF
       
    63 Usage: $0 [-I] [-p|-d] [-h]
       
    64     -I : do not run install
       
    65     -h : print this message
       
    66     -p : build for production
       
    67     -d : build for development
       
    68 EOF
       
    69 }
       
    70 
       
    71 environment=""
       
    72 do_install=true
       
    73 
       
    74 
       
    75 while getopts "Ihpd" opt; do
       
    76   case $opt in
       
    77     I) do_install=false ;;
       
    78     h) usage; exit 0 ;;
       
    79     p) [[ -n "$environment" ]] && { usage >&2; exit 1; } || environment='production' ;;
       
    80     d) [[ -n "$environment" ]] && { usage >&2; exit 1; } || environment='development' ;;
       
    81     \?) usage >&2; exit 1 ;;
       
    82   esac
       
    83 done
       
    84 shift $((OPTIND-1))
       
    85 
       
    86 [[ -z "$environment" ]] && environment='production'
       
    87 
       
    88 case $environment in
       
    89     development) build_option='--dev' ;;
       
    90     *) build_option='--prod' ;;
       
    91 esac
       
    92 
       
    93 echo "environment: $environment"
       
    94 echo "do_install: $do_install"
       
    95 [[ "$do_install" == true ]] && echoblue "DO INSTALL" && install;
       
    96 
       
    97 pushd "$DIR"
       
    98 
       
    99 echoblue "---> cleaning build folder"
       
   100 rm -fr root
       
   101 
       
   102 echoblue "---> creating build folder"
       
   103 mkdir -p root/var/www/corpusdelaparole/corpus-back
       
   104 mkdir -p root/var/www/corpusdelaparole/drupal/sites/all/modules
       
   105 
       
   106 echoblue "---> buiding back"
       
   107 pushd ../server/src
       
   108 version=$(sed -n "s/[[:space:]]*\'version\'[[:space:]]*=>[[:space:]]*\'\([\.0-9]*\)\'/\1/p" config/version.php)
       
   109 version=${version:-0.0.0}
       
   110 ./node_modules/.bin/gulp copy-build ${build_option}
       
   111 popd
       
   112 echoblue "---> buiding back done"
       
   113 
       
   114 echoblue "---> building app-client"
       
   115 pushd ../cms/app-client
       
   116 ./node_modules/.bin/ember build ${build_option}
       
   117 popd
       
   118 echoblue "---> building app-client done"
       
   119 
       
   120 echoblue "---> building module"
       
   121 pushd ../cms
       
   122 ./node_modules/.bin/gulp copy-build ${build_option} --version="$version"
       
   123 popd
       
   124 
       
   125 echoblue "---> building package"
       
   126 vagrant ssh -c "/vagrant/build_rpm.sh"
       
   127 
       
   128 echoblue "---> done"
       
   129 
       
   130 popd