Skip to content

Build your personal knowledge base with Trilium Notes

build(copy-dist): add initial cleanupNodeModules functionality

Panagiotis Papadopoulos6260ea1532e2
diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts
index 6d9fcf0e0b..f5901225bb 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 6291380482..e99bf08b92 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