Skip to content

Commit d6b7440

Browse files
kjose90github-actions[bot]devinea
authored
Move cap updates to generate functions of FE/FF (#2810)
* add enable npm workspaces to appOptions * removing unecessary console logs * removing debugger * lint issues * Linting auto fix commit * unit tests * Linting auto fix commit * remove unused reference to package type * sonar qube fix * add documentation to enable npm workspaces type * add enableNPMWorkspaces doc to f-f-w * add comment * Move and types from to * remve old changeset * Linting auto fix commit * enable npm workspace comment * js doc fix * Linting auto fix commit * js doc fix * Linting auto fix commit * remove enable npm workspace options from ff and fe appOptions --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Austin Devine <[email protected]>
1 parent 8d067ca commit d6b7440

File tree

25 files changed

+330
-55
lines changed

25 files changed

+330
-55
lines changed

.changeset/friendly-toes-beg.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@sap-ux/odata-service-inquirer': major
3+
'@sap-ux/cap-config-writer': minor
4+
'@sap-ux/fiori-freestyle-writer': patch
5+
'@sap-ux/fiori-elements-writer': patch
6+
---
7+
8+
Move `CapService` and `CapRuntime` types from `@sap-ux/odata-service-inquirer` to `@sap-ux/cap-config-writer` for better relevance; add CAP updates to generate functions of Fiori Elements and Freestyle writers

packages/cap-config-writer/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"xml-js": "1.6.11"
4040
},
4141
"devDependencies": {
42-
"@sap-ux/odata-service-inquirer": "workspace:*",
4342
"@types/mem-fs": "1.1.2",
4443
"@types/mem-fs-editor": "7.0.1",
4544
"@types/semver": "7.5.2"

packages/cap-config-writer/src/cap-config/types.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CapService } from '@sap-ux/odata-service-inquirer';
1+
import type { CdsVersionInfo } from '@sap-ux/project-access';
22

33
export type CdsUi5PluginInfo = {
44
/**
@@ -19,6 +19,40 @@ export type CdsUi5PluginInfo = {
1919
hasCdsUi5Plugin: boolean;
2020
};
2121

22+
export type CapRuntime = 'Node.js' | 'Java';
23+
24+
export interface CapService {
25+
/**
26+
* The path to the CAP project.
27+
*/
28+
projectPath: string;
29+
/**
30+
* The CDS info for the Cds instance that was used to compile the project when determining the service.
31+
*/
32+
cdsVersionInfo?: CdsVersionInfo;
33+
/**
34+
* The name of the CAP service as identified by the cds model.
35+
*/
36+
serviceName: string;
37+
/**
38+
* The URL path to the service, as specfied in the manifest.json of generated apps
39+
* This is also provided as `OdataServicePromptAnswers` property `servicePath`
40+
*/
41+
urlPath?: string;
42+
/**
43+
* The relative path (from the `projectPath`) to the service cds file.
44+
*/
45+
serviceCdsPath?: string;
46+
/**
47+
* The runtime of the Cds instance that was used to compile the project when determining the service.
48+
*/
49+
capType?: CapRuntime;
50+
/**
51+
* The relative path (from the `projectPath`) to the app folder
52+
*/
53+
appPath?: string;
54+
}
55+
2256
export interface CapServiceCdsInfo extends CapService {
2357
cdsUi5PluginInfo: CdsUi5PluginInfo;
2458
}

packages/cap-config-writer/src/cap-writer/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { t } from '../i18n';
2-
import type { CapRuntime } from '@sap-ux/odata-service-inquirer';
2+
import type { CapRuntime } from '../cap-config/types';
33

44
/**
55
* Returns the url to the specified cap app as served by `cds serve` or `cds watch`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { checkCdsUi5PluginEnabled, enableCdsUi5Plugin, satisfiesMinCdsVersion } from './cap-config';
2+
export type { CapService, CapRuntime } from './cap-config/types';
23
export type { CdsUi5PluginInfo, CapServiceCdsInfo, CapProjectSettings } from './cap-config/types';
34
export * from './cap-writer';

packages/cap-config-writer/test/unit/cap-writer/package-json.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CapRuntime } from '@sap-ux/odata-service-inquirer';
1+
import type { CapRuntime } from '../../../src/cap-config/types';
22
import { satisfiesMinCdsVersion } from '../../../src/cap-config/package-json';
33
import memFs from 'mem-fs';
44
import { ToolsLogger } from '@sap-ux/logger';

packages/cap-config-writer/tsconfig.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
{
1717
"path": "../logger"
1818
},
19-
{
20-
"path": "../odata-service-inquirer"
21-
},
2219
{
2320
"path": "../project-access"
2421
},

packages/fiori-elements-writer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@sap-ux/ui5-config": "workspace:*",
3838
"@sap-ux/ui5-test-writer": "workspace:*",
3939
"@sap-ux/fiori-generator-shared": "workspace:*",
40+
"@sap-ux/cap-config-writer": "workspace:*",
4041
"ejs": "3.1.10",
4142
"i18next": "20.6.1",
4243
"lodash": "4.17.21",

packages/fiori-elements-writer/src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import semVer from 'semver';
2121
import { initI18n } from './i18n';
2222
import { getBootstrapResourceUrls, getPackageScripts } from '@sap-ux/fiori-generator-shared';
2323
import { generateFpmConfig } from './fpmConfig';
24+
import { applyCAPUpdates, type CapProjectSettings } from '@sap-ux/cap-config-writer';
2425

2526
export const V2_FE_TYPES_AVAILABLE = '1.108.0';
2627
/**
@@ -206,6 +207,21 @@ async function generate<T extends {}>(basePath: string, data: FioriElementsApp<T
206207
fs
207208
);
208209
}
210+
if (feApp.service.capService) {
211+
const hasCdsUi5PluginInfo = !!feApp.service.capService.cdsUi5PluginInfo;
212+
const settings: CapProjectSettings = {
213+
appRoot: basePath,
214+
packageName: feApp.package.name ?? '',
215+
appId: feApp.app.id,
216+
sapux: feApp.appOptions?.sapux,
217+
enableTypescript: feApp.appOptions?.typescript,
218+
// Enable CDS UI5 plugin and NPM workspaces if the CDS UI5 plugin info is present
219+
enableCdsUi5Plugin: hasCdsUi5PluginInfo,
220+
enableNPMWorkspaces: hasCdsUi5PluginInfo
221+
};
222+
// apply cap updates when service is cap
223+
await applyCAPUpdates(fs, feApp.service.capService, settings);
224+
}
209225

210226
return fs;
211227
}

packages/fiori-elements-writer/src/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Ui5App, App, AppOptions } from '@sap-ux/ui5-application-writer';
22
import type { OdataService } from '@sap-ux/odata-service-writer';
3+
import type { CapServiceCdsInfo } from '@sap-ux/cap-config-writer';
34

45
export const TemplateType = {
56
Worklist: 'worklist',
@@ -109,7 +110,9 @@ export interface FioriApp extends App {
109110

110111
export interface FioriElementsApp<T> extends Ui5App {
111112
template: Template<T>;
112-
service: Omit<OdataService, 'model'>; // Model name will use defaults
113+
service: Omit<OdataService, 'model'> & {
114+
capService?: CapServiceCdsInfo;
115+
};
113116
app: FioriApp;
114117
appOptions: Partial<AppOptions> & {
115118
/**

packages/fiori-elements-writer/test/lrop.test.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { FioriElementsApp, LROPSettings } from '../src';
22
import { generate, TableType, TemplateType } from '../src';
33
import { join } from 'path';
44
import { removeSync } from 'fs-extra';
5+
import { OdataVersion } from '@sap-ux/odata-service-writer';
56
import {
67
testOutputDir,
78
debug,
@@ -17,6 +18,9 @@ import {
1718
} from './common';
1819
import { ServiceType } from '@sap-ux/odata-service-writer';
1920
import { type OdataService } from '@sap-ux/odata-service-writer';
21+
import { applyCAPUpdates, type CapServiceCdsInfo } from '@sap-ux/cap-config-writer';
22+
import { create as createStorage } from 'mem-fs';
23+
import { create } from 'mem-fs-editor';
2024

2125
const TEST_NAME = 'lropTemplates';
2226
if (debug?.enabled) {
@@ -32,6 +36,11 @@ jest.mock('read-pkg-up', () => ({
3236
})
3337
}));
3438

39+
jest.mock('@sap-ux/cap-config-writer', () => ({
40+
...jest.requireActual('@sap-ux/cap-config-writer'),
41+
applyCAPUpdates: jest.fn()
42+
}));
43+
3544
describe(`Fiori Elements template: ${TEST_NAME}`, () => {
3645
const curTestOutPath = join(testOutputDir, TEST_NAME);
3746

@@ -424,4 +433,89 @@ describe(`Fiori Elements template: ${TEST_NAME}`, () => {
424433
const packageJson = fs.readJSON(packageJsonPath);
425434
expect((packageJson as any)?.sapuxLayer).toBe('CUSTOMER_BASE');
426435
});
436+
437+
describe('CAP updates', () => {
438+
const capProjectSettings = {
439+
appRoot: curTestOutPath,
440+
packageName: 'felrop1',
441+
appId: 'felrop1',
442+
sapux: true,
443+
enableTypescript: undefined
444+
};
445+
446+
const getFioriElementsApp = (capService?: CapServiceCdsInfo) => {
447+
return {
448+
...Object.assign(feBaseConfig('felrop1'), {
449+
template: {
450+
type: TemplateType.ListReportObjectPage,
451+
settings: v4TemplateSettings
452+
}
453+
}),
454+
service: {
455+
version: OdataVersion.v4,
456+
capService
457+
},
458+
package: {
459+
...feBaseConfig('felrop1').package,
460+
sapuxLayer: 'CUSTOMER_BASE'
461+
}
462+
} as FioriElementsApp<LROPSettings>;
463+
};
464+
465+
afterEach(() => {
466+
jest.clearAllMocks();
467+
jest.resetAllMocks();
468+
});
469+
470+
test('should perform CAP updates when CAP service is available and cds ui5 plugin is enabled', async () => {
471+
const capService: CapServiceCdsInfo = {
472+
cdsUi5PluginInfo: {
473+
isCdsUi5PluginEnabled: true,
474+
hasMinCdsVersion: true,
475+
isWorkspaceEnabled: true,
476+
hasCdsUi5Plugin: true
477+
},
478+
projectPath: 'test/path',
479+
serviceName: 'test-service',
480+
capType: 'Node.js'
481+
};
482+
const fs = create(createStorage());
483+
484+
const fioriElementsApp = getFioriElementsApp(capService);
485+
await generate(curTestOutPath, fioriElementsApp, fs);
486+
expect(applyCAPUpdates).toBeCalledTimes(1);
487+
488+
expect(applyCAPUpdates).toBeCalledWith(fs, capService, {
489+
...capProjectSettings,
490+
enableNPMWorkspaces: true,
491+
enableCdsUi5Plugin: true
492+
});
493+
});
494+
495+
test('should perform CAP updates when CAP service is available and cds ui5 plugin is disabled', async () => {
496+
const fs = create(createStorage());
497+
const capServiceWithoutCdsUi5PluginInfo = {
498+
projectPath: 'test/path',
499+
serviceName: 'test-service',
500+
capType: 'Node.js'
501+
};
502+
const fioriElementsApp = getFioriElementsApp(capServiceWithoutCdsUi5PluginInfo as CapServiceCdsInfo);
503+
await generate(curTestOutPath, fioriElementsApp, fs);
504+
505+
expect(applyCAPUpdates).toBeCalledTimes(1);
506+
expect(applyCAPUpdates).toBeCalledWith(fs, capServiceWithoutCdsUi5PluginInfo, {
507+
...capProjectSettings,
508+
enableNPMWorkspaces: false,
509+
enableCdsUi5Plugin: false
510+
});
511+
});
512+
513+
test('should not perform CAP updates, when no cap service provided', async () => {
514+
const fs = create(createStorage());
515+
516+
const fioriElementsApp = getFioriElementsApp();
517+
await generate(curTestOutPath, fioriElementsApp, fs);
518+
expect(applyCAPUpdates).toBeCalledTimes(0);
519+
});
520+
});
427521
});

packages/fiori-elements-writer/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"outDir": "dist"
1111
},
1212
"references": [
13+
{
14+
"path": "../cap-config-writer"
15+
},
1316
{
1417
"path": "../eslint-plugin-fiori-tools"
1518
},

packages/fiori-freestyle-writer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@sap-ux/ui5-application-writer": "workspace:*",
3737
"@sap-ux/ui5-config": "workspace:*",
3838
"@sap-ux/fiori-generator-shared": "workspace:*",
39+
"@sap-ux/cap-config-writer": "workspace:*",
3940
"ejs": "3.1.10",
4041
"i18next": "20.6.1",
4142
"lodash": "4.17.21",

packages/fiori-freestyle-writer/src/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { UI5Config } from '@sap-ux/ui5-config';
1212
import { initI18n } from './i18n';
1313
import { getBootstrapResourceUrls, getPackageScripts } from '@sap-ux/fiori-generator-shared';
1414
import { getTemplateVersionPath, processDestinationPath } from './utils';
15+
import { applyCAPUpdates, type CapProjectSettings } from '@sap-ux/cap-config-writer';
1516

1617
/**
1718
* Generate a UI5 application based on the specified Fiori Freestyle floorplan template.
@@ -166,6 +167,27 @@ async function generate<T>(basePath: string, data: FreestyleApp<T>, fs?: Editor)
166167
fs.write(ui5LocalConfigPath, ui5LocalConfig.toString());
167168
}
168169

170+
if (ffApp.service?.capService) {
171+
const hasCdsUi5PluginInfo = !!ffApp.service.capService.cdsUi5PluginInfo;
172+
const settings: CapProjectSettings = {
173+
appRoot: basePath,
174+
packageName: ffApp.package.name ?? '',
175+
appId: ffApp.app.id,
176+
sapux: ffApp.appOptions?.sapux,
177+
enableTypescript: ffApp.appOptions?.typescript,
178+
// Enable CDS UI5 plugin and NPM workspaces if the CDS UI5 plugin info is present
179+
enableCdsUi5Plugin: hasCdsUi5PluginInfo,
180+
enableNPMWorkspaces: hasCdsUi5PluginInfo
181+
};
182+
// Enable CDS UI5 plugin and NPM workspaces if the CDS UI5 plugin info is present
183+
if (ffApp.service?.capService.cdsUi5PluginInfo) {
184+
settings.enableCdsUi5Plugin = true;
185+
settings.enableNPMWorkspaces = true;
186+
}
187+
// apply cap updates when service is cap
188+
await applyCAPUpdates(fs, ffApp.service.capService, settings);
189+
}
190+
169191
return fs;
170192
}
171193

packages/fiori-freestyle-writer/src/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Ui5App, App } from '@sap-ux/ui5-application-writer';
22
import type { OdataService } from '@sap-ux/odata-service-writer';
3+
import type { CapServiceCdsInfo } from '@sap-ux/cap-config-writer';
34

45
export const TemplateType = {
56
Basic: 'basic',
@@ -38,7 +39,9 @@ export interface FioriApp extends App {
3839
}
3940
export interface FreestyleApp<T> extends Ui5App {
4041
template: Template<T>;
41-
service?: OdataService;
42+
service?: OdataService & {
43+
capService?: CapServiceCdsInfo;
44+
};
4245
app: FioriApp;
4346
}
4447

0 commit comments

Comments
 (0)