Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#39 - add update dependencies command #43

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Changelog for Woodoo Buildtools

Check failure on line 1 in CHANGELOG.md

View check run for this annotation

Trunk.io / Trunk Check

prettier

Incorrect formatting, autoformat by running 'trunk fmt'

All notable changes to this project will be documented in this file.

Expand All @@ -10,6 +10,10 @@
- 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]

Check notice on line 14 in CHANGELOG.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

CHANGELOG.md#L14

Expected: 80; Actual: 192
- 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]

Check notice on line 15 in CHANGELOG.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

CHANGELOG.md#L15

Expected: 80; Actual: 198

---

## Latest Release
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [DDEV] Woodoo Frontend Buildtools for Magento & Hyvä

Check failure on line 1 in README.md

View check run for this annotation

Trunk.io / Trunk Check

prettier

Incorrect formatting, autoformat by running 'trunk fmt'

[![tests](https://github.com/dermatz/ddev-woodoo-buildtools-magento/actions/workflows/tests.yml/badge.svg)](https://github.com/dermatz/ddev-woodoo-buildtools-magento/actions/workflows/tests.yml) <img src="https://img.shields.io/librariesio/github/dermatz/ddev-woodoo-buildtools-magento" alt="Dependencies"> <img src="https://img.shields.io/github/last-commit/dermatz/ddev-woodoo-buildtools-magento" alt="Last commit date Badge">
<img src="https://img.shields.io/github/v/release/dermatz/ddev-woodoo-buildtools-magento" alt="Release-Badge"> <img src="https://img.shields.io/github/sponsors/dermatz" alt="Sponsors"> [<img src="https://img.shields.io/badge/Discord-Join%20Chat-orange" alt="Join our Discord">](https://discord.gg/H5CjMXQQHn)
Expand Down Expand Up @@ -111,6 +111,8 @@
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
Expand Down Expand Up @@ -147,6 +149,22 @@
ddev frontend watch <theme_code>
```

### Updating npm Dependencies

To update npm dependencies for a specific theme, use:

```shell
ddev frontend update-npm-deps <theme_code>
```

### Checking Outdated npm Dependencies

To check outdated npm dependencies for a specific theme, use:

```shell
ddev frontend check-npm-deps <theme_code>
```

## Troubleshooting Tips

- Ensure that your theme paths in `.ddev/config-themes.yaml` are correct and relative to your project root.
Expand Down
1 change: 1 addition & 0 deletions commands/web/frontend
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions commands/web/woodoo_components/help
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
102 changes: 102 additions & 0 deletions commands/web/woodoo_components/npm-deps
Original file line number Diff line number Diff line change
@@ -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)

Check notice on line 66 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2086)

[new] Double quote to prevent globbing and word splitting.

Check notice on line 66 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.
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')

Check notice on line 68 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2005)

[new] Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.

Check warning on line 68 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2046)

[new] Quote this to prevent word splitting.

Check notice on line 68 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2086)

[new] Double quote to prevent globbing and word splitting.

Check notice on line 68 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

Check notice on line 68 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2086)

[new] Double quote to prevent globbing and word splitting.

Check notice on line 68 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.
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)

Check notice on line 90 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2086)

[new] Double quote to prevent globbing and word splitting.

Check notice on line 90 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.
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')

Check notice on line 92 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2005)

[new] Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.

Check warning on line 92 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2046)

[new] Quote this to prevent word splitting.

Check notice on line 92 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2086)

[new] Double quote to prevent globbing and word splitting.

Check notice on line 92 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

Check notice on line 92 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2086)

[new] Double quote to prevent globbing and word splitting.

Check notice on line 92 in commands/web/woodoo_components/npm-deps

View check run for this annotation

Trunk.io / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

# 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
1 change: 1 addition & 0 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ project_files:
- commands/web/woodoo_components/
- commands/web/frontend
- commands/host/frontend-update
- web-build/Dockerfile.woodoo
8 changes: 8 additions & 0 deletions web-build/Dockerfile.woodoo
Original file line number Diff line number Diff line change
@@ -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
Loading