diff --git a/.editorconfig b/.editorconfig index 39fd6e0..f7cf72f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,7 +13,10 @@ indent_size = 2 [*.{yml,yaml}] indent_size = 2 -[*.js] +[*.{js,ts}] +indent_size = 2 + +[*.json] indent_size = 2 [Makefile] diff --git a/.github/actions/build-js/action.yml b/.github/actions/build-js/action.yml new file mode 100644 index 0000000..9761bb8 --- /dev/null +++ b/.github/actions/build-js/action.yml @@ -0,0 +1,46 @@ +--- + +name: 'Build JS' +description: 'Compile the TS source code' + +inputs: + npm-package: + description: Build NPM package + required: false + default: 'false' + + django-staticfiles: + description: Bundle Django staticfiles + required: false + default: 'false' + +runs: + using: 'composite' + + steps: + + - uses: actions/setup-node@v4 + with: + node-version-file: 'js/.nvmrc' + cache: npm + cache-dependency-path: js/package-lock.json + # Blocked by https://github.com/jazzband/django-cookie-consent/issues/120 + # registry-url: 'https://registry.npmjs.org' + # scope: '@jazzband' + + - name: Install dependencies + run: npm ci + shell: bash + working-directory: js + + - name: Build NPM package + if: ${{ inputs.npm-package == 'true' }} + run: npm run build + shell: bash + working-directory: js + + - name: Build Django assets package + if: ${{ inputs.django-staticfiles == 'true' }} + run: npm run build:django-static + shell: bash + working-directory: js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2878be2..7b4ad9f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,17 @@ on: workflow_dispatch: jobs: + build-js: + runs-on: ubuntu-latest + name: Compile the frontend code + + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/build-js + with: + npm-package: 'true' + django-staticfiles: 'false' + tests: runs-on: ubuntu-latest strategy: @@ -54,6 +65,11 @@ jobs: with: python-version: '3.10' + - uses: ./.github/actions/build-js + with: + npm-package: 'false' + django-staticfiles: 'true' + - name: Install dependencies run: | pip install tox tox-gh-actions pytest-playwright diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cb25d2c..1fa8cfe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,10 +7,14 @@ on: jobs: build: - name: Publish package to Jazzband private PyPI + name: Publish packages runs-on: ubuntu-latest if: github.repository == 'jazzband/django-cookie-consent' + permissions: + contents: read + packages: write + steps: - uses: actions/checkout@v3 with: @@ -26,16 +30,29 @@ jobs: python -m pip install -U pip python -m pip install -U setuptools twine wheel + - uses: ./.github/actions/build-js + with: + npm-package: 'true' + django-staticfiles: 'true' + - name: Build package run: | python setup.py --version python setup.py sdist --format=gztar bdist_wheel twine check dist/* - - name: Upload packages to Jazzband + - name: Upload packages to Jazzband private PyPI if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@release/v1 with: user: jazzband password: ${{ secrets.JAZZBAND_RELEASE_KEY }} repository_url: https://jazzband.co/projects/django-cookie-consent/upload + + # Blocked on https://github.com/jazzband/django-cookie-consent/issues/120 + # - name: Publish NPM package to Github + # if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + # run: npm publish + # working-directory: js + # env: + # NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 9751be2..a46d039 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,8 @@ dist/ htmlcov/ reports/ testapp/*.db + +# frontend tooling / builds +js/node_modules/ +js/lib/ +cookie_consent/static/cookie_consent/cookiebar.module.* diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 3a63f46..63846fb 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -46,6 +46,18 @@ You can then install the project with all the dev-tools: pip install -e .[tests,pep8,coverage,docs,release] +Some frontend tooling is needed to: + +* NodeJS (for the version, see ``.nvmrc``, you can use ``nvm``) + +.. code-block:: bash + + cd js + nvm use + npm install + npm run build:django-static + npm run build # optional, but a nice check + **Running the testapp as dev environment** In Django project's, you are typically expecting a ``manage.py`` file. This is less @@ -127,6 +139,11 @@ After updating changelogs etc. .. code-block:: bash tbump {new-version} --only-patch + cd js + npm version major|minor|patch --no-git-tag-version + cd .. + git commit -am ":bookmark: Bump to version " + git tag -s X.Y.Z git push origin master --tags diff --git a/cookie_consent/static/cookie_consent/cookiebar.module.js b/cookie_consent/static/cookie_consent/cookiebar.module.js deleted file mode 100644 index af27203..0000000 --- a/cookie_consent/static/cookie_consent/cookiebar.module.js +++ /dev/null @@ -1,203 +0,0 @@ -/** - * Cookiebar functionality, as a Javascript module. - * - * About modules: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules - * - * The code is organized here in a way to make the templates work with Django's page - * cache. This means that anything user-specific (so different django session and even - * cookie consent cookies) cannot be baked into the templates, as that breaks caches. - * - * The cookie bar operates on the following principles: - * - * - The developer using the library includes the desired template in their django - * templates, using the HTML