-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run component generation in browser
- Loading branch information
Showing
17 changed files
with
256 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,4 @@ dist/** | |
**/.rollup.cache | ||
|
||
ui-components | ||
browser-integration-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/test-generator/browser-integration-test-templates/cypress.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
5 changes: 5 additions & 0 deletions
5
...ges/test-generator/browser-integration-test-templates/cypress/integration/browser-spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe('Generate Components', () => { | ||
it('Generates all components', () => { | ||
cy.visit('http://localhost:3000'); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
packages/test-generator/browser-integration-test-templates/src/App.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
import React from 'react'; | ||
import { BrowserTestGenerator } from '@amzn/test-generator'; | ||
import logo from './logo.svg'; | ||
import './App.css'; | ||
|
||
function App() { | ||
const generator = new BrowserTestGenerator({ | ||
writeToLogger: true, | ||
writeToDisk: false, | ||
disabledSchemas: [ | ||
'BasicComponentCustom', // TODO: Add as part of basic components part 2 | ||
'BasicComponentDivider', // TODO: Add as part of basic components part 2 | ||
'BasicComponentFlex', // TODO: Add as part of basic components part 2 | ||
'BasicComponentImage', // TODO: Add as part of basic components part 2 | ||
], | ||
}); | ||
generator.generate(); | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<img src={logo} className="App-logo" alt="logo" /> | ||
<p> | ||
Edit <code>src/App.tsx</code> and save to reload. | ||
</p> | ||
<a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer"> | ||
Learn React | ||
</a> | ||
</header> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
37 changes: 37 additions & 0 deletions
37
packages/test-generator/lib/generators/BrowserTestGenerator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
/* Test Generator to be used in the browser environment */ | ||
import { StudioComponent, StudioTheme } from '@amzn/amplify-ui-codegen-schema'; | ||
import { AmplifyRenderer, ReactThemeStudioTemplateRenderer } from '@amzn/studio-ui-codegen-react'; | ||
import { TestGenerator } from './TestGenerator'; | ||
|
||
export class BrowserTestGenerator extends TestGenerator { | ||
writeComponentToDisk() {} // no-op | ||
|
||
writeThemeToDisk() {} // no-op | ||
|
||
renderComponent(component: StudioComponent) { | ||
return { | ||
renderedComponent: new AmplifyRenderer(component, this.renderConfig).renderComponentOnly(), | ||
appSample: { compText: '', importsText: '' }, | ||
}; | ||
} | ||
|
||
renderTheme(theme: StudioTheme) { | ||
return new ReactThemeStudioTemplateRenderer(theme, this.renderConfig).renderComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/test-generator/lib/generators/NodeTestGenerator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
/* Test Generator to be used in the Node environment */ | ||
import { StudioComponent, StudioTheme } from '@amzn/amplify-ui-codegen-schema'; | ||
import { StudioTemplateRendererManager, StudioTemplateRendererFactory } from '@amzn/studio-ui-codegen'; | ||
import { AmplifyRenderer, ReactOutputConfig, ReactThemeStudioTemplateRenderer } from '@amzn/studio-ui-codegen-react'; | ||
import path from 'path'; | ||
import { TestGenerator, TestGeneratorParams } from './TestGenerator'; | ||
|
||
export class NodeTestGenerator extends TestGenerator { | ||
private readonly componentRendererFactory: any; | ||
|
||
private readonly themeRendererFactory: any; | ||
|
||
private readonly rendererManager: any; | ||
|
||
private readonly themeRendererManager: any; | ||
|
||
constructor(params: TestGeneratorParams) { | ||
super(params); | ||
this.componentRendererFactory = new StudioTemplateRendererFactory( | ||
(component: StudioComponent) => new AmplifyRenderer(component, this.renderConfig), | ||
); | ||
this.themeRendererFactory = new StudioTemplateRendererFactory( | ||
(theme: StudioTheme) => new ReactThemeStudioTemplateRenderer(theme, this.renderConfig), | ||
); | ||
const outputPathDir = path.resolve(path.join(__dirname, '..', '..', 'test-app-templates', 'src', 'ui-components')); | ||
const outputConfig: ReactOutputConfig = { outputPathDir }; | ||
this.rendererManager = new StudioTemplateRendererManager(this.componentRendererFactory, outputConfig); | ||
this.themeRendererManager = new StudioTemplateRendererManager(this.themeRendererFactory, outputConfig); | ||
} | ||
|
||
writeComponentToDisk(component: StudioComponent) { | ||
this.rendererManager.renderSchemaToTemplate(component); | ||
} | ||
|
||
renderComponent(component: StudioComponent) { | ||
const buildRenderer = this.componentRendererFactory.buildRenderer(component); | ||
const renderedComponent = buildRenderer.renderComponentOnly(); | ||
const appSample = buildRenderer.renderSampleCodeSnippet(); | ||
return { renderedComponent, appSample }; | ||
} | ||
|
||
writeThemeToDisk(theme: StudioTheme) { | ||
this.themeRendererManager.renderSchemaToTemplate(theme); | ||
} | ||
|
||
renderTheme(theme: StudioTheme) { | ||
const buildRenderer = this.themeRendererFactory.buildRenderer(theme); | ||
return buildRenderer.renderComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.