From ad60030fda0a90cfb95ed165f33794255793b328 Mon Sep 17 00:00:00 2001
From: David Cook <dcook@prosentient.com.au>
Date: Fri, 11 Apr 2025 04:54:33 +0000
Subject: [PATCH] Bug 37911: Update Makefile.PL to handle generated "vue/dist"
 files

This change modifies Makefile.PL so that we no longer have to
manually add to the Makefile.PL all the files that end up in the
"vue/dist" folder.

Instead, we dynamically generate the files, and then copy them over
to the build target.

Test plan:
0. Apply all patches
1. Setup intall target
sudo mkdir /opt/koha
sudo chown kohadev-koha  /opt/koha
2. Clean build env
rm -rf koha-tmpl/intranet-tmpl/prog/js/vue/dist/* blib Makefile /opt/koha/*
3. perl Makefile.PL
Installation mode (dev, single, standard) [standard] single
Please specify the directory in which to install Koha [/var/lib/koha/kohadev/koha] /opt/koha
NOTE: Otherwise accept all defaults
4. make install
5. "vue/dist" successfully installed
Note all our expected files are installed including islands.esm.js

Amended-by: Jonathan Druart
Tidy

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
---
 Makefile.PL | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/Makefile.PL b/Makefile.PL
index f5e0525d443..f198e0178e0 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -676,11 +676,8 @@ $file_map->{'koha-tmpl/intranet-tmpl/prog/css/holds.css'}        = 'blib/INTRANE
 $file_map->{'koha-tmpl/intranet-tmpl/prog/css/installer.css'}    = 'blib/INTRANET_TMPL_DIR/prog/css/installer.css';
 $file_map->{'koha-tmpl/intranet-tmpl/prog/css/mainpage.css'}     = 'blib/INTRANET_TMPL_DIR/prog/css/mainpage.css';
 $file_map->{'koha-tmpl/intranet-tmpl/prog/css/staff-global.css'} = 'blib/INTRANET_TMPL_DIR/prog/css/staff-global.css';
-$file_map->{'koha-tmpl/intranet-tmpl/prog/js/vue/dist/erm.js'}   = 'blib/INTRANET_TMPL_DIR/prog/js/vue/dist/erm.js';
-$file_map->{'koha-tmpl/intranet-tmpl/prog/js/vue/dist/preservation.js'} =
-    'blib/INTRANET_TMPL_DIR/prog/js/vue/dist/preservation.js';
-$file_map->{'koha-tmpl/intranet-tmpl/prog/js/vue/dist/admin/record_sources.js'} =
-    'blib/INTRANET_TMPL_DIR/prog/js/vue/dist/admin/record_sources.js';
+
+#NOTE: The 'koha-tmpl/intranet-tmpl/prog/js/vue/dist' directory is now handled in the "top_targets" function
 
 #OPAC_TMPL_DIR
 $file_map->{'koha-tmpl/opac-tmpl/bootstrap/css/opac.css'}      = 'blib/OPAC_TMPL_DIR/bootstrap/css/opac.css';
@@ -1910,11 +1907,19 @@ sub postamble {
 sub top_targets {
     my $inherited = shift->SUPER::top_targets(@_);
     my $compile_step;
+
+    #NOTE: Make "all" depend on "compile_css_js"
     $compile_step .= "all :: compile_css_js\n";
     $compile_step .= "\t" . '$(NOECHO) $(NOOP)' . "\n";
     $compile_step .= "\n";
-    $compile_step .= "compile_css_js:\n";
+
+    #NOTE: Make compile_css_js depend on pm_to_blib, so we have access to the blib directory
+    $compile_step .= "compile_css_js: pm_to_blib\n";
     $compile_step .= "\t" . '$(PERLRUN) build-resources.PL' . "\n";
+
+    #NOTE: Copy the generated vue dist files into the relevant blib
+    $compile_step .= "\t" . 'cp -r koha-tmpl/intranet-tmpl/prog/js/vue/dist blib/INTRANET_TMPL_DIR/prog/js/vue/' . "\n";
+
     my $top_targets = $compile_step . "\n" . $inherited;
     return $top_targets;
 }
-- 
2.48.1