Skip to content

Commit eaf886a

Browse files
add an upgrade option to the docs updater
Signed-off-by: Brian McGillion <[email protected]>
1 parent e5e8d27 commit eaf886a

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

packages/pkgs-by-name/update-docs-depends/package.nix

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,38 @@ writeShellApplication {
1616
text = ''
1717
set -euo pipefail
1818
19-
echo "[update-docs-deps] Starting…"
19+
# Parse command-line arguments
20+
UPGRADE=false
21+
while [[ $# -gt 0 ]]; do
22+
case $1 in
23+
--upgrade)
24+
UPGRADE=true
25+
shift
26+
;;
27+
-h|--help)
28+
echo "Usage: update-docs-deps [--upgrade]"
29+
echo ""
30+
echo "Options:"
31+
echo " --upgrade Upgrade dependencies to latest versions (npm upgrade)"
32+
echo " --help Show this help message"
33+
echo ""
34+
echo "By default, runs 'npm update' to update within semver constraints."
35+
echo "With --upgrade, runs 'npm upgrade' to get latest versions."
36+
exit 0
37+
;;
38+
*)
39+
echo "Error: Unknown option: $1" >&2
40+
echo "Use --help for usage information." >&2
41+
exit 1
42+
;;
43+
esac
44+
done
45+
46+
if [ "$UPGRADE" = true ]; then
47+
echo "[update-docs-deps] Starting (upgrade mode)…"
48+
else
49+
echo "[update-docs-deps] Starting (update mode)…"
50+
fi
2051
2152
# Find repo root (directory containing .git)
2253
if ROOT="$(git rev-parse --show-toplevel 2>/dev/null)"; then
@@ -44,15 +75,28 @@ writeShellApplication {
4475
exit 1
4576
fi
4677
47-
echo "[update-docs-deps] Running npm update in $DOCS_DIR"
4878
pushd "$DOCS_DIR" >/dev/null
4979
5080
# Prefer using existing lock file; do not delete it
5181
if [ -f package-lock.json ]; then
5282
echo "[update-docs-deps] Using existing package-lock.json"
5383
fi
5484
55-
npm update
85+
if [ "$UPGRADE" = true ]; then
86+
echo "[update-docs-deps] Running npm upgrade in $DOCS_DIR (latest versions)"
87+
# npm upgrade requires npm-check-updates or manual package.json edits
88+
# We'll use npx to run npm-check-updates to upgrade package.json, then npm install
89+
if command -v npx &> /dev/null; then
90+
npx --yes npm-check-updates -u
91+
npm install
92+
else
93+
echo "Error: npx not found. Cannot run upgrade mode." >&2
94+
exit 1
95+
fi
96+
else
97+
echo "[update-docs-deps] Running npm update in $DOCS_DIR (within semver constraints)"
98+
npm update
99+
fi
56100
57101
WANTED_HASH=$(prefetch-npm-deps ./package-lock.json)
58102
if [ -z "$WANTED_HASH" ]; then
@@ -83,7 +127,11 @@ writeShellApplication {
83127
84128
# Create a unique branch
85129
TS="$(date -u +%Y%m%d-%H%M%S)"
86-
BRANCH="update-docs-deps-$TS"
130+
if [ "$UPGRADE" = true ]; then
131+
BRANCH="upgrade-docs-deps-$TS"
132+
else
133+
BRANCH="update-docs-deps-$TS"
134+
fi
87135
88136
# Detect default remote and branch
89137
REMOTE="''${REMOTE:-origin}"
@@ -114,7 +162,11 @@ writeShellApplication {
114162
echo "[update-docs-deps] Changes staged on branch $BRANCH."
115163
echo "Next steps:"
116164
echo " 1. Review with: git diff --cached"
117-
echo " 2. Commit: git commit -sm 'docs: update npm dependencies & hash'"
165+
if [ "$UPGRADE" = true ]; then
166+
echo " 2. Commit: git commit -sm 'docs: upgrade npm dependencies to latest versions'"
167+
else
168+
echo " 2. Commit: git commit -sm 'docs: update npm dependencies & hash'"
169+
fi
118170
echo " 3. Push: git push -u origin $BRANCH"
119171
echo " 4. Open a PR."
120172
echo

0 commit comments

Comments
 (0)