#!/usr/bin/env bash

source ./bin/env
cloned=()

cd ../
mkdir -p industry-dev
cd industry-dev

for ext in "${exts[@]}"; do
  if [ ! -d "$ext" ]; then
    printf "\nCloning and installing $ext...\n"
    git clone git@github.com:invrs/$ext.git
    cd $ext
    npm install
    rm -rf node_modules/industry
    for e in "${exts[@]}"; do
      if [ "$e" != "$ext" ]; then
        rm -rf node_modules/$e
      fi
    done
    cloned+=( "$ext" )
    cd ../
  fi
done

for ext in "${cloned[@]}"; do
  if [ -d $ext ]; then
    printf "\nLinking $ext...\n"
    cd $ext
    npm link ../../industry
    for e in "${exts[@]}"; do
      if [ "$e" != "$ext" ]; then
        npm link ../$e
      fi
    done
  fi
  cd ../
done
