diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index dcb70ab1..58091abf 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -30,7 +30,9 @@ jobs: - name: Build run: | npm install - ./hugo/scripts/build.sh production "/pr-${{github.event.number}}" + npm run build + env: + BASE_URL: /pr-${{github.event.number}} - name: Upload artifact uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 with: diff --git a/hugo/package.json b/hugo/package.json index 32197431..9abe2344 100644 --- a/hugo/package.json +++ b/hugo/package.json @@ -18,7 +18,7 @@ "build:worker/sql": "esbuild ./assets/scripts/sql/language-server.ts --bundle --format=iife --outfile=./static/showcase/libs/worker/sqlServerWorker.js", "build:worker/minilogo": "esbuild ../node_modules/langium-minilogo/out/language-server/main-browser.js --bundle --format=iife --outfile=./static/showcase/libs/worker/minilogoServerWorker.js", "build:static": "npm run clean:static && npm run build:worker/statemachine && npm run build:worker/domainmodel && npm run build:worker/sql && npm run build:worker/minilogo && npm run build:worker/arithmetics && npm run build:worker/playground-common && npm run build:worker/playground-langium && npm run build:worker/playground-user && npm run copy:monaco-workers", - "build": "./scripts/build.sh production /", + "build": "npm run build:static && node ./scripts/build.js", "watch": "npm run build:static && cross-env NODE_ENV=development hugo server --config ./config.toml -D -b localhost:1313 -d ../public --appendPort=false", "watch:gitpod": "npm run build:static && cross-env NODE_ENV=development hugo server --config ./config.toml -D -b `gp url 1313` -d ../public --appendPort=false" }, diff --git a/hugo/scripts/build.js b/hugo/scripts/build.js new file mode 100755 index 00000000..6252d479 --- /dev/null +++ b/hugo/scripts/build.js @@ -0,0 +1,29 @@ +import cp from 'child_process'; +import { dirname, resolve } from 'path'; + +const baseUrl = getBaseUrl(); +console.log(`Building website for location '${baseUrl}'...`); +performHugoBuild(baseUrl); + +function getBaseUrl() { + return process.env['BASE_URL'] || '/'; +} + +function performHugoBuild(rootDir) { + const executable = resolve(dirname(process.execPath), 'npm'); + cp.spawnSync(executable, [ + 'exec', + '--', 'hugo', + '--config', 'config.toml', + '-b', rootDir, + '-d', '../public', + '--gc', + '--minify' + ], { + env: { + NODE_ENV: "production" + }, + shell: true, + stdio: 'inherit' + }); +} \ No newline at end of file diff --git a/hugo/scripts/build.sh b/hugo/scripts/build.sh deleted file mode 100755 index b87dbc69..00000000 --- a/hugo/scripts/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -cd $(dirname "$0")/.. -npm run build:static && npx cross-env NODE_ENV=${1} hugo --config config.toml -b ${2} -d ../public --gc --minify \ No newline at end of file