#!/bin/bash

# Input Ruby file
INPUT_FILE="lambda_function.rb"
# Source directory where the files are located
SOURCE_DIR="../../ruby/lib"

# Destination directory to copy the files
DEST_DIR="./lib"



# Ensure the destination directory exists
mkdir -p "$DEST_DIR"

# Parse the Ruby file
while IFS= read -r line; do
  # Check if the line starts with `require "jam_ruby`
  if [[ $line =~ ^require\ \"jam_ruby/(.*)\"$ ]]; then
    # Extract the relative path from the require statement
    RELATIVE_PATH=${BASH_REMATCH[1]}

    # Build the source and destination paths
    SOURCE_FILE="$SOURCE_DIR/jam_ruby/$RELATIVE_PATH.rb"
    DEST_FILE="$DEST_DIR/jam_ruby/$RELATIVE_PATH.rb"

    # Ensure the destination subdirectory exists
    DEST_SUBDIR=$(dirname "$DEST_FILE")
    mkdir -p "$DEST_SUBDIR"

    # Copy the file
    if [ -f "$SOURCE_FILE" ]; then
      cp "$SOURCE_FILE" "$DEST_FILE"
      echo "Copied: $SOURCE_FILE -> $DEST_FILE"
    else
      echo "Warning: Source file not found: $SOURCE_FILE"
    fi
  fi
done < "$INPUT_FILE"

