Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe('AmplifyInitializer E2E', () => {
console.log('✅ Amplify CLI is available, proceeding with test');

// Generate a unique alphanumeric app name (3-20 chars, alphanumeric only)
const appName = generateTimeBasedE2EAmplifyAppName();
const appName = generateTimeBasedE2EAmplifyAppName('app-name');
const profile = TEST_RUNNER_PROFILE;

const config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ describe('ConfigurationLoader', () => {
},
],
},
hosting: {
type: 'amplify-console',
},
},
};

Expand Down
170 changes: 62 additions & 108 deletions packages/amplify-gen2-migration-e2e-system/src/cli.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
* Uses the e2e-core utilities for reliable amplify init execution
*/

import { ILogger, IAppInitializer, InitializeAppOptions } from '../interfaces';
import { AppConfiguration, LogContext } from '../types';
import { AppConfiguration } from '../types';
import { initJSProjectWithProfile } from '@aws-amplify/amplify-e2e-core';
import { Logger } from '../utils/logger';

export interface InitializeAppOptions {
appPath: string;
config: AppConfiguration;
deploymentName: string;
/** Amplify environment name (required, 2-10 lowercase letters) */
envName: string;
profile: string;
}

export interface AmplifyInitSettings {
name: string;
Expand All @@ -31,18 +40,16 @@ interface BuildInitSettingsOptions {
profile: string;
}

export class AmplifyInitializer implements IAppInitializer {
constructor(private readonly logger: ILogger) {}
export class AmplifyInitializer {
constructor(private readonly logger: Logger) {}

async initializeApp(options: InitializeAppOptions): Promise<void> {
const { appPath, config, deploymentName, envName, profile } = options;

const context: LogContext = { appName: deploymentName, operation: 'initializeApp' };

this.logger.info(`Starting amplify init for ${deploymentName} (config: ${config.app.name})`, context);
this.logger.debug(`App path: ${appPath}`, context);
this.logger.debug(`Configuration: ${JSON.stringify(config, null, 2)}`, context);
this.logger.debug(`Deployment name: ${deploymentName}`, context);
this.logger.info(`Starting amplify init for ${deploymentName} (config: ${config.app.name})`);
this.logger.debug(`App path: ${appPath}`);
this.logger.debug(`Configuration: ${JSON.stringify(config, null, 2)}`);
this.logger.debug(`Deployment name: ${deploymentName}`);

const appNameValidation = this.validateAppName(deploymentName);
if (!appNameValidation.valid) {
Expand All @@ -56,16 +63,16 @@ export class AmplifyInitializer implements IAppInitializer {

const startTime = Date.now();
try {
this.logger.debug(`Calling initJSProjectWithProfile...`, context);
this.logger.debug(`Calling initJSProjectWithProfile...`);
const settings = this.buildInitSettings({ config, deploymentName, profile, envName });
this.logger.debug(`Init settings: ${JSON.stringify(settings, null, 2)}`, context);
this.logger.debug(`Init settings: ${JSON.stringify(settings, null, 2)}`);
await initJSProjectWithProfile(appPath, settings);

const duration = Date.now() - startTime;
this.logger.info(`Successfully initialized Amplify app in ${appPath}, ${deploymentName} (took ${duration}ms)`, context);
this.logger.info(`Successfully initialized Amplify app in ${appPath} (${duration}ms)`);
} catch (error) {
const duration = Date.now() - startTime;
this.logger.error(`Failed to initialize Amplify app: ${deploymentName} (failed after ${duration}ms)`, error as Error, context);
this.logger.error(`Failed to initialize Amplify app: ${deploymentName} (failed after ${duration}ms)`, error as Error);
throw error;
}
}
Expand Down Expand Up @@ -132,11 +139,10 @@ export class AmplifyInitializer implements IAppInitializer {
};

// Log the settings being used
const context: LogContext = { appName: deploymentName, operation: 'buildInitSettings' };
this.logger.debug(`Built init settings for ${deploymentName} (config: ${config.app.name}):`, context);
this.logger.debug(`- Name: ${settings.name}`, context);
this.logger.info(`Using Amplify environment name: ${settings.envName}`, context);
this.logger.debug(`- Using default selections for editor, framework, etc.`, context);
this.logger.debug(`Built init settings for ${deploymentName} (config: ${config.app.name}):`);
this.logger.debug(`- Name: ${settings.name}`);
this.logger.info(`Using Amplify environment name: ${settings.envName}`);
this.logger.debug(`- Using default selections for editor, framework, etc.`);

return settings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
*/

import * as path from 'path';
import { IAppSelector, ILogger, IFileManager } from '../interfaces';
import { CLIOptions } from '../types';
import { Logger } from '../utils/logger';
import { FileManager } from '../utils/file-manager';

export class AppSelector implements IAppSelector {
export class AppSelector {
private readonly appsBasePath: string;
private availableApps?: string[];

constructor(private readonly logger: ILogger, private readonly fileManager: IFileManager, appsBasePath = '../../amplify-migration-apps') {
constructor(private readonly logger: Logger, private readonly fileManager: FileManager, appsBasePath = '../../amplify-migration-apps') {
// Resolve path relative to the project root, not the current file
this.appsBasePath = path.resolve(process.cwd(), appsBasePath);
}
Expand All @@ -30,15 +31,15 @@ export class AppSelector implements IAppSelector {
const appDirectories = await this.fileManager.listDirectories(this.appsBasePath);

this.availableApps = appDirectories.sort();
this.logger.info(`Discovered ${this.availableApps.length} available apps: ${this.availableApps.join(', ')}`);
this.logger.debug(`Discovered ${this.availableApps.length} available apps: ${this.availableApps.join(', ')}`);

return this.availableApps;
} catch (error) {
throw Error(`Failed to discover available apps: ${error}`);
}
}

async validateAppExists(appName: string): Promise<boolean> {
public async validateAppExists(appName: string): Promise<boolean> {
this.logger.debug(`Validating app exists: ${appName}`);

const availableApps = await this.discoverAvailableApps();
Expand All @@ -52,7 +53,7 @@ export class AppSelector implements IAppSelector {
}

async selectApp(options: CLIOptions): Promise<string> {
this.logger.debug('Selecting app based on CLI option', { operation: 'selectApp' });
this.logger.debug('Selecting app based on CLI option');

const availableApps = await this.discoverAvailableApps();

Expand Down
Loading
Loading