Skip to content

Commit

Permalink
Merge branch 'main' into fix/1841/add-NavTargetResolution
Browse files Browse the repository at this point in the history
  • Loading branch information
heimwege committed Apr 19, 2024
2 parents ce86f56 + fdec55f commit 0664afc
Show file tree
Hide file tree
Showing 85 changed files with 6,095 additions and 482 deletions.
14 changes: 14 additions & 0 deletions examples/simple-generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @sap-ux/generator-simple-fe

## 0.3.40

### Patch Changes

- Updated dependencies [8b227bb4]
- @sap-ux/fiori-elements-writer@0.18.15

## 0.3.39

### Patch Changes

- Updated dependencies [4599ee7f]
- @sap-ux/fiori-elements-writer@0.18.14

## 0.3.38

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-generator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sap-ux/generator-simple-fe",
"version": "0.3.38",
"version": "0.3.40",
"description": "Simple example of a yeoman generator for Fiori elements.",
"license": "Apache-2.0",
"private": true,
Expand Down
15 changes: 15 additions & 0 deletions packages/adp-tooling/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# @sap-ux/adp-tooling

## 0.9.17

### Patch Changes

- fc55fd6b: Component Usages writer produces incorrect content of a change

## 0.9.16

### Patch Changes

- Updated dependencies [f8e16120]
- @sap-ux/project-access@1.19.10
- @sap-ux/axios-extension@1.11.6
- @sap-ux/system-access@0.3.20

## 0.9.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adp-tooling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bugs": {
"url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aadp-tooling"
},
"version": "0.9.15",
"version": "0.9.17",
"license": "Apache-2.0",
"author": "@SAP/ux-tools-team",
"main": "dist/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export class ComponentUsagesWriter implements IWriter<ComponentUsagesData> {
* @returns {object} The constructed content object for the component usages change.
*/
private constructContent({ component }: ComponentUsagesData): object {
const { data, usageId, settings, isLazy } = component;
const { data, usageId, settings, isLazy, name } = component;
const componentUsages = {
[usageId]: {
name: usageId,
name,
lazy: isLazy === 'true',
settings: parseStringToObject(settings),
data: parseStringToObject(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@ describe('ComponentUsagesWriter', () => {

expect(getGenericChangeMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ componentUsages: expect.anything() }),
expect.objectContaining({
componentUsages: {
[mockData.component.usageId]: {
name: mockData.component.name,
lazy: true,
settings: { key: 'value' },
data: { key: 'value' }
}
}
}),
ChangeType.ADD_COMPONENT_USAGES
);

Expand Down
8 changes: 8 additions & 0 deletions packages/app-config-writer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @sap-ux/app-config-writer

## 0.3.48

### Patch Changes

- Updated dependencies [f8e16120]
- @sap-ux/project-access@1.19.10
- @sap-ux/axios-extension@1.11.6

## 0.3.47

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/app-config-writer/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sap-ux/app-config-writer",
"description": "Add or update configuration for SAP Fiori tools application",
"version": "0.3.47",
"version": "0.3.48",
"repository": {
"type": "git",
"url": "https://github.com/SAP/open-ux-tools.git",
Expand Down
7 changes: 7 additions & 0 deletions packages/cap-config-writer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @sap-ux/cap-config-writer

## 0.2.30

### Patch Changes

- Updated dependencies [f8e16120]
- @sap-ux/project-access@1.19.10

## 0.2.29

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cap-config-writer/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sap-ux/cap-config-writer",
"description": "Add or update configuration for SAP CAP projects",
"version": "0.2.29",
"version": "0.2.30",
"repository": {
"type": "git",
"url": "https://github.com/SAP/open-ux-tools.git",
Expand Down
1 change: 1 addition & 0 deletions packages/cards-editor-config-writer/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
7 changes: 7 additions & 0 deletions packages/cards-editor-config-writer/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['../../.eslintrc'],
parserOptions: {
project: './tsconfig.eslint.json',
tsconfigRootDir: __dirname
}
};
7 changes: 7 additions & 0 deletions packages/cards-editor-config-writer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @sap-ux/cards-editor-config-writer

## 0.3.0

### Minor Changes

- 7693fcfc: Experimental middleware to create UI5 integration cards for Fiori elements applications
22 changes: 22 additions & 0 deletions packages/cards-editor-config-writer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# @sap-ux/cards-editor-config-writer

Adds or removes configuration for the experimental middleware module `@sap-ux/cards-editor-middleware` to an SAP UX project.

## Installation
Npm
`npm install --save @sap-ux/cards-editor-config-writer`

Yarn
`yarn add @sap-ux/cards-editor-config-writer`

Pnpm
`pnpm add @sap-ux/cards-editor-config-writer`

## Usage
npx @sap-ux/cards-editor-config-writer@latest

See more complex example in [`/test/unit`](./test/unit)

## Keywords
SAP Fiori elements
EXPERIMENTAL
2 changes: 2 additions & 0 deletions packages/cards-editor-config-writer/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const config = require('../../jest.base');
module.exports = config;
40 changes: 40 additions & 0 deletions packages/cards-editor-config-writer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@sap-ux/cards-editor-config-writer",
"version": "0.3.0",
"repository": {
"type": "git",
"url": "https://github.com/SAP/open-ux-tools.git",
"directory": "packages/cards-editor-config-writer"
},
"bugs": {
"url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Acards-editor-config-writer"
},
"license": "Apache-2.0",
"main": "dist/index.js",
"scripts": {
"build": "pnpm clean && tsc --build",
"watch": "tsc --watch",
"clean": "rimraf --glob dist test/test-output *.tsbuildinfo",
"format": "prettier --write '**/*.{js,json,ts,yaml,yml}' --ignore-path ../../.prettierignore",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"test": "jest --ci --forceExit --detectOpenHandles --colors"
},
"files": [
"LICENSE",
"dist"
],
"dependencies": {
"@sap-ux/ui5-config": "workspace:*",
"mem-fs": "2.1.0",
"mem-fs-editor": "9.4.0"
},
"devDependencies": {
"@types/mem-fs": "1.1.2",
"@types/mem-fs-editor": "7.0.1",
"@sap-ux/project-access": "workspace:*"
},
"engines": {
"node": ">=18.x"
}
}
102 changes: 102 additions & 0 deletions packages/cards-editor-config-writer/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { join } from 'path';
import type { Editor } from 'mem-fs-editor';
import { create as createStorage } from 'mem-fs';
import { create } from 'mem-fs-editor';
import type { Package } from '@sap-ux/project-access';
import { UI5Config } from '@sap-ux/ui5-config';

/**
* Check if package.json has devDependency to @ui5/cli version > 2.
*
* @param devDependencies - parsed devDependencies from package.json
* @returns - true: @ui/cli higher version 2; false: @ui/cli
*/
function isUi5CliHigherTwo(devDependencies: Partial<Record<string, string>>): boolean {
let isHigherTwo = false;
try {
const versionString = devDependencies['@ui5/cli'];
if (typeof versionString === 'string') {
const regex = /\d+/;
const result = regex.exec(versionString.split('.')[0]);
const majorVersionValue = result ? result[0] : '0';
const majorVersion = parseInt(majorVersionValue, 10);
isHigherTwo = majorVersion > 2;
}
} catch {
// if something went wrong we don't have @ui/cli > version 2
}
return isHigherTwo;
}

/**
* Updates the package.json file to include the cards editor middleware and the start-cards-generator script.
*
* @param basePath - The path to the project root
* @param fs - Mem-fs editor instance
*/
function updatePackageJson(basePath: string, fs: Editor) {
const packageJsonPath = join(basePath, 'package.json');
if (!fs.exists(packageJsonPath)) {
throw new Error('package.json not found');
}

const packageJson = (fs.readJSON(packageJsonPath) ?? {}) as Package;

packageJson.devDependencies ??= {};
packageJson.devDependencies['@sap-ux/cards-editor-middleware'] ??= '0';

packageJson.scripts ??= {};
packageJson.scripts['start-cards-generator'] = `fiori run --open 'test/flpGeneratorSandbox.html#Cards-generator'`;

if (!isUi5CliHigherTwo(packageJson.devDependencies)) {
packageJson.ui5 ??= {};
packageJson.ui5.dependencies ??= [];
if (!packageJson.ui5.dependencies.includes('@sap-ux/cards-editor-middleware')) {
packageJson.ui5.dependencies.push('@sap-ux/cards-editor-middleware');
}
}
fs.writeJSON(packageJsonPath, packageJson);
}

/**
* Updates the ui5.yaml file to include the cards editor middleware.
*
* @param basePath - The path to the project root
* @param fs - Mem-fs editor instance
* @param middlewares - The middlewares to add to the ui5.yaml file
*/
async function updateYaml(basePath: string, fs: Editor, middlewares: string[]) {
const ui5ConfigPath = join(basePath, 'ui5.yaml');
if (!fs.exists(ui5ConfigPath)) {
throw new Error('ui5.yaml not found');
}
const config = await UI5Config.newInstance(fs.read(ui5ConfigPath));
config.addCustomMiddleware(
middlewares
.filter((name) => !config.findCustomMiddleware(name))
.map((name) => ({
name,
afterMiddleware: 'compression',
configuration: undefined
}))
);
fs.write(ui5ConfigPath, config.toString());
}

/**
* Enables the cards editor in the given project.
*
* @param basePath - path to the project root
* @param fs - optional mem-fs editor instance
* @returns updated mem-fs editor instance
*/
export async function enableCardsEditor(basePath: string, fs?: Editor): Promise<Editor> {
if (!fs) {
fs = create(createStorage());
}

updatePackageJson(basePath, fs);
await updateYaml(basePath, fs, ['sap-cards-generator']);

return fs;
}
Loading

0 comments on commit 0664afc

Please sign in to comment.