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

Refactor build scripts #91

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 24 additions & 62 deletions shopware/administration/6.6/bin/build-administration.sh
Original file line number Diff line number Diff line change
@@ -1,87 +1,49 @@
#!/usr/bin/env bash

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

# Set project root directory
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 functions
source "${PROJECT_ROOT}/bin/functions.sh"

curenv=$(declare -p -x)

# Load environment variables from .env file
load_dotenv "$ENV_FILE"

# Load current environment variables
curenv=$(declare -p -x)

# Restore environment variables set globally
set -o allexport
eval "$curenv"
set +o allexport

set -euo pipefail

# Puppeteer and admin configurations
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
export DISABLE_ADMIN_COMPILATION_TYPECHECK=true
export PROJECT_ROOT="${PROJECT_ROOT:-"$(dirname "$CWD")"}"
export ADMIN_ROOT="${ADMIN_ROOT:-"${PROJECT_ROOT}/vendor/shopware/administration"}"

if [[ -e "${PROJECT_ROOT}/vendor/shopware/platform" ]]; then
ADMIN_ROOT="${ADMIN_ROOT:-"${PROJECT_ROOT}/vendor/shopware/platform/src/Administration"}"
else
ADMIN_ROOT="${ADMIN_ROOT:-"${PROJECT_ROOT}/vendor/shopware/administration"}"
fi
# Ensure BIN_TOOL is set and executable
get_bin_tool

BIN_TOOL="${CWD}/console"

if [[ ${CI:-""} ]]; then
BIN_TOOL="${CWD}/ci"

if [[ ! -x "$BIN_TOOL" ]]; then
chmod +x "$BIN_TOOL"
fi
fi

# build admin
# Dump bundles and features if not skipped
[[ ${SHOPWARE_SKIP_BUNDLE_DUMP:-""} ]] || "${BIN_TOOL}" bundle:dump
"${BIN_TOOL}" feature:dump || true

if [[ $(command -v jq) ]]; then
OLDPWD=$(pwd)
cd "$PROJECT_ROOT" || exit

jq -c '.[]' "var/plugins.json" | while read -r config; do
srcPath=$(echo "$config" | jq -r '(.basePath + .administration.path)')
[[ ${SHOPWARE_SKIP_FEATURE_DUMP:-""} ]] || "${BIN_TOOL}" feature:dump

# the package.json files are always one upper
path=$(dirname "$srcPath")
name=$(echo "$config" | jq -r '.technicalName' )
# Install administration npm dependencies for extensions
install_extensions_npm_dependencies "administration"

skippingEnvVarName="SKIP_$(echo "$name" | sed -e 's/\([a-z]\)/\U\1/g' -e 's/-/_/g')"

if [[ ${!skippingEnvVarName:-""} ]]; then
continue
fi

if [[ -f "$path/package.json" && ! -d "$path/node_modules" && $name != "administration" ]]; then
echo "=> Installing npm dependencies for ${name}"

npm install --prefix "$path" --no-audit --prefer-offline
fi
done
cd "$OLDPWD" || exit
else
echo "Cannot check extensions for required npm installations as jq is not installed"
fi

(cd "${ADMIN_ROOT}"/Resources/app/administration && npm install --prefer-offline --production)
# Install npm dependencies for administration in production mode
npm --prefix "${ADMIN_ROOT}/Resources/app/administration" install --production

# Dump entity schema
if [[ -z "${SHOPWARE_SKIP_ENTITY_SCHEMA_DUMP:-""}" ]] && [[ -f "${ADMIN_ROOT}"/Resources/app/administration/scripts/entitySchemaConverter/entity-schema-converter.ts ]]; then
mkdir -p "${ADMIN_ROOT}"/Resources/app/administration/test/_mocks_
"${BIN_TOOL}" -e prod framework:schema -s 'entity-schema' "${ADMIN_ROOT}"/Resources/app/administration/test/_mocks_/entity-schema.json
(cd "${ADMIN_ROOT}"/Resources/app/administration && npm run convert-entity-schema)
fi
dump_entity_schema

# Build administration
npm --prefix "${ADMIN_ROOT}/Resources/app/administration" run build

(cd "${ADMIN_ROOT}"/Resources/app/administration && npm run build)
[[ ${SHOPWARE_SKIP_ASSET_COPY:-""} ]] ||"${BIN_TOOL}" assets:install
# Install assets if not skipped
[[ ${SHOPWARE_SKIP_ASSET_COPY:-""} ]] || "${BIN_TOOL}" assets:install
67 changes: 23 additions & 44 deletions shopware/administration/6.6/bin/watch-administration.sh
Original file line number Diff line number Diff line change
@@ -1,69 +1,48 @@
#!/usr/bin/env bash

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

# Set project root directory
CWD="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
export PROJECT_ROOT="${PROJECT_ROOT:-"$(dirname "$CWD")"}"
export ENV_FILE=${ENV_FILE:-"${PROJECT_ROOT}/.env"}

# shellcheck source=functions.sh
# Source functions
source "${PROJECT_ROOT}/bin/functions.sh"

curenv=$(declare -p -x)

# Load environment variables from .env file
load_dotenv "$ENV_FILE"

# Load current environment variables
curenv=$(declare -p -x)

# Restore environment variables set globally
set -o allexport
eval "$curenv"
set +o allexport

export HOST=${HOST:-"localhost"}
# Set default values for environment variables
export APP_URL
export ESLINT_DISABLE
export HOST=${HOST:-"localhost"}
export PORT
export APP_URL
export ADMIN_ROOT="${ADMIN_ROOT:-"${PROJECT_ROOT}/vendor/shopware/administration"}"

BIN_TOOL="${CWD}/console"
# Ensure BIN_TOOL is set and executable
get_bin_tool

# Dump bundles and features if not skipped
[[ ${SHOPWARE_SKIP_BUNDLE_DUMP:-""} ]] || "${BIN_TOOL}" bundle:dump
"${BIN_TOOL}" feature:dump || true

if [[ $(command -v jq) ]]; then
OLDPWD=$(pwd)
cd "$PROJECT_ROOT" || exit

jq -c '.[]' "var/plugins.json" | while read -r 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' )

skippingEnvVarName="SKIP_$(echo "$name" | sed -e 's/\([a-z]\)/\U\1/g' -e 's/-/_/g')"

if [[ ${!skippingEnvVarName:-""} ]]; then
continue
fi

if [[ -f "$path/package.json" && ! -d "$path/node_modules" && $name != "administration" ]]; then
echo "=> Installing npm dependencies for ${name}"
[[ ${SHOPWARE_SKIP_FEATURE_DUMP:-""} ]] || "${BIN_TOOL}" feature:dump

npm install --prefix "$path"
fi
done
cd "$OLDPWD" || exit
else
echo "Cannot check extensions for required npm installations as jq is not installed"
fi
# Install webpack-dev-server if not present
[[ ! -d "${ADMIN_ROOT}"/Resources/app/administration/node_modules/webpack-dev-server ]] && npm --prefix "${ADMIN_ROOT}"/Resources/app/administration install || true

if [ ! -d vendor/shopware/administration/Resources/app/administration/node_modules/webpack-dev-server ]; then
npm install --prefix vendor/shopware/administration/Resources/app/administration/
fi
# Install administration npm dependencies for extensions
install_extensions_npm_dependencies "administration"

# Dump entity schema
if [[ -z "${SHOPWARE_SKIP_ENTITY_SCHEMA_DUMP:-""}" ]] && [[ -f "${ADMIN_ROOT}"/Resources/app/administration/scripts/entitySchemaConverter/entity-schema-converter.ts ]]; then
mkdir -p "${ADMIN_ROOT}"/Resources/app/administration/test/_mocks_
"${BIN_TOOL}" -e prod framework:schema -s 'entity-schema' "${ADMIN_ROOT}"/Resources/app/administration/test/_mocks_/entity-schema.json
(cd "${ADMIN_ROOT}"/Resources/app/administration && npm run convert-entity-schema)
fi
dump_entity_schema

npm run --prefix vendor/shopware/administration/Resources/app/administration/ dev
# Build administration in development mode
npm --prefix "${ADMIN_ROOT}/Resources/app/administration" run dev
80 changes: 79 additions & 1 deletion shopware/core/6.6/bin/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ load_dotenv() {
fi

CURRENT_ENV=${APP_ENV:-"dev"}
env_file="$1"
local env_file="$1"

# If we have an actual .env file load it
if [[ -e "$env_file" ]]; then
Expand Down Expand Up @@ -37,3 +37,81 @@ load_dotenv() {
source "$env_file.$CURRENT_ENV.local"
fi
}

get_bin_tool() {
local bin_tool_path="${CWD}/console"

if [[ -n ${CI:-} ]]; then
bin_tool_path="${CWD}/ci"

if [[ ! -x "$bin_tool_path" ]]; then
chmod +x "$bin_tool_path"
fi
fi

BIN_TOOL="$bin_tool_path"
}

dump_entity_schema() {
# Check if entity schema dump should be skipped or the file exists
if [[ -z "${SHOPWARE_SKIP_ENTITY_SCHEMA_DUMP:-}" ]] && \
[[ -f "${ADMIN_ROOT}/Resources/app/administration/scripts/entitySchemaConverter/entity-schema-converter.ts" ]]; then

local mocks_dir="${ADMIN_ROOT}/Resources/app/administration/test/_mocks_"

# Ensure mocks directory exists
mkdir -p "$mocks_dir"

# Generate entity schema JSON
"${BIN_TOOL}" -e prod framework:schema -s 'entity-schema' "${mocks_dir}/entity-schema.json"

# Convert entity schema JSON
npm --prefix "${ADMIN_ROOT}/Resources/app/administration" run convert-entity-schema
fi
}

install_extensions_npm_dependencies() {
local component_name="$1"
local npm_args=${2:-""}

if [[ $(command -v jq) ]]; then
OLDPWD=$(pwd)
cd "$PROJECT_ROOT" || exit

jq -c '.[]' "var/plugins.json" | while read -r config; do
srcPath=$(echo "$config" | jq -r "(.basePath + .${component_name}.path)")

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

skippingEnvVarName="SKIP_$(echo "$name" | sed -e 's/\([a-z]\)/\U\1/g' -e 's/-/_/g')"

if [[ ${!skippingEnvVarName:-""} ]]; then
continue
fi

if [[ -f "$path/package.json" && ! -d "$path/node_modules" && $name != "$component_name" ]]; then
echo "=> Installing npm dependencies for ${name}"

npm --prefix "$path" install $npm_args
fi
done
cd "$OLDPWD" || exit
else
echo "Cannot check extensions for required npm installations as jq is not installed"
fi
}

install_and_build_storefront() {
local storefront_app_dir="${STOREFRONT_ROOT}/Resources/app/storefront"

# Install npm dependencies for storefront
npm --prefix "$storefront_app_dir" install --prefer-offline --production

# Copy to vendor
node "$storefront_app_dir/copy-to-vendor.js"

# Run production build
npm --prefix "$storefront_app_dir" run production
}
6 changes: 6 additions & 0 deletions shopware/core/6.6/root/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fund=false
audit=false
update-notifier=false
prefer-offline=true
progress=false
loglevel=silent
67 changes: 18 additions & 49 deletions shopware/storefront/6.6/bin/build-storefront.sh
Original file line number Diff line number Diff line change
@@ -1,69 +1,38 @@
#!/usr/bin/env bash

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

set -euo pipefail

export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
# Set project root directory
CWD="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
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"}"
else
STOREFRONT_ROOT="${STOREFRONT_ROOT:-"${PROJECT_ROOT}/vendor/shopware/storefront"}"
fi

BIN_TOOL="${CWD}/console"
# Source functions
source "${PROJECT_ROOT}/bin/functions.sh"

if [[ ${CI:-""} ]]; then
BIN_TOOL="${CWD}/ci"
# Puppeteer and storefront configurations
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
export STOREFRONT_ROOT="${STOREFRONT_ROOT:-"${PROJECT_ROOT}/vendor/shopware/storefront"}"

if [[ ! -x "$BIN_TOOL" ]]; then
chmod +x "$BIN_TOOL"
fi
fi
# Ensure BIN_TOOL is set and executable
get_bin_tool

# build storefront
# Dump bundles and features if not skipped
[[ ${SHOPWARE_SKIP_BUNDLE_DUMP:-""} ]] || "${BIN_TOOL}" bundle:dump
[[ ${SHOPWARE_SKIP_FEATURE_DUMP:-""} ]] || "${BIN_TOOL}" feature:dump

if [[ $(command -v jq) ]]; then
OLDPWD=$(pwd)
cd "$PROJECT_ROOT" || exit
# Install storefront npm dependencies for extensions
install_extensions_npm_dependencies "storefront"

jq -c '.[]' "var/plugins.json" | while read -r config; do
srcPath=$(echo "$config" | jq -r '(.basePath + .storefront.path)')
# Install and build storefront
install_and_build_storefront

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

skippingEnvVarName="SKIP_$(echo "$name" | sed -e 's/\([a-z]\)/\U\1/g' -e 's/-/_/g')"

if [[ ${!skippingEnvVarName:-""} ]]; then
continue
fi

if [[ -f "$path/package.json" && ! -d "$path/node_modules" && $name != "storefront" ]]; then
echo "=> Installing npm dependencies for ${name}"

npm install --prefix "$path" --prefer-offline
fi
done
cd "$OLDPWD" || exit
else
echo "Cannot check extensions for required npm installations as jq is not installed"
fi

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
# Install assets if not skipped
[[ ${SHOPWARE_SKIP_ASSET_COPY:-""} ]] ||"${BIN_TOOL}" assets:install

# Compile theme if not skipped
[[ ${SHOPWARE_SKIP_THEME_COMPILE:-""} ]] || "${BIN_TOOL}" theme:compile --active-only

# Clear cache if not instructed otherwise
if ! [ "${1:-default}" = "--keep-cache" ]; then
"${BIN_TOOL}" cache:clear
fi
Loading
Loading