copy-trilium.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bash
  2. if [[ $# -eq 0 ]] ; then
  3. echo "Missing argument of target directory"
  4. exit 1
  5. fi
  6. if ! [[ $(which npm) ]]; then
  7. echo "Missing npm"
  8. exit 1
  9. fi
  10. n exec 18.18.2 npm run webpack || npm run webpack
  11. DIR="$1"
  12. rm -rf "$DIR"
  13. mkdir -pv "$DIR"
  14. echo "Copying Trilium to build directory $DIR"
  15. for d in 'images' 'libraries' 'src' 'db'; do
  16. cp -r "$d" "$DIR"/
  17. done
  18. for f in 'package.json' 'package-lock.json' 'README.md' 'LICENSE' 'config-sample.ini' 'electron.js'; do
  19. cp "$f" "$DIR"/
  20. done
  21. cp webpack-* "$DIR"/ # here warning because there is no 'webpack-*', but webpack.config.js only
  22. # run in subshell (so we return to original dir)
  23. (cd $DIR && n exec 18.18.2 npm install --only=prod)
  24. if [[ -d "$DIR"/node_modules ]]; then
  25. # cleanup of useless files in dependencies
  26. for d in 'image-q/demo' 'better-sqlite3/Release' 'better-sqlite3/deps/sqlite3.tar.gz' '@jimp/plugin-print/fonts' 'jimp/browser' 'jimp/fonts'; do
  27. [[ -e "$DIR"/node_modules/"$d" ]] && rm -rv "$DIR"/node_modules/"$d"
  28. done
  29. # delete all tests (there are often large images as test file for jimp etc.)
  30. for d in 'test' 'docs' 'demo'; do
  31. find "$DIR"/node_modules -name "$d" -exec rm -rf {} \;
  32. done
  33. fi
  34. find $DIR/libraries -name "*.map" -type f -delete
  35. d="$DIR"/src/public
  36. [[ -d "$d"/app-dist ]] || mkdir -pv "$d"/app-dist
  37. cp "$d"/app/share.js "$d"/app-dist/
  38. cp -r "$d"/app/doc_notes "$d"/app-dist/
  39. rm -rf "$d"/app
  40. unset f d DIR