Skip to content
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

Add ReactNative language target #125

Merged
merged 4 commits into from
Feb 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ String getTemplateFileName() {
}
},

/**
* ReactNative-specific language target.
* Note: ReactNative target extends from Browser target. You only need to add
* ReactNative dependencies if they are different to Browser dependencies.
*/
REACT_NATIVE {
@Override
String getTemplateFileName() {
return "runtimeConfig.rn.ts.template";
}
},

/**
* A language target that shares configuration that is shared across all
* runtimes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ static void writePackageJson(
// Add the Node vs Browser hook.
node = node.withMember("browser", Node.objectNode()
.withMember("./runtimeConfig", "./runtimeConfig.browser"));
// Add the ReactNative hook.
node = node.withMember("react-native", Node.objectNode()
.withMember("./runtimeConfig", "./runtimeConfig.rn"));

// Expand template parameters.
String template = Node.prettyPrintJson(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public enum TypeScriptDependency implements SymbolDependencyContainer {

AWS_SDK_STREAM_COLLECTOR_NODE("dependencies", "@aws-sdk/stream-collector-node", "^1.0.0-alpha.1", true),
AWS_SDK_STREAM_COLLECTOR_BROWSER("dependencies", "@aws-sdk/stream-collector-browser", "^1.0.0-alpha.1", true),
AWS_SDK_STREAM_COLLECTOR_RN("dependencies", "@aws-sdk/stream-collector-rn", "^1.0.0-alpha.0", true),

AWS_SDK_URL_PARSER_BROWSER("dependencies", "@aws-sdk/url-parser-browser", "^1.0.0-alpha.1", true),
AWS_SDK_URL_PARSER_NODE("dependencies", "@aws-sdk/url-parser-node", "^1.0.0-alpha.1", true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"browser": {
"./runtimeConfig": "./runtimeConfig.browser"
},
"react-native": {
"./runtimeConfig": "./runtimeConfig.rn"
},
"sideEffects": false,
"dependencies": {
"tslib": "^1.8.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { parseUrl } from "@aws-sdk/url-parser-node";
import { name, version } from "./package.json";
import { ClientDefaults } from "${clientModuleName}";
import { ClientDefaultValues as BrowserDefaults } from "./runtimeConfig.browser";

export const ClientDefaultValues: Required<ClientDefaults> = {
...BrowserDefaults,
urlParser: parseUrl,
defaultUserAgent: `aws-sdk-js-v3-react-native-${name}/${version}`,
runtime: "browser",
${customizations}
};
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ public void addRuntimeConfigValues(
settings, model, symbolProvider, delegator, integrations);
generator.generate(LanguageTarget.NODE);
generator.generate(LanguageTarget.BROWSER);
generator.generate(LanguageTarget.REACT_NATIVE);
generator.generate(LanguageTarget.SHARED);
delegator.flushWriters();

Assertions.assertTrue(manifest.hasFile("runtimeConfig.ts"));
Assertions.assertTrue(manifest.hasFile("runtimeConfig.browser.ts"));
Assertions.assertTrue(manifest.hasFile("runtimeConfig.rn.ts"));
Assertions.assertTrue(manifest.hasFile("runtimeConfig.shared.ts"));

// Does the runtimeConfig.shared.ts file expand the template properties properly?
Expand All @@ -64,9 +66,17 @@ public void addRuntimeConfigValues(
assertThat(runtimeConfigContents, containsString("syn: 'ack',"));

// Does the runtimeConfig.browser.ts file expand the template properties properly?
String runtimeConfigBrowserContents = manifest.getFileString("runtimeConfig.ts").get();
String runtimeConfigBrowserContents = manifest.getFileString("runtimeConfig.browser.ts").get();
assertThat(runtimeConfigBrowserContents,
containsString("import { ClientDefaults } from \"./ExampleClient\";"));
assertThat(runtimeConfigContents, containsString("syn: 'ack',"));

// Does the runtimeConfig.rn.ts file expand the browser template properties properly?
String runtimeConfigRNContents = manifest.getFileString("runtimeConfig.rn.ts").get();
assertThat(runtimeConfigRNContents,
containsString("import { ClientDefaults } from \"./ExampleClient\";"));
assertThat(runtimeConfigRNContents,
containsString("import { ClientDefaultValues as BrowserDefaults } from \"./runtimeConfig.browser\";"));
assertThat(runtimeConfigContents, containsString("syn: 'ack',"));
}
}