Skip to content

Commit 045847a

Browse files
committed
Add setting to generate private packages
1 parent 440f312 commit 045847a

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

smithy-typescript-codegen-test/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ repositories {
2929

3030
dependencies {
3131
implementation(project(":smithy-typescript-codegen"))
32-
implementation("software.amazon.smithy:smithy-protocol-test-traits:0.9.8")
32+
implementation("software.amazon.smithy:smithy-protocol-test-traits:0.9.9")
3333
}

smithy-typescript-codegen/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ extra["displayName"] = "Smithy :: Typescript :: Codegen"
1818
extra["moduleName"] = "software.amazon.smithy.typescript.codegen"
1919

2020
dependencies {
21-
api("software.amazon.smithy:smithy-codegen-core:0.9.8")
22-
implementation("software.amazon.smithy:smithy-protocol-test-traits:0.9.8")
21+
api("software.amazon.smithy:smithy-codegen-core:0.9.9")
22+
implementation("software.amazon.smithy:smithy-protocol-test-traits:0.9.9")
2323
}

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/PackageJsonGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ static void writePackageJson(
5858
node = node.withMember("react-native", Node.objectNode()
5959
.withMember("./runtimeConfig", "./runtimeConfig.native"));
6060

61+
// Set the package to private if required.
62+
if (settings.isPrivate()) {
63+
node = node.withMember("private", true);
64+
}
65+
6166
// Expand template parameters.
6267
String template = Node.prettyPrintJson(node);
6368
template = template.replace("${package}", settings.getPackageName());

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptSettings.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.stream.Collectors;
2424
import software.amazon.smithy.codegen.core.CodegenException;
2525
import software.amazon.smithy.model.Model;
26+
import software.amazon.smithy.model.node.BooleanNode;
2627
import software.amazon.smithy.model.node.Node;
2728
import software.amazon.smithy.model.node.ObjectNode;
2829
import software.amazon.smithy.model.node.StringNode;
@@ -45,6 +46,7 @@ public final class TypeScriptSettings {
4546
private static final String PACKAGE_JSON = "packageJson";
4647
private static final String SERVICE = "service";
4748
private static final String PROTOCOL = "protocol";
49+
private static final String PRIVATE = "private";
4850

4951
private String packageName;
5052
private String packageDescription = "";
@@ -53,6 +55,7 @@ public final class TypeScriptSettings {
5355
private ShapeId service;
5456
private ObjectNode pluginSettings = Node.objectNode();
5557
private String protocol = "";
58+
private boolean isPrivate;
5659

5760
/**
5861
* Create a settings object from a configuration object node.
@@ -64,7 +67,8 @@ public final class TypeScriptSettings {
6467
public static TypeScriptSettings from(Model model, ObjectNode config) {
6568
TypeScriptSettings settings = new TypeScriptSettings();
6669
config.warnIfAdditionalProperties(Arrays.asList(
67-
PACKAGE, PACKAGE_DESCRIPTION, PACKAGE_JSON, PACKAGE_VERSION, SERVICE, PROTOCOL, TARGET_NAMESPACE));
70+
PACKAGE, PACKAGE_DESCRIPTION, PACKAGE_JSON, PACKAGE_VERSION,
71+
SERVICE, PROTOCOL, TARGET_NAMESPACE, PRIVATE));
6872

6973
// Get the service from the settings or infer one from the given model.
7074
settings.setService(config.getStringMember(SERVICE)
@@ -77,6 +81,7 @@ public static TypeScriptSettings from(Model model, ObjectNode config) {
7781
PACKAGE_DESCRIPTION, settings.getPackageName() + " client"));
7882
settings.packageJson = config.getObjectMember(PACKAGE_JSON).orElse(Node.objectNode());
7983
config.getStringMember(PROTOCOL).map(StringNode::getValue).ifPresent(settings::setProtocol);
84+
settings.setPrivate(config.getBooleanMember(PRIVATE).map(BooleanNode::getValue).orElse(false));
8085

8186
settings.setPluginSettings(config);
8287
return settings;
@@ -196,6 +201,19 @@ public void setPluginSettings(ObjectNode pluginSettings) {
196201
this.pluginSettings = Objects.requireNonNull(pluginSettings);
197202
}
198203

204+
/**
205+
* Returns if the generated package will be made private.
206+
*
207+
* @return If the package will be private.
208+
*/
209+
public boolean isPrivate() {
210+
return isPrivate;
211+
}
212+
213+
public void setPrivate(boolean isPrivate) {
214+
this.isPrivate = isPrivate;
215+
}
216+
199217
/**
200218
* Gets the corresponding {@link ServiceShape} from a model.
201219
*

0 commit comments

Comments
 (0)