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 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/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/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" diff --git a/commands/web/woodoo_components/npm-deps b/commands/web/woodoo_components/npm-deps new file mode 100644 index 0000000..f47062d --- /dev/null +++ b/commands/web/woodoo_components/npm-deps @@ -0,0 +1,102 @@ +#!/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 ${txtcyn}ddev restart${txtylw} to install.${txtrst}" + exit 1 + 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 +} + +# 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 + updateNpmDeps "${THEME_TO_UPDATE}" + else + 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 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 + checkNpmDeps "${THEME_TO_CHECK}" + else + 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 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..6f4ce66 --- /dev/null +++ b/web-build/Dockerfile.woodoo @@ -0,0 +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