|
1 | 1 | import * as fs from 'fs-extra';
|
2 | 2 | import * as path from 'path';
|
3 |
| -import { prompter } from '@aws-amplify/amplify-prompts'; |
| 3 | +import { printer, prompter } from '@aws-amplify/amplify-prompts'; |
4 | 4 | import { twoStringSetsAreEqual, twoStringSetsAreDisjoint } from './utils/set-ops';
|
5 | 5 | import { Context } from './domain/context';
|
6 | 6 | import { scan, getPluginsWithNameAndCommand, getPluginsWithEventHandler } from './plugin-manager';
|
@@ -269,6 +269,9 @@ const raisePreExportEvent = async (context: Context): Promise<void> => {
|
269 | 269 | };
|
270 | 270 |
|
271 | 271 | const raisePreCodegenModelsEvent = async (context: Context): Promise<void> => {
|
| 272 | + if (shouldSkipCodegenModelsEvents(context, AmplifyEvent.PreCodegenModels)) { |
| 273 | + return; |
| 274 | + } |
272 | 275 | await raiseEvent(context, { event: AmplifyEvent.PreCodegenModels, data: {} });
|
273 | 276 | };
|
274 | 277 |
|
@@ -309,7 +312,22 @@ const raisePostPullEvent = async (context: Context): Promise<void> => {
|
309 | 312 | await raiseEvent(context, { event: AmplifyEvent.PostPull, data: {} });
|
310 | 313 | };
|
311 | 314 |
|
| 315 | +const shouldSkipCodegenModelsEvents = (context: Context, event: AmplifyEvent): boolean => { |
| 316 | + const optionsIndicatingUninitializedModelgen = ['target', 'model-schema']; |
| 317 | + const cliOptions = context?.parameters?.options ? new Set(Object.keys(context.parameters.options)) : new Set(); |
| 318 | + const skipEvents = optionsIndicatingUninitializedModelgen.every((option) => cliOptions.has(option)); |
| 319 | + if (skipEvents) { |
| 320 | + printer.info( |
| 321 | + `Skipping ${event} lifecycle event, due to presence of ${JSON.stringify(optionsIndicatingUninitializedModelgen)} in context options`, |
| 322 | + ); |
| 323 | + } |
| 324 | + return skipEvents; |
| 325 | +}; |
| 326 | + |
312 | 327 | const raisePostCodegenModelsEvent = async (context: Context): Promise<void> => {
|
| 328 | + if (shouldSkipCodegenModelsEvents(context, AmplifyEvent.PostCodegenModels)) { |
| 329 | + return; |
| 330 | + } |
313 | 331 | await raiseEvent(context, { event: AmplifyEvent.PostCodegenModels, data: {} });
|
314 | 332 | };
|
315 | 333 |
|
|
0 commit comments