mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-15 08:16:39 +00:00
build: refactor build scripts
This commit is contained in:
1 parent
1a58412b34
commit
ee50bbf7e8
2 files changed
+131
-53
No files matched your search
+95
-50
@@ -1,68 +1,113 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
exitfn () {
|
set -euo pipefail
|
||||||
trap SIGINT # Restore signal handling for SIGINT
|
|
||||||
cd ../..
|
INITIAL_DIR="$(pwd)"
|
||||||
exit # then exit script.
|
|
||||||
|
cleanup() {
|
||||||
|
cd "$INITIAL_DIR" || true
|
||||||
|
}
|
||||||
|
trap cleanup EXIT INT TERM
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: ./scripts/view-starter-dev.sh <starter-name> [--debug] [--no-pagefind]"
|
||||||
|
echo "Example: ./scripts/view-starter-dev.sh blog --debug"
|
||||||
}
|
}
|
||||||
|
|
||||||
trap "exitfn" INT # Set up SIGINT trap to call function.
|
if [ $# -lt 1 ]; then
|
||||||
|
usage
|
||||||
# Check if starter name is provided
|
|
||||||
if [ -z "$1" ]; then
|
|
||||||
echo "Usage: ./scripts/view-starter-dev.sh <starter-name>"
|
|
||||||
echo "Example: ./scripts/view-starter-dev.sh blog"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install Tailwind v4 dependencies if blox-tailwind module is present
|
STARTER=""
|
||||||
if [ -d "modules/blox-tailwind" ]; then
|
DEBUG_MODE=false
|
||||||
echo "📦 Installing Tailwind v4 dependencies in module..."
|
PAGEFIND=true
|
||||||
cd modules/blox-tailwind
|
|
||||||
if command -v pnpm &> /dev/null; then
|
while [ $# -gt 0 ]; do
|
||||||
pnpm install
|
case "$1" in
|
||||||
else
|
--debug)
|
||||||
npm install
|
DEBUG_MODE=true
|
||||||
fi
|
shift
|
||||||
cd ../..
|
;;
|
||||||
|
--no-pagefind)
|
||||||
|
PAGEFIND=false
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
echo "Unknown option: $1"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
STARTER="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$STARTER" ]; then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# export HUGO_STATS_PATH="./starters/$1/hugo_stats.json"
|
# Run Hugo from the site dir so Tailwind CLI is discoverable
|
||||||
# printf 'HUGO_STATS_PATH: %s\n' "$HUGO_STATS_PATH"
|
cd "starters/$STARTER"
|
||||||
|
|
||||||
# `--source "starters/$1"` won't work for Tailwind Module
|
# Ensure Tailwind CLI exists in starter (required for Hugo css.TailwindCSS)
|
||||||
# due to Hugo limitation requiring Hugo to be run from site dir
|
if [ -f "package.json" ] && [ ! -x "node_modules/.bin/tailwindcss" ]; then
|
||||||
cd "starters/$1"
|
|
||||||
|
|
||||||
# Install Tailwind CLI in starter directory if package.json exists
|
|
||||||
# Hugo's css.TailwindCSS function needs to find the CLI from where Hugo runs
|
|
||||||
if [ -f "package.json" ]; then
|
|
||||||
echo "📦 Installing Tailwind CLI in starter directory for Hugo..."
|
echo "📦 Installing Tailwind CLI in starter directory for Hugo..."
|
||||||
if command -v pnpm &> /dev/null; then
|
if command -v pnpm >/dev/null 2>&1; then
|
||||||
pnpm install
|
pnpm install
|
||||||
else
|
else
|
||||||
npm install
|
npm install
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export HUGO_BLOX_DEMO=true \
|
# Core environment for local dev linking modules and enabling demo/debug flags
|
||||||
export HUGO_BLOX_DEBUG=true \
|
export HUGO_BLOX_DEMO=true
|
||||||
export HUGO_ENVIRONMENT=development \
|
export HUGO_BLOX_DEBUG=true
|
||||||
export HUGOxPARAMSxDECAP_CMSxLOCAL_BACKEND=true \
|
export HUGO_ENVIRONMENT=development
|
||||||
export HUGO_MODULE_REPLACEMENTS="github.com/HugoBlox/hugo-blox-builder/modules/blox-bootstrap/v5 -> ../../../modules/blox-bootstrap,
|
export HUGOxPARAMSxDECAP_CMSxLOCAL_BACKEND=true
|
||||||
github.com/HugoBlox/hugo-blox-builder/modules/blox-plugin-netlify -> ../../../modules/blox-plugin-netlify,
|
export HUGO_MODULE_REPLACEMENTS="github.com/HugoBlox/hugo-blox-builder/modules/blox-bootstrap/v5 -> ../../../modules/blox-bootstrap,github.com/HugoBlox/hugo-blox-builder/modules/blox-plugin-netlify -> ../../../modules/blox-plugin-netlify,github.com/HugoBlox/hugo-blox-builder/modules/blox-plugin-reveal -> ../../../modules/blox-plugin-reveal,github.com/HugoBlox/hugo-blox-builder/modules/blox-tailwind -> ../../../modules/blox-tailwind,github.com/HugoBlox/hugo-blox-builder/modules/blox-plugin-decap-cms -> ../../../modules/blox-plugin-decap-cms,github.com/HugoBlox/hugo-blox-builder/modules/blox-core -> ../../../modules/blox-core,github.com/HugoBlox/hugo-blox-builder/modules/blox-seo -> ../../../modules/blox-seo,github.com/HugoBlox/hugo-blox-builder/modules/blox-analytics -> ../../../modules/blox-analytics"
|
||||||
github.com/HugoBlox/hugo-blox-builder/modules/blox-plugin-reveal -> ../../../modules/blox-plugin-reveal,
|
|
||||||
github.com/HugoBlox/hugo-blox-builder/modules/blox-tailwind -> ../../../modules/blox-tailwind,
|
|
||||||
github.com/HugoBlox/hugo-blox-builder/modules/blox-plugin-decap-cms -> ../../../modules/blox-plugin-decap-cms,
|
|
||||||
github.com/HugoBlox/hugo-blox-builder/modules/blox-core -> ../../../modules/blox-core,
|
|
||||||
github.com/HugoBlox/hugo-blox-builder/modules/blox-seo -> ../../../modules/blox-seo,
|
|
||||||
github.com/HugoBlox/hugo-blox-builder/modules/blox-analytics -> ../../../modules/blox-analytics" \
|
|
||||||
# START PAGEFIND
|
|
||||||
hugo && \
|
|
||||||
npm_config_yes=true npx pagefind --site "public" --output-subdir ../static/pagefind && \
|
|
||||||
# END PAGEFIND
|
|
||||||
# --renderStaticToDisk --printUnusedTemplates --panicOnWarning
|
|
||||||
# --templateMetrics --templateMetricsHints --ignoreCache --noHTTPCache
|
|
||||||
hugo server --disableFastRender --printI18nWarnings --printPathWarnings --gc --port 8081 --bind 0.0.0.0 --logLevel debug
|
|
||||||
|
|
||||||
trap SIGINT # Restore signal handling to previous before exit.
|
# Optionally pre-build and generate Pagefind index for local search
|
||||||
|
if [ "$PAGEFIND" = true ]; then
|
||||||
|
hugo
|
||||||
|
if command -v pnpm >/dev/null 2>&1; then
|
||||||
|
pnpm dlx pagefind --site "public" --output-subdir ../static/pagefind
|
||||||
|
else
|
||||||
|
npm_config_yes=true npx pagefind --site "public" --output-subdir ../static/pagefind
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Compose Hugo server args
|
||||||
|
HUGO_ARGS=(
|
||||||
|
server
|
||||||
|
--disableFastRender
|
||||||
|
--printI18nWarnings
|
||||||
|
--printPathWarnings
|
||||||
|
--gc
|
||||||
|
-F
|
||||||
|
--port 8081
|
||||||
|
--bind 0.0.0.0
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ "$DEBUG_MODE" = true ]; then
|
||||||
|
HUGO_ARGS+=(
|
||||||
|
--logLevel debug
|
||||||
|
--panicOnWarning
|
||||||
|
--templateMetrics
|
||||||
|
--templateMetricsHints
|
||||||
|
--ignoreCache
|
||||||
|
--noHTTPCache
|
||||||
|
--renderStaticToDisk
|
||||||
|
-D
|
||||||
|
-E
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
|
hugo "${HUGO_ARGS[@]}"
|
||||||
+36
-3
@@ -1,5 +1,38 @@
|
|||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
HUGOxPARAMSxCMSxLOCAL_BACKEND=true \
|
exitfn () {
|
||||||
hugo server --panicOnWarning --renderStaticToDisk -F --port 8081 --bind 0.0.0.0 \
|
trap SIGINT
|
||||||
--source "starters/$1"
|
cd "$INITIAL_DIR"
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
trap "exitfn" INT
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Usage: ./scripts/view-starter.sh <starter-name>"
|
||||||
|
echo "Example: ./scripts/view-starter.sh blog"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
INITIAL_DIR=$(pwd)
|
||||||
|
|
||||||
|
# Run Hugo from the starter directory so Tailwind v4 CLI is discoverable by Hugo
|
||||||
|
cd "starters/$1"
|
||||||
|
|
||||||
|
# Ensure Tailwind CLI is available for Hugo
|
||||||
|
if [ -f "package.json" ]; then
|
||||||
|
if [ ! -x "node_modules/.bin/tailwindcss" ]; then
|
||||||
|
echo "📦 Installing Tailwind CLI in starter directory for Hugo..."
|
||||||
|
if command -v pnpm >/dev/null 2>&1; then
|
||||||
|
pnpm install
|
||||||
|
else
|
||||||
|
npm install
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
HUGO_ENVIRONMENT=development \
|
||||||
|
HUGOxPARAMSxDECAP_CMSxLOCAL_BACKEND=true \
|
||||||
|
hugo server --panicOnWarning --renderStaticToDisk -F --port 8081 --bind 0.0.0.0
|
||||||
|
|
||||||
|
trap SIGINT
|
||||||
Reference in new issue
Block a user