-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: main
Are you sure you want to change the base?
Changes from 24 commits
d207584
bb4a0a0
363a702
2cffde0
774f0ac
a9ae35a
ef58dd5
9aa7edc
0d0bef9
464b534
5ad6495
82b0238
32a3214
5956a34
8a25655
5d6d4cb
004b5cb
f28ca6e
43ca69a
4af85b2
8ac89f4
09d5cf4
d42387b
0e31e07
2507b01
cb495b2
0ca6004
3dba791
6c21e2f
0516fc4
35a6347
a2c2b71
1da5255
3bed8d2
edb43db
b970461
31153cf
196fc44
0e12110
4158c84
113e2af
513b0f7
328b15d
c05b0dd
8f5b365
bce2d5c
db1a539
a6ac36a
78f7a82
c190b64
a933d59
5e74a2a
be4d7e1
515d984
114591d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@sap-ux/adp-tooling': minor | ||
'@sap-ux/preview-middleware': patch | ||
--- | ||
|
||
Adds writer functionality for generation of adaptation projects |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
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 { Editor } from 'mem-fs-editor'; | ||
|
||
export interface DescriptorVariant { | ||
|
@@ -35,21 +35,41 @@ export interface AdpWriterConfig { | |
target: AbapTarget; | ||
ui5?: { | ||
tobiasqueck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
minVersion?: string; | ||
ui5Version?: string; | ||
ui5EndpointUrl?: string; | ||
nikmace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
package?: { | ||
name?: string; | ||
description?: string; | ||
}; | ||
flp?: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That object is odd. What is the difference between There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
flpTitle?: string; | ||
flpSubtitle?: string; | ||
nikmace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
*/ | ||
fioriTools?: boolean; | ||
}; | ||
appdescr?: ManifestAppdescr; | ||
tobiasqueck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
export interface Language { | ||
sap: string; | ||
i18n: string; | ||
} | ||
|
||
export interface ManifestAppdescr { | ||
|
@@ -171,6 +191,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. | ||
*/ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
@@ -192,6 +213,14 @@ export const enum ChangeType { | |
CHANGE_INBOUND = 'appdescr_app_changeInbound' | ||
} | ||
|
||
/** | ||
* Enumerates the types of projects that can be made, each representing a specific kind of project structure. | ||
*/ | ||
export const enum ProjectType { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both are S/4 systems here, so please change it to something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
ON_PREM = 'OnPrem', | ||
S4 = 'S4', | ||
} | ||
|
||
/** | ||
* Maps a ChangeType to the corresponding data structure needed for that type of change. | ||
* This conditional type ensures type safety by linking each change type with its relevant data model. | ||
|
@@ -340,3 +369,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: ProjectType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBD: the environment is now 'OnPrem' but our change editors still have checks for 'ABAP' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nikmace Why would the change editors need to know about the target environment? |
||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
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, | ||
writeManifestAppdescr, | ||
writeUI5Yaml, | ||
writeUI5DeployYaml, | ||
writeEnvFile | ||
} from './project-utils'; | ||
|
||
/** | ||
* Set default values for optional properties. | ||
|
@@ -18,7 +22,10 @@ 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, | ||
appdescr: config.appdescr ? { ...config.appdescr } : undefined | ||
}; | ||
configWithDefaults.app.title ??= `Adaptation of ${config.app.reference}`; | ||
configWithDefaults.app.layer ??= 'CUSTOMER_BASE'; | ||
|
@@ -42,26 +49,18 @@ export async function generate(basePath: string, config: AdpWriterConfig, fs?: E | |
if (!fs) { | ||
fs = create(createStorage()); | ||
} | ||
|
||
const tmplPath = join(__dirname, '../../templates/project'); | ||
const fullConfig = setDefaults(config); | ||
const ignoredFiles = fullConfig.appdescr ? ['**/manifest.appdescr_variant'] : []; | ||
|
||
fs.copyTpl(join(tmplPath, '**/*.*'), join(basePath), fullConfig, undefined, { | ||
globOptions: { dot: true }, | ||
processDestinationPath: (filePath: string) => filePath.replace(/gitignore.tmpl/g, '.gitignore') | ||
}); | ||
|
||
// ui5.yaml | ||
const ui5ConfigPath = join(basePath, 'ui5.yaml'); | ||
const baseUi5ConfigContent = fs.read(ui5ConfigPath); | ||
const ui5Config = await UI5Config.newInstance(baseUi5ConfigContent); | ||
enhanceUI5Yaml(ui5Config, fullConfig); | ||
fs.write(ui5ConfigPath, ui5Config.toString()); | ||
// ui5-deploy.yaml | ||
if (hasDeployConfig(fullConfig)) { | ||
const ui5DeployConfig = await UI5Config.newInstance(baseUi5ConfigContent); | ||
enhanceUI5DeployYaml(ui5DeployConfig, fullConfig); | ||
fs.write(join(basePath, 'ui5-deploy.yaml'), ui5DeployConfig.toString()); | ||
writeTemplateToFolder(join(tmplPath, '**/*.*'), join(basePath), fullConfig, fs, ignoredFiles); | ||
if (fullConfig.appdescr) { | ||
writeManifestAppdescr(tmplPath, basePath, fullConfig.appdescr, fs); | ||
} | ||
await writeUI5DeployYaml(basePath, fullConfig, fs); | ||
await writeUI5Yaml(basePath, fullConfig, fs); | ||
await writeEnvFile(basePath, fullConfig, fs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the user know that we are writing user/password to the filesystem? If not, we cannot do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed, please remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
return fs; | ||
} | ||
} |
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. | ||
|
@@ -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. | ||
*/ | ||
|
@@ -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, | ||
|
@@ -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?.ui5EndpointUrl | ||
}, | ||
backend: [ | ||
{ | ||
|
@@ -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', | ||
|
@@ -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:ABAP_USERNAME'; | ||
const pass = 'env:ABAP_PASSWORD'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in my other comment, this shouldn't be here. In the very worst case that there is a valid scenario for this, use at least There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed on the phone, please remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
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 | ||
} | ||
} | ||
} | ||
]; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done