From 787d4615b8079c2a7260349da4ec552d68a2ea26 Mon Sep 17 00:00:00 2001 From: I743583 Date: Thu, 5 Sep 2024 09:17:17 +0100 Subject: [PATCH] updates --- packages/ui5-application-writer/src/index.ts | 15 ++++++++------- packages/ui5-application-writer/src/types.ts | 13 +++++-------- .../ui5-application-writer/test/index.test.ts | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/packages/ui5-application-writer/src/index.ts b/packages/ui5-application-writer/src/index.ts index 67b8482756..b6780e30a8 100644 --- a/packages/ui5-application-writer/src/index.ts +++ b/packages/ui5-application-writer/src/index.ts @@ -8,7 +8,7 @@ import { getMinimumUI5Version, type Manifest } from '@sap-ux/project-access'; import { mergeWithDefaults } from './data'; import { ui5TSSupport } from './data/ui5Libs'; import { applyOptionalFeatures, enableTypescript as enableTypescriptOption, getTemplateOptions } from './options'; -import { Ui5App, API_HUB_API_KEY, API_HUB_TYPE } from './types'; +import { Ui5App } from './types'; /** * Writes the template to the memfs editor instance. @@ -19,7 +19,6 @@ import { Ui5App, API_HUB_API_KEY, API_HUB_TYPE } from './types'; * @returns the updated memfs editor instance */ async function generate(basePath: string, ui5AppConfig: Ui5App, fs?: Editor): Promise { - console.log("---- basePath ----", basePath); if (!fs) { fs = create(createStorage()); } @@ -86,11 +85,13 @@ async function generate(basePath: string, ui5AppConfig: Ui5App, fs?: Editor): Pr // write ui5 yaml fs.write(ui5ConfigPath, ui5Config.toString()); - // Create the files for apiHub integration. - fs.write( - `${basePath}/.env`, - `${API_HUB_API_KEY}=${ui5App.appOptions.apiHubConfig?.apiHubKey}\n${API_HUB_TYPE}=${ui5App.appOptions.apiHubConfig?.apiHubType}` - ); + if(ui5App.appOptions.apiHubConfig) { + // Create .env to store apiHub integration. + fs.write( + `${basePath}/.env`, + `API_HUB_API_KEY=${ui5App.appOptions.apiHubConfig.apiHubKey}\nAPI_HUB_TYPE=${ui5App.appOptions.apiHubConfig.apiHubType}` + ); + } return fs; } diff --git a/packages/ui5-application-writer/src/types.ts b/packages/ui5-application-writer/src/types.ts index bc9cf0f635..d57be9a978 100644 --- a/packages/ui5-application-writer/src/types.ts +++ b/packages/ui5-application-writer/src/types.ts @@ -146,14 +146,6 @@ export interface UI5 { customUi5Libs?: string[]; } -export const API_HUB_API_KEY = 'API_HUB_API_KEY'; -export const API_HUB_TYPE = 'API_HUB_TYPE'; - -const enum ApiHubType { - apiHub = 'API_HUB', - apiHubEnterprise = 'API_HUB_ENTERPRISE' -} - /** * SAP UX Layer */ @@ -162,6 +154,11 @@ export enum SapUxLayer { CUSTOMER_BASE = 'CUSTOMER_BASE' } +export const enum ApiHubType { + apiHub = 'API_HUB', + apiHubEnterprise = 'API_HUB_ENTERPRISE' +} + /** * Defines the api hub service properties or enterprise and non-enterprise versions */ diff --git a/packages/ui5-application-writer/test/index.test.ts b/packages/ui5-application-writer/test/index.test.ts index e17a435719..3f264313f9 100644 --- a/packages/ui5-application-writer/test/index.test.ts +++ b/packages/ui5-application-writer/test/index.test.ts @@ -5,6 +5,7 @@ import { create } from 'mem-fs-editor'; import type { Ui5App } from '../src'; import { generate, isTypescriptEnabled, enableTypescript } from '../src'; import { updatePackageJSONDependencyToUseLocalPath } from './common'; +import { ApiHubType } from '../src/types'; describe('UI5 templates', () => { const fs = create(createStorage()); @@ -151,4 +152,19 @@ describe('UI5 templates', () => { // Check if ui5.yaml exist expect(fs.exists(join(projectDir, 'ui5.yaml'))).toBe(true); }); + + it('Check that .env file is generated when apiHubConfig is provided', async () => { + let projectDir = join(outputDir, 'testapp-simple'); + ui5AppConfig.appOptions = { + apiHubConfig: { + apiHubKey: 'apiHubKeyTest:abcd1234', + apiHubType: ApiHubType.apiHub + } + } + projectDir = join(outputDir, 'testapp-withtoolsid'); + await generate(projectDir, ui5AppConfig, fs); + const envConfig = (fs.read(join(projectDir, '/.env')) as any) + expect(envConfig).toContain('API_HUB_API_KEY=apiHubKeyTest:abcd1234') + expect(envConfig).toContain('API_HUB_TYPE=API_HUB') + }); });