#!/bin/bash

set -x

# Copy README.md to /vp/docs if it does not exists
if [ ! -f /vp/docs/README.md ] ; then
	echo Copy README.md to /vp/docs
	cp /tmp/stash/README.md /vp/docs/README.md
fi

# Copy demo folder to /vp/docs if it does not exists
if [ ! -d /vp/docs/demo ] ; then
	echo Copy demo to /vp/docs
	cp -r /tmp/stash/demo /vp/docs
fi

if [ ! -d /vp/docs/.vuepress ] ; then
	echo Copy dot_vuepress
	cp -r /tmp/stash/dot_vuepress /vp/docs/.vuepress
fi

# this is for the search
if [ ! -f /var/tmp/init ] ; then
	echo npm install --save-dev /vp/docs/.vuepress/plugins/pageData -loglevel verbose
	npm install --save-dev /vp/docs/.vuepress/plugins/pageData -loglevel verbose
	touch /var/tmp/init
fi

case "$1" in
	npm )
		echo Entrypoint
    	exec "$@"
    	;;
	*)
    	# The command is something like bash. Just run it in the right environment.
    	exec "$@"
    	;;
esac
