Skip to content

Add setting to generate private packages #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion smithy-typescript-codegen-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ repositories {

dependencies {
implementation(project(":smithy-typescript-codegen"))
implementation("software.amazon.smithy:smithy-protocol-test-traits:0.9.8")
implementation("software.amazon.smithy:smithy-protocol-test-traits:0.9.9")
}
4 changes: 2 additions & 2 deletions smithy-typescript-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ extra["displayName"] = "Smithy :: Typescript :: Codegen"
extra["moduleName"] = "software.amazon.smithy.typescript.codegen"

dependencies {
api("software.amazon.smithy:smithy-codegen-core:0.9.8")
implementation("software.amazon.smithy:smithy-protocol-test-traits:0.9.8")
api("software.amazon.smithy:smithy-codegen-core:0.9.9")
implementation("software.amazon.smithy:smithy-protocol-test-traits:0.9.9")
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ static void writePackageJson(
node = node.withMember("react-native", Node.objectNode()
.withMember("./runtimeConfig", "./runtimeConfig.native"));

// Set the package to private if required.
if (settings.isPrivate()) {
node = node.withMember("private", true);
}

// Expand template parameters.
String template = Node.prettyPrintJson(node);
template = template.replace("${package}", settings.getPackageName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.stream.Collectors;
import software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.node.BooleanNode;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.node.StringNode;
Expand All @@ -45,6 +46,7 @@ public final class TypeScriptSettings {
private static final String PACKAGE_JSON = "packageJson";
private static final String SERVICE = "service";
private static final String PROTOCOL = "protocol";
private static final String PRIVATE = "private";

private String packageName;
private String packageDescription = "";
Expand All @@ -53,6 +55,7 @@ public final class TypeScriptSettings {
private ShapeId service;
private ObjectNode pluginSettings = Node.objectNode();
private String protocol = "";
private boolean isPrivate;

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

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

settings.setPluginSettings(config);
return settings;
Expand Down Expand Up @@ -196,6 +201,19 @@ public void setPluginSettings(ObjectNode pluginSettings) {
this.pluginSettings = Objects.requireNonNull(pluginSettings);
}

/**
* Returns if the generated package will be made private.
*
* @return If the package will be private.
*/
public boolean isPrivate() {
return isPrivate;
}

public void setPrivate(boolean isPrivate) {
this.isPrivate = isPrivate;
}

/**
* Gets the corresponding {@link ServiceShape} from a model.
*
Expand Down