#!/bin/bash

set +e

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
cd "$DIR/.."

# Build script to combine all source files into a single content.js

# Create the output file and start the IIFE
echo '(function() {' >content.js
echo '' >>content.js

# Add each external library first
for file in lib/*; do
  cat "$file" >>content.js
  echo "// === $file ===" >>content.js
  echo '' >>content.js
  echo '' >>content.js
done

# Add each source file in order
for file in src/*; do
  echo "// === $file ===" >>content.js
  cat "$file" >>content.js
  echo '' >>content.js
  echo '' >>content.js
done

echo 'main();' >>content.js

# Close the IIFE
echo '})();' >>content.js

echo "Built content.js from source files"
