From bf71bb0393faa389df5ff36248b4b52f110f405b Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sun, 14 Jul 2024 04:17:22 +0200 Subject: [PATCH] Add script to create single-theme builds --- .gitignore | 1 + package.json | 1 + scripts/generateLayouts.ts | 2 +- scripts/single_build.sh | 94 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100755 scripts/single_build.sh diff --git a/.gitignore b/.gitignore index dc8529f7a..7ce5a6d82 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ dist/* +dist_*/* node_modules .cache/* .idea/* diff --git a/package.json b/package.json index b0cc06e68..d35530ef3 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "strt:https": "vite --host | sed 's/localhost:/127.0.0.1:/g'", "strt": "vite --host | sed 's/localhost:/127.0.0.1:/g'", "build": "./scripts/build.sh", + "build:single": "./scripts/single_build.sh", "prepare-deploy": "npm run generate:service-worker && ./scripts/prepare-build.sh && npm run build", "watch:css": "tailwindcss -i src/index.css -o public/css/index-tailwind-output.css --watch", diff --git a/scripts/generateLayouts.ts b/scripts/generateLayouts.ts index e759f54fb..abb1d6a64 100644 --- a/scripts/generateLayouts.ts +++ b/scripts/generateLayouts.ts @@ -630,7 +630,7 @@ class GenerateLayouts extends Script { const layout = new LayoutConfig(layoutConfigJson, true) const layoutName = layout.id if (blacklist.indexOf(layoutName.toLowerCase()) >= 0) { - console.log(`Skipping a layout with name${layoutName}, it is on the blacklist`) + console.log(`Skipping a layout with name ${layoutName}, it is on the blacklist`) continue } const err = (err) => { diff --git a/scripts/single_build.sh b/scripts/single_build.sh new file mode 100755 index 000000000..a3161cb5d --- /dev/null +++ b/scripts/single_build.sh @@ -0,0 +1,94 @@ +THEME=$1 + +if [ $# -eq 0 ] + then + echo "No arguments given. Expected a themename" +fi + +pwd +if [ -f "$THEME.html" ] +then + echo "$THEME.html found." +else + echo "Theme '$THEME' not found. Did you run 'npm run generate:layouts'?" + exit 1 +fi + +echo "Building theme $THEME" +rm -rf dist/* + +cp vite.config.js vite_single.config.js + +if [ -f index.bu.html ] +then + echo "Backup already exists" +else + cp index.html index.bu.html +fi + +rm index.html +cp "$THEME.html" index.html + +sed -i "s/input,/input: {index:\".\/index.html\"}/" vite_single.config.js + + + + + +export NODE_OPTIONS=--max-old-space-size=20000 +vite build --sourcemap --config vite_single.config.js || { echo 'Vite build failed' ; exit 1; } + + + + +cp -r assets/layers/ dist/assets/layers/ +cp -r assets/themes/ dist/assets/themes/ +cp -r assets/svg/ dist/assets/svg/ +cp -r assets/png/ dist/assets/png/ +mkdir dist/assets/langs +mkdir dist/assets/langs/layers +cp -r langs/layers/ dist/assets/langs/ +ls dist/assets/langs/layers/ +export NODE_OPTIONS="" +rm vite_single.config.js + + + +mkdir "dist_$THEME" +cp -r dist/* "dist_$THEME" + + +cd "dist_$THEME" || exit 1 +mv "$THEME.webmanifest" manif +rm *.webmanifest +mv manif "$THEME.webmanifest" + +rm -rf assets/docs/ +cd assets/generated/images/ || exit +pwd +ls . +for f in * +do + # echo ">>>" $f + case "$f" in + *$THEME* ) + echo "Keeping $f" + ;; + *) + rm "$f" + # echo "Not keeping $f" + esac + +done +cd - + +cd .. + +if [ -f index.bu.html ] +then + rm index.html + mv index.bu.html index.html +fi + +echo "BUILD COMPLETED" +echo "Deploying on github pages? Don't forget to add a CNAME file (containing your domain name verbatim, without protocol) and a .nojekyll file (which is empty)"