diff --git a/Dockerfile b/Dockerfile index 2436a8124..4aac3160f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,8 @@ COPY . . RUN npm ci && \ npm run build:prepare-dist && \ npm cache clean --force && \ - rm -rf dist/node_modules && \ - mv dist/* \ + rm -rf build/node_modules && \ + mv build/* \ start-docker.sh \ /usr/src/app/ && \ rm -rf \ diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 9370bd6da..f83789399 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -10,8 +10,8 @@ COPY . . RUN npm ci && \ npm run build:prepare-dist && \ npm cache clean --force && \ - rm -rf dist/node_modules && \ - mv dist/* \ + rm -rf build/node_modules && \ + mv build/* \ start-docker.sh \ /usr/src/app/ && \ rm -rf \ diff --git a/bin/build-server.sh b/bin/build-server.sh index ff2912470..3af7ec9f5 100755 --- a/bin/build-server.sh +++ b/bin/build-server.sh @@ -22,53 +22,42 @@ echo "Selected Arch: $ARCH" # Set Node.js version and architecture-specific filename NODE_VERSION=20.15.1 -NODE_ARCH=$ARCH -# Debug output -echo "Node arch: $NODE_ARCH" +BUILD_DIR="./build" +DIST_DIR="./dist" -# Special case for x64 in Node.js downloads -if [ "$NODE_ARCH" = "x64" ]; then - NODE_FILENAME="x64" -elif [ "$NODE_ARCH" = "arm64" ]; then - NODE_FILENAME="arm64" -fi +./bin/copy-trilium.sh -# Debug output -echo "Node filename: $NODE_FILENAME" +NODE_FILENAME=node-v${NODE_VERSION}-linux-${ARCH} -PKG_DIR=dist/trilium-linux-${ARCH}-server -echo "Package directory: $PKG_DIR" - -if [ "$1" != "DONTCOPY" ] -then - # Need to modify copy-trilium.sh to accept the target directory - ./bin/copy-trilium.sh "$PKG_DIR" -fi - -cd dist -wget https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${NODE_FILENAME}.tar.xz -tar xfJ node-v${NODE_VERSION}-linux-${NODE_FILENAME}.tar.xz -rm node-v${NODE_VERSION}-linux-${NODE_FILENAME}.tar.xz +echo "Downloading Node.js runtime $NODE_FILENAME..." +cd $BUILD_DIR +wget -qO- https://nodejs.org/dist/v${NODE_VERSION}/${NODE_FILENAME}.tar.xz | tar xfJ - +mv $NODE_FILENAME node cd .. -mv dist/node-v${NODE_VERSION}-linux-${NODE_FILENAME} $PKG_DIR/node -rm -r $PKG_DIR/node/lib/node_modules/npm -rm -r $PKG_DIR/node/include/node +rm -r $BUILD_DIR/node/lib/node_modules/npm \ + $BUILD_DIR/node/include/node \ + $BUILD_DIR/node_modules/electron* \ + $BUILD_DIR/electron*.{js,map} -rm -r $PKG_DIR/node_modules/electron* -rm -r $PKG_DIR/electron*.js +printf "#!/bin/sh\n./node/bin/node src/main" > $BUILD_DIR/trilium.sh +chmod 755 $BUILD_DIR/trilium.sh -printf "#!/bin/sh\n./node/bin/node src/main" > $PKG_DIR/trilium.sh -chmod 755 $PKG_DIR/trilium.sh - -cp bin/tpl/anonymize-database.sql $PKG_DIR/ - -cp -r translations $PKG_DIR/ +# TriliumNextTODO: is this still required? If yes → move to copy-dist/copy-trilium +cp bin/tpl/anonymize-database.sql $BUILD_DIR/ VERSION=`jq -r ".version" package.json` -cd dist -tar cJf trilium-linux-${ARCH}-server-${VERSION}.tar.xz trilium-linux-${ARCH}-server +ARCHIVE_NAME="TriliumNextNotes-Server-${VERSION}-linux-${ARCH}" +echo "Creating Archive $ARCHIVE_NAME..." + +mkdir $DIST_DIR +cp -r "$BUILD_DIR" "$DIST_DIR/$ARCHIVE_NAME" +cd $DIST_DIR +tar cJf "$ARCHIVE_NAME.tar.xz" "$ARCHIVE_NAME" +rm -rf "$ARCHIVE_NAME" + +echo "Server Build Completed!" \ No newline at end of file diff --git a/bin/build.sh b/bin/build.sh deleted file mode 100755 index 7fb41cfcb..000000000 --- a/bin/build.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash - -set -e # Fail on any command error - -if ! command -v jq &> /dev/null; then - echo "Missing command: jq" - exit 1 -fi - -if ! command -v fakeroot &> /dev/null; then - echo "Missing command: fakeroot" - exit 1 -fi - -if ! command -v dpkg-deb &> /dev/null; then - echo "Missing command: dpkg-deb" - exit 1 -fi - -if dpkg-deb 2>&1 | grep BusyBox &> /dev/null; then - echo "The dpkg-deb binary provided by BusyBox is not compatible. The Debian tool needs to be used instead." - exit 1 -fi - -if ! command -v wine &> /dev/null; then - echo "Missing command: wine" - exit 1 -fi - -echo "Deleting existing builds" - -rm -rf dist/* - -SRC_DIR=dist/trilium-src - -bin/copy-trilium.sh $SRC_DIR - -# we'll just copy the same SRC dir to all the builds so we don't have to do npm install in each separately -cp -r $SRC_DIR ./dist/trilium-linux-x64-src -cp -r $SRC_DIR ./dist/trilium-linux-x64-server -cp -r $SRC_DIR ./dist/trilium-windows-x64-src -cp -r $SRC_DIR ./dist/trilium-mac-x64-src -cp -r $SRC_DIR ./dist/trilium-mac-arm64-src - -bin/build-win-x64.sh DONTCOPY - -bin/build-mac-x64.sh DONTCOPY - -bin/build-mac-arm64.sh DONTCOPY - -bin/build-linux-x64.sh DONTCOPY - -bin/build-server.sh DONTCOPY diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index 289334321..0f9e62c99 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -1,7 +1,7 @@ import fs from "fs-extra"; import path from "path"; -const DEST_DIR = "./dist"; +const DEST_DIR = "./build"; const VERBOSE = process.env.VERBOSE; @@ -28,6 +28,8 @@ try { "./config-sample.ini", "./package-lock.json", "./package.json", + "./LICENSE", + "./README.md", "./src/views/", "./src/etapi/etapi.openapi.yaml", "./src/routes/api/openapi.json", diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh index f62b180a0..55c5cf6de 100755 --- a/bin/copy-trilium.sh +++ b/bin/copy-trilium.sh @@ -3,72 +3,42 @@ set -e # Fail on any command error shopt -s globstar -if [[ $# -eq 0 ]] ; then - echo "Missing argument of target directory" - exit 1 -fi +BUILD_DIR="./build" + if ! [[ $(which npm) ]]; then echo "Missing npm" exit 1 fi -# Trigger the TypeScript build -echo TypeScript build start -npm run build:ts -echo TypeScript build finished - -# Copy the TypeScript artifacts -DIR="$1" -rm -rf "$DIR" -mkdir -pv "$DIR" - -echo Webpack start -npm run build:webpack -echo Webpack finish - -echo "Copying Trilium to build directory $DIR" - -for d in 'images' 'libraries' 'src' 'db'; do - cp -r "$d" "$DIR"/ -done - -for f in 'package.json' 'package-lock.json' 'README.md' 'LICENSE' 'config-sample.ini'; do - cp "$f" "$DIR"/ -done +# Trigger the build +echo Build start +npm run build:prepare-dist +echo Build finished # Patch package.json main -sed -i 's/.\/dist\/electron-main.js/electron-main.js/g' "$DIR/package.json" - -script_dir=$(realpath $(dirname $0)) -cp -R "$script_dir/../build/src" "$DIR" -cp "$script_dir/../build/electron-main.js" "$DIR" +sed -i 's|./dist/electron-main.js|electron-main.js|g' "$BUILD_DIR/package.json" # run in subshell (so we return to original dir) -(cd $DIR && npm install --omit=dev --legacy-peer-deps) +(cd $BUILD_DIR && npm ci --omit=dev) -if [[ -d "$DIR"/node_modules ]]; then +if [[ -d "$BUILD_DIR"/node_modules ]]; then # cleanup of useless files in dependencies for d in 'image-q/demo' \ '@excalidraw/excalidraw/dist/excalidraw-assets-dev' '@excalidraw/excalidraw/dist/excalidraw.development.js' '@excalidraw/excalidraw/dist/excalidraw-with-preact.development.js' \ 'mermaid/dist/mermaid.js' \ 'boxicons/svg' 'boxicons/node_modules/react'/* \ '@jimp/plugin-print/fonts' 'jimp/browser' 'jimp/fonts'; do - [[ -e "$DIR"/node_modules/"$d" ]] && rm -r "$DIR"/node_modules/"$d" + [[ -e "$BUILD_DIR"/node_modules/"$d" ]] && rm -r "$BUILD_DIR"/node_modules/"$d" done # delete all tests (there are often large images as test file for jimp etc.) for d in 'test' 'docs' 'demo' 'example'; do - find "$DIR"/node_modules -name "$d" -exec rm -rf {} + + find "$BUILD_DIR"/node_modules -name "$d" -exec rm -rf {} + done fi -find $DIR/libraries -name "*.map" -type f -delete -find $DIR/node_modules -name "*.map" -type f -delete -find $DIR -name "*.ts" -type f -delete +find $BUILD_DIR/libraries -name "*.map" -type f -delete +find $BUILD_DIR/node_modules -name "*.map" -type f -delete +find $BUILD_DIR -name "*.ts" -type f -delete -d="$DIR"/src/public -[[ -d "$d"/app-dist ]] || mkdir -pv "$d"/app-dist -cp -r "$d"/app/doc_notes "$d"/app-dist/ - -rm -rf "$d"/app -unset f d DIR +unset f d BUILD_DIR diff --git a/tsconfig.build.json b/tsconfig.build.json index 4d4ffd342..1987c96c0 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -3,7 +3,7 @@ "module": "NodeNext", "declaration": false, "sourceMap": true, - "outDir": "./dist", + "outDir": "./build", "strict": true, "noImplicitAny": true, "resolveJsonModule": true, diff --git a/tsconfig.json b/tsconfig.json index d94fcef82..c1f3ef48b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "module": "NodeNext", "declaration": false, "sourceMap": true, - "outDir": "./dist", + "outDir": "./build", "strict": true, "noImplicitAny": true, "resolveJsonModule": true, diff --git a/tsconfig.webpack.json b/tsconfig.webpack.json index cbfe8cbdb..ed622818b 100644 --- a/tsconfig.webpack.json +++ b/tsconfig.webpack.json @@ -3,7 +3,7 @@ "module": "NodeNext", "declaration": false, "sourceMap": true, - "outDir": "./dist", + "outDir": "./build", "strict": true, "noImplicitAny": true, "resolveJsonModule": true, diff --git a/webpack.config.ts b/webpack.config.ts index 207ff2fcf..82439ea6d 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -19,7 +19,7 @@ const config: Configuration = { }, output: { publicPath: `${assetPath}/app-dist/`, - path: path.resolve(rootDir, "dist/src/public/app-dist"), + path: path.resolve(rootDir, "build/src/public/app-dist"), filename: "[name].js" }, plugins: [