Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Switch Adaptation Project's generator/wizard to use Open Source writers #1775

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
d207584
feat: enhance writer for ADP Project to be able to create proper ADP …
IvoSG Mar 24, 2024
bb4a0a0
feat: enhance s4hana project generation
IvoSG Mar 25, 2024
363a702
feat: enhance cf project generation
IvoSG Apr 2, 2024
2cffde0
Merge branch 'main' of https://github.com/SAP/open-ux-tools into feat…
IvoSG Apr 2, 2024
774f0ac
fix/lint errors and tests
IvoSG Apr 2, 2024
a9ae35a
fix: unit tests and code corrections
IvoSG Apr 3, 2024
ef58dd5
Linting auto fix commit
github-actions[bot] Apr 3, 2024
9aa7edc
chore: add changeset
IvoSG Apr 3, 2024
0d0bef9
Merge branch 'feat/1611/writersForAdpProjects' of https://github.com/…
IvoSG Apr 3, 2024
464b534
fix: sonar security issue
IvoSG Apr 3, 2024
5ad6495
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG Apr 3, 2024
82b0238
chore: split the project template files for the different environments
IvoSG Apr 16, 2024
32a3214
chore: use btp-utils to check the running environment
IvoSG Apr 16, 2024
5956a34
chore: split the writers logic
IvoSG Apr 16, 2024
8a25655
chore: add writer factory to instantiate class for different environm…
IvoSG Apr 16, 2024
5d6d4cb
fix: remove cf writer logic, move project utils and fix ui5-deploy.ya…
IvoSG Apr 24, 2024
004b5cb
chore: use one project template for onprem and s4 project types
IvoSG Apr 24, 2024
f28ca6e
fix: ui5-deploy.yaml writer and add appredload middleware
IvoSG Apr 25, 2024
43ca69a
chore: revert all writers factory logic, revert project template stru…
IvoSG Apr 26, 2024
4af85b2
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG Apr 26, 2024
8ac89f4
chore: revert autoupdated import type
IvoSG Apr 26, 2024
09d5cf4
fix: add whitespace
IvoSG Apr 26, 2024
d42387b
fix: merge issue
IvoSG Apr 26, 2024
0e31e07
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG Apr 30, 2024
2507b01
chore: change types and remove unit tests for cf
IvoSG Apr 30, 2024
cb495b2
fix: default url if not provided
IvoSG Apr 30, 2024
0ca6004
fix: remove .env file, write only changes in apdescr content, use fra…
IvoSG May 16, 2024
3dba791
fix: typo
IvoSG May 16, 2024
6c21e2f
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG May 16, 2024
0516fc4
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG May 17, 2024
35a6347
fix: migrator ui5 yaml writers
IvoSG May 17, 2024
a2c2b71
chore: remove credentials from ui5.yaml config, move inbound change l…
IvoSG May 22, 2024
1da5255
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG May 22, 2024
3bed8d2
Merge branch 'main' of https://github.com/SAP/open-ux-tools into feat…
IvoSG May 23, 2024
edb43db
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG May 23, 2024
b970461
Merge branch 'main' into feat/1611/writersForAdpProjects
tobiasqueck May 24, 2024
31153cf
Merge branch 'main' into feat/1611/writersForAdpProjects
tobiasqueck May 27, 2024
196fc44
chore: resolve code review comments
IvoSG May 29, 2024
0e12110
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG May 29, 2024
4158c84
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG May 29, 2024
113e2af
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG May 30, 2024
513b0f7
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG Jun 3, 2024
328b15d
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG Jun 3, 2024
c05b0dd
fix: add JSDoc to the types, remove unused tests and revert fs, cover…
IvoSG Jun 4, 2024
8f5b365
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG Jun 4, 2024
bce2d5c
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG Jun 4, 2024
db1a539
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG Jun 4, 2024
a6ac36a
chore: move new inbound navigation properties to an internal type
IvoSG Jun 5, 2024
78f7a82
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG Jun 5, 2024
c190b64
fix: adapt existed tests
IvoSG Jun 5, 2024
a933d59
test: adding missing tests, refactoring tests
IvoSG Jun 6, 2024
5e74a2a
fix: resolve sonar issue
IvoSG Jun 6, 2024
be4d7e1
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG Jun 6, 2024
515d984
Merge branch 'main' into feat/1611/writersForAdpProjects
IvoSG Jun 6, 2024
114591d
Merge branch 'main' into feat/1611/writersForAdpProjects
GDamyanov Jun 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/famous-panthers-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@sap-ux/adp-tooling': minor
'@sap-ux/preview-middleware': patch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove preview-middleware and axios-extension from the changeset.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

'@sap-ux/axios-extension': patch
---

Adds writer functionality for generation of adaptation projects
33 changes: 31 additions & 2 deletions packages/adp-tooling/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { UI5FlexLayer } from '@sap-ux/project-access';
import type { DestinationAbapTarget, UrlAbapTarget } from '@sap-ux/system-access';
import type { Adp } from '@sap-ux/ui5-config';
import type { Adp, BspApp } from '@sap-ux/ui5-config';
import type { OperationsType } from '@sap-ux/axios-extension';
import type { Editor } from 'mem-fs-editor';

export interface DescriptorVariant {
Expand Down Expand Up @@ -31,19 +32,34 @@ export interface AdpWriterConfig {
reference: string;
layer?: UI5FlexLayer;
title?: string;
content?: Content[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are only using it if it is a cloud system (if I read the code correctly) which I think is a bit odd because the API does not indicate that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content is used by both onPrem and Cloud if it's provided

};
target: AbapTarget;
ui5?: {
tobiasqueck marked this conversation as resolved.
Show resolved Hide resolved
minVersion?: string;
version?: string;
frameworkUrl?: string;
};
package?: {
name?: string;
description?: string;
};
flp?: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That object is odd. bspName and credentials are used to access the original app while title, subtitle and inboundId are only being used in the i18n file. Did you miss adding a change to the appdescr if these properties are present or did I miss it in the code or is there some magic backend functionality that does something on deploy?

What is the difference between bspName and reference in the app section?

Copy link
Contributor Author

@IvoSG IvoSG May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the title, subtitle and inbound id are only used in the i18n file because the appdescr information comes already filtered after the prompting.
bspName is the base app repoName and reference is the base app id

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed on the phone, please add the change for the inbound communication to the appdescr template file with the condtion that the flp object is provided

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change for the inbound it's more complex to be in the aprdescr template and because of that it's passed with other changes in the content

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is too complex for ejs, implement it as a plain function and then add it to the list of changes. Most importantly move the logic here because you have a reference to it in your generated i18n.properties file

title?: string;
subtitle?: string;
inboundId?: string;
bspName?: string;
languages?: Language[];
credentials?: {
username: string;
password: string;
};
};
customConfig?: AdpCustomConfig;
/**
* Optional: configuration for deployment to ABAP
*/
deploy?: Adp;
deploy?: Adp | BspApp;
options?: {
/**
* Optional: if set to true then the generated project will be recognized by the SAP Fiori tools
Expand All @@ -52,6 +68,11 @@ export interface AdpWriterConfig {
};
}

export interface Language {
sap: string;
i18n: string;
}

export interface ManifestAppdescr {
fileName: string;
layer: string;
Expand Down Expand Up @@ -171,6 +192,7 @@ export type IWriterData<T extends ChangeType> = IWriter<GeneratorData<T>>;
*
* @template T - The specific type of data the writer will handle, determined by the associated ChangeType.
*/

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this extra empty line as it detaches the jsdoc from the interface.

export interface IWriter<T> {
/**
* Writes the provided data to the project.
Expand Down Expand Up @@ -340,3 +362,10 @@ export interface AdpProjectData {
reference: string;
id: string;
}

export interface AdpCustomConfig {
adp: {
safeMode: boolean;
nikmace marked this conversation as resolved.
Show resolved Hide resolved
environment: OperationsType;
};
}
44 changes: 16 additions & 28 deletions packages/adp-tooling/src/writer/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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 { create, type Editor } from 'mem-fs-editor';
import type { AdpWriterConfig } from '../types';
import { UI5Config } from '@sap-ux/ui5-config';
import { enhanceUI5Yaml, enhanceUI5DeployYaml, hasDeployConfig } from './options';
import {
writeTemplateToFolder,
writeUI5Yaml,
writeUI5DeployYaml,
} from './project-utils';

const tmplPath = join(__dirname, '../../templates/project');

Expand All @@ -20,7 +22,9 @@ function setDefaults(config: AdpWriterConfig): AdpWriterConfig {
target: { ...config.target },
ui5: { ...config.ui5 },
deploy: config.deploy ? { ...config.deploy } : undefined,
options: { ...config.options }
options: { ...config.options },
flp: config.flp ? { ...config.flp } : undefined,
customConfig: config.customConfig ? { ...config.customConfig } : undefined,
};
configWithDefaults.app.title ??= `Adaptation of ${config.app.reference}`;
configWithDefaults.app.layer ??= 'CUSTOMER_BASE';
Expand All @@ -32,21 +36,6 @@ function setDefaults(config: AdpWriterConfig): AdpWriterConfig {
return configWithDefaults;
}

async function writeUi5Yaml(basePath: string, config: AdpWriterConfig, fs: Editor) {
// ui5.yaml
const ui5ConfigPath = join(basePath, 'ui5.yaml');
const baseUi5ConfigContent = fs.read(ui5ConfigPath);
const ui5Config = await UI5Config.newInstance(baseUi5ConfigContent);
enhanceUI5Yaml(ui5Config, config);
fs.write(ui5ConfigPath, ui5Config.toString());
// ui5-deploy.yaml
if (hasDeployConfig(config)) {
const ui5DeployConfig = await UI5Config.newInstance(baseUi5ConfigContent);
enhanceUI5DeployYaml(ui5DeployConfig, config);
fs.write(join(basePath, 'ui5-deploy.yaml'), ui5DeployConfig.toString());
}
}

/**
* Writes the adp-project template to the mem-fs-editor instance.
*
Expand All @@ -59,14 +48,12 @@ export async function generate(basePath: string, config: AdpWriterConfig, fs?: E
if (!fs) {
fs = create(createStorage());
}
const fullConfig = setDefaults(config);

fs.copyTpl(join(tmplPath, '**/*.*'), join(basePath), fullConfig, undefined, {
globOptions: { dot: true },
processDestinationPath: (filePath: string) => filePath.replace(/gitignore.tmpl/g, '.gitignore')
});
const fullConfig = setDefaults(config);

await writeUi5Yaml(basePath, fullConfig, fs);
writeTemplateToFolder(join(tmplPath, '**/*.*'), join(basePath), fullConfig, fs);
await writeUI5DeployYaml(basePath, fullConfig, fs);
await writeUI5Yaml(basePath, fullConfig, fs);

return fs;
}
Expand Down Expand Up @@ -109,7 +96,8 @@ export async function migrate(basePath: string, config: AdpWriterConfig, fs?: Ed
fs.delete(join(basePath, 'neo-app.json'));
}

