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

formgen: add type declaration generation #430

Merged
merged 9 commits into from
Oct 24, 2023
5 changes: 5 additions & 0 deletions .changeset/famous-rockets-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/form-generator': patch
---

Generate type declaration files for rendered components
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/form-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@aws-amplify/appsync-modelgen-plugin": "^2.6.0",
"@aws-amplify/codegen-ui": "^2.15.8",
"@aws-amplify/codegen-ui-react": "^2.15.9",
"@aws-amplify/codegen-ui-react": "^2.18.0",
"@aws-amplify/graphql-docs-generator": "^4.1.0",
"@aws-sdk/client-amplifyuibuilder": "^3.398.0",
"@aws-sdk/client-appsync": "^3.398.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ScriptKind,
ScriptTarget,
UtilTemplateType,
getDeclarationFilename,
} from '@aws-amplify/codegen-ui-react';
import {
FormGenerationOptions,
Expand Down Expand Up @@ -125,11 +126,20 @@ export class LocalGraphqlFormGenerator implements GraphqlFormGenerator {
formFeatureFlags
);
const { componentText, declaration } = renderer.renderComponentInternal();
return {
componentText,
fileName: renderer.fileName,
declaration,
};
const files = [
{
componentText,
fileName: renderer.fileName,
},
];
if (declaration) {
files.push({
componentText: declaration,
fileName: getDeclarationFilename(renderer.fileName),
});
}

return files;
};
sdstolworthy marked this conversation as resolved.
Show resolved Hide resolved
private filterModelsByName = (
filteredModelNames: string[],
Expand Down Expand Up @@ -262,8 +272,10 @@ export class LocalGraphqlFormGenerator implements GraphqlFormGenerator {
);
const forms = baseForms.reduce<Record<string, string>>(
(prev, formSchema) => {
const result = this.codegenForm(dataSchema, formSchema);
prev[result.fileName] = result.componentText;
const results = this.codegenForm(dataSchema, formSchema);
results.forEach((result) => {
prev[result.fileName] = result.componentText;
});
return prev;
},
{}
Expand Down
Loading