Skip to content
Merged
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
20 changes: 20 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.git
.github
.dockerignore
.php-cs-fixer.cache
.php-cs-fixer.dist.php
.vscode
.env*
build
config_*.xml
dist
docker
node_modules
scripts
vendor
work
_dev/node_modules
views/css/_dev
views/images/*
!views/images/favicon.ico
**/.DS_Store
94 changes: 26 additions & 68 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,32 @@
name: Build
on: [push, pull_request]
name: Build release package

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
deploy:
name: Build dependencies & create artifact
build-release:
name: Build installable ZIP
runs-on: ubuntu-latest
timeout-minutes: 20

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install composer dependencies
run: composer install --no-dev -o
- name: Setup node env
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install node dependencies
working-directory: ./_dev
run: npm i
- name: Build assets
working-directory: ./_dev
run: npm run build
- name: Remove unuseful data
run: |
rm .git/ -rf
rm .github/ -rf
- name: Prepare auto-index tool
run: |
composer global require prestashop/autoindex
- name: Generate index.php
run: |
~/.composer/vendor/bin/autoindex
- name: Create & upload artifact
uses: actions/upload-artifact@v1
with:
name: ${{ github.event.repository.name }}
path: ../
update_release_draft:
runs-on: ubuntu-latest
needs: [deploy]
if: github.event_name == 'push' && github.event.ref == 'refs/heads/master'
steps:
- name: Download artifact
uses: actions/download-artifact@v1
with:
name: ${{ github.event.repository.name }}
- id: release_info
uses: toolmantim/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare for Release
run: |
cd ${{ github.event.repository.name }}
zip -r ${{ github.event.repository.name }}.zip ${{ github.event.repository.name }}
- name: Clean existing assets
shell: bash
run: |
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
assets=`bin/hub api -t repos/${{ github.repository }}/releases/${{ steps.release_info.outputs.id }}/assets | awk '/\].url/ { print $2 }'`
for asset in $assets
do
bin/hub api -X DELETE $asset
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to GitHub Release
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: actions/checkout@v7

- name: Build and validate release
run: scripts/build-release.sh

- name: Upload release packages
uses: actions/upload-artifact@v7
with:
upload_url: ${{ steps.release_info.outputs.upload_url }}
asset_path: ./${{ github.event.repository.name }}/${{ github.event.repository.name }}.zip
asset_name: ${{ github.event.repository.name }}.zip
asset_content_type: application/zip
name: prettyblocks-${{ github.sha }}
path: dist/*.zip
if-no-files-found: error
retention-days: 14
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
config_*.xml
build/
dist/
vendor/
node_modules/
**/node_modules
Expand All @@ -12,4 +13,4 @@ test.php
.php-cs-fixer.cache
_dev/yarn.lock
.env
!views/js/build
!views/js/build
10 changes: 3 additions & 7 deletions _dev/src/components/Iframe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ let currentPrettyBlocksId = computed(() => currentBlock.id_prettyblocks)
* onMounted events
*/
onMounted(() => {

document.addEventListener('DOMContentLoaded', () => {
setTimeout(() => {
prettyBlocksContext.setIframe()
}, 200)
})
prettyBlocksContext.setIframe()
})

watch(currentBlock, (newVal, oldValue) => {
Expand Down Expand Up @@ -71,6 +66,7 @@ watch(prettyBlocksContext.psContext, () => {
allow="geolocation; microphone; camera; midi; encrypted-media"
:sandbox="iframe_sandbox"
:class="[height, width, showLoader ? 'opacity-50' : '']" class="border-none h-full mx-auto rounded" :src="filteredURL"
@load="prettyBlocksContext.iframeLoaded"
frameborder="0"></iframe>
<Loader :visible="showLoader" class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2">
Chargement en cours</Loader>
Expand All @@ -81,4 +77,4 @@ watch(prettyBlocksContext.psContext, () => {
#website-iframe {
transition: all 0.5s ease;
}
</style>
</style>
30 changes: 19 additions & 11 deletions _dev/src/store/pinia.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export const usePrettyBlocksContext = defineStore('prettyBlocksContext', {
setIframe() {
this.$patch((state) => {
state.iframe.domElement = ref(document.getElementById('website-iframe'))
this.listenIframe()
})
this.listenIframe()
},
displaySettingsPanel() {
this.$patch((state) => {
Expand Down Expand Up @@ -157,16 +157,24 @@ export const usePrettyBlocksContext = defineStore('prettyBlocksContext', {
})
},
listenIframe() {
window.removeEventListener("message", eventHandler);
window.addEventListener("message", eventHandler);
this.iframe.domElement.addEventListener('load', (e) => {
setTimeout(() => {
this.sendPrettyBlocksEvents('initIframe')
this.sendPrettyBlocksEvents('getContext')
this.sendPrettyBlocksEvents('getZones')
this.hideLoader()
this.emit('iframeLoaded')
},100)
})
},
iframeLoaded(event) {
if (!this.iframe.domElement && event && event.currentTarget) {
this.$patch((state) => {
state.iframe.domElement = ref(event.currentTarget)
})
this.listenIframe()
}

setTimeout(() => {
this.sendPrettyBlocksEvents('initIframe')
this.sendPrettyBlocksEvents('getContext')
this.sendPrettyBlocksEvents('getZones')
this.hideLoader()
this.emit('iframeLoaded')
},100)
},

sendPrettyBlocksEvents(eventType, data = []) {
Expand Down Expand Up @@ -440,4 +448,4 @@ export const storedBlocks = defineStore('storedBlocks', {
}


})
})
2 changes: 2 additions & 0 deletions controllers/front/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,14 @@ public function displayAjaxduplicateState()
'id_shop',
'id_lang',
'position',
'instance_id',
];
foreach ($excludedProperties as $property) {
unset($originalValues[$property]);
}
$newBlock = new PrettyBlocksModel();
$newBlock->hydrate($originalValues);
$newBlock->instance_id = uniqid();
$newBlock->id_shop = $idShop;
$newBlock->id_lang = (int) $language;
$newBlock->add();
Expand Down
11 changes: 11 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ARG PRESTASHOP_IMAGE=prestashop/prestashop:8.2.7-8.1-apache

FROM composer:2 AS composer

FROM ${PRESTASHOP_IMAGE}

COPY --from=composer /usr/bin/composer /usr/local/bin/composer
COPY scripts/install-prettyblocks.sh /tmp/init-scripts/90-install-prettyblocks.sh
COPY scripts/install-prettyblocks-release.php /usr/local/lib/prettyblocks/install-release.php

RUN chmod +x /tmp/init-scripts/90-install-prettyblocks.sh
81 changes: 81 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# PrettyBlocks compatibility stacks

This Compose project runs the current PrettyBlocks checkout against two isolated
shops:

| Service | PrestaShop | PHP | URL |
| --- | --- | --- | --- |
| `ps82` | 8.2.7 | 8.1 | <http://localhost:8082> |
| `ps91` | 9.1.4 | 8.5 | <http://localhost:8091> |

Both shops use MariaDB 10.11. The repository is bind-mounted into each shop,
while each stack keeps its own Composer `vendor` volume. A one-shot Node
container builds the Vite assets before the shops start, then the image init
hook installs PrettyBlocks automatically on the first boot.

## Start

```bash
docker compose -f docker/compose.yml up --build -d --wait
docker/scripts/smoke-test.sh
```

The back office is available at `/admin-dev` on both ports:

- login: `demo@prestashop.com`
- password: `prestashop_demo`

Use `PS82_PORT` and `PS91_PORT` to override the host ports if needed. The PS 9.1
stack uses its recommended PHP 8.5 runtime by default. To compare both
PrestaShop cores on PHP 8.1 instead:

```bash
PS91_IMAGE=prestashop/prestashop:9.1.4-8.1 \
docker compose -f docker/compose.yml up --build -d --wait
```

After changing files in `_dev`, rebuild the editor bundle with:

```bash
docker compose -f docker/compose.yml run --rm assets
```

## Logs and shell access

```bash
docker compose -f docker/compose.yml logs -f ps82 ps91
docker compose -f docker/compose.yml exec ps82 bash
docker compose -f docker/compose.yml exec ps91 bash
```

## Reset everything

This removes both shops and databases, including all test content:

```bash
docker compose -f docker/compose.yml down -v
```

## Build and test the release ZIP

The release builder runs Composer and Vite in Docker, creates an installable ZIP
with a top-level `prettyblocks/` directory, and validates its contents:

```bash
scripts/build-release.sh
```

The versioned archive and its stable `prettyblocks.zip` alias are written to
`dist/`. To prove that the ZIP is self-contained, run it against two fresh,
temporary shops. This test disables both the source asset build and the runtime
Composer install, so only files present in the archive can be used:

```bash
scripts/test-release.sh
```

The release test validates and extracts the ZIP with PrestaShop's native ZIP
handler, then installs that extracted artifact with the PrestaShop CLI. It uses
ports `8182` and `8191` by default and deletes its shops, databases, and
extracted module when it finishes. Override the ports with `PS82_RELEASE_PORT`
and `PS91_RELEASE_PORT` if needed.
19 changes: 19 additions & 0 deletions docker/compose.release-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
assets:
working_dir: /tmp
command: ["true"]
volumes: !override []

ps82:
environment:
PRETTYBLOCKS_RELEASE_ARCHIVE: /tmp/prettyblocks.zip
volumes: !override
- ps82-data:/var/www/html
- ${PRETTYBLOCKS_RELEASE_ARCHIVE_PATH}:/tmp/prettyblocks.zip:ro

ps91:
environment:
PRETTYBLOCKS_RELEASE_ARCHIVE: /tmp/prettyblocks.zip
volumes: !override
- ps91-data:/var/www/html
- ${PRETTYBLOCKS_RELEASE_ARCHIVE_PATH}:/tmp/prettyblocks.zip:ro
Loading