From a9d2fe59e0274ab93c58b4995fd0305636e3c6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Frankiewicz?= Date: Tue, 14 May 2024 15:48:38 +0200 Subject: [PATCH 1/9] add 'consent-banner.ready' event on library load, optimize script size --- src/app.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/app.js b/src/app.js index f42e5c2..0743cef 100644 --- a/src/app.js +++ b/src/app.js @@ -55,6 +55,10 @@ function addEventListener(elements, event, callback) { } } +function dispatchBodyEvent(eventName) { + document.body.dispatchEvent(new CustomEvent('consent-banner.' + eventName)); +} + // State Management function isConsentStateProvided(consentState) { return null !== consentState; @@ -255,7 +259,7 @@ function consentBannerJsMain(config) { updateSettings(settings, config, consentState); saveConsentState(consentState); hideMain(main); - document.body.dispatchEvent(new CustomEvent('consent-banner.hidden')); + dispatchBodyEvent('hidden'); }); addEventListener(modal.querySelector('[href="#accept"]'), 'click', function(ev) { @@ -269,7 +273,7 @@ function consentBannerJsMain(config) { updateSettings(settings, config, consentState); saveConsentState(consentState); hideMain(main); - document.body.dispatchEvent(new CustomEvent('consent-banner.hidden')); + dispatchBodyEvent('hidden'); }); addEventListener(settings.querySelector('[href="#close"]'), 'click', function(ev) { @@ -284,7 +288,7 @@ function consentBannerJsMain(config) { ev.preventDefault(); hideModal(main); showSettings(main); - document.body.dispatchEvent(new CustomEvent('consent-banner.shown')); + dispatchBodyEvent('shown'); }); addEventListener(modal.querySelector('[href="#reject"]'),'click', function(ev) { @@ -298,7 +302,7 @@ function consentBannerJsMain(config) { saveConsentState(consentState); updateSettings(settings, config, consentState); hideMain(main); - document.body.dispatchEvent(new CustomEvent('consent-banner.hidden')); + dispatchBodyEvent('hidden'); }); addEventListener(settings.querySelector('[href="#reject"]'), 'click', function(ev) { @@ -312,7 +316,7 @@ function consentBannerJsMain(config) { saveConsentState(consentState); updateSettings(settings, config, consentState); hideMain(main); - document.body.dispatchEvent(new CustomEvent('consent-banner.hidden')); + dispatchBodyEvent('hidden'); }); @@ -329,21 +333,21 @@ function consentBannerJsMain(config) { saveConsentState(consentState); updateSettings(settings, config, consentState); hideMain(main); - document.body.dispatchEvent(new CustomEvent('consent-banner.hidden')); + dispatchBodyEvent('hidden'); }); addEventListener(body.querySelector('[href$="#consent-banner-settings"]'), 'click', function(ev) { ev.preventDefault(); showSettings(main); hideModal(main); - document.body.dispatchEvent(new CustomEvent('consent-banner.shown')); + dispatchBodyEvent('shown'); }); addEventListener(body, 'consent-banner.show-settings', function(ev) { ev.preventDefault(); showSettings(main); hideModal(main); - document.body.dispatchEvent(new CustomEvent('consent-banner.shown')); + dispatchBodyEvent('shown'); }); body.appendChild(main); @@ -372,7 +376,7 @@ function consentBannerJsMain(config) { 'margin-left': '20px' }); showModal(main); - document.body.dispatchEvent(new CustomEvent('consent-banner.shown')); + dispatchBodyEvent('shown'); } if ('modal' === config.display.mode) { @@ -386,12 +390,12 @@ function consentBannerJsMain(config) { display: 'block' }); showModal(main); - document.body.dispatchEvent(new CustomEvent('consent-banner.shown')); + dispatchBodyEvent('shown'); } if ('settings' === config.display.mode) { showSettings(main); - document.body.dispatchEvent(new CustomEvent('consent-banner.shown')); + dispatchBodyEvent('shown'); } } @@ -403,5 +407,4 @@ window.cookiesBannerJs = function(overrideLoadConsentState, overrideSaveConsentS ready(consentBannerJsMain.bind(null, config)); } - - +dispatchBodyEvent('ready'); From ed355a54b0563dceb868e6b388fd316c5ae8e4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Frankiewicz?= Date: Tue, 14 May 2024 15:49:19 +0200 Subject: [PATCH 2/9] add build workflow, lock node version --- .github/workflows/main.yaml | 22 ++++++++++++++++++++++ docker-compose.yml | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/main.yaml diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..1f0f8bb --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,22 @@ +name: Build +on: + workflow_dispatch: + branches: [ feature/body-event-on-library-loaded ] +jobs: + deployment: + runs-on: node:21 + steps: + - uses: actions/checkout@v4 + - name: 'Build' + run: yarn && yarn build + - name: get-npm-version + id: package-version + uses: martinbeentjes/npm-get-version-action@v1.3.1 + - name: 'Upload Artifacts' + uses: actions/upload-artifact@v4 + with: + name: dist-files + path: | + dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/styles/light.css + dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/consent-banner.min.js + dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/consent-banner.bundle.min.js \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 364a29a..160e0dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: dev: - image: node + image: node:21 entrypoint: command: npm run serve volumes: From e33db44d8a51615bef52670bf3261d317ef2d9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Frankiewicz?= Date: Tue, 14 May 2024 15:50:18 +0200 Subject: [PATCH 3/9] fix yaml syntax --- .github/workflows/main.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 1f0f8bb..0d24607 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -16,7 +16,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: dist-files - path: | - dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/styles/light.css - dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/consent-banner.min.js - dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/consent-banner.bundle.min.js \ No newline at end of file + path: | + dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/styles/light.css + dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/consent-banner.min.js + dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/consent-banner.bundle.min.js \ No newline at end of file From 094b012b7d8bcb336323191ffc323a5fda4e30b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Frankiewicz?= Date: Tue, 14 May 2024 16:01:01 +0200 Subject: [PATCH 4/9] fixes workflow --- .github/workflows/main.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0d24607..2674d7d 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -4,11 +4,13 @@ on: branches: [ feature/body-event-on-library-loaded ] jobs: deployment: - runs-on: node:21 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: 'Build' - run: yarn && yarn build + - uses: actions/setup-node@v4 + with: + node-version: 21 + - run: yarn && yarn build - name: get-npm-version id: package-version uses: martinbeentjes/npm-get-version-action@v1.3.1 From 6ea21cc85844f621cde7194cf476d03493ee93ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Frankiewicz?= Date: Tue, 14 May 2024 16:05:26 +0200 Subject: [PATCH 5/9] fixes workflow --- .github/workflows/main.yaml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 2674d7d..4f363e7 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,4 +1,4 @@ -name: Build +name: app-build on: workflow_dispatch: branches: [ feature/body-event-on-library-loaded ] @@ -14,11 +14,15 @@ jobs: - name: get-npm-version id: package-version uses: martinbeentjes/npm-get-version-action@v1.3.1 - - name: 'Upload Artifacts' - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v4 with: - name: dist-files - path: | - dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/styles/light.css - dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/consent-banner.min.js - dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/consent-banner.bundle.min.js \ No newline at end of file + name: consent-banner.bundle.min.js + path: dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/consent-banner.bundle.min.js + - uses: actions/upload-artifact@v4 + with: + name: consent-banner.min.js + path: dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/consent-banner.min.js + - uses: actions/upload-artifact@v4 + with: + name: light.css + path: dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/styles/light.css From 318e4e36b89c27f5514f0b38ca9ae3b9a151d90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Frankiewicz?= Date: Tue, 14 May 2024 16:08:25 +0200 Subject: [PATCH 6/9] changes workflow trigger --- .github/workflows/main.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 4f363e7..420529e 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,7 +1,9 @@ name: app-build on: - workflow_dispatch: - branches: [ feature/body-event-on-library-loaded ] + push: + branches: + - main + - develop jobs: deployment: runs-on: ubuntu-latest From 115157ec9158539982e8e52aaca088a96000325d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Frankiewicz?= Date: Tue, 14 May 2024 16:13:20 +0200 Subject: [PATCH 7/9] change workflow name, 1.2.0 package version --- .github/workflows/main.yaml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 420529e..e7fe285 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -5,7 +5,7 @@ on: - main - develop jobs: - deployment: + build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/package.json b/package.json index 2f0a1d3..6f45190 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tagconcierge/consent-banner", - "version": "1.1.1", + "version": "1.2.0", "description": "A zero-dependency, lightweight (~3kB), consent platform agnostic, cookie banner for any website.", "main": "src/app.js", "keywords": ["consent banner", "consent mode", "gtm consent", "cookie banner"], From 75eeb79e335b62b02fecc45966a6c847092cc229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Frankiewicz?= Date: Tue, 14 May 2024 16:24:40 +0200 Subject: [PATCH 8/9] zip all artifacts into one archive --- .github/workflows/main.yaml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e7fe285..f937af5 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -18,13 +18,5 @@ jobs: uses: martinbeentjes/npm-get-version-action@v1.3.1 - uses: actions/upload-artifact@v4 with: - name: consent-banner.bundle.min.js - path: dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/consent-banner.bundle.min.js - - uses: actions/upload-artifact@v4 - with: - name: consent-banner.min.js - path: dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/consent-banner.min.js - - uses: actions/upload-artifact@v4 - with: - name: light.css - path: dist/consent-banner-js/${{ steps.package-version.outputs.current-version}}/styles/light.css + name: consent-banner-${{ steps.package-version.outputs.current-version}}.zip + path: dist/consent-banner-js/${{ steps.package-version.outputs.current-version}} \ No newline at end of file From 3fc705c3a07924af33414d64f8a262622a5353ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Frankiewicz?= Date: Tue, 14 May 2024 16:27:52 +0200 Subject: [PATCH 9/9] remove zip from artifact name --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index f937af5..1611961 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -18,5 +18,5 @@ jobs: uses: martinbeentjes/npm-get-version-action@v1.3.1 - uses: actions/upload-artifact@v4 with: - name: consent-banner-${{ steps.package-version.outputs.current-version}}.zip + name: consent-banner-${{ steps.package-version.outputs.current-version}} path: dist/consent-banner-js/${{ steps.package-version.outputs.current-version}} \ No newline at end of file