From c05ecf28a54aa3b2e990183438166c3ab0fbe58b Mon Sep 17 00:00:00 2001 From: mmilko01 Date: Thu, 9 Jan 2025 21:22:27 +0200 Subject: [PATCH] fix: logging --- .../src/app/index.ts | 32 +++++++++++++++---- .../src/app/types.ts | 24 ++++++++++++++ .../adp-flp-config-sub-generator.i18n.json | 5 ++- .../test/app.test.ts | 6 ---- 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/packages/adp-flp-config-sub-generator/src/app/index.ts b/packages/adp-flp-config-sub-generator/src/app/index.ts index f3faf0547e..9e752e9dd8 100644 --- a/packages/adp-flp-config-sub-generator/src/app/index.ts +++ b/packages/adp-flp-config-sub-generator/src/app/index.ts @@ -57,12 +57,12 @@ export default class extends Generator { super(args, opts); this.appWizard = opts.appWizard ?? AppWizard.create(opts); this.launchAsSubGen = !!opts.launchAsSubGen; - this.manifest = opts.manifest as Manifest; + this.manifest = opts.manifest; this.toolsLogger = new ToolsLogger(); - this.logger = AdpFlpConfigLogger.logger; - this.projectRootPath = opts.data?.projectRootPath ?? this.destinationRoot(); + this._configureLogging(); + // If launched standalone add navigation steps if (!this.launchAsSubGen) { this._setupPrompts(); @@ -103,7 +103,7 @@ export default class extends Generator { try { await generateInboundConfig(this.projectRootPath, this.answers as InternalInboundNavigation, this.fs); } catch (error) { - this.logger.error(t('error.writingPhase', { error })); + this.logger.error(`Writing phase failed: ${error}`); throw new Error(t('error.updatingApp')); } } @@ -140,7 +140,7 @@ export default class extends Generator { throw new Error(t('error.systemNotFound')); } - const configuredSystem = (await getCredentialsFromStore(target as UrlAbapTarget, this.toolsLogger))?.name; + configuredSystem = (await getCredentialsFromStore(target as UrlAbapTarget, this.toolsLogger))?.name; if (!configuredSystem) { throw new Error(t('error.systemNotFoundInStore', { url })); } @@ -159,7 +159,11 @@ export default class extends Generator { const configuredSystem = await this._findConfiguredSystem(target); try { const systemSelectionQuestions = await getSystemSelectionQuestions({ - systemSelection: { onlyShowDefaultChoice: true, defaultChoice: configuredSystem }, + systemSelection: { + onlyShowDefaultChoice: true, + defaultChoice: configuredSystem, + showConnectionSuccessMessage: true + }, serviceSelection: { hide: true } }); await this.prompt(systemSelectionQuestions.prompts); @@ -172,7 +176,7 @@ export default class extends Generator { ); this.manifest = manifestService.getManifest(); } catch (error) { - this.logger.error(t('error.fetchingManifest', { error })); + this.logger.error(`Manifest fetching failed: ${error}`); throw new Error(t('error.fetchingManifest')); } } @@ -197,6 +201,20 @@ export default class extends Generator { } }; } + + /** + * Configures logging for the generator. + */ + private _configureLogging(): void { + AdpFlpConfigLogger.configureLogging( + this.options.logger, + this.rootGeneratorName(), + this.log, + this.options.vscode, + this.options.logLevel + ); + this.logger = AdpFlpConfigLogger.logger; + } } export type { FlpConfigOptions }; diff --git a/packages/adp-flp-config-sub-generator/src/app/types.ts b/packages/adp-flp-config-sub-generator/src/app/types.ts index 2421fe1e01..5933afa8cd 100644 --- a/packages/adp-flp-config-sub-generator/src/app/types.ts +++ b/packages/adp-flp-config-sub-generator/src/app/types.ts @@ -1,12 +1,36 @@ import type { AppWizard } from '@sap-devx/yeoman-ui-types'; import type { Manifest } from '@sap-ux/project-access'; import type Generator from 'yeoman-generator'; +import type { TelemetryData } from '@sap-ux/fiori-generator-shared'; export interface FlpConfigOptions extends Generator.GeneratorOptions { + /** + * VSCode instance + */ + vscode?: unknown; + /** + * Option to force the conflicter property of the yeoman environment (prevents additional prompt for overwriting files) + */ force?: boolean; + /** + * AppWizard instance + */ appWizard?: AppWizard; + /** + * Whether the generator is launched as a subgenerator + */ launchAsSubGen?: boolean; + /** + * The manifest of the base application + */ manifest: Manifest; + /** + * Telemetry data to be send after deployment configuration has been added + */ + telemetryData?: TelemetryData; + /** + * Additional data for the generator + */ data?: { projectRootPath: string; }; diff --git a/packages/adp-flp-config-sub-generator/src/translations/adp-flp-config-sub-generator.i18n.json b/packages/adp-flp-config-sub-generator/src/translations/adp-flp-config-sub-generator.i18n.json index c39dc8752b..0424f8285f 100644 --- a/packages/adp-flp-config-sub-generator/src/translations/adp-flp-config-sub-generator.i18n.json +++ b/packages/adp-flp-config-sub-generator/src/translations/adp-flp-config-sub-generator.i18n.json @@ -10,12 +10,11 @@ }, "error": { "cfNotSupported": "FLP Configuration is not supported for CF projects", - "fetchingManifest": "Error fetching merged manifest for app: {{- error}}", + "fetchingManifest": "Error fetching merged manifest for base application", "destinationNotFound": "Missing destination configuration in ui5.yaml", "systemNotFound": "Missing system configuration in ui5.yaml", "systemNotFoundInStore" : "System not found in the system store: {{- systemUrl}}", - "endPhase": "Error in end phase of the adaptation project FLP configuration: {{- error}}", - "writingPhase": "Error in writing phase of the adaptation project FLP configuration: {{- error}}", + "writingPhase": "Error in writing phase of the adaptation project FLP configuration", "telemetry": "Error sending telemetry data: {{- error}}", "updatingApp": "Error updating app with FLP configuration. Inspect the logs for full error." } diff --git a/packages/adp-flp-config-sub-generator/test/app.test.ts b/packages/adp-flp-config-sub-generator/test/app.test.ts index 4b98fea047..e15629236e 100644 --- a/packages/adp-flp-config-sub-generator/test/app.test.ts +++ b/packages/adp-flp-config-sub-generator/test/app.test.ts @@ -27,12 +27,6 @@ jest.mock('@sap-ux/adp-tooling', () => ({ generateInboundConfig: jest.fn() })); -jest.mock('../src/utils/logger', () => ({ - logger: { - error: jest.fn() - } -})); - jest.mock('@sap-ux/fiori-generator-shared', () => ({ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion ...(jest.requireActual('@sap-ux/fiori-generator-shared') as {}),