Skip to content

Instantly share code, notes, and snippets.

@shyim
Created July 14, 2021 18:53
Show Gist options
  • Save shyim/937ce400b1c18888d3fe3ee7c7d243d5 to your computer and use it in GitHub Desktop.
Save shyim/937ce400b1c18888d3fe3ee7c7d243d5 to your computer and use it in GitHub Desktop.
Install node_modules of Shopware extensions automatically
#!/usr/bin/env bash
CWD="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
set -e
export PROJECT_ROOT="${PROJECT_ROOT:-"$(dirname "$CWD")"}"
ADMIN_ROOT="${ADMIN_ROOT:-"${PROJECT_ROOT}/vendor/shopware/administration"}"
# build admin
[[ ${CI} ]] || "${CWD}/console" bundle:dump
if [[ `command -v jq` ]]; then
OLDPWD=$(pwd)
cd $PROJECT_ROOT
jq -c '.[]' "var/plugins.json" | while read config; do
srcPath=$(echo $config | jq -r '(.basePath + .administration.path)')
# the package.json files are always one upper
path=$(dirname $srcPath)
name=$(echo $config | jq -r '.technicalName' )
if [[ -f "$path/package.json" && ! -f "$path/node_modules" && $name != "administration" ]]; then
echo "=> Installing npm dependencies for ${name}"
npm install --prefix "$path"
fi
done
cd "$OLDPWD"
else
echo "Cannot check extensions for required npm installations as jq is not installed"
fi
(cd "${ADMIN_ROOT}"/Resources/app/administration && npm clean-install && npm run build)
[[ ${CI} ]] || "${CWD}/console" asset:install
#!/usr/bin/env bash
CWD="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
export PROJECT_ROOT="${PROJECT_ROOT:-"$(dirname "$CWD")"}"
STOREFRONT_ROOT="${STOREFRONT_ROOT:-"${PROJECT_ROOT}/vendor/shopware/storefront"}"
# build storefront
[[ ${CI} ]] || "${CWD}/console" bundle:dump
if [[ `command -v jq` ]]; then
OLDPWD=$(pwd)
cd $PROJECT_ROOT
jq -c '.[]' "var/plugins.json" | while read config; do
srcPath=$(echo $config | jq -r '(.basePath + .storefront.path)')
# the package.json files are always one upper
path=$(dirname $srcPath)
name=$(echo $config | jq -r '.technicalName' )
if [[ -f "$packageJsonPath/package.json" && ! -f "$packageJsonPath/node_modules" && $name != "storefront" ]]; then
echo "=> Installing npm dependencies for ${name}"
npm install --prefix "$packageJsonPath"
fi
done
cd "$OLDPWD"
else
echo "Cannot check extensions for required npm installations as jq is not installed"
fi
npm --prefix "${STOREFRONT_ROOT}"/Resources/app/storefront clean-install
node "${STOREFRONT_ROOT}"/Resources/app/storefront/copy-to-vendor.js
npm --prefix "${STOREFRONT_ROOT}"/Resources/app/storefront run production
[[ ${CI} ]] || "${CWD}/console" asset:install
[[ ${CI} ]] || "${CWD}/console" theme:compile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment