diff --git a/base/configs/openmrs/frontend_assembly/spa-assemble-config.json b/base/configs/openmrs/frontend_assembly/spa-assemble-config.json
index 06ae725b..fa883d5a 100644
--- a/base/configs/openmrs/frontend_assembly/spa-assemble-config.json
+++ b/base/configs/openmrs/frontend_assembly/spa-assemble-config.json
@@ -1,4 +1,5 @@
{
+ "coreVersion": "5.6.1-pre.1857",
"frontendModules": {
"@openmrs/esm-form-entry-app": "8.0.0"
},
@@ -6,4 +7,4 @@
"frontendModuleExcludes": [
"@openmrs/esm-form-engine-app"
]
-}
\ No newline at end of file
+}
diff --git a/base/pom.xml b/base/pom.xml
index d29539ed..e159f0c2 100644
--- a/base/pom.xml
+++ b/base/pom.xml
@@ -175,6 +175,30 @@
+
+
+
+ Override OpenMRS frontend build Groovy script
+ process-resources
+
+ copy-resources
+
+
+ ${project.build.directory}
+ true
+
+
+ ${project.basedir}/scripts
+
+
+ openmrs/frontend_assembly/build-openmrs-frontend.groovy
+
+
+
+
+
+
+
@@ -301,4 +325,4 @@
-->
-
\ No newline at end of file
+
diff --git a/base/scripts/openmrs/frontend_assembly/build-openmrs-frontend.groovy b/base/scripts/openmrs/frontend_assembly/build-openmrs-frontend.groovy
new file mode 100644
index 00000000..bc9dcead
--- /dev/null
+++ b/base/scripts/openmrs/frontend_assembly/build-openmrs-frontend.groovy
@@ -0,0 +1,61 @@
+import java.nio.file.Paths
+
+log.info("Checking for frontend customizations in ${Paths.get("${project.build.directory}", "openmrs_frontend", "spa-assemble-config.json").toString()}")
+
+def refAppConfigFile = Paths.get("${project.build.directory}", "openmrs_frontend", "reference-application-spa-assemble-config.json").toFile()
+def slurper = new groovy.json.JsonSlurper()
+def refAppConfig = slurper.parse(refAppConfigFile)
+def openmrsVersion = refAppConfig["coreVersion"] ?: "next"
+def outputDirectory = "${project.groupId}" == "com.ozonehis" && "${project.artifactId}" == "ozone-distro" ?
+ "${project.build.directory}/${project.artifactId}-${project.version}/binaries/openmrs/frontend" :
+ "${project.build.directory}/${project.artifactId}-${project.version}/distro/binaries/openmrs/frontend"
+
+def outputDirectoryFile = new File(outputDirectory)
+
+def assembleCommand = "npx --legacy-peer-deps openmrs@${openmrsVersion} assemble --manifest --mode config --target ${outputDirectory} --config ${refAppConfigFile.getAbsolutePath()}"
+log.info("Project: ${project.groupId}:${project.artifactId}")
+// by default, we build the frontend as part of Ozone and only rebuild if there are local customizations
+def shouldBuildFrontend = "${project.groupId}" == "com.ozonehis" && "${project.artifactId}" == "ozone-distro"
+
+if (!shouldBuildFrontend) {
+ frontendCustomizationsFile = Paths.get("${project.build.directory}", "openmrs_frontend", "spa-assemble-config.json").toFile()
+ if (frontendCustomizationsFile.exists()) {
+ log.info("Found frontend customizations. Rebuilding frontend...")
+
+ assembleCommand += " --config ${frontendCustomizationsFile.getAbsolutePath()}"
+ shouldBuildFrontend = true
+ // Update the openmrs version to the one specified in the customizations file if it exists.
+ openmrsVersion = slurper.parse(frontendCustomizationsFile)["coreVersion"] ?: openmrsVersion
+ log.info("Using OpenMRS Frontend Core Version: ${openmrsVersion}")
+ }
+}
+
+if (shouldBuildFrontend) {
+ log.info("Cleaning ${outputDirectory}...")
+ if (outputDirectoryFile.exists()) {
+ outputDirectoryFile.eachFile(it -> it.delete())
+ outputDirectoryFile.eachDir(it -> { if (it.getName() != "ozone") { it.deleteDir() } })
+ }
+
+ log.info("Running assemble command...")
+
+ def assembleProcess = assembleCommand.execute()
+ assembleProcess.consumeProcessOutput(System.out, System.err)
+ assembleProcess.waitFor()
+
+ if (assembleProcess.exitValue() != 0) {
+ throw new RuntimeException("'openmrs assemble' step failed. See previous messages for details.")
+ }
+
+ log.info("Running build command...")
+
+ def buildProcess = "npx --legacy-peer-deps openmrs@${openmrsVersion} build --config-url \$SPA_CONFIG_URLS --default-locale \$SPA_DEFAULT_LOCALE --target ${outputDirectory}".execute()
+ buildProcess.consumeProcessOutput(System.out, System.err)
+ buildProcess.waitFor()
+
+ if (buildProcess.exitValue() != 0) {
+ throw new RuntimeException("'openmrs build' step failed. See previous messages for details.")
+ }
+} else {
+ log.info("No need to re-build the frontend detected")
+}
diff --git a/prod/pom.xml b/prod/pom.xml
index 998c72b7..7bf4943d 100644
--- a/prod/pom.xml
+++ b/prod/pom.xml
@@ -63,6 +63,36 @@
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+
+
+
+ Override OpenMRS frontend build Groovy script
+ process-resources
+
+ copy-resources
+
+
+ ${project.build.directory}
+ true
+
+
+ ${project.basedir}/../base/scripts
+
+
+ openmrs/frontend_assembly/build-openmrs-frontend.groovy
+
+
+
+
+
+
+
+
+
net.mekomsolutions.maven.plugin