#!/bin/bash

# This script creates symlinks for the external dependencies of the library
# in the node_modules directory of the consumer project.
# You can use this command to develop the library using a local laravel project
# as a consumer. This way you can test the library in the context of the consumer
# project without having to publish it to npm.

# Usage: ./link_external_deps.sh <path_to_consumer_project>
# Example: ./link_external_deps.sh /var/www/html/my-laravel-project

# To actually link the projects, you need to run this command in the library directory
# (where this script is located)
# npm link
# Then, in the consumer project directory, run
# npm link @arandu/lmaplugin-datepicker-input

# Specify your dependencies
declare -a dependencies=("react"
                         "react-dom"
                        "@mui/base"
                        "@mui/core-downloads-tracker"
                        "@mui/material"
                        "@mui/private-theming"
                        "@mui/styled-engine"
                        "@mui/system"
                        "@mui/types"
                        "@mui/utils"
                        "@emotion/babel-plugin"
                        "@emotion/cache"
                        "@emotion/hash"
                        "@emotion/is-prop-valid"
                        "@emotion/memoize"
                        "@emotion/react"
                        "@emotion/serialize"
                        "@emotion/sheet"
                        "@emotion/styled"
                        "@emotion/unitless"
                        "@emotion/use-insertion-effect-with-fallbacks"
                        "@emotion/utils"
                        "@emotion/weak-memoize")

# Get the argument - path to the consumer project
consumer_project_path=$1

# Path to the node_modules directory of the consumer project
node_modules_path="$consumer_project_path/node_modules"

# Loop over dependencies and create symlinks for each one
for dep in "${dependencies[@]}"
do
   echo "Linking $dep"
   rm -rf "node_modules/$dep"
   ln -s "$node_modules_path/$dep" "node_modules/$dep"
done