mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-30 11:42:26 +08:00
Merge pull request #1369 from TriliumNext/build_improve-server-build
build: fix/improve server build
This commit is contained in:
commit
e6c04e70e4
@ -10,8 +10,8 @@ COPY . .
|
|||||||
RUN npm ci && \
|
RUN npm ci && \
|
||||||
npm run build:prepare-dist && \
|
npm run build:prepare-dist && \
|
||||||
npm cache clean --force && \
|
npm cache clean --force && \
|
||||||
rm -rf dist/node_modules && \
|
rm -rf build/node_modules && \
|
||||||
mv dist/* \
|
mv build/* \
|
||||||
start-docker.sh \
|
start-docker.sh \
|
||||||
/usr/src/app/ && \
|
/usr/src/app/ && \
|
||||||
rm -rf \
|
rm -rf \
|
||||||
|
@ -10,8 +10,8 @@ COPY . .
|
|||||||
RUN npm ci && \
|
RUN npm ci && \
|
||||||
npm run build:prepare-dist && \
|
npm run build:prepare-dist && \
|
||||||
npm cache clean --force && \
|
npm cache clean --force && \
|
||||||
rm -rf dist/node_modules && \
|
rm -rf build/node_modules && \
|
||||||
mv dist/* \
|
mv build/* \
|
||||||
start-docker.sh \
|
start-docker.sh \
|
||||||
/usr/src/app/ && \
|
/usr/src/app/ && \
|
||||||
rm -rf \
|
rm -rf \
|
||||||
|
@ -22,53 +22,42 @@ echo "Selected Arch: $ARCH"
|
|||||||
|
|
||||||
# Set Node.js version and architecture-specific filename
|
# Set Node.js version and architecture-specific filename
|
||||||
NODE_VERSION=20.15.1
|
NODE_VERSION=20.15.1
|
||||||
NODE_ARCH=$ARCH
|
|
||||||
|
|
||||||
# Debug output
|
BUILD_DIR="./build"
|
||||||
echo "Node arch: $NODE_ARCH"
|
DIST_DIR="./dist"
|
||||||
|
|
||||||
# Special case for x64 in Node.js downloads
|
./bin/copy-trilium.sh
|
||||||
if [ "$NODE_ARCH" = "x64" ]; then
|
|
||||||
NODE_FILENAME="x64"
|
|
||||||
elif [ "$NODE_ARCH" = "arm64" ]; then
|
|
||||||
NODE_FILENAME="arm64"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Debug output
|
NODE_FILENAME=node-v${NODE_VERSION}-linux-${ARCH}
|
||||||
echo "Node filename: $NODE_FILENAME"
|
|
||||||
|
|
||||||
PKG_DIR=dist/trilium-linux-${ARCH}-server
|
echo "Downloading Node.js runtime $NODE_FILENAME..."
|
||||||
echo "Package directory: $PKG_DIR"
|
cd $BUILD_DIR
|
||||||
|
wget -qO- https://nodejs.org/dist/v${NODE_VERSION}/${NODE_FILENAME}.tar.xz | tar xfJ -
|
||||||
if [ "$1" != "DONTCOPY" ]
|
mv $NODE_FILENAME node
|
||||||
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
|
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
mv dist/node-v${NODE_VERSION}-linux-${NODE_FILENAME} $PKG_DIR/node
|
|
||||||
|
|
||||||
rm -r $PKG_DIR/node/lib/node_modules/npm
|
rm -r $BUILD_DIR/node/lib/node_modules/npm \
|
||||||
rm -r $PKG_DIR/node/include/node
|
$BUILD_DIR/node/include/node \
|
||||||
|
$BUILD_DIR/node_modules/electron* \
|
||||||
|
$BUILD_DIR/electron*.{js,map}
|
||||||
|
|
||||||
rm -r $PKG_DIR/node_modules/electron*
|
printf "#!/bin/sh\n./node/bin/node src/main" > $BUILD_DIR/trilium.sh
|
||||||
rm -r $PKG_DIR/electron*.js
|
chmod 755 $BUILD_DIR/trilium.sh
|
||||||
|
|
||||||
printf "#!/bin/sh\n./node/bin/node src/main" > $PKG_DIR/trilium.sh
|
# TriliumNextTODO: is this still required? If yes → move to copy-dist/copy-trilium
|
||||||
chmod 755 $PKG_DIR/trilium.sh
|
cp bin/tpl/anonymize-database.sql $BUILD_DIR/
|
||||||
|
|
||||||
cp bin/tpl/anonymize-database.sql $PKG_DIR/
|
|
||||||
|
|
||||||
cp -r translations $PKG_DIR/
|
|
||||||
|
|
||||||
VERSION=`jq -r ".version" package.json`
|
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!"
|
53
bin/build.sh
53
bin/build.sh
@ -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
|
|
@ -1,7 +1,7 @@
|
|||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
const DEST_DIR = "./dist";
|
const DEST_DIR = "./build";
|
||||||
|
|
||||||
const VERBOSE = process.env.VERBOSE;
|
const VERBOSE = process.env.VERBOSE;
|
||||||
|
|
||||||
@ -28,6 +28,8 @@ try {
|
|||||||
"./config-sample.ini",
|
"./config-sample.ini",
|
||||||
"./package-lock.json",
|
"./package-lock.json",
|
||||||
"./package.json",
|
"./package.json",
|
||||||
|
"./LICENSE",
|
||||||
|
"./README.md",
|
||||||
"./src/views/",
|
"./src/views/",
|
||||||
"./src/etapi/etapi.openapi.yaml",
|
"./src/etapi/etapi.openapi.yaml",
|
||||||
"./src/routes/api/openapi.json",
|
"./src/routes/api/openapi.json",
|
||||||
|
@ -3,72 +3,42 @@
|
|||||||
set -e # Fail on any command error
|
set -e # Fail on any command error
|
||||||
shopt -s globstar
|
shopt -s globstar
|
||||||
|
|
||||||
if [[ $# -eq 0 ]] ; then
|
BUILD_DIR="./build"
|
||||||
echo "Missing argument of target directory"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if ! [[ $(which npm) ]]; then
|
if ! [[ $(which npm) ]]; then
|
||||||
echo "Missing npm"
|
echo "Missing npm"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Trigger the TypeScript build
|
# Trigger the build
|
||||||
echo TypeScript build start
|
echo Build start
|
||||||
npm run build:ts
|
npm run build:prepare-dist
|
||||||
echo TypeScript build finished
|
echo 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
|
|
||||||
|
|
||||||
# Patch package.json main
|
# Patch package.json main
|
||||||
sed -i 's/.\/dist\/electron-main.js/electron-main.js/g' "$DIR/package.json"
|
sed -i 's|./dist/electron-main.js|electron-main.js|g' "$BUILD_DIR/package.json"
|
||||||
|
|
||||||
script_dir=$(realpath $(dirname $0))
|
|
||||||
cp -R "$script_dir/../build/src" "$DIR"
|
|
||||||
cp "$script_dir/../build/electron-main.js" "$DIR"
|
|
||||||
|
|
||||||
# run in subshell (so we return to original dir)
|
# 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
|
# cleanup of useless files in dependencies
|
||||||
for d in 'image-q/demo' \
|
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' \
|
'@excalidraw/excalidraw/dist/excalidraw-assets-dev' '@excalidraw/excalidraw/dist/excalidraw.development.js' '@excalidraw/excalidraw/dist/excalidraw-with-preact.development.js' \
|
||||||
'mermaid/dist/mermaid.js' \
|
'mermaid/dist/mermaid.js' \
|
||||||
'boxicons/svg' 'boxicons/node_modules/react'/* \
|
'boxicons/svg' 'boxicons/node_modules/react'/* \
|
||||||
'@jimp/plugin-print/fonts' 'jimp/browser' 'jimp/fonts'; do
|
'@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
|
done
|
||||||
|
|
||||||
# delete all tests (there are often large images as test file for jimp etc.)
|
# delete all tests (there are often large images as test file for jimp etc.)
|
||||||
for d in 'test' 'docs' 'demo' 'example'; do
|
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
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
find $DIR/libraries -name "*.map" -type f -delete
|
find $BUILD_DIR/libraries -name "*.map" -type f -delete
|
||||||
find $DIR/node_modules -name "*.map" -type f -delete
|
find $BUILD_DIR/node_modules -name "*.map" -type f -delete
|
||||||
find $DIR -name "*.ts" -type f -delete
|
find $BUILD_DIR -name "*.ts" -type f -delete
|
||||||
|
|
||||||
d="$DIR"/src/public
|
unset f d BUILD_DIR
|
||||||
[[ -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
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"declaration": false,
|
"declaration": false,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"outDir": "./dist",
|
"outDir": "./build",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"declaration": false,
|
"declaration": false,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"outDir": "./dist",
|
"outDir": "./build",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"declaration": false,
|
"declaration": false,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"outDir": "./dist",
|
"outDir": "./build",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
|
@ -19,7 +19,7 @@ const config: Configuration = {
|
|||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
publicPath: `${assetPath}/app-dist/`,
|
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"
|
filename: "[name].js"
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user