Skip to content

Instantly share code, notes, and snippets.

@hpgsantos
Last active March 3, 2019 05:09
Show Gist options
  • Save hpgsantos/831f1cc5c9741b566df31ae2fdef47d1 to your computer and use it in GitHub Desktop.
Save hpgsantos/831f1cc5c9741b566df31ae2fdef47d1 to your computer and use it in GitHub Desktop.

Look in node_modules global for exisint paths

build_command_lambda_local=$(getPathFromModulesNode mongoose,express,mongoose)
echo $build_command_lambda_local 

Recover global dir for node_modules

# this function need do be split in two and refactorated
function getPathFromModulesNode() {

  local mystring=$1
  local ref_item=""
  local -a arrPaths
  arrPaths=()
  arr=("${(@s/,/)mystring}")
   #getNodeModulePath $arr[1]
   for i in $arr; do
      
      local global_dir="$NODE_MODULES_GLOBAL_DIR/$i"
       
       if [ -d "$global_dir" ]
       then
          arrPaths+=($global_dir)
        else
          arrPaths+=($i)
       fi
    
   done
   echo ${(u)arrPaths[@]}

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment