Skip to content

Commit

Permalink
KH-572: Build OpenMRS frontend with core version 5.6.1-pre.1857 (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliouzbett authored Jul 8, 2024
1 parent 53feb62 commit 34ed432
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"coreVersion": "5.6.1-pre.1857",
"frontendModules": {
"@openmrs/esm-form-entry-app": "8.0.0"
},
"__comment": "We exclude the React Form Engine app in favor of the Angular Form Engine.",
"frontendModuleExcludes": [
"@openmrs/esm-form-engine-app"
]
}
}
26 changes: 25 additions & 1 deletion base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,30 @@
</resources>
</configuration>
</execution>

<!-- Override the Groovy script provided by Ozone to allow overriding the App Shell version -->
<execution>
<id>Override OpenMRS frontend build Groovy script</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.basedir}/scripts</directory>
<includes>
<include>
openmrs/frontend_assembly/build-openmrs-frontend.groovy
</include>
</includes>
</resource>
</resources>
</configuration>
</execution>

</executions>
</plugin>

Expand Down Expand Up @@ -301,4 +325,4 @@
</build>
</profile>
</profiles> -->
</project>
</project>
Original file line number Diff line number Diff line change
@@ -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")
}
30 changes: 30 additions & 0 deletions prod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<!-- Override the Groovy script provided by Ozone to allow overriding the App Shell version -->
<execution>
<id>Override OpenMRS frontend build Groovy script</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.basedir}/../base/scripts</directory>
<includes>
<include>
openmrs/frontend_assembly/build-openmrs-frontend.groovy
</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<!-- Compile a dependency report -->
<plugin>
<groupId>net.mekomsolutions.maven.plugin</groupId>
Expand Down

0 comments on commit 34ed432

Please sign in to comment.