From 3636e9e7547376e66a61d285126eb8a869c5f856 Mon Sep 17 00:00:00 2001 From: Thomas Hauschild <7961978+Morgy93@users.noreply.github.com> Date: Sun, 18 Aug 2024 10:37:50 +0200 Subject: [PATCH 01/10] install npm-check-updates --- install.yaml | 1 + web-build/Dockerfile.woodoo | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 web-build/Dockerfile.woodoo diff --git a/install.yaml b/install.yaml index 893db1d..956b702 100644 --- a/install.yaml +++ b/install.yaml @@ -9,3 +9,4 @@ project_files: - commands/web/woodoo_components/ - commands/web/frontend - commands/host/frontend-update + - web-build/Dockerfile.woodoo diff --git a/web-build/Dockerfile.woodoo b/web-build/Dockerfile.woodoo new file mode 100644 index 0000000..0adc8b1 --- /dev/null +++ b/web-build/Dockerfile.woodoo @@ -0,0 +1,4 @@ +#ddev-generated + +# https://github.com/raineorshine/npm-check-updates +RUN npm install -g npm-check-updates From 047c379cf6a007180349563ef830595db03f8fda Mon Sep 17 00:00:00 2001 From: Thomas Hauschild <7961978+Morgy93@users.noreply.github.com> Date: Sun, 18 Aug 2024 10:38:06 +0200 Subject: [PATCH 02/10] add npm-deps --- commands/web/frontend | 1 + commands/web/woodoo_components/npm-deps | 76 +++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 commands/web/woodoo_components/npm-deps diff --git a/commands/web/frontend b/commands/web/frontend index 46c8958..f2f940c 100644 --- a/commands/web/frontend +++ b/commands/web/frontend @@ -27,6 +27,7 @@ source ".ddev/commands/web/woodoo_components/functions" source ".ddev/commands/web/woodoo_components/themes" source ".ddev/commands/web/woodoo_components/build" source ".ddev/commands/web/woodoo_components/watch" +source ".ddev/commands/web/woodoo_components/npm-deps" ## should be last source source ".ddev/commands/web/woodoo_components/selftest" diff --git a/commands/web/woodoo_components/npm-deps b/commands/web/woodoo_components/npm-deps new file mode 100644 index 0000000..97a5e72 --- /dev/null +++ b/commands/web/woodoo_components/npm-deps @@ -0,0 +1,76 @@ +#!/bin/bash +#ddev-generated - Do not modify this file; your modifications will be overwritten. + +# Function to check if npm check prerequisites are met +# Parameters: +# $1: The theme path +function checkPrequisites() { + local THEME_PATH=$1 + + if [[ ! -d "${THEME_PATH}/web/tailwind" ]]; then + echo -e "${txtred}${ICON_ERROR} ${THEME_PATH}/web/tailwind does not exist.${txtrst}" + exit 1 + fi + + cd "${THEME_PATH}/web/tailwind" || exit + + if ! command -v ncu &>/dev/null; then + echo -e "${txtylw}${ICON_WARNING} npm-check-updates is not installed. Run 'ddev restart' to install.${txtrst}" + npm install -g npm-check-updates + fi +} + +# Function to update npm dependencies using npm-check-updates +# Parameters: +# $1: The theme path +function updateNpmDeps() { + local THEME_PATH=$1 + + checkPrequisites "${THEME_PATH}" + + echo -e "${txtcyn}${ICON_ARROW_RIGHT} Updating npm dependencies...${txtrst}" + ncu -u + npm install + + echo -e "${txtgrn}${ICON_SUCCESS} npm dependencies updated.${txtrst}" + cd - >/dev/null || exit +} + +# Function to check outdated npm dependencies using npm-check-updates +# Parameters: +# $1: The theme path +function checkNpmDeps() { + local THEME_PATH=$1 + + checkPrequisites "${THEME_PATH}" + + echo -e "${txtcyn}${ICON_ARROW_RIGHT} Checking outdated npm dependencies...${txtrst}" + ncu + + echo -e "${txtgrn}${ICON_SUCCESS} npm dependencies check completed.${txtrst}" + cd - >/dev/null || exit +} + +# Add a command to update npm dependencies for a specific theme or all themes +if [[ $1 == "update-npm-deps" && $2 != "" ]]; then + THEME_TO_UPDATE=$(grep -oP "(?<=${2}: ).*" "${PROJECT_CONFIG_FILE}" | cut -d ' ' -f 1 | tr -d '"') + checkHyva "${THEME_TO_UPDATE}" + if [[ ${HYVA} == true ]]; then + updateNpmDeps "${THEME_TO_UPDATE}" + else + echo -e "${txtred}${ICON_ERROR} ${2} is not a Hyvä theme. Please update manually.${txtrst}" + fi + exit 0 +fi + +# Add a command to check outdated npm dependencies for a specific theme or all themes +if [[ $1 == "check-npm-deps" && $2 != "" ]]; then + THEME_TO_CHECK=$(grep -oP "(?<=${2}: ).*" "${PROJECT_CONFIG_FILE}" | cut -d ' ' -f 1 | tr -d '"') + checkHyva "${THEME_TO_CHECK}" + if [[ ${HYVA} == true ]]; then + checkNpmDeps "${THEME_TO_CHECK}" + else + echo -e "${txtred}${ICON_ERROR} ${2} is not a Hyvä theme. Please check manually.${txtrst}" + fi + exit 0 +fi From c34ea859695e79c3d8d3ba5e95a81861aee44b21 Mon Sep 17 00:00:00 2001 From: Thomas Hauschild <7961978+Morgy93@users.noreply.github.com> Date: Sun, 18 Aug 2024 10:40:11 +0200 Subject: [PATCH 03/10] add npm-deps docs --- README.md | 18 ++++++++++++++++++ commands/web/woodoo_components/help | 2 ++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 6661a6e..7d59a8a 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,8 @@ Command: build -f Builds all configured themes without yes/no confirmation build theme Build a specific theme watch theme Watch for CSS and JS changes in a specific theme + update-npm-deps theme Update npm dependencies for a specific theme + check-npm-deps theme Check outdated npm dependencies for a specific theme Option: -f Force the build command to run without yes/no confirmation @@ -147,6 +149,22 @@ To watch for CSS and JS changes in a specific theme, use: ddev frontend watch ``` +### Updating npm Dependencies + +To update npm dependencies for a specific theme, use: + +```shell +ddev frontend update-npm-deps +``` + +### Checking Outdated npm Dependencies + +To check outdated npm dependencies for a specific theme, use: + +```shell +ddev frontend check-npm-deps +``` + ## Troubleshooting Tips - Ensure that your theme paths in `.ddev/config-themes.yaml` are correct and relative to your project root. diff --git a/commands/web/woodoo_components/help b/commands/web/woodoo_components/help index 808d8a5..0fc22f7 100644 --- a/commands/web/woodoo_components/help +++ b/commands/web/woodoo_components/help @@ -29,6 +29,8 @@ if [[ ${found} == true ]]; then echo -e " ${txtcyn}build ${txtylw}-f${txtrst} Builds all configured themes without yes/no confirmation" echo -e " ${txtcyn}build ${txtpur}theme${txtrst} Build a specific theme${txtrst}" echo -e " ${txtcyn}watch ${txtpur}theme${txtrst} Watch for CSS and JS changes in a specific theme${txtrst}" + echo -e " ${txtcyn}update-npm-deps ${txtpur}theme${txtrst} Update npm dependencies for a specific theme" + echo -e " ${txtcyn}check-npm-deps ${txtpur}theme${txtrst} Check outdated npm dependencies for a specific theme" echo -e "${txtylw}\nOption:${txtrst}" echo -e " ${txtylw}-f${txtrst} Force the build command to run without yes/no confirmation\n" From c6e6865f2b885ee151a7d1bb6694ada6517ca54c Mon Sep 17 00:00:00 2001 From: Thomas Hauschild <7961978+Morgy93@users.noreply.github.com> Date: Sun, 18 Aug 2024 10:46:32 +0200 Subject: [PATCH 04/10] ignore unused trunk errors --- web-build/Dockerfile.woodoo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web-build/Dockerfile.woodoo b/web-build/Dockerfile.woodoo index 0adc8b1..6f4ce66 100644 --- a/web-build/Dockerfile.woodoo +++ b/web-build/Dockerfile.woodoo @@ -1,4 +1,8 @@ #ddev-generated +# trunk-ignore-all(trivy/DS002) +# trunk-ignore-all(trivy/DS026) +# trunk-ignore-all(checkov/CKV_DOCKER_2) +# trunk-ignore-all(checkov/CKV_DOCKER_3) # https://github.com/raineorshine/npm-check-updates RUN npm install -g npm-check-updates From e533171acaa3d8d229c74e35a65224bd4b8fae10 Mon Sep 17 00:00:00 2001 From: Thomas Hauschild <7961978+Morgy93@users.noreply.github.com> Date: Sun, 18 Aug 2024 10:50:56 +0200 Subject: [PATCH 05/10] fix message --- commands/web/woodoo_components/npm-deps | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/web/woodoo_components/npm-deps b/commands/web/woodoo_components/npm-deps index 97a5e72..a8cf200 100644 --- a/commands/web/woodoo_components/npm-deps +++ b/commands/web/woodoo_components/npm-deps @@ -14,9 +14,9 @@ function checkPrequisites() { cd "${THEME_PATH}/web/tailwind" || exit - if ! command -v ncu &>/dev/null; then - echo -e "${txtylw}${ICON_WARNING} npm-check-updates is not installed. Run 'ddev restart' to install.${txtrst}" - npm install -g npm-check-updates + if ! command -v ncuu &>/dev/null; then + echo -e "${txtylw}${ICON_WARNING} npm-check-updates is not installed. Run ${txtcyn}ddev restart${txtylw} to install.${txtrst}" + exit 1 fi } From 9139461032b7367598581865c2534ed53d8c106c Mon Sep 17 00:00:00 2001 From: Thomas Hauschild <7961978+Morgy93@users.noreply.github.com> Date: Mon, 19 Aug 2024 08:26:04 +0200 Subject: [PATCH 06/10] update comments --- commands/web/woodoo_components/npm-deps | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/web/woodoo_components/npm-deps b/commands/web/woodoo_components/npm-deps index a8cf200..77ecd30 100644 --- a/commands/web/woodoo_components/npm-deps +++ b/commands/web/woodoo_components/npm-deps @@ -51,7 +51,7 @@ function checkNpmDeps() { cd - >/dev/null || exit } -# Add a command to update npm dependencies for a specific theme or all themes +# A command to update npm dependencies for a specific theme if [[ $1 == "update-npm-deps" && $2 != "" ]]; then THEME_TO_UPDATE=$(grep -oP "(?<=${2}: ).*" "${PROJECT_CONFIG_FILE}" | cut -d ' ' -f 1 | tr -d '"') checkHyva "${THEME_TO_UPDATE}" @@ -63,7 +63,7 @@ if [[ $1 == "update-npm-deps" && $2 != "" ]]; then exit 0 fi -# Add a command to check outdated npm dependencies for a specific theme or all themes +# A command to check outdated npm dependencies for a specific theme if [[ $1 == "check-npm-deps" && $2 != "" ]]; then THEME_TO_CHECK=$(grep -oP "(?<=${2}: ).*" "${PROJECT_CONFIG_FILE}" | cut -d ' ' -f 1 | tr -d '"') checkHyva "${THEME_TO_CHECK}" From a3f4fc9fd250e7407b4a22c034b9aba7f9938c0a Mon Sep 17 00:00:00 2001 From: Thomas Hauschild <7961978+Morgy93@users.noreply.github.com> Date: Tue, 20 Aug 2024 08:19:13 +0200 Subject: [PATCH 07/10] fix command --- commands/web/woodoo_components/npm-deps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/web/woodoo_components/npm-deps b/commands/web/woodoo_components/npm-deps index 77ecd30..f0ce443 100644 --- a/commands/web/woodoo_components/npm-deps +++ b/commands/web/woodoo_components/npm-deps @@ -14,7 +14,7 @@ function checkPrequisites() { cd "${THEME_PATH}/web/tailwind" || exit - if ! command -v ncuu &>/dev/null; then + if ! command -v ncu &>/dev/null; then echo -e "${txtylw}${ICON_WARNING} npm-check-updates is not installed. Run ${txtcyn}ddev restart${txtylw} to install.${txtrst}" exit 1 fi From f2328070f69c156ea63ee013c45dc3b040001c46 Mon Sep 17 00:00:00 2001 From: Mathias Elle Date: Sun, 27 Oct 2024 16:46:37 +0100 Subject: [PATCH 08/10] Update commands/web/woodoo_components/npm-deps --- commands/web/woodoo_components/npm-deps | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/commands/web/woodoo_components/npm-deps b/commands/web/woodoo_components/npm-deps index f0ce443..4aa211d 100644 --- a/commands/web/woodoo_components/npm-deps +++ b/commands/web/woodoo_components/npm-deps @@ -51,8 +51,8 @@ function checkNpmDeps() { cd - >/dev/null || exit } -# A command to update npm dependencies for a specific theme -if [[ $1 == "update-npm-deps" && $2 != "" ]]; then +# A command to update npm dependencies for a specific Hyvä theme +if [[ $1 == "hyva-npm-update" && $2 != "" ]]; then THEME_TO_UPDATE=$(grep -oP "(?<=${2}: ).*" "${PROJECT_CONFIG_FILE}" | cut -d ' ' -f 1 | tr -d '"') checkHyva "${THEME_TO_UPDATE}" if [[ ${HYVA} == true ]]; then @@ -61,6 +61,18 @@ if [[ $1 == "update-npm-deps" && $2 != "" ]]; then echo -e "${txtred}${ICON_ERROR} ${2} is not a Hyvä theme. Please update manually.${txtrst}" fi exit 0 +elif [[ $1 == "hyva-npm-update" && $2 == "" ]]; then + checkThemePathExists silent + THEMES_TO_UPDATE=$(gum choose --cursor-prefix "[ ] " --unselected-prefix "[ ] " --selected-prefix "[✓] " --no-limit $THEMES_IN_CONFIG) + for THEME_CODE in ${THEMES_TO_UPDATE}; do + THEMES_TO_UPDATE=$(echo $(grep -oP '(?<='$THEME_CODE': ).*' $PROJECT_CONFIG_FILE) | cut -d ' ' -f 1 | sed 's/"//g') + checkHyva "${THEMES_TO_UPDATE}" + if [[ ${HYVA} == true ]]; then + checkNpmDeps "${THEMES_TO_UPDATE}" + else + echo -e "${txtred}${ICON_ERROR} ${THEME_CODE} is not a Hyvä theme. Please check manually.${txtrst}" + fi + done fi # A command to check outdated npm dependencies for a specific theme From 336e098a71ed561bb99464ca88a144ed86962454 Mon Sep 17 00:00:00 2001 From: Mathias Elle Date: Sun, 27 Oct 2024 16:46:46 +0100 Subject: [PATCH 09/10] Update commands/web/woodoo_components/npm-deps --- commands/web/woodoo_components/npm-deps | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/commands/web/woodoo_components/npm-deps b/commands/web/woodoo_components/npm-deps index 4aa211d..f47062d 100644 --- a/commands/web/woodoo_components/npm-deps +++ b/commands/web/woodoo_components/npm-deps @@ -75,8 +75,8 @@ elif [[ $1 == "hyva-npm-update" && $2 == "" ]]; then done fi -# A command to check outdated npm dependencies for a specific theme -if [[ $1 == "check-npm-deps" && $2 != "" ]]; then +# A command to check outdated npm dependencies for a specific Hyvä theme +if [[ $1 == "hyva-npm-check" && $2 != "" ]]; then THEME_TO_CHECK=$(grep -oP "(?<=${2}: ).*" "${PROJECT_CONFIG_FILE}" | cut -d ' ' -f 1 | tr -d '"') checkHyva "${THEME_TO_CHECK}" if [[ ${HYVA} == true ]]; then @@ -85,4 +85,18 @@ if [[ $1 == "check-npm-deps" && $2 != "" ]]; then echo -e "${txtred}${ICON_ERROR} ${2} is not a Hyvä theme. Please check manually.${txtrst}" fi exit 0 +elif [[ $1 == "hyva-npm-check" && $2 == "" ]]; then + checkThemePathExists silent + THEMES_TO_CHECK=$(gum choose --cursor-prefix "[ ] " --unselected-prefix "[ ] " --selected-prefix "[✓] " --no-limit $THEMES_IN_CONFIG) + for THEME_CODE in ${THEMES_TO_CHECK}; do + THEMES_TO_CHECK=$(echo $(grep -oP '(?<='$THEME_CODE': ).*' $PROJECT_CONFIG_FILE) | cut -d ' ' -f 1 | sed 's/"//g') + + # checks to figure out if it is a Hyvä Theme + checkHyva "${THEMES_TO_CHECK}" + if [[ ${HYVA} == true ]]; then + checkNpmDeps "${THEMES_TO_CHECK}" + else + echo -e "${txtred}${ICON_ERROR} ${THEME_CODE} is not a Hyvä theme. Please check manually.${txtrst}" + fi + done fi From c7625573fc5518213d06c4c250685ee9fad05bfe Mon Sep 17 00:00:00 2001 From: Mathias Elle Date: Sun, 27 Oct 2024 16:58:18 +0100 Subject: [PATCH 10/10] #39 update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6373d94..206c23c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ All notable changes to this project will be documented in this file. - updated trunk plugin and linters - fix typo in several files +- updated README.md for dependencies checker by [@Morgy93] +- added command to `update` npm dependencies for a specific theme with `ddev frontend update-npm-deps theme` [https://github.com/dermatz/ddev-woodoo-buildtools-magento/issues/39] by [@Morgy93] +- added command to `check` outdated npm dependencies in a specific theme with `ddev frontend check-npm-deps theme` [https://github.com/dermatz/ddev-woodoo-buildtools-magento/issues/39] by [@Morgy93] + --- ## Latest Release