From dfc26852e888e6a4f682b623f40081ca743947f1 Mon Sep 17 00:00:00 2001 From: Ion Obreja Date: Fri, 20 Dec 2024 14:08:02 +0200 Subject: [PATCH] Add script in composer --- README.md | 53 ++++++++++++++++++------------ compile-theme.sh | 54 +++++++++++++++++++++++++++++++ composer.json | 10 +++++- web/themes/custom/frontend/.nvmrc | 2 +- 4 files changed, 97 insertions(+), 22 deletions(-) create mode 100755 compile-theme.sh diff --git a/README.md b/README.md index b526f6f694..54bb3f2e53 100644 --- a/README.md +++ b/README.md @@ -21,36 +21,49 @@ https://www.project.org ## I. Prerequisites -| Using DDEV | Using LAMP stack | -|---------------------------------------------------------------------------|---------------------------------------------------| -| [mkcert](https://github.com/FiloSottile/mkcert?tab=readme-ov-file#mkcert) | PHP 8.2 | -| [DDEV 1.22.0+](https://ddev.com/get-started) | MySQL 5.7.8+ / MariaDB 10.3.7+ | -| | Apache / NGINX | -| | [Composer](https://getcomposer.org) | -| | [NVM](https://github.com/nvm-sh/nvm) | -| | Node.js 18 (run `nvm use 18`) | +| Using DDEV | Using LAMP stack | +| ------------------------------------------------------------------------- | ------------------------------------ | +| [mkcert](https://github.com/FiloSottile/mkcert?tab=readme-ov-file#mkcert) | PHP 8.2 | +| [DDEV 1.22.0+](https://ddev.com/get-started) | MySQL 5.7.8+ / MariaDB 10.3.7+ | +| | Apache / NGINX | +| | [Composer](https://getcomposer.org) | +| | [NVM](https://github.com/nvm-sh/nvm) | +| | Node.js 18 (run `nvm use 18`) | ## II. Project setup -* Clone the repository -* Copy `example.robo.yml` to `robo.yml` and customize `username`, `password` and `admin_username` -* Copy `.env.example` to `.env` and configure the variables there +- Clone the repository +- Copy `example.robo.yml` to `robo.yml` and customize `username`, `password` and `admin_username` +- Copy `.env.example` to `.env` and configure the variables there If you are using LAMP stack and not DDEV, also the following steps are also required: -* Create a new database -* Create a new virtual host pointing to the web folder of this project -* Update your `/etc/hosts` file accordingly -* Copy `web/sites/example.settings.local.php` to `web/sites/default/settings.local.php` and customize database credentials. -* Copy `example.salt.txt` to `salt.txt` +- Create a new database +- Create a new virtual host pointing to the web folder of this project +- Update your `/etc/hosts` file accordingly +- Copy `web/sites/example.settings.local.php` to `web/sites/default/settings.local.php` and customize database credentials. +- Copy `example.salt.txt` to `salt.txt` ## III. Installation -* Run `./install.sh` +- Run `./install.sh` ## IV. Development Please make sure you are familiar with: -* Working with helpdesk: https://drupal.eaudeweb.ro/docs/use/helpdesk -* Our GIT workflow: https://drupal.eaudeweb.ro/docs/development-guide/git-workflow -* DDEV deveopment guide: https://drupal.eaudeweb.ro/docs/technical/documentation/development-ddev + +- Working with helpdesk: https://drupal.eaudeweb.ro/docs/use/helpdesk +- Our GIT workflow: https://drupal.eaudeweb.ro/docs/development-guide/git-workflow +- DDEV deveopment guide: https://drupal.eaudeweb.ro/docs/technical/documentation/development-ddev + +## V. Theme + +theme compilation + +- `ddev composer run theme-build` +- `ddev composer run theme-watch` + +In theme folder: + +- `npm run build` +- `npm run watch` diff --git a/compile-theme.sh b/compile-theme.sh new file mode 100755 index 0000000000..cc9d831f9f --- /dev/null +++ b/compile-theme.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/web/themes/custom/frontend" +SCRIPT_VERSION=0.1 +echo -e "${C_LIME}Theme compilation script, version: ${SCRIPT_VERSION}${NO_FORMAT}" +C_LIME="\033[38;5;10m" +C_YELLOW="\033[38;5;11m" +C_RED="\033[38;5;9m" +NO_FORMAT="\033[0m" +NVM_HOME="$HOME/.nvm" + +validate_node () { + REQUIRED_VERSION=$(awk '/^[0-9][0-9]/' "${SCRIPT_DIR}/.nvmrc") + ACTUAL_VERSION=$(echo "${NODE_VERSION}" | sed -n "s/^v\?\([0-9][0-9]\).*/\1/p") + if [ "${ACTUAL_VERSION}" == "${REQUIRED_VERSION}" ]; + then + echo -e "${C_LIME}Using existing node version ${ACTUAL_VERSION} for compilation ...${NO_FORMAT}" + else + echo -e "${C_RED}Incompatible node version, to compile the theme you need version ${REQUIRED_VERSION}, and you have ${ACTUAL_VERSION}. ${NO_FORMAT}" + exit 1 + fi +} + +echo -ne "${C_LIME}Looking for nvm: ${NO_FORMAT}" + +if [ -d "${NVM_HOME}" ]; +then + echo -e "${C_LIME}found${NO_FORMAT}" + echo -e "${C_LIME}Enabling Node ...${NO_FORMAT}" + source $NVM_HOME/nvm.sh; + cd "${SCRIPT_DIR}" && nvm install && nvm use +else + echo -e "${C_YELLOW}not found${NO_FORMAT}" + echo -ne "${C_LIME}Looking for existing node: ${NO_FORMAT}" + if command -v node 2>&1 >/dev/null + then + NODE_VERSION=$(node -v) + echo -e "${C_LIME}found (${NODE_VERSION})${NO_FORMAT}" + validate_node + else + echo -e "${C_RED}not found${NO_FORMAT}" + echo "" + echo -e "${C_RED}To compile the theme you need to install node or nvm tool ${NO_FORMAT}" + exit 1 + fi +fi + +echo -e "${C_LIME}Installing packages using npm ...${NO_FORMAT}" +cd ${SCRIPT_DIR} && npm install --no-audit --silent + +echo -e "${C_LIME}Compiling theme ...${NO_FORMAT}" +cd ${SCRIPT_DIR} && which node && npm run build --silent + +echo -e "${C_LIME}Done.${NO_FORMAT}" diff --git a/composer.json b/composer.json index 68cd405efa..466039ce77 100644 --- a/composer.json +++ b/composer.json @@ -249,6 +249,14 @@ "post-update-cmd": [ "@remove-git-folders" ], - "post-drupal-scaffold-cmd": [] + "post-drupal-scaffold-cmd": [], + "theme-build": [ + "Composer\\Config::disableProcessTimeout", + "./compile-theme.sh" + ], + "theme-watch": [ + "Composer\\Config::disableProcessTimeout", + "cd web/themes/custom/frontend/ && npm run watch" + ] } } diff --git a/web/themes/custom/frontend/.nvmrc b/web/themes/custom/frontend/.nvmrc index 7124fdc300..379b25d1cb 100644 --- a/web/themes/custom/frontend/.nvmrc +++ b/web/themes/custom/frontend/.nvmrc @@ -1 +1 @@ -v12.20.0 +v22.1.0