| 
									
										
										
										
											2019-10-11 21:22:59 +02:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-22 21:44:48 +03:00
										 |  |  | set -e  # Fail on any command error | 
					
						
							| 
									
										
										
										
											2024-07-13 21:11:03 +03:00
										 |  |  | shopt -s globstar | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 21:22:59 +02:00
										 |  |  | if [[ $# -eq 0 ]] ; then | 
					
						
							|  |  |  |     echo "Missing argument of target directory" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2024-03-02 14:18:39 +08:00
										 |  |  | if ! [[ $(which npm) ]]; then | 
					
						
							|  |  |  |     echo "Missing npm" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2019-10-11 21:22:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-13 21:11:03 +03:00
										 |  |  | # Trigger the TypeScript build | 
					
						
							|  |  |  | echo TypeScript build start | 
					
						
							|  |  |  | npx tsc | 
					
						
							|  |  |  | echo TypeScript build finished | 
					
						
							| 
									
										
										
										
											2020-04-20 23:14:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-13 21:11:03 +03:00
										 |  |  | # Copy the TypeScript artifacts | 
					
						
							| 
									
										
										
										
											2024-03-02 11:49:17 +08:00
										 |  |  | DIR="$1" | 
					
						
							|  |  |  | rm -rf "$DIR" | 
					
						
							| 
									
										
										
										
											2024-03-02 14:18:39 +08:00
										 |  |  | mkdir -pv "$DIR" | 
					
						
							| 
									
										
										
										
											2019-10-11 21:22:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-13 21:11:03 +03:00
										 |  |  | echo Webpack start | 
					
						
							|  |  |  | npm run webpack | 
					
						
							|  |  |  | echo Webpack finish | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 21:22:59 +02:00
										 |  |  | echo "Copying Trilium to build directory $DIR" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-02 11:49:17 +08:00
										 |  |  | for d in 'images' 'libraries' 'src' 'db'; do | 
					
						
							|  |  |  |     cp -r "$d" "$DIR"/ | 
					
						
							|  |  |  | done | 
					
						
							| 
									
										
										
										
											2024-07-13 21:11:03 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | for f in 'package.json' 'package-lock.json' 'README.md' 'LICENSE' 'config-sample.ini'; do | 
					
						
							| 
									
										
										
										
											2024-03-02 11:49:17 +08:00
										 |  |  |     cp "$f" "$DIR"/ | 
					
						
							|  |  |  | done | 
					
						
							| 
									
										
										
										
											2024-07-13 21:11:03 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-21 09:12:46 +03:00
										 |  |  | # Patch package.json main | 
					
						
							| 
									
										
										
										
											2024-09-08 17:40:05 +03:00
										 |  |  | sed -i 's/.\/dist\/electron-main.js/electron-main.js/g' "$DIR/package.json" | 
					
						
							| 
									
										
										
										
											2024-07-21 09:12:46 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-13 21:11:03 +03:00
										 |  |  | script_dir=$(realpath $(dirname $0)) | 
					
						
							| 
									
										
										
										
											2024-07-21 09:12:46 +03:00
										 |  |  | cp -R "$script_dir/../build/src" "$DIR" | 
					
						
							| 
									
										
										
										
											2024-09-08 17:40:05 +03:00
										 |  |  | cp "$script_dir/../build/electron-main.js" "$DIR" | 
					
						
							| 
									
										
										
										
											2019-10-11 21:22:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | # run in subshell (so we return to original dir) | 
					
						
							| 
									
										
										
										
											2024-12-14 08:56:38 +02:00
										 |  |  | (cd $DIR && npm install --omit=dev --legacy-peer-deps) | 
					
						
							| 
									
										
										
										
											2019-10-11 21:22:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-02 11:49:17 +08:00
										 |  |  | if [[ -d "$DIR"/node_modules ]]; then | 
					
						
							| 
									
										
										
										
											2024-07-20 20:31:36 +03:00
										 |  |  |     # cleanup of useless files in dependencies | 
					
						
							| 
									
										
										
										
											2024-07-20 20:39:18 +03:00
										 |  |  |     for d in 'image-q/demo' \
 | 
					
						
							| 
									
										
										
										
											2025-01-18 11:19:35 +02:00
										 |  |  |         '@excalidraw/excalidraw/dist/excalidraw-assets-dev' '@excalidraw/excalidraw/dist/excalidraw.development.js' '@excalidraw/excalidraw/dist/excalidraw-with-preact.development.js' \
 | 
					
						
							| 
									
										
										
										
											2024-07-20 20:39:18 +03:00
										 |  |  |         'mermaid/dist/mermaid.js' \
 | 
					
						
							| 
									
										
										
										
											2024-07-20 20:53:33 +03:00
										 |  |  |         'boxicons/svg' 'boxicons/node_modules/react'/* \
 | 
					
						
							| 
									
										
										
										
											2024-07-20 20:39:18 +03:00
										 |  |  |         '@jimp/plugin-print/fonts' 'jimp/browser' 'jimp/fonts'; do | 
					
						
							| 
									
										
										
										
											2024-07-20 20:31:36 +03:00
										 |  |  |         [[ -e "$DIR"/node_modules/"$d" ]] && rm -r "$DIR"/node_modules/"$d" | 
					
						
							| 
									
										
										
										
											2024-03-02 11:49:17 +08:00
										 |  |  |     done | 
					
						
							| 
									
										
										
										
											2020-08-27 23:04:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-20 20:31:36 +03:00
										 |  |  |     # delete all tests (there are often large images as test file for jimp etc.) | 
					
						
							| 
									
										
										
										
											2024-07-20 20:39:18 +03:00
										 |  |  |     for d in 'test' 'docs' 'demo' 'example'; do | 
					
						
							| 
									
										
										
										
											2024-07-20 20:31:36 +03:00
										 |  |  |         find "$DIR"/node_modules -name "$d" -exec rm -rf {} + | 
					
						
							| 
									
										
										
										
											2024-03-02 11:49:17 +08:00
										 |  |  |     done | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2020-08-27 23:04:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-12 14:22:51 +02:00
										 |  |  | find $DIR/libraries -name "*.map" -type f -delete | 
					
						
							| 
									
										
										
										
											2024-07-20 20:55:38 +03:00
										 |  |  | find $DIR/node_modules -name "*.map" -type f -delete | 
					
						
							|  |  |  | find $DIR -name "*.ts" -type f -delete | 
					
						
							| 
									
										
										
										
											2020-04-12 14:22:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-02 11:49:17 +08:00
										 |  |  | d="$DIR"/src/public | 
					
						
							|  |  |  | [[ -d "$d"/app-dist ]] || mkdir -pv "$d"/app-dist | 
					
						
							| 
									
										
										
										
											2024-03-02 14:18:39 +08:00
										 |  |  | cp -r "$d"/app/doc_notes "$d"/app-dist/ | 
					
						
							| 
									
										
										
										
											2022-03-21 23:28:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-02 11:49:17 +08:00
										 |  |  | rm -rf "$d"/app | 
					
						
							|  |  |  | unset f d DIR |