Sunday, November 12, 2017

NodeJs Bash Build Script

#!/bin/bash
# Each lambda is technically its own project with its own dependencies
function npmTask() {
  startingDir=$(pwd)
  npmCommand=$1
  for nodeDir in $startingDir/lambdas/*/;
    do
      echo "start node dir: $nodeDir from $startingDir"
      if [ -d $nodeDir  ] && [ $nodeDir != "$startingDir/lambdas/spec/" ];
      then
        echo "start node dir: $nodeDir from $startingDir"
        cd $nodeDir
        npm $npmCommand
        cd $startingDir
      else
        echo "no node modules found"
      fi
    done
}
npmTask "install"
npmTask "build"
npmTask "test"