await writeUi5Yaml(basePath, fullConfig, fs);
await writeUI5Yaml(basePath, fullConfig, fs);
await writeUI5DeployYaml(basePath, fullConfig, fs);

return fs;
}
}
85 changes: 81 additions & 4 deletions packages/adp-tooling/src/writer/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CustomMiddleware, UI5Config } from '@sap-ux/ui5-config';
import type { AdpWriterConfig } from '../types';
import type { CustomMiddleware, UI5Config, CustomTask, AbapTarget } from '@sap-ux/ui5-config';
import type { AdpCustomConfig, AdpWriterConfig, Language } from '../types';

/**
* Generate the configuration for the middlewares required for the ui5.yaml.
Expand All @@ -9,9 +9,34 @@ import type { AdpWriterConfig } from '../types';
*/
export function enhanceUI5Yaml(ui5Config: UI5Config, config: AdpWriterConfig) {
const middlewares = config.options?.fioriTools ? getFioriToolsMiddlwares(config) : getOpenSourceMiddlewares(config);
ui5Config.setConfiguration({ propertiesFileSourceEncoding: 'UTF-8' });
ui5Config.addCustomMiddleware(middlewares);
}

/**
* Generate the configuration for the custom tasks required for the ui5.yaml.
*
* @param ui5Config configuration representing the ui5.yaml
* @param config full project configuration
*/
export function enhanceUI5YamlWithCustomTask(ui5Config: UI5Config, config: AdpWriterConfig) {
const tasks = getAdpCloudCustomTasks(config);
ui5Config.addCustomTasks(tasks);
}

/**
* Generate custom configuration required for the ui5.yaml.
*
* @param ui5Config configuration representing the ui5.yaml
* @param config full project configuration
*/
export function enhanceUI5YamlWithCustomConfig(ui5Config: UI5Config, config?: AdpCustomConfig) {
if (config?.adp) {
const { safeMode } = config.adp;
ui5Config.addCustomConfiguration('adp', { safeMode });
}
}

/**
* Writer configuration with deploy configuration.
*/
Expand Down Expand Up @@ -46,8 +71,17 @@ export function enhanceUI5DeployYaml(ui5Config: UI5Config, config: AdpWriterConf
function getFioriToolsMiddlwares(config: AdpWriterConfig): CustomMiddleware<unknown>[] {
return [
{
name: 'fiori-tools-preview',
name: 'fiori-tools-appreload',
afterMiddleware: 'compression',
configuration: {
port: 35729,
path: 'webapp',
delay: 300,
}
},
{
name: 'fiori-tools-preview',
afterMiddleware: 'fiori-tools-appreload',
configuration: {
adp: {
target: config.target,
Expand All @@ -61,8 +95,9 @@ function getFioriToolsMiddlwares(config: AdpWriterConfig): CustomMiddleware<unkn
configuration: {
ignoreCertErrors: false,
ui5: {
version: config?.ui5?.minVersion,
path: ['/resources', '/test-resources'],
url: 'https://ui5.sap.com'
url: config?.ui5?.frameworkUrl ?? 'https://ui5.sap.com'
},
backend: [
{
Expand All @@ -83,6 +118,15 @@ function getFioriToolsMiddlwares(config: AdpWriterConfig): CustomMiddleware<unkn
*/
function getOpenSourceMiddlewares(config: AdpWriterConfig): CustomMiddleware<object | undefined>[] {
return [
{
name: 'reload-middleware',
afterMiddleware: 'compression',
configuration: {
port: 35729,
path: 'webapp',
delay: 300,
}
},
{
name: 'preview-middleware',
afterMiddleware: 'compression',
Expand Down Expand Up @@ -120,3 +164,36 @@ function getOpenSourceMiddlewares(config: AdpWriterConfig): CustomMiddleware<obj
}
];
}

/**
* Get a list of required custom tasks for S4.
*
* @param config full project configuration
* @returns list of required tasks.
*/
function getAdpCloudCustomTasks(config: AdpWriterConfig & { target: AbapTarget }): CustomTask[] {
const user = 'env:FIORI_TOOLS_USER';
const pass = 'env:FIORI_TOOLS_PASSWORD';

return [
{
name: 'app-variant-bundler-build',
beforeTask: 'escapeNonAsciiCharacters',
configuration: {
type: 'abap',
destination: config.target?.destination,
appName: config?.flp?.bspName,
languages: config?.flp?.languages?.map((language: Language) => {
return {
sap: language.sap,
i18n: language.i18n
};
}),
credentials: {
username: user,
password: pass
}
}
}
];
}
84 changes: 84 additions & 0 deletions packages/adp-tooling/src/writer/project-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { join } from 'path';
import type { Editor } from 'mem-fs-editor';
import { AdpWriterConfig } from '../types';
import {
enhanceUI5DeployYaml,
enhanceUI5Yaml,
hasDeployConfig,
enhanceUI5YamlWithCustomConfig,
enhanceUI5YamlWithCustomTask
} from './options';
import { UI5Config } from '@sap-ux/ui5-config';

/**
* Writes a given project template files within a specified folder in the project directory.
*
* @param {string} templatePath - The root path of the project template.
* @param {string} projectPath - The root path of the project.
* @param {CfModuleData | AdpWriterConfig} data - The data to be populated in the template file.
* @param {Editor} fs - The `mem-fs-editor` instance used for file operations.
* @returns {void}
*/
export function writeTemplateToFolder(
templatePath: string,
projectPath: string,
data: AdpWriterConfig,
fs: Editor,
): void {
try {
fs.copyTpl(templatePath, projectPath, data, undefined, {
globOptions: { dot: true },
processDestinationPath: (filePath: string) => filePath.replace(/gitignore.tmpl/g, '.gitignore')
});
} catch (e) {
throw new Error(`Could not write template files to folder. Reason: ${e.message}`);
}
}

/**
* Writes a ui5.yaml file within a specified folder in the project directory.
*
* @param {string} projectPath - The root path of the project.
* @param {AdpWriterConfig} data - The data to be populated in the template file.
* @param {Editor} fs - The `mem-fs-editor` instance used for file operations.
* @returns {void}
*/
export async function writeUI5Yaml(projectPath: string, data: AdpWriterConfig, fs: Editor): Promise<void> {
try {
const ui5ConfigPath = join(projectPath, 'ui5.yaml');
const baseUi5ConfigContent = fs.read(ui5ConfigPath);
const ui5Config = await UI5Config.newInstance(baseUi5ConfigContent);
enhanceUI5Yaml(ui5Config, data);
enhanceUI5YamlWithCustomConfig(ui5Config, data?.customConfig);
if (data.customConfig?.adp?.environment === "C") {
enhanceUI5YamlWithCustomTask(ui5Config, data);
}

fs.write(ui5ConfigPath, ui5Config.toString());
} catch (e) {
throw new Error(`Could not write ui5.yaml file. Reason: ${e.message}`);
}
}

/**
* Writes a ui5-deploy.yaml file within a specified folder in the project directory.
*
* @param {string} projectPath - The root path of the project.
* @param {AdpWriterConfig} data - The data to be populated in the template file.
* @param {Editor} fs - The `mem-fs-editor` instance used for file operations.
* @returns {void}
*/
export async function writeUI5DeployYaml(projectPath: string, data: AdpWriterConfig, fs: Editor): Promise<void> {
try {
if (hasDeployConfig(data)) {
const ui5ConfigPath = join(projectPath, 'ui5.yaml');
const baseUi5ConfigContent = fs.read(ui5ConfigPath);
const ui5DeployConfig = await UI5Config.newInstance(baseUi5ConfigContent);
enhanceUI5DeployYaml(ui5DeployConfig, data);

fs.write(join(projectPath, 'ui5-deploy.yaml'), ui5DeployConfig.toString());
}
} catch (e) {
throw new Error(`Could not write ui5-deploy.yaml file. Reason: ${e.message}`);
}
}