Skip to content

Commit 7f2ae93

Browse files
committed
Support SSDK generation via DirectedCodegen
The 2 SmithyBuildPlugins have duplication, which can be reduced via refactoring Ran `yarn generate-clients -s && yarn test:server-protocols` in aws-sdk-js-v3 with this commit. Compared the generated ssdks with https://github.com/gosar/aws-sdk-js-v3/tree/f47b48a1eb1187657f489b4e041f979e72e0134d and found there were differences but only some moving around of code within some files.
1 parent 0a776f9 commit 7f2ae93

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ final class DirectedTypeScriptCodegen
7474

7575
@Override
7676
public SymbolProvider createSymbolProvider(CreateSymbolProviderDirective<TypeScriptSettings> directive) {
77-
return new SymbolVisitor(directive.model(), directive.settings());
77+
return directive.settings().getArtifactType().createSymbolProvider(directive.model(), directive.settings());
7878
}
7979

8080
@Override

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ public void execute(PluginContext context) {
4949
runner.model(context.getModel());
5050

5151
// Create the TypeScriptSettings object from the plugin settings.
52-
// TypeScriptSettings settings = runner.settings(TypeScriptSettings.class, context.getSettings());
53-
TypeScriptSettings settings = TypeScriptSettings.from(context.getModel(), context.getSettings());
54-
// TypeScriptSettings settings = TypeScriptSettings.from(context.getModel(), context.getSettings(),
55-
// TypeScriptSettings.ArtifactType.CLIENT);
52+
TypeScriptSettings settings = TypeScriptSettings.from(context.getModel(), context.getSettings(),
53+
TypeScriptSettings.ArtifactType.CLIENT);
5654
runner.settings(settings);
5755

5856
runner.service(settings.getService());

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
import software.amazon.smithy.build.PluginContext;
1919
import software.amazon.smithy.build.SmithyBuildPlugin;
20-
import software.amazon.smithy.typescript.codegen.TypeScriptSettings.ArtifactType;
20+
import software.amazon.smithy.codegen.core.directed.CodegenDirector;
21+
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
2122
import software.amazon.smithy.utils.SmithyInternalApi;
2223

2324
/**
@@ -33,6 +34,32 @@ public String getName() {
3334

3435
@Override
3536
public void execute(PluginContext context) {
36-
new CodegenVisitor(context, ArtifactType.SSDK).execute();
37+
CodegenDirector<TypeScriptWriter, TypeScriptIntegration, TypeScriptCodegenContext, TypeScriptSettings> runner
38+
= new CodegenDirector<>();
39+
40+
runner.directedCodegen(new DirectedTypeScriptCodegen());
41+
42+
// Set the SmithyIntegration class to look for and apply using SPI.
43+
runner.integrationClass(TypeScriptIntegration.class);
44+
45+
// Set the FileManifest and Model from the plugin.
46+
runner.fileManifest(context.getFileManifest());
47+
runner.model(context.getModel());
48+
49+
// Create the TypeScriptSettings object from the plugin settings.
50+
TypeScriptSettings settings = TypeScriptSettings.from(context.getModel(), context.getSettings(),
51+
TypeScriptSettings.ArtifactType.SSDK);
52+
runner.settings(settings);
53+
54+
runner.service(settings.getService());
55+
56+
// Configure the director to perform some common model transforms.
57+
runner.performDefaultCodegenTransforms();
58+
59+
// TODO: How is smithy-typescript currently dealing with no input/output?
60+
// runner.createDedicatedInputsAndOutputs();
61+
62+
// Run it!
63+
runner.run();
3764
}
3865
}

0 commit comments

Comments
 (0)