Skip to content

Commit

Permalink
NEXT-26798 - Install npm dependencies for extensions on init:js
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik28111 committed Jun 6, 2023
1 parent 89e9f80 commit 7cc1f0d
Show file tree
Hide file tree
Showing 6 changed files with 337 additions and 193 deletions.
60 changes: 60 additions & 0 deletions bin/install-extension-npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash

CWD="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"

set -euo pipefail

export PROJECT_ROOT="${PROJECT_ROOT:-"$(dirname "$CWD")"}"

"$CWD"/console bundle:dump

if ! [[ $(command -v jq) ]]; then
echo "Cannot check extensions for required npm installations as jq is not installed"
exit 1
fi

OLDPWD=$(pwd)
cd "$PROJECT_ROOT" || exit

jq -c '.[]' "var/plugins.json" | while read -r config; do
srcPath=$(echo "$config" | jq -r '.basePath')
adminPath=$(echo "$config" | jq -r '(.basePath + .administration.path)')
storefrontPath=$(echo "$config" | jq -r '(.basePath + .storefront.path)')
bundlePaths=()

if [[ -d "$adminPath" ]]; then
bundlePaths+=("$adminPath")
fi

if [[ -d "$storefrontPath" ]]; then
bundlePaths+=("$storefrontPath")
fi

if [[ ${#bundlePaths[@]} -eq 0 ]]; then
continue
fi

# the package.json files are always one upper
path=$(dirname "$srcPath")
name=$(echo "$config" | jq -r '.technicalName')

for bundlePath in "${bundlePaths[@]}"; do
if [[ $path == "custom/plugins/"* && -f "$bundlePath/../package.json" && ! -d "$bundlePath/../node_modules" ]]; then
bundleName="administration"

if [[ "$bundlePath" == *"storefront"* ]]; then
bundleName="storefront"
fi

echo "=> Installing ${bundleName} npm dependencies for ${name}"

if [[ -f "$bundlePath/../package-lock.json" ]]; then
npm --prefix "$bundlePath/../" clean-install --no-audit --prefer-offline
else
npm --prefix "$bundlePath/../" install --no-audit --prefer-offline
fi
fi
done
done

cd "$OLDPWD" || exit
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@
"init:e2e": "@npm:e2e clean-install --no-audit --prefer-offline",
"init:js": [
"@npm:admin clean-install --no-audit --prefer-offline",
"@npm:storefront clean-install --no-audit --prefer-offline"
"@npm:storefront clean-install --no-audit --prefer-offline",
"export PROJECT_ROOT=\"$PWD\"; \"$PROJECT_ROOT\"/bin/install-extension-npm"
],
"init:testdb": [
"FORCE_INSTALL=true vendor/bin/phpunit --group=none"
Expand Down
1 change: 1 addition & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ in {
pkgs.gnused
pkgs.symfony-cli
pkgs.deno
pkgs.jq
( pkgs.writeShellScriptBin "php-pcov" ''
export PHP_INI_SCAN_DIR=''${PHP_INI_SCAN_DIR-'${pcov}/lib'}
exec -a "$0" "${pcov}/bin/.php-wrapped" "$@"
Expand Down
5 changes: 4 additions & 1 deletion src/Storefront/Resources/app/storefront/.babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ module.exports = {
bugfixes: true,
}],
'@babel/preset-typescript',
]
],
plugins: [
['@babel/plugin-proposal-decorators', { version: '2023-01' }],
],
};
Loading

0 comments on commit 7cc1f0d

Please sign in to comment.