build(copy-dist): add initial cleanupNodeModules functionality

adapted from copy-trilium.sh
This commit is contained in:
Panagiotis Papadopoulos 2025-03-16 01:50:59 +01:00
parent bee7793d32
commit 6260ea1532
2 changed files with 23 additions and 5 deletions

View File

@ -61,7 +61,30 @@ try {
// TriliumNextTODO: for Docker this needs to run separately *after* build-stage // TriliumNextTODO: for Docker this needs to run separately *after* build-stage
console.log("Pruning npm packages...") console.log("Pruning npm packages...")
execSync(`npm ci --omit=dev --prefix ${DEST_DIR}`); execSync(`npm ci --omit=dev --prefix ${DEST_DIR}`);
cleanupNodeModules();
} catch(err) { } catch(err) {
console.error("Error during copy:", err) console.error("Error during copy:", err)
process.exit(1) 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);
})
}

View File

@ -19,11 +19,6 @@ if [[ -d "$BUILD_DIR"/node_modules ]]; then
'@jimp/plugin-print/fonts' 'jimp/browser' 'jimp/fonts'; do '@jimp/plugin-print/fonts' 'jimp/browser' 'jimp/fonts'; do
[[ -e "$BUILD_DIR"/node_modules/"$d" ]] && rm -r "$BUILD_DIR"/node_modules/"$d" [[ -e "$BUILD_DIR"/node_modules/"$d" ]] && rm -r "$BUILD_DIR"/node_modules/"$d"
done 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 fi
find $BUILD_DIR/libraries -name "*.map" -type f -delete find $BUILD_DIR/libraries -name "*.map" -type f -delete