Skip to content

Commit

Permalink
feat(amplify-util-uibuilder): add studio forms (#11165)
Browse files Browse the repository at this point in the history
Co-authored-by: Hein Jeong <[email protected]>
Co-authored-by: Justin Shih <[email protected]>
Co-authored-by: Christopher Woolum <[email protected]>

Co-authored-by: Hein Jeong <[email protected]>
Co-authored-by: Justin Shih <[email protected]>
Co-authored-by: Christopher Woolum <[email protected]>
  • Loading branch information
4 people authored Oct 18, 2022
1 parent cba0ff6 commit 6f15294
Show file tree
Hide file tree
Showing 41 changed files with 1,007 additions and 338 deletions.
4 changes: 2 additions & 2 deletions packages/amplify-appsync-simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@graphql-tools/schema": "^8.3.1",
"@graphql-tools/utils": "^8.5.1",
"amplify-velocity-template": "1.4.8",
"aws-sdk": "^2.1169.0",
"aws-sdk": "^2.1233.0",
"chalk": "^4.1.1",
"cors": "^2.8.5",
"dataloader": "^2.0.0",
Expand Down Expand Up @@ -83,4 +83,4 @@
"node"
]
}
}
}
4 changes: 2 additions & 2 deletions packages/amplify-category-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"amplify-prompts": "2.6.0",
"amplify-util-headless-input": "1.9.6",
"amplify-util-import": "2.2.36",
"aws-sdk": "^2.1169.0",
"aws-sdk": "^2.1233.0",
"chalk": "^4.1.1",
"change-case": "^4.1.1",
"enquirer": "^2.3.6",
Expand Down Expand Up @@ -71,4 +71,4 @@
"node"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"devDependencies": {
"aws-sdk": "^2.1113.0"
}
}
}
4 changes: 2 additions & 2 deletions packages/amplify-category-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"amplify-function-plugin-interface": "1.9.5",
"amplify-prompts": "2.6.0",
"archiver": "^5.3.0",
"aws-sdk": "^2.1169.0",
"aws-sdk": "^2.1233.0",
"chalk": "^4.1.1",
"cloudform-types": "^4.2.0",
"enquirer": "^2.3.6",
Expand Down Expand Up @@ -62,4 +62,4 @@
"node"
]
}
}
}
4 changes: 2 additions & 2 deletions packages/amplify-category-geo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"amplify-headless-interface": "1.15.0",
"amplify-prompts": "2.6.0",
"amplify-util-headless-input": "1.9.6",
"aws-sdk": "^2.1169.0",
"aws-sdk": "^2.1233.0",
"fs-extra": "^8.1.0",
"lodash": "^4.17.21",
"uuid": "^8.3.2"
Expand All @@ -51,4 +51,4 @@
"node"
]
}
}
}
4 changes: 2 additions & 2 deletions packages/amplify-category-predictions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
},
"dependencies": {
"amplify-cli-core": "3.2.2",
"aws-sdk": "^2.1169.0",
"aws-sdk": "^2.1233.0",
"chalk": "^4.1.1",
"fs-extra": "^8.1.0",
"inquirer": "^7.3.3",
"uuid": "^8.3.2"
}
}
}
5 changes: 2 additions & 3 deletions packages/amplify-category-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"amplify-headless-interface": "1.15.0",
"amplify-prompts": "2.6.0",
"amplify-util-import": "2.2.36",
"aws-sdk": "^2.1169.0",
"aws-sdk": "^2.1233.0",
"chalk": "^4.1.1",
"enquirer": "^2.3.6",
"fs-extra": "^8.1.0",
Expand All @@ -45,7 +45,6 @@
"vm2": "^3.9.8"
},
"devDependencies": {
"aws-sdk": "^2.1169.0",
"cloudform-types": "^4.2.0",
"rimraf": "^3.0.2"
},
Expand All @@ -69,4 +68,4 @@
"html"
]
}
}
}
2 changes: 1 addition & 1 deletion packages/amplify-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"amplify-python-function-template-provider": "1.3.16",
"amplify-util-import": "2.2.36",
"amplify-util-mock": "4.5.3",
"aws-sdk": "^2.1169.0",
"aws-sdk": "^2.1233.0",
"chalk": "^4.1.1",
"ci-info": "^2.0.0",
"cli-table3": "^0.6.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-console-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@aws-amplify/amplify-e2e-core": "4.3.0",
"@types/ini": "^1.3.30",
"amplify-cli-core": "3.2.2",
"aws-sdk": "^2.1169.0",
"aws-sdk": "^2.1233.0",
"dotenv": "^8.2.0",
"fs-extra": "^8.1.0",
"ini": "^1.3.5",
Expand Down Expand Up @@ -88,4 +88,4 @@
"usePathForSuiteName": "true",
"addFileAttribute": "true"
}
}
}
4 changes: 2 additions & 2 deletions packages/amplify-dynamodb-simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"amplify-cli-core": "3.2.2",
"aws-sdk": "^2.1169.0",
"aws-sdk": "^2.1233.0",
"detect-port": "^1.3.0",
"execa": "^5.1.1",
"fs-extra": "^8.1.0",
Expand All @@ -42,4 +42,4 @@
"testEnvironment": "node",
"collectCoverage": true
}
}
}
37 changes: 37 additions & 0 deletions packages/amplify-e2e-core/src/init/amplifyPull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,40 @@ export const amplifyPullNonInteractive = (
.wait('Successfully pulled backend environment')
.runAsync();
};

/**
* headless studio pull
* instead of opening the browser for login pass the profile name so aws creds are used instead
* accepts defaults by using yes flag
*
* if testing locally
* set useDevCLI to `true`
* use profile name in local aws config
*/
export const amplifyStudioHeadlessPull = (
cwd: string,
settings: { appId: string, envName: string, profileName?: string, useDevCLI?: boolean },
): Promise<void> => {
const {
appId, envName, profileName, useDevCLI,
} = settings;
const providersConfig = {
awscloudformation: {
configLevel: 'project',
useProfile: true,
// eslint-disable-next-line spellcheck/spell-checker
profileName: profileName ?? 'amplify-integ-test-user',
},
};
const args = [
'pull',
'--amplify',
JSON.stringify({ appId, envName }),
'--providers',
JSON.stringify(providersConfig),
'--yes',
];
return spawn(getCLIPath(useDevCLI), args, { cwd, stripColors: true })
.wait('Successfully pulled backend environment')
.runAsync();
};
4 changes: 2 additions & 2 deletions packages/amplify-e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"amplify-headless-interface": "^1.15.0",
"aws-amplify": "^4.2.8",
"aws-appsync": "^4.1.1",
"aws-sdk": "^2.1169.0",
"aws-sdk": "^2.1233.0",
"circleci-api": "^4.1.4",
"dotenv": "^8.2.0",
"esm": "^3.2.25",
Expand Down Expand Up @@ -115,4 +115,4 @@
"usePathForSuiteName": "true",
"addFileAttribute": "true"
}
}
}
14 changes: 9 additions & 5 deletions packages/amplify-e2e-tests/src/__tests__/uibuilder.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable spellcheck/spell-checker */
import {
getBackendAmplifyMeta, getAppId, amplifyPull, createNewProjectDir, deleteProject, deleteProjectDir, initJSProjectWithProfile,

getNpxPath, getNpmPath, myIconComponent, formCheckoutComponent,
getBackendAmplifyMeta, getAppId, createNewProjectDir, deleteProject, deleteProjectDir, initJSProjectWithProfile,
getNpxPath, getNpmPath, myIconComponent, formCheckoutComponent, enableAdminUI, amplifyStudioHeadlessPull,
} from '@aws-amplify/amplify-e2e-core';
import { spawnSync, spawn } from 'child_process';
import { AmplifyUIBuilder } from 'aws-sdk';
Expand Down Expand Up @@ -40,7 +40,8 @@ describe('amplify pull with uibuilder', () => {

appId = getAppId(projRoot);
const meta = getBackendAmplifyMeta(projRoot);
const amplifyUIBuilder = new AmplifyUIBuilder({ region: meta.providers.awscloudformation.Region });
const region = meta.providers.awscloudformation.Region;
const amplifyUIBuilder = new AmplifyUIBuilder({ region });

await amplifyUIBuilder.createComponent({
appId,
Expand All @@ -53,6 +54,9 @@ describe('amplify pull with uibuilder', () => {
environmentName: envName,
componentToCreate: formCheckoutComponent,
}).promise();

// needs to enable studio for resources to be pull down
await enableAdminUI(appId, envName, region);
});

afterEach(async () => {
Expand All @@ -64,7 +68,7 @@ describe('amplify pull with uibuilder', () => {

it('appropriate uibuilder files are generated', async () => {
spawnSync(getNpxPath(), ['create-react-app', projectName], { cwd: projectDir, encoding: 'utf-8' });
await amplifyPull(reactDir, { appId, envName, emptyDir: true });
await amplifyStudioHeadlessPull(reactDir, { appId, envName });
const fileList = fs.readdirSync(`${reactDir}/src/ui-components/`);
expect(fileList).toContain('FormCheckout.jsx');
expect(fileList).toContain('FormCheckout.d.ts');
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-environment-parameters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"lodash": "^4.17.21"
},
"devDependencies": {
"aws-sdk": "^2.1113.0"
"aws-sdk": "^2.1233.0"
},
"jest": {
"collectCoverage": true,
Expand All @@ -47,4 +47,4 @@
"node"
]
}
}
}
2 changes: 1 addition & 1 deletion packages/amplify-provider-awscloudformation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"amplify-prompts": "2.6.0",
"amplify-util-import": "2.2.36",
"archiver": "^5.3.0",
"aws-sdk": "^2.1169.0",
"aws-sdk": "^2.1233.0",
"bottleneck": "2.19.5",
"chalk": "^4.1.1",
"cloudform": "^4.2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-storage-simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@types/serve-static": "^1.13.3",
"@types/uuid": "^8.3.1",
"@types/xml": "^1.0.4",
"aws-sdk": "^2.1113.0"
"aws-sdk": "^2.1233.0"
},
"jest": {
"transform": {
Expand Down Expand Up @@ -71,4 +71,4 @@
"/lib/"
]
}
}
}
4 changes: 2 additions & 2 deletions packages/amplify-util-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"author": "Amazon Web Services",
"license": "Apache-2.0",
"dependencies": {
"aws-sdk": "^2.1113.0"
"aws-sdk": "^2.1233.0"
},
"devDependencies": {
"@types/node": "^12.12.6"
}
}
}
4 changes: 2 additions & 2 deletions packages/amplify-util-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
"amplify-function-plugin-interface": "1.9.5",
"amplify-nodejs-function-runtime-provider": "2.3.3",
"aws-appsync": "^4.1.4",
"aws-sdk": "^2.1113.0",
"aws-sdk-mock": "^5.6.2",
"aws-sdk": "^2.1233.0",
"aws-sdk-mock": "^5.8.0",
"axios": "^0.26.0",
"graphql-auth-transformer": "^7.2.44",
"graphql-connection-transformer": "^5.2.43",
Expand Down
13 changes: 10 additions & 3 deletions packages/amplify-util-uibuilder/amplify-plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"name": "ui-builder",
"type": "util",
"commands": ["version", "cloneComponentsFromEnv", "generateComponents"],
"eventHandlers": ["PostEnvAdd"]
}
"commands": [
"version",
"cloneComponentsFromEnv",
"generateComponents"
],
"eventHandlers": [
"PostEnvAdd",
"PostPush"
]
}
7 changes: 4 additions & 3 deletions packages/amplify-util-uibuilder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
"access": "public"
},
"dependencies": {
"@aws-amplify/codegen-ui": "^2.4.2",
"@aws-amplify/codegen-ui-react": "^2.4.2",
"@aws-amplify/codegen-ui": "2.5.2",
"@aws-amplify/codegen-ui-react": "2.5.2",
"amplify-cli-core": "3.2.2",
"amplify-prompts": "2.6.0",
"aws-sdk": "^2.1113.0",
"aws-sdk": "^2.1233.0",
"fs-extra": "^8.1.0",
"ora": "^4.0.3"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { run } from '../commands/cloneComponentsFromEnv';
const extractArgsDependencyMock = extractArgsDependency as any;
const awsMock = aws as any;

jest.mock('../commands/utils/featureFlags', () => ({
getTransformerVersion: jest.fn().mockReturnValue(2),
}));
jest.mock('../commands/utils/extractArgs');
jest.mock('amplify-cli-core');

Expand All @@ -18,7 +21,7 @@ const mockedComponentExport = jest.fn((envName: string) => {
entities: [{}],
};
});
const mockedComponentCreate = jest.fn(() => ({ entity: {} }));
const mockedComponentCreate = jest.fn().mockReturnValue({ entity: {} });

describe('can clone components to new environment', () => {
let context: any;
Expand All @@ -34,18 +37,26 @@ describe('can clone components to new environment', () => {
},
},
};
extractArgsDependencyMock.extractArgs = jest.fn().mockImplementation(() => ({
extractArgsDependencyMock.extractArgs = jest.fn().mockReturnValue({
sourceEnvName: 'sourceEnvName',
newEnvName: 'newEnvName',
appId: 'appId',
environmentName: 'environmentName',
}));
awsMock.AmplifyUIBuilder = jest.fn(() => ({
});
awsMock.AmplifyUIBuilder = jest.fn().mockReturnValue({
exportComponents: jest.fn(({ environmentName }) => ({
promise: () => mockedComponentExport(environmentName),
})),
createComponent: jest.fn(() => ({ promise: () => mockedComponentCreate() })),
}));
createComponent: jest.fn().mockReturnValue({ promise: () => mockedComponentCreate() }),
getMetadata: jest.fn().mockReturnValue({
promise: jest.fn().mockReturnValue({
features: {
autoGenerateForms: 'true',
autoGenerateViews: 'true',
},
}),
}),
});
});

it('clones components to a new env', async () => {
Expand Down
Loading

0 comments on commit 6f15294

Please sign in to comment.