Skip to content

Commit

Permalink
fix(prestashop): fix building themes in prestashop 8
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Sep 29, 2023
1 parent 4326e82 commit abb1c09
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 61 deletions.
12 changes: 2 additions & 10 deletions images/prestashop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ COPY --from=node /usr/local/include /usr/local/include
COPY --from=node /usr/local/lib /usr/local/lib

ARG PS_VERSION="8.0.4"
ARG YARN_VERSION="berry"

ARG ROOT_DIR=/var/www/html

Expand Down Expand Up @@ -81,14 +80,8 @@ RUN PHP_VERSION="$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;")" && \
rm -rf vendor && \
# Set composer cache location
composer config --global cache-dir /tmp/.cache/composer && \
# Set up Yarn
yarn set version ${YARN_VERSION} && \
yarn config set --home enableTelemetry 0 && \
yarn config set enableGlobalCache true && \
yarn config set globalFolder /tmp/.cache/yarn && \
yarn config set logFilters --json '[ {"code":"YN0060","level":"discard"}, {"code":"YN0002","level":"discard"} ]' && \
yarn config set nodeLinker node-modules && \
yarn plugin import workspace-tools && \
# Set npm cache location
npm config set cache /tmp/.cache/npm && \
# Reset permissions
chown -R www-data . && \
# Clear cache and unnecessary dependencies
Expand All @@ -102,7 +95,6 @@ COPY ./config/php /usr/local/etc/php
COPY ./scripts/ /tmp/scripts

ENV PS_VERSION=${PS_VERSION}
ENV YARN_VERSION=${YARN_VERSION}

ENV ROOT_DIR=${ROOT_DIR}

Expand Down
103 changes: 52 additions & 51 deletions images/prestashop/scripts/_build-themes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,69 @@
build-themes() {
h2 "Building themes..."

npm pkg set name=root
npm pkg delete workspaces
npm pkg set \
"workspaces[]=admin-dev/**" \
"workspaces[]=themes" \
"workspaces[]=themes/**"
# Some super hacky changes needed to be able to compile the scss of admin-dev/themes/new-theme with sass^1 :(
sed -i 's/@extend a:hover;/@extend a, :hover;/' './admin-dev/themes/new-theme/node_modules/prestakit/scss/_breadcrumb.scss' || true
sed -i 's/@extend .btn-primary:disabled;/@extend .btn-primary, :disabled;/' './admin-dev/themes/new-theme/node_modules/prestakit/scss/_custom-forms.scss' || true
sed -i 's/ - 2;/;/' './admin-dev/themes/new-theme/node_modules/select2-bootstrap-theme/src/select2-bootstrap.scss' || true

if major-version-is 1; then
yarn config set nmHoistingLimits workspaces
fi
yarn set version berry

# Replace node-sass with sass in all workspaces
yarn remove -A node-sass
yarn workspaces foreach -pv --exclude root exec npm pkg set devDependencies.sass=^1
yarn config set --home enableTelemetry 0

yarn install
yarn config set enableGlobalCache true
yarn config set globalFolder /tmp/.cache/yarn
yarn config set logFilters --json '[ {"code":"YN0060","level":"discard"}, {"code":"YN0002","level":"discard"} ]'
yarn config set nodeLinker node-modules

if major-version-is 1; then
# Some super hacky changes needed to be able to compile the scss of admin-dev/themes/new-theme with sass^1 :(
sed -i 's/@extend a:hover;/@extend a, :hover;/' './admin-dev/themes/new-theme/node_modules/prestakit/scss/_breadcrumb.scss' || true
sed -i 's/@extend .btn-primary:disabled;/@extend .btn-primary, :disabled;/' './admin-dev/themes/new-theme/node_modules/prestakit/scss/_custom-forms.scss' || true
sed -i 's/ - 2;/;/' './admin-dev/themes/new-theme/node_modules/select2-bootstrap-theme/src/select2-bootstrap.scss' || true
yarn plugin import workspace-tools

npm pkg set name=root
npm pkg delete workspaces
npm pkg set \
"workspaces[]=admin-dev/**" \
"workspaces[]=themes" \
"workspaces[]=themes/**"

yarn config set nmHoistingLimits workspaces

# Replace node-sass with sass in all workspaces
yarn remove -A node-sass
yarn workspaces foreach -pv --exclude root exec npm pkg set devDependencies.sass=^1

yarn install

yarn workspaces foreach -pv exec npm pkg set "scripts.build:dev=NODE_ENV=development webpack --mode development"
yarn workspaces foreach -pv run build:dev

if [ "$?" -eq 0 ]; then
h2 "Built themes."
else
h2 "One or more themes failed to build."
fi
fi

if major-version-is 8; then
ROOT=$(echo "$ROOT_DIR" | sed 's/\//\\\//g')

### default
# Replace relative node_modules paths with absolute paths
sed -i "s/..\/node_modules\//$ROOT\/node_modules\//" './admin-dev/themes/default/js/theme.js' || true
sed -i "s/..\/node_modules\//$ROOT\/node_modules\//" './admin-dev/themes/default/scss/modules/_variables.scss' || true
sed -i "s/..\/node_modules\//$ROOT\/node_modules\//" './admin-dev/themes/default/css/font.css' || true
### /default

### new-theme
# Tweak tsconfig so the new-theme can be built
TSCONFIG='./admin-dev/themes/new-theme/tsconfig.json'
echo "$(jq '(.compilerOptions |= . + {strict: false, noImplicitAny: false, noImplicitThis: false})' $TSCONFIG)" > $TSCONFIG
echo "$(jq 'del(.compilerOptions.typeRoots)' $TSCONFIG)" > $TSCONFIG

# Aadd // @ts-nocheck to the top of all ts files
find './admin-dev/themes/new-theme' -type f -name '*.ts' -exec sed -i '1i // @ts-nocheck' {} \;
# Add // @ts-nocheck after all script tags in .vue files
find './admin-dev/themes/new-theme' -type f -name '*.vue' -exec sed -i 's/<script lang="ts">/<script lang="ts">\n\/\/ @ts-nocheck/' {} \;

# Remove tsconfig path resolution to node_modules
find './admin-dev/themes/new-theme' -type f -name '*.ts' -exec sed -i "s/'@node_modules\//'/g" {} \; || true

# Remove deprecation warnings caused by postcss-preset-env 6
yarn workspace new-theme exec npm pkg set "devDependencies.postcss-preset-env=^7"
### /new-theme

# Build
yarn workspaces foreach -pv --exclude root run build
fi
workspaces=$(find themes admin-dev -type f -name package.json -not -path "*/node_modules/*" -not -path "*/vendor/*" -exec dirname {} \;)

for workspace in $workspaces; do
cd "$workspace" || exit 1
h2 "Building $workspace..."

npm pkg delete devDependencies.node-sass
npm pkg delete dependencies.node-sass
npm pkg set devDependencies.sass=^1

npm install --legacy-peer-deps
npm run build

if [ "$?" -ne 0 ]; then
h2 "Failed to build $workspace."
else
h2 "Done building $workspace."
fi

if [ "$?" -eq 0 ]; then
h2 "Built themes."
else
h2 "One or more themes failed to build."
cd - || exit 1
done
fi
}

0 comments on commit abb1c09

Please sign in to comment.