Skip to content

Commit

Permalink
feat: allow conditional formatting of outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Woolum authored and cwoolum committed Aug 15, 2022
1 parent aafaccb commit 16bba8c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const supportedTranspilationTargets = [
export function transpile(
code: string,
renderConfig: ReactRenderConfig,
shouldFormatCode = true,
): { componentText: string; declaration?: string } {
const { target, module, script, renderTypeDeclarations, inlineSourceMap } = renderConfig;
if (script === ScriptKind.JS || script === ScriptKind.JSX) {
Expand All @@ -78,7 +79,7 @@ export function transpile(
},
}).outputText;

const componentText = formatCode(transpiledCode);
const componentText = shouldFormatCode ? formatCode(transpiledCode) : transpiledCode;

/*
* createProgram is less performant than traspileModule and should only be used when necessary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ export abstract class ReactStudioTemplateRenderer extends StudioTemplateRenderer
const result = printer.printNode(EmitHint.Unspecified, wrappedFunction, file);

// do not produce declaration becuase it is not used
const { componentText: compText } = transpile(result, { ...this.renderConfig, renderTypeDeclarations: false });
// also do not format because we don't care what the component looks like in Studio UI
const { componentText: compText } = transpile(
result,
{ ...this.renderConfig, renderTypeDeclarations: false },
false,
);

return { compText, importsText, requiredDataModels: this.componentMetadata.requiredDataModels };
}
Expand Down
4 changes: 2 additions & 2 deletions packages/codegen-ui-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@aws-amplify/codegen-ui": "2.3.2",
"@typescript/vfs": "~1.3.5",
"typescript": "~4.4.4"
"typescript": "^4.4.4"
},
"peerDependencies": {
"react": "^16.8 || ^17.0 || ^18.0",
Expand Down Expand Up @@ -72,4 +72,4 @@
"hermes-engine": ">=0.10.0",
"shell-quote": ">=1.7.3"
}
}
}

0 comments on commit 16bba8c

Please sign in to comment.