generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/1841/add-NavTargetResolution
- Loading branch information
Showing
85 changed files
with
6,095 additions
and
482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const config = require('../../jest.base'); | ||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.