From bcbbf4dc3eb9f75b561cb3af99e200bc709c5388 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 11 Oct 2019 21:22:59 +0200 Subject: [PATCH] improvements to build process --- bin/build-linux-x64.sh | 29 ++++++++++++++++-------- bin/build-mac-x64.sh | 41 +++++++++++++++++++--------------- bin/build-server.sh | 50 ++++++++++++++++++------------------------ bin/build-win-x64.sh | 39 ++++++++++++++++++-------------- bin/build.sh | 24 ++++++++++---------- bin/copy-trilium.sh | 32 +++++++++++++++++++++++++++ bin/reset-local.sh | 3 --- package.json | 3 +-- 8 files changed, 132 insertions(+), 89 deletions(-) create mode 100755 bin/copy-trilium.sh delete mode 100755 bin/reset-local.sh diff --git a/bin/build-linux-x64.sh b/bin/build-linux-x64.sh index e89a449fd..473dd5c04 100755 --- a/bin/build-linux-x64.sh +++ b/bin/build-linux-x64.sh @@ -1,19 +1,26 @@ #!/usr/bin/env bash -BUILD_DIR=./dist/trilium-linux-x64 -rm -rf $BUILD_DIR +SRC_DIR=./dist/trilium-linux-x64-src + +if [ "$1" != "DONTCOPY" ] +then + ./bin/copy-trilium.sh $SRC_DIR +fi echo "Copying required linux-x64 binaries" -rm -r node_modules/sqlite3/lib/binding/* -rm -r node_modules/pngquant-bin/vendor/* -rm -r node_modules/@felixrieseberg/spellchecker/build/Release/* +rm -r $SRC_DIR/node_modules/sqlite3/lib/binding/* +rm -r $SRC_DIR/node_modules/pngquant-bin/vendor/* +rm -r $SRC_DIR/node_modules/@felixrieseberg/spellchecker/build/Release/* -cp -r bin/deps/linux-x64/sqlite/* node_modules/sqlite3/lib/binding/ -cp bin/deps/linux-x64/image/pngquant node_modules/pngquant-bin/vendor/ -cp bin/deps/linux-x64/spellchecker/* node_modules/@felixrieseberg/spellchecker/build/Release/ +cp -r bin/deps/linux-x64/sqlite/* $SRC_DIR/node_modules/sqlite3/lib/binding/ +cp bin/deps/linux-x64/image/pngquant $SRC_DIR/node_modules/pngquant-bin/vendor/ +cp bin/deps/linux-x64/spellchecker/* $SRC_DIR/node_modules/@felixrieseberg/spellchecker/build/Release/ -./node_modules/.bin/electron-packager . --asar --out=dist --executable-name=trilium --platform=linux --arch=x64 --overwrite +./node_modules/.bin/electron-packager $SRC_DIR --asar --out=dist --executable-name=trilium --platform=linux --arch=x64 --overwrite + +BUILD_DIR=./dist/trilium-linux-x64 +rm -rf $BUILD_DIR mv "./dist/Trilium Notes-linux-x64" $BUILD_DIR @@ -28,3 +35,7 @@ VERSION=`jq -r ".version" package.json` cd dist tar cJf trilium-linux-x64-${VERSION}.tar.xz trilium-linux-x64 + +cd .. + +bin/build-debian.sh \ No newline at end of file diff --git a/bin/build-mac-x64.sh b/bin/build-mac-x64.sh index c0e7c5502..d7e9f3dbb 100755 --- a/bin/build-mac-x64.sh +++ b/bin/build-mac-x64.sh @@ -1,29 +1,34 @@ #!/usr/bin/env bash +SRC_DIR=./dist/trilium-mac-x64-src + +if [ "$1" != "DONTCOPY" ] +then + ./bin/copy-trilium.sh $SRC_DIR +fi + +echo "Copying required mac binaries" + +rm -r $SRC_DIR/node_modules/sqlite3/lib/binding/* +rm -r $SRC_DIR/node_modules/mozjpeg/vendor/* +rm -r $SRC_DIR/node_modules/pngquant-bin/vendor/* +rm -r $SRC_DIR/node_modules/giflossy/vendor/* +rm -r $SRC_DIR/node_modules/@felixrieseberg/spellchecker/build/Release/* + +cp -r bin/deps/mac-x64/sqlite/* $SRC_DIR/node_modules/sqlite3/lib/binding/ +cp bin/deps/mac-x64/image/cjpeg $SRC_DIR/node_modules/mozjpeg/vendor/ +cp bin/deps/mac-x64/image/pngquant $SRC_DIR/node_modules/pngquant-bin/vendor/ +cp bin/deps/mac-x64/image/gifsicle $SRC_DIR/node_modules/giflossy/vendor/ +cp bin/deps/mac-x64/spellchecker/* $SRC_DIR/node_modules/@felixrieseberg/spellchecker/build/Release/ + +./node_modules/.bin/electron-packager $SRC_DIR --asar --out=dist --executable-name=trilium --platform=darwin --arch=x64 --overwrite --icon=images/app-icons/mac/icon.icns + BUILD_DIR=./dist/trilium-mac-x64 rm -rf $BUILD_DIR -echo "Copying required mac binaries" - -rm -r node_modules/sqlite3/lib/binding/* -rm -r node_modules/mozjpeg/vendor/* -rm -r node_modules/pngquant-bin/vendor/* -rm -r node_modules/giflossy/vendor/* -rm -r node_modules/@felixrieseberg/spellchecker/build/Release/* - -cp -r bin/deps/mac-x64/sqlite/* node_modules/sqlite3/lib/binding/ -cp bin/deps/mac-x64/image/cjpeg node_modules/mozjpeg/vendor/ -cp bin/deps/mac-x64/image/pngquant node_modules/pngquant-bin/vendor/ -cp bin/deps/mac-x64/image/gifsicle node_modules/giflossy/vendor/ -cp bin/deps/mac-x64/spellchecker/* node_modules/@felixrieseberg/spellchecker/build/Release/ - -./node_modules/.bin/electron-packager . --asar --out=dist --executable-name=trilium --platform=darwin --arch=x64 --overwrite --icon=images/app-icons/mac/icon.icns - # Mac build has by default useless directory level mv "./dist/Trilium Notes-darwin-x64" $BUILD_DIR -./bin/reset-local.sh - echo "Zipping mac x64 electron distribution..." VERSION=`jq -r ".version" package.json` diff --git a/bin/build-server.sh b/bin/build-server.sh index 811f3e804..65fe5a858 100755 --- a/bin/build-server.sh +++ b/bin/build-server.sh @@ -1,40 +1,32 @@ #!/usr/bin/env bash -PKG_DIR=dist/trilium-linux-x64-server +PKG_DIR=dist/trilium-linux-x64-server-src NODE_VERSION=12.11.1 -rm -r $PKG_DIR -mkdir $PKG_DIR -cd $PKG_DIR +if [ "$1" != "DONTCOPY" ] +then + ./bin/copy-trilium.sh $PKG_DIR +fi +cd dist wget https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz tar xvfJ node-v${NODE_VERSION}-linux-x64.tar.xz rm node-v${NODE_VERSION}-linux-x64.tar.xz - -mv node-v${NODE_VERSION}-linux-x64 node - -cp -r ../../node_modules/ ./ -cp -r ../../images/ ./ -cp -r ../../libraries/ ./ -cp -r ../../src/ ./ -cp -r ../../db/ ./ -cp -r ../../package.json ./ -cp -r ../../package-lock.json ./ -cp -r ../../README.md ./ -cp -r ../../LICENSE ./ -cp -r ../../config-sample.ini ./ - -rm -r ./node_modules/electron* - -rm -r ./node_modules/sqlite3/lib/binding/* - -cp -r ../../bin/deps/linux-x64/sqlite/node* ./node_modules/sqlite3/lib/binding/ - -printf "#!/bin/sh\n./node/bin/node src/www" > trilium.sh -chmod 755 trilium.sh - cd .. -VERSION=`jq -r ".version" ../package.json` +mv dist/node-v${NODE_VERSION}-linux-x64 $PKG_DIR/node -tar cJf trilium-linux-x64-server-${VERSION}.tar.xz trilium-linux-x64-server +rm -r $PKG_DIR/node_modules/electron* + +rm -r $PKG_DIR/node_modules/sqlite3/lib/binding/* + +cp -r ./bin/deps/linux-x64/sqlite/node* $PKG_DIR/node_modules/sqlite3/lib/binding/ + +printf "#!/bin/sh\n./node/bin/node src/www" > $PKG_DIR/trilium.sh +chmod 755 $PKG_DIR/trilium.sh + +VERSION=`jq -r ".version" package.json` + +cd dist + +tar cJf trilium-linux-x64-server-${VERSION}.tar.xz trilium-linux-x64-server-src diff --git a/bin/build-win-x64.sh b/bin/build-win-x64.sh index 61baa57b2..048400eae 100755 --- a/bin/build-win-x64.sh +++ b/bin/build-win-x64.sh @@ -1,33 +1,38 @@ #!/usr/bin/env bash -BUILD_DIR=./dist/trilium-windows-x64 -rm -rf $BUILD_DIR +SRC_DIR=./dist/trilium-windows-x64-src + +if [ "$1" != "DONTCOPY" ] +then + ./bin/copy-trilium.sh $SRC_DIR +fi echo "Copying required windows binaries" -rm -r node_modules/sqlite3/lib/binding/* -rm -r node_modules/mozjpeg/vendor/* -rm -r node_modules/pngquant-bin/vendor/* -rm -r node_modules/giflossy/vendor/* -rm -r node_modules/@felixrieseberg/spellchecker/build/Release/* -rm -r node_modules/keyboard-layout/build/Release/* +rm -r $SRC_DIR/node_modules/sqlite3/lib/binding/* +rm -r $SRC_DIR/node_modules/mozjpeg/vendor/* +rm -r $SRC_DIR/node_modules/pngquant-bin/vendor/* +rm -r $SRC_DIR/node_modules/giflossy/vendor/* +rm -r $SRC_DIR/node_modules/@felixrieseberg/spellchecker/build/Release/* +rm -r $SRC_DIR/node_modules/keyboard-layout/build/Release/* -cp -r bin/deps/win-x64/sqlite/* node_modules/sqlite3/lib/binding/ -cp bin/deps/win-x64/image/cjpeg.exe node_modules/mozjpeg/vendor/ -cp bin/deps/win-x64/image/pngquant.exe node_modules/pngquant-bin/vendor/ -cp bin/deps/win-x64/image/gifsicle.exe node_modules/giflossy/vendor/ -cp bin/deps/win-x64/spellchecker/* node_modules/@felixrieseberg/spellchecker/build/Release/ -cp bin/deps/win-x64/keyboard-layout-manager.node node_modules/keyboard-layout/build/Release/ +cp -r bin/deps/win-x64/sqlite/* $SRC_DIR/node_modules/sqlite3/lib/binding/ +cp bin/deps/win-x64/image/cjpeg.exe $SRC_DIR/node_modules/mozjpeg/vendor/ +cp bin/deps/win-x64/image/pngquant.exe $SRC_DIR/node_modules/pngquant-bin/vendor/ +cp bin/deps/win-x64/image/gifsicle.exe $SRC_DIR/node_modules/giflossy/vendor/ +cp bin/deps/win-x64/spellchecker/* $SRC_DIR/node_modules/@felixrieseberg/spellchecker/build/Release/ +cp bin/deps/win-x64/keyboard-layout-manager.node $SRC_DIR/node_modules/keyboard-layout/build/Release/ -./node_modules/.bin/electron-packager . --asar --out=dist --executable-name=trilium --platform=win32 --arch=x64 --overwrite --icon=images/app-icons/win/icon.ico +./node_modules/.bin/electron-packager $SRC_DIR --asar --out=dist --executable-name=trilium --platform=win32 --arch=x64 --overwrite --icon=images/app-icons/win/icon.ico + +BUILD_DIR=./dist/trilium-windows-x64 +rm -rf $BUILD_DIR mv "./dist/Trilium Notes-win32-x64" $BUILD_DIR # removing software WebGL binaries because they are pretty huge and not necessary rm -r $BUILD_DIR/swiftshader -./bin/reset-local.sh - echo "Zipping windows x64 electron distribution..." VERSION=`jq -r ".version" package.json` diff --git a/bin/build.sh b/bin/build.sh index c19fb5dc6..fd78d0570 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -1,21 +1,23 @@ #!/usr/bin/env bash -rm -r node_modules - -npm install - echo "Deleting existing builds" rm -r dist/* -bin/build-win-x64.sh +SRC_DIR=dist/trilium-src -bin/build-mac-x64.sh +bin/copy-trilium.sh $SRC_DIR -# building X64 linux as the last so electron-rebuild will prepare X64 binaries for local development -bin/build-linux-x64.sh +# 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-src +cp -r $SRC_DIR ./dist/trilium-windows-x64-src +cp -r $SRC_DIR ./dist/trilium-mac-x64-src -# this needs to be run after linux build -bin/build-debian.sh +bin/build-win-x64.sh DONTCOPY -bin/build-server.sh \ No newline at end of file +bin/build-mac-x64.sh DONTCOPY + +bin/build-linux-x64.sh DONTCOPY + +bin/build-server.sh DONTCOPY diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh new file mode 100755 index 000000000..70cdee57d --- /dev/null +++ b/bin/copy-trilium.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +if [[ $# -eq 0 ]] ; then + echo "Missing argument of target directory" + exit 1 +fi + +DIR=$1 + +rm -rf $DIR +mkdir $DIR + +echo "Copying Trilium to build directory $DIR" + +cp -r images $DIR/ +cp -r libraries $DIR/ +cp -r src $DIR/ +cp -r db $DIR/ +cp -r package.json $DIR/ +cp -r package-lock.json $DIR/ +cp -r README.md $DIR/ +cp -r LICENSE $DIR/ +cp -r config-sample.ini $DIR/ +cp -r electron.js $DIR/ + +# run in subshell (so we return to original dir) +(cd $DIR && npm install --only=prod) + +rm -r $DIR/node_modules/cld/deps + +find $DIR/libraries -name "*.map" -type f -delete +find $DIR/libraries -name "hunspell.lib" -type f -delete \ No newline at end of file diff --git a/bin/reset-local.sh b/bin/reset-local.sh deleted file mode 100755 index 37e2a1d7d..000000000 --- a/bin/reset-local.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -./node_modules/.bin/electron-rebuild --arch=x64 \ No newline at end of file diff --git a/package.json b/package.json index c9da9f58f..78d187254 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,7 @@ "start-electron": "TRILIUM_ENV=dev electron . --disable-gpu", "build-backend-docs": "./node_modules/.bin/jsdoc -c jsdoc-conf.json -d ./docs/backend_api src/entities/*.js src/services/backend_script_api.js", "build-frontend-docs": "./node_modules/.bin/jsdoc -c jsdoc-conf.json -d ./docs/frontend_api src/public/javascripts/entities/*.js src/public/javascripts/services/frontend_script_api.js", - "build-docs": "npm run build-backend-docs && npm run build-frontend-docs", - "postinstall": "electron-builder install-app-deps" + "build-docs": "npm run build-backend-docs && npm run build-frontend-docs" }, "dependencies": { "async-mutex": "0.1.4",