#!/usr/bin/env bash

#ddev-generated
## Command provided by https://github.com/ddev/ddev-drupal-contrib
## Description: Run stylelint inside the web container
## Usage: stylelint [flags] [args]
## Example: "ddev stylelint"
## ExecRaw: true

set -eu -o pipefail

if "$DDEV_DOCROOT/core/node_modules/.bin/stylelint" --version >/dev/null ; then
  # Configure prettier
  test -e .prettierrc.json || ln -s $DDEV_DOCROOT/core/.prettierrc.json .
  # Change directory to the project root folder
  cd "$DDEV_DOCROOT/$DRUPAL_PROJECTS_PATH/${DDEV_SITENAME//-/_}" || exit
  "$DDEV_COMPOSER_ROOT/$DDEV_DOCROOT/core/node_modules/.bin/stylelint" --color --config "$DDEV_COMPOSER_ROOT/$DDEV_DOCROOT/core/.stylelintrc.json" "./**/*.css" "$@"
else
  echo "stylelint is not available. You may need to 'ddev exec \"cd $DDEV_DOCROOT/core && yarn install\"'"
  exit 1
fi
