Skip to content

Commit

Permalink
fix: logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mmilko01 committed Jan 9, 2025
1 parent c40b159 commit c05ecf2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
32 changes: 25 additions & 7 deletions packages/adp-flp-config-sub-generator/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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'));
}
}
Expand Down Expand Up @@ -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 }));
}
Expand All @@ -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);
Expand All @@ -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'));
}
}
Expand All @@ -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 };
24 changes: 24 additions & 0 deletions packages/adp-flp-config-sub-generator/src/app/types.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Expand Down
6 changes: 0 additions & 6 deletions packages/adp-flp-config-sub-generator/test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}),
Expand Down

0 comments on commit c05ecf2

Please sign in to comment.