Skip to content

Commit

Permalink
Add sapuxlayer to package json (#2359)
Browse files Browse the repository at this point in the history
* add sapuxlayer

* document sapuxLayer property

* update snap shots and set default sapuxLayer

* update test name

* Update index.ts fix typp

* reverting default sap ux layer settings

* use package type from project-access in ui5-application-writer
  • Loading branch information
kjose90 authored Sep 18, 2024
1 parent 0e01690 commit fe1c8d2
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 23 deletions.
21 changes: 21 additions & 0 deletions packages/fiori-elements-writer/test/lrop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,25 @@ describe(`Fiori Elements template: ${TEST_NAME}`, () => {
await projectChecks(testPath, config, debug?.debugFull);
});
});

test('sapuxLayer is added to package json for edmx projects when provided', async () => {
const fioriElementsApp: FioriElementsApp<LROPSettings> = {
...Object.assign(feBaseConfig('felrop1'), {
template: {
type: TemplateType.ListReportObjectPage,
settings: v4TemplateSettings
}
}),
service: v4Service,
package: {
...feBaseConfig('felrop1').package,
sapuxLayer: 'CUSTOMER_BASE'
}
} as FioriElementsApp<LROPSettings>;

const fs = await generate(curTestOutPath, fioriElementsApp);
const packageJsonPath = join(curTestOutPath, 'package.json');
const packageJson = fs.readJSON(packageJsonPath);
expect((packageJson as any)?.sapuxLayer).toBe('CUSTOMER_BASE');
});
});
22 changes: 22 additions & 0 deletions packages/fiori-freestyle-writer/test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,28 @@ describe(`Fiori freestyle template: ${TEST_NAME}`, () => {
expect(await fs.read(Component.js).includes('my/demo/App')).toBeTruthy();
});

test('sapuxLayer is added to package json for edmx projects when provided', async () => {
const freestyleApp: FreestyleApp<any> = {
app: {
id: 'my.demo.App',
projectType: 'EDMXBackend'
},
package: {
name: 'my.demo.App',
sapuxLayer: 'CUSTOMER_BASE'
},
template: {
type: TemplateType.Basic,
settings: {}
}
};

const fs = await generate(curTestOutPath, freestyleApp);
const packageJsonPath = join(curTestOutPath, 'package.json');
const packageJson = fs.readJSON(packageJsonPath);
expect((packageJson as any)?.sapuxLayer).toBe('CUSTOMER_BASE');
});

