#!/bin/bash

if [ $# -eq 0 ];
then
	echo "no command provided"
	exit 0
fi

if [ -d .git ];
then
	echo "dont run this in a git directory"
	exit 1
fi

# https://serverfault.com/questions/72744/command-to-prepend-string-to-each-line
function prepend() { while read line; do echo "${1} ${line}"; done; }

for dirr in */ ;
do
	
	if [ -d "$dirr" ];
	then
		pushd "$dirr" > /dev/null

		if [ -f package.json ];
		then

			echo "begin $dirr"
			npm $@ | prepend "$dirr" &

		fi

		popd > /dev/null
	fi

done

echo "wait for process to complete"

wait

echo "the end"
