Merge pull request #2480 from hapifhir/issue-2479-bad-packages
Have CreatePackageCommand automatically add fhirVersions based on --fhir-version flag
This commit is contained in:
commit
b191f1da2b
|
@ -24,6 +24,8 @@ import ca.uhn.fhir.parser.DataFormatException;
|
|||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
|
@ -37,7 +39,6 @@ import org.hl7.fhir.utilities.npm.PackageGenerator;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.print.attribute.standard.MediaSize;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -67,7 +68,7 @@ public class CreatePackageCommand extends BaseCommand {
|
|||
|
||||
@Override
|
||||
public String getCommandDescription() {
|
||||
return "Create an NPM package using the FHIR packging format";
|
||||
return "Create an NPM package using the FHIR packaging format";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -129,6 +130,7 @@ public class CreatePackageCommand extends BaseCommand {
|
|||
manifestGenerator.name(myPackageName);
|
||||
manifestGenerator.version(myPackageVersion);
|
||||
manifestGenerator.description(myPackageDescription);
|
||||
injectFhirVersionsArray(manifestGenerator);
|
||||
if (isNotBlank(myPackageDescription)) {
|
||||
manifestGenerator.description(myPackageDescription);
|
||||
}
|
||||
|
@ -177,6 +179,13 @@ public class CreatePackageCommand extends BaseCommand {
|
|||
}
|
||||
}
|
||||
|
||||
private void injectFhirVersionsArray(PackageGenerator manifestGenerator) {
|
||||
JsonObject rootJsonObject = manifestGenerator.getRootJsonObject();
|
||||
JsonArray fhirVersionsArray = new JsonArray();
|
||||
fhirVersionsArray.add(myFhirCtx.getVersion().getVersion().getFhirVersionString());
|
||||
rootJsonObject.add("fhirVersions", fhirVersionsArray);
|
||||
}
|
||||
|
||||
public void addFiles(String[] thePackageValues, String theFolder) throws ParseException, ExecutionException {
|
||||
if (thePackageValues != null) {
|
||||
for (String nextPackageValue : thePackageValues) {
|
||||
|
|
|
@ -101,6 +101,9 @@ public class CreatePackageCommandTest extends BaseTest {
|
|||
String expectedPackageJson = "{\n" +
|
||||
" \"name\": \"com.example.ig\",\n" +
|
||||
" \"version\": \"1.0.1\",\n" +
|
||||
" \"fhirVersions\": [\n" +
|
||||
" \"4.0.1\"\n" +
|
||||
" ],\n" +
|
||||
" \"dependencies\": {\n" +
|
||||
" \"hl7.fhir.core\": \"4.0.1\",\n" +
|
||||
" \"foo.bar\": \"1.2.3\"\n" +
|
||||
|
@ -111,7 +114,6 @@ public class CreatePackageCommandTest extends BaseTest {
|
|||
// Try parsing the module again to make sure we can
|
||||
NpmPackage loadedPackage = NpmPackage.fromPackage(new FileInputStream(igArchive));
|
||||
assertEquals("com.example.ig", loadedPackage.name());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -152,7 +154,10 @@ public class CreatePackageCommandTest extends BaseTest {
|
|||
|
||||
String expectedPackageJson = "{\n" +
|
||||
" \"name\": \"com.example.ig\",\n" +
|
||||
" \"version\": \"1.0.1\"\n" +
|
||||
" \"version\": \"1.0.1\",\n" +
|
||||
" \"fhirVersions\": [\n" +
|
||||
" \"4.0.1\"\n" +
|
||||
" ]\n" +
|
||||
"}";
|
||||
assertEquals(expectedPackageJson, packageJsonContents);
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 2479
|
||||
title: "the create-package command of the HAPI FHIR CLI was not correctly adding the `fhirVersions` section to the generated package.json. This has been fixed"
|
Loading…
Reference in New Issue