diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index 6d9fcf0e0..f5901225b 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -61,7 +61,30 @@ try { // TriliumNextTODO: for Docker this needs to run separately *after* build-stage console.log("Pruning npm packages...") execSync(`npm ci --omit=dev --prefix ${DEST_DIR}`); + + cleanupNodeModules(); + } catch(err) { console.error("Error during copy:", err) process.exit(1) } +function cleanupNodeModules() { + const nodeDir = fs.readdirSync(path.join(DEST_DIR, "./node_modules"), { recursive: true, withFileTypes: true }); + + const filterableDirs = new Set([ + "test", + "docs", + "demo", + "example", + ]); + + const filteredDirs = nodeDir + .filter(el => el.isDirectory() && filterableDirs.has(el.name)) + .map(el => path.join(DEST_DIR, el.parentPath, el.name)); + + filteredDirs.forEach(dir => { + fs.removeSync(dir); + }) + +} + diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh index 629138048..e99bf08b9 100755 --- a/bin/copy-trilium.sh +++ b/bin/copy-trilium.sh @@ -19,11 +19,6 @@ if [[ -d "$BUILD_DIR"/node_modules ]]; then '@jimp/plugin-print/fonts' 'jimp/browser' 'jimp/fonts'; do [[ -e "$BUILD_DIR"/node_modules/"$d" ]] && rm -r "$BUILD_DIR"/node_modules/"$d" done - - # delete all tests (there are often large images as test file for jimp etc.) - for d in 'test' 'docs' 'demo' 'example'; do - find "$BUILD_DIR"/node_modules -name "$d" -exec rm -rf {} + - done fi find $BUILD_DIR/libraries -name "*.map" -type f -delete