#!/usr/bin/env bash
set -e;
relativePath=$(dirname $0);
cd ${relativePath};
absolutePath=$(pwd);
cd ..;
projectRootPath=$(pwd);

demoRootPath="${projectRootPath}/demo";
cd ${demoRootPath};

echo "now running demo testing";  
for demoPath in $(ls)
do
    echo "demo testing ${demoPath}";  
    cd "${demoRootPath}/${demoPath}";
    echo "demo testing ${demoPath} (1/4)";  
    npm i;
    echo "$?";
    if [ "$?" -eq 0 ]
    then
         echo "demo testing ${demoPath} (1/4) --- done";  
    else
        exit 1;
    fi
    
    echo "demo testing ${demoPath} (2/4)";  
    npm run lint; 
    echo "$?";
    if [ "$?" -eq 0 ]
    then
         echo "demo testing ${demoPath} (2/4) --- done";  
    else
        exit 1;
    fi
    
    echo "demo testing ${demoPath} (3/4)";  
    npm run build;  
        echo "$?";
    if [ "$?" -eq 0 ]
    then
         echo "demo testing ${demoPath} (3/4) --- done";  
    else
        exit 1;
    fi
    
    echo "demo testing ${demoPath} (4/4)";  
    npm run test;     
    if [ "$?" -eq 0 ]
    then
         echo "demo testing ${demoPath} (4/4) --- done";  
    else
        exit 1;
    fi
done
