Notes/bin/copy-trilium.sh

75 lines
2.0 KiB
Bash
Raw Normal View History

2019-10-11 21:22:59 +02:00
#!/usr/bin/env bash
set -e # Fail on any command error
shopt -s globstar
2019-10-11 21:22:59 +02:00
if [[ $# -eq 0 ]] ; then
echo "Missing argument of target directory"
exit 1
fi
if ! [[ $(which npm) ]]; then
echo "Missing npm"
exit 1
fi
2019-10-11 21:22:59 +02:00
# Trigger the TypeScript build
echo TypeScript build start
npx tsc
echo TypeScript build finished
2020-04-20 23:14:50 +02:00
# Copy the TypeScript artifacts
DIR="$1"
rm -rf "$DIR"
mkdir -pv "$DIR"
2019-10-11 21:22:59 +02: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"
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
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
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)
(cd $DIR && npm install --omit=dev --legacy-peer-deps)
2019-10-11 21:22:59 +02: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' \
'@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' \
'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"
done
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 {} +
done
fi
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
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