Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bundle dump to storefront watch script #92

Merged
merged 1 commit into from
Mar 28, 2024
Merged

Conversation

tobiasberge
Copy link
Contributor

After creating a fresh setup, the first attempt to run the watch-storefront.sh script fails because the var/plugins.json file is still missing.

> [email protected] hot-proxy
> NODE_ENV=development MODE=hot node ./build/start-hot-reload.js

/Users/tobiasberge/www/flex/vendor/shopware/storefront/Resources/app/storefront/webpack.config.js:58
        throw new Error(`The file ${pluginFile} could not be found. Try bin/console bundle:dump to create this file.`);
              ^

You have to manually run bin/console bundle:dump to get it to run.

Adding bundle:dump to the script, similar to the shopware composer script (composer watch:storefront) so it works right away.

Also, when installing or removing extensions it is considered after re-starting the watcher.

@tobiasberge tobiasberge requested a review from shyim March 28, 2024 13:15
@tobiasberge tobiasberge self-assigned this Mar 28, 2024
Copy link

Thanks for the PR 😍

How to test these changes in your application

  1. Add the Shopware flex endpoint in your composer.json to https://raw.githubusercontent.com/shopware/recipes/flex/pull-92/index.json.

    # When jq is installed
    jq '.extra.symfony.endpoint |= [ "https://raw.githubusercontent.com/shopware/recipes/flex/pull-92/index.json" ] + .' composer.json > composer.tmp && mv composer.tmp composer.json

    or manually

    "endpoint": [
        "https://raw.githubusercontent.com/shopware/recipes/flex/pull-92/index.json",
        "https://raw.githubusercontent.com/shopware/recipes/flex/main/index.json",
        "flex://defaults"
    ]
  2. Install the package(s) related to this recipe:

    composer req 'shopware/storefront:^6.6'

Diff between recipe versions

In order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes.
I'm going keep this comment up to date with any updates of the attached patch.

shopware/storefront

6.4 vs 6.6
diff --git a/shopware/storefront/6.4/bin/build-storefront.sh b/shopware/storefront/6.6/bin/build-storefront.sh
index 410d5a7..1859856 100755
--- a/shopware/storefront/6.4/bin/build-storefront.sh
+++ b/shopware/storefront/6.6/bin/build-storefront.sh
@@ -6,6 +6,9 @@ set -euo pipefail
 
 export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
 export PROJECT_ROOT="${PROJECT_ROOT:-"$(dirname "$CWD")"}"
+export NPM_CONFIG_FUND=false
+export NPM_CONFIG_AUDIT=false
+export NPM_CONFIG_UPDATE_NOTIFIER=false
 
 if [[ -e "${PROJECT_ROOT}/vendor/shopware/platform" ]]; then
     STOREFRONT_ROOT="${STOREFRONT_ROOT:-"${PROJECT_ROOT}/vendor/shopware/platform/src/Storefront"}"
@@ -47,7 +50,7 @@ if [[ $(command -v jq) ]]; then
         if [[ -f "$path/package.json" && ! -d "$path/node_modules" && $name != "storefront" ]]; then
             echo "=> Installing npm dependencies for ${name}"
 
-            npm install --prefix "$path" --no-audit --prefer-offline
+            npm install --prefix "$path" --prefer-offline
         fi
     done
     cd "$OLDPWD" || exit
@@ -55,8 +58,12 @@ else
     echo "Cannot check extensions for required npm installations as jq is not installed"
 fi
 
-npm --prefix "${STOREFRONT_ROOT}"/Resources/app/storefront install --no-audit --prefer-offline
+npm --prefix "${STOREFRONT_ROOT}"/Resources/app/storefront install --prefer-offline --production
 node "${STOREFRONT_ROOT}"/Resources/app/storefront/copy-to-vendor.js
 npm --prefix "${STOREFRONT_ROOT}"/Resources/app/storefront run production
 [[ ${SHOPWARE_SKIP_ASSET_COPY:-""} ]] ||"${BIN_TOOL}" assets:install
-[[ ${SHOPWARE_SKIP_THEME_COMPILE:-""} ]] || "${BIN_TOOL}" theme:compile
+[[ ${SHOPWARE_SKIP_THEME_COMPILE:-""} ]] || "${BIN_TOOL}" theme:compile --active-only
+
+if ! [ "${1:-default}" = "--keep-cache" ]; then
+    "${BIN_TOOL}" cache:clear
+fi
diff --git a/shopware/storefront/6.4/bin/watch-storefront.sh b/shopware/storefront/6.6/bin/watch-storefront.sh
index f6c9015..58adad2 100755
--- a/shopware/storefront/6.4/bin/watch-storefront.sh
+++ b/shopware/storefront/6.6/bin/watch-storefront.sh
@@ -4,6 +4,9 @@ CWD="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
 
 export PROJECT_ROOT="${PROJECT_ROOT:-"$(dirname "$CWD")"}"
 export ENV_FILE=${ENV_FILE:-"${PROJECT_ROOT}/.env"}
+export NPM_CONFIG_FUND=false
+export NPM_CONFIG_AUDIT=false
+export NPM_CONFIG_UPDATE_NOTIFIER=false
 
 # shellcheck source=functions.sh
 source "${PROJECT_ROOT}/bin/functions.sh"
@@ -23,8 +26,19 @@ export PROXY_URL
 export STOREFRONT_ASSETS_PORT
 export STOREFRONT_PROXY_PORT
 
+if [[ -e "${PROJECT_ROOT}/vendor/shopware/platform" ]]; then
+    STOREFRONT_ROOT="${STOREFRONT_ROOT:-"${PROJECT_ROOT}/vendor/shopware/platform/src/Storefront"}"
+else
+    STOREFRONT_ROOT="${STOREFRONT_ROOT:-"${PROJECT_ROOT}/vendor/shopware/storefront"}"
+fi
+
+if [[ ! -d "${STOREFRONT_ROOT}"/Resources/app/storefront/node_modules/webpack-dev-server ]]; then
+    npm --prefix "${STOREFRONT_ROOT}"/Resources/app/storefront install --prefer-offline
+fi
+
+DATABASE_URL="" "${CWD}"/console bundle:dump
 DATABASE_URL="" "${CWD}"/console feature:dump
-"${CWD}"/console theme:compile
+"${CWD}"/console theme:compile --active-only
 "${CWD}"/console theme:dump
 
 if [[ $(command -v jq) ]]; then
@@ -55,4 +69,4 @@ else
     echo "Cannot check extensions for required npm installations as jq is not installed"
 fi
 
-npm --prefix vendor/shopware/storefront/Resources/app/storefront/ run-script hot-proxy
+npm --prefix "${STOREFRONT_ROOT}"/Resources/app/storefront run-script hot-proxy

@shyim shyim merged commit 26d968d into main Mar 28, 2024
2 checks passed
@shyim shyim deleted the watch-script-bundle-dump branch March 28, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants