Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kjose90 committed Sep 5, 2024
1 parent dc197e8 commit 787d461
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
15 changes: 8 additions & 7 deletions packages/ui5-application-writer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<Editor> {
console.log("---- basePath ----", basePath);
if (!fs) {
fs = create(createStorage());
}
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 5 additions & 8 deletions packages/ui5-application-writer/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down
16 changes: 16 additions & 0 deletions packages/ui5-application-writer/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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')
});
});

0 comments on commit 787d461

Please sign in to comment.