Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Created May 28, 2019 04:05
Show Gist options
  • Save fakenickels/a06e2e808a437d16681c1f5fa7f9b1ab to your computer and use it in GitHub Desktop.
Save fakenickels/a06e2e808a437d16681c1f5fa7f9b1ab to your computer and use it in GitHub Desktop.
files=$(ls src/**/*.re)
# Make them functors
for file in $files; do
sed -i '' -e '1s/^/module Make = (AppConfig: AppConfigTypes.AppConfig) => { /' $file
echo "\n}" >> $file
done
# Forward functor to other functors
for file in $files; do
content=$(cat $file);
filename=`basename -- $file`
current_file_module_name="${filename%.*}"
for file_b in $files; do
filename=`basename -- $file_b`
module_name="${filename%.*}"
if [[ $current_file_module_name != $module_name ]]; then
# Only if current file uses the module
is_used=$(echo "$content" | grep -c -w "$module_name")
if [[ $is_used -gt 0 ]]; then
echo "Will add functor usage for $module_name in $current_file_module_name"
sed -i '' -e "2s/^/module $module_name = $module_name.Make(AppConfig); /" $file
fi
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment