#!/bin/sh

mkdir -p ~/.n8n/nodes
if [ -n "$NPM_PACKAGES" ]; then
  cd ~/.n8n/nodes
  npm install $NPM_PACKAGES
  cd -
fi

if [ -n "$CUSTOM_UI" ]; then
  rm -rf /usr/local/lib/node_modules/n8n/packages/editor-ui/dist
  tar -xzf /tmp/dist.tgz -C /usr/local/lib/node_modules/n8n/packages/editor-ui
fi

if [ "$#" -gt 0 ]; then
  # Got started with arguments
  exec n8n "$@"
else
  # Got started without arguments
  exec n8n
fi