describe('set view-name at scaffolding time', () => {
const viewPrefix = 'MainView';
const freestyleApp: FreestyleApp<BasicAppSettings> = {
Expand Down
3 changes: 2 additions & 1 deletion packages/ui5-application-writer/src/data/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { UI5_DEFAULT, getEsmTypesVersion, getTypesVersion, getTypesPackage } from '@sap-ux/ui5-config';
import type { App, AppOptions, Package, UI5, UI5Framework } from '../types';
import type { App, AppOptions, UI5, UI5Framework } from '../types';
import type { Package } from '@sap-ux/project-access';
import versionToManifestDescMapping from '@ui5/manifest/mapping.json'; // from https://github.com/SAP/ui5-manifest/blob/master/mapping.json
import { getUI5Libs } from './ui5Libs';
import semVer from 'semver';
Expand Down
8 changes: 7 additions & 1 deletion packages/ui5-application-writer/src/data/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { App, UI5, AppOptions, Package, Ui5App } from '../types';
import type { App, UI5, AppOptions, Ui5App } from '../types';
import type { Package } from '@sap-ux/project-access';
import { mergeObjects } from '@sap-ux/ui5-config';
import { mergeApp, packageDefaults, mergeUi5, getSpecTagVersion } from './defaults';
import { validate } from './validators';
Expand Down Expand Up @@ -31,6 +32,11 @@ export function mergeWithDefaults(ui5App: Ui5App): {
ui5App.package
);

if (!isEdmxProjectType) {
// sapuxLayer is not defined for cap projects
ui5App.package.sapuxLayer = undefined;
}

if (ui5App.appOptions.sapux && isEdmxProjectType) {
// Add @sap/ux-specification to devDependencies only for non-CAP projects
ui5App.package.devDependencies = ui5App.package.devDependencies || {};
Expand Down
3 changes: 2 additions & 1 deletion packages/ui5-application-writer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { join } from 'path';
import { create as createStorage } from 'mem-fs';
import type { Editor } from 'mem-fs-editor';
import { create } from 'mem-fs-editor';
import type { App, AppOptions, Package, UI5 } from './types';
import type { App, AppOptions, UI5 } from './types';
import type { Package } from '@sap-ux/project-access';
import { UI5Config, getEsmTypesVersion, getTypesPackage } from '@sap-ux/ui5-config';
import { getMinimumUI5Version, type Manifest } from '@sap-ux/project-access';
import { mergeWithDefaults } from './data';
Expand Down
13 changes: 1 addition & 12 deletions packages/ui5-application-writer/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import type { ProjectType } from '@sap-ux/project-access';
export interface Package {
name: string;
version?: string;
description?: string;
scripts?: Record<string, string>;
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
ui5?: {
dependencies?: string[];
};
}
import type { ProjectType, Package } from '@sap-ux/project-access';

export interface App {
id: string;
Expand Down
9 changes: 6 additions & 3 deletions packages/ui5-application-writer/templates/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
],
"main": "webapp/index.html",
"dependencies": {},
"devDependencies": <%- JSON.stringify(package.devDependencies, null, 8) -%>,
"scripts": <%- JSON.stringify(package.scripts, null, 4) -%>
}
"devDependencies": <%- JSON.stringify(package.devDependencies, null, 8).trim() -%>,
"scripts": <%- JSON.stringify(package.scripts, null, 4).trim() -%>
<% if (package.sapuxLayer) { %>
,"sapuxLayer": "<%= package.sapuxLayer %>"
<% } %>
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ archive.zip
\\"start\\": \\"ui5 serve --config=ui5.yaml --open index.html\\",
\\"start-local\\": \\"ui5 serve --config=ui5-local.yaml --open index.html\\",
\\"build\\": \\"ui5 build --config=ui5.yaml --clean-dest --dest dist\\"
}}
",
}
}",
"state": "modified",
},
"ui5-local.yaml": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ archive.zip
\\"start\\": \\"ui5 serve --config=ui5.yaml --open index.html\\",
\\"start-local\\": \\"ui5 serve --config=ui5-local.yaml --open index.html\\",
\\"build\\": \\"ui5 build --config=ui5.yaml --clean-dest --dest dist\\"
}}
",
}
}",
"state": "modified",
},
"ui5-local.yaml": Object {
Expand Down
5 changes: 4 additions & 1 deletion packages/ui5-application-writer/test/data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ describe('Setting defaults', () => {
devDepB: '9.10.11',
'@ui5/cli': '3.0.0'
},
sapuxLayer: 'CUSTOMER_BASE',
scripts: {
doTaskA: 'echo "Doing task A"',
doTaskB: 'echo "Doing task B"'
Expand All @@ -300,6 +301,7 @@ describe('Setting defaults', () => {
devDepB: '9.10.11'
},
name: 'test-package-name',
sapuxLayer: 'CUSTOMER_BASE',
scripts: {
start: 'ui5 serve --config=ui5.yaml --open index.html',
'start-local': 'ui5 serve --config=ui5-local.yaml --open index.html',
Expand Down Expand Up @@ -332,7 +334,8 @@ describe('Setting defaults', () => {
scripts: {
doTaskA: 'echo "Doing task A"',
doTaskB: 'echo "Doing task B"'
}
},
sapuxLayer: 'CUSTOMER_BASE' // expect sapuxLayer to be undefined for cap projects
}
};

Expand Down

0 comments on commit fe1c8d2

Please sign in to comment.