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

feat: consolidate dependent resource types in backend/ #8709

Merged
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
1 change: 1 addition & 0 deletions packages/amplify-category-custom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';
import { buildCustomResources } from './utils/build-custom-resources';
import { categoryName } from './utils/constants';
export { addCDKResourceDependency } from './utils/dependency-management-utils';
export { generateDependentResourcesType } from './utils/build-custom-resources';

export async function executeAmplifyCommand(context: $TSContext) {
let commandPath = path.normalize(path.join(__dirname, 'commands'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import execa from 'execa';
import * as fs from 'fs-extra';
import ora from 'ora';
import * as path from 'path';
import { categoryName } from './constants';
import { categoryName, TYPES_DIR_NAME, AMPLIFY_RESOURCES_TYPE_DEF_FILENAME } from './constants';
import { getAllResources } from './dependency-management-utils';
import { generateCloudFormationFromCDK } from './generate-cfn-from-cdk';

Expand Down Expand Up @@ -38,12 +38,14 @@ const getSelectedResources = async (context: $TSContext, resourceName?: string)
return (await context.amplify.getResourceStatus(categoryName, resourceName)).allResources as ResourceMeta[];
};

async function generateDependentResourcesType(context: $TSContext, resourceDirPath: string) {
export async function generateDependentResourcesType(context: $TSContext) {
const resourceDirPath = path.join(pathManager.getBackendDirPath(), TYPES_DIR_NAME);

const copyJobs = [
{
dir: resourcesDirRoot,
template: amplifyDependentResourcesFilename,
target: path.join(resourceDirPath, 'amplify-dependent-resources-ref.d.ts'),
target: path.join(resourceDirPath, AMPLIFY_RESOURCES_TYPE_DEF_FILENAME),
},
];

Expand Down Expand Up @@ -100,5 +102,5 @@ async function buildResource(context: $TSContext, resource: ResourceMeta) {

await generateCloudFormationFromCDK(resource.resourceName);

await generateDependentResourcesType(context, targetDir);
await generateDependentResourcesType(context);
}
2 changes: 2 additions & 0 deletions packages/amplify-category-custom/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const CFN_SERVICE_NAME = 'customCloudformation';
export const DEPLOYMENT_PROVIDER_NAME = 'awscloudformation';
export const customResourceCFNFilenameSuffix = `cloudformation-template.json`;
export const cdkFileName = 'cdk-stack.ts';
export const TYPES_DIR_NAME = 'types';
export const AMPLIFY_RESOURCES_TYPE_DEF_FILENAME = 'amplify-dependent-resources-ref.d.ts';
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function addCDKResourceDependency(
dependentResources: AmplifyDependentResourceDefinition[],
) {
const dependsOn: AmplifyDependentResourceDefinition[] = [];
const dependentParameters: $TSObject = {};
const dependentParameters: any = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit : can revert to $TSObject or $TSAny


dependentResources.forEach(resource => {
const attributeList = getResourceCfnOutputAttributes(resource.category, resource.resourceName);
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-cli/src/__tests__/commands/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { $TSContext } from 'amplify-cli-core';

jest.mock('amplify-cli-core');
jest.mock('amplify-provider-awscloudformation');
jest.mock('@aws-amplify/amplify-category-custom');

describe('run build command', () => {
it('runs build command for only a resource', async () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/amplify-cli/src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { $TSContext, IAmplifyResource } from 'amplify-cli-core';
import { printer } from 'amplify-prompts';
import { generateDependentResourcesType } from '@aws-amplify/amplify-category-custom';
/**
* Command to transform CFN with overrides
*/
Expand All @@ -14,6 +15,7 @@ export const run = async (context: $TSContext) => {
}

try {
await generateDependentResourcesType(context);
const resourcesToBuild: IAmplifyResource[] = await getResources(context);
let filteredResources: IAmplifyResource[] = resourcesToBuild;
if (categoryName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getProjectConfig } from './get-project-config';
import { getProviderPlugins } from './get-provider-plugins';
import { onCategoryOutputsChange } from './on-category-outputs-change';
import { showResourceTable } from './resource-status';
import { generateDependentResourcesType } from '@aws-amplify/amplify-category-custom';

export async function pushResources(
context: $TSContext,
Expand Down Expand Up @@ -53,6 +54,7 @@ export async function pushResources(
}

// building all CFN stacks here to get the resource Changes
await generateDependentResourcesType(context);
const resourcesToBuild: IAmplifyResource[] = await getResources(context);
await context.amplify.executeProviderUtils(context, 'awscloudformation', 'buildOverrides', { resourcesToBuild, forceCompile: true });

Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{ "path": "../amplify-provider-awscloudformation" },
{ "path": "../amplify-util-import" },
{ "path": "../graphql-transformer-core" },
{ "path": "../amplify-category-auth" }
{ "path": "../amplify-category-auth" },
{ "path": "../amplify-category-custom" }
]
}