#!/bin/bash

# The purpose of this script is to inject templates into the source files
# so when they are bundled they are good to go. Browserify can do this itself
# as a transform, but it doesn't do it for files it finds from node_modules,
# which rather defeats the point of loading files from the imtables package.

set -e

inline () {
  echo "Inlining $1"
  echo "$(brfs $1)" > $1;
}

# Generate a template module that will hold all our templates in a
# requireable form.
./bin/generate-template-module > build/templates.js

find build/ -type f \
            -name '*.js' \
            -exec grep -q readFileSync '{}' ';' \
            -print \
            | while read file; do inline "$file"; done

