Skip to content

Commit

Permalink
SDK-344 - Spa Installer does not remove previously deployed frontend …
Browse files Browse the repository at this point in the history
…on a deploy / update
  • Loading branch information
mseaton committed Nov 8, 2024
1 parent 0d54196 commit 8e9c65d
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.io.MoreFiles;
import com.google.common.io.RecursiveDeleteOption;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.openmrs.maven.plugins.model.DistroProperties;
Expand Down Expand Up @@ -56,15 +57,15 @@ public SpaInstaller(DistroHelper distroHelper, NodeHelper nodeHelper) {
* @param distroProperties Non-null
* @throws MojoExecutionException
*/
public void installFromDistroProperties(File appDataDir, DistroProperties distroProperties)
throws MojoExecutionException {

public void installFromDistroProperties(File appDataDir, DistroProperties distroProperties) throws MojoExecutionException {
installFromDistroProperties(appDataDir, distroProperties, false, null);
}

public void installFromDistroProperties(File appDataDir, DistroProperties distroProperties, boolean ignorePeerDependencies, Boolean overrideReuseNodeCache)
throws MojoExecutionException {

File buildTargetDir = prepareTargetDirectory(appDataDir);

// We find all the lines in distro properties beginning with `spa` and convert these
// into a JSON structure. This is passed to the frontend build tool.
// If no SPA elements are present in the distro properties, the SPA is not installed.
Expand Down Expand Up @@ -93,7 +94,6 @@ public void installFromDistroProperties(File appDataDir, DistroProperties distro
Properties sdkProperties = getSdkProperties();
boolean reuseNodeCache = (overrideReuseNodeCache != null) ? overrideReuseNodeCache : Boolean.parseBoolean(sdkProperties.getProperty("reuseNodeCache"));
nodeHelper.installNodeAndNpm(nodeVersion, npmVersion, reuseNodeCache);
File buildTargetDir = new File(appDataDir, BUILD_TARGET_DIR);

String program = "openmrs@" + coreVersion;
String legacyPeerDeps = ignorePeerDependencies ? "--legacy-peer-deps" : "";
Expand Down Expand Up @@ -217,5 +217,20 @@ private static void writeJSONObject(File file, Map<String, Object> jsonObject) t
"Exception while writing JSON to \"" + file.getAbsolutePath() + "\" " + e.getMessage(), e);
}
}


private File prepareTargetDirectory(File appDataDir) throws MojoExecutionException{
File targetDir = new File(appDataDir, BUILD_TARGET_DIR);
if (targetDir.exists()) {
try {
distroHelper.wizard.showMessage("Removing existing frontend directory: " + targetDir);
FileUtils.deleteDirectory(targetDir);
}
catch (IOException e) {
throw new MojoExecutionException("Unable to delete existing " + BUILD_TARGET_DIR + " directory", e);
}
}
distroHelper.wizard.showMessage("Creating new frontend directory: " + targetDir);
targetDir.mkdirs();
return targetDir;
}
}

0 comments on commit 8e9c65d

Please sign in to comment.