ministryofjustice / justice-gov-uk

Justice UK website
https://www.justice.gov.uk/
MIT License
2 stars 0 forks source link

Creating vendor-assets with composer-post-install #68

Open wilson1000-MoJ opened 8 months ago

wilson1000-MoJ commented 8 months ago

This looks good, I have a suggestion to consider, which is very much a matter of preference.

Is there potential for this to be @docker compose exec php-fpm composer install.

And, leverage the composer script hook post-install-cmd, to run the following?

// ./bin/local-composer-assets.sh renamed to ./bin/composer-post-install.sh

// Remove the composer install line.

if [ ! -d "./vendor-assets" ]; then
  # Nginx file sharing regex-parts
  regex_files='\(htm\|html\|js\|css\|png\|jpg\|jpeg\|gif\|ico\|svg\|webmanifest\)'
  regex_path='\(app\/themes\/justice\|app\/mu\-plugins\|app\/plugins\|wp\)'

  echo "Generating vendor-assets directory..."

  mkdir -p ./vendor-assets
  find public/ -name '*node_modules*' -prune -name '*justice/src*' -prune -name '*justice/webpack*' -prune -o -type f -regex "public\/${regex_path}.*\.${regex_files}" -exec cp --parent "{}" vendor-assets/  \;

  echo "Done."
fi

_Originally posted by @EarthlingDavey in https://github.com/ministryofjustice/justice-gov-uk/pull/64#discussion_r1503809185_

wilson1000-MoJ commented 8 months ago

@EarthlingDavey says:

Here, we could be missing assets from recently installed packages.

composer.lock has a content-hash property.

After we generate vendor-assets could we write the content-hash value to vendor-assets/composer-lock-hash.txt?

And add an additional check to this conditional, like the following pseudo code.

if [ ! -d "./vendor-assets" OR composer-lock-hash.txt != composer.lock.content-hash ]; then

_Originally posted by @EarthlingDavey in https://github.com/ministryofjustice/justice-gov-uk/pull/64#discussion_r1503816537_