import { AbapApp , AbapTarget , CustomTask , FioriToolsProxyConfig , ProxyBackend , ProxyUIConfig } from './types' ; import { YamlDocument , NodeComment , YAMLMap } from '@sap-ux/yaml' ; import { getAppReloadMiddlewareConfig , getFioriToolsProxyMiddlewareConfig , getMockServerMiddlewareConfig } from './middlewares' ; import { CustomMiddleware } from 'index' ; class export class UI5Config { private document : YamlDocument ; static param { string } serializedYaml returns { UI5Config } memberof static async newInstance ( serializedYaml ) { const instance = new UI5Config ( ) ; instance . document = await YamlDocument . newInstance ( serializedYaml ) ; return instance ; } param { string } ui5Framework param { string } ui5Version param { string [ ] } ui5Libraries param { string } ui5Theme returns { UI5Config } memberof public addUI5Framework ( ui5Framework , ui5Version , ui5Libraries , ui5Theme = 'sap_fiori_3' ) { const libraryObjs = [ ] ; for ( const library of ui5Libraries ) { libraryObjs . push ( { name : library } ) ; } libraryObjs . push ( { name : `themelib_${ ui5Theme . replace ( /_dark$/ , '' ) }` } ) ; this . document . setIn ( { path : 'framework' , value : { name : ui5Framework , version : ui5Version , libraries : libraryObjs } } ) ; return this ; } param { CustomTask < any > [ ] } tasks param { NodeComment < CustomMiddleware < any > > [ ] } comments returns { UI5Config } memberof public addCustomTasks ( tasks , comments ? ) { for ( const task of tasks ) { this . document . appendTo ( { path : 'builder.customTasks' , value : task , comments } ) ; } return this ; } param { CustomMiddleware < any > [ ] } middlewares param { NodeComment < CustomMiddleware < any > > [ ] } comments returns { UI5Config } memberof public addCustomMiddleware ( middlewares , comments ? ) { for ( const mw of middlewares ) { this . document . appendTo ( { path : 'server.customMiddleware' , value : mw , comments } ) ; } return this ; } returns { UI5Config } memberof public addFioriToolsAppReloadMiddleware ( ) { this . document . appendTo ( { path : 'server.customMiddleware' , value : getAppReloadMiddlewareConfig ( ) } ) ; return this ; } param proxyConfig returns { UI5Config } memberof public addFioriToolsProxydMiddleware ( proxyConfig ) { const { config , comments } = getFioriToolsProxyMiddlewareConfig ( proxyConfig . backend , proxyConfig . ui5 ) ; this . document . appendTo ( { path : 'server.customMiddleware' , value : config , comments : comments as any } ) ; return this ; } param backend returns { UI5Config } memberof public addBackendToFioriToolsProxydMiddleware ( backend ) { const middlewareList = this . document . getSequence ( { path : 'server.customMiddleware' } ) ; const proxyMiddleware = this . document . findItem ( middlewareList , ( item ) => item . name === 'fiori-tools-proxy' ) ; if ( ! proxyMiddleware ) { throw new Error ( 'Could not find fiori-tools-proxy' ) ; } this . document . getMap ( { start : proxyMiddleware as YAMLMap , path : 'configuration' } ) . set ( 'backend' , [ backend ] ) ; return this ; } param ui5 returns { UI5Config } memberof public addUi5ToFioriToolsProxydMiddleware ( ui5 ) { try { const middlewareList = this . document . getSequence ( { path : 'server.customMiddleware' } ) ; const proxyMiddleware = this . document . findItem ( middlewareList , ( item ) => item . name === 'fiori-tools-proxy' ) ; if ( proxyMiddleware && ui5 !== undefined ) { const configurationUi5Doc = this . document . getMap ( { start : proxyMiddleware as YAMLMap , path : 'configuration.ui5' } ) ; if ( ui5 . version ) { configurationUi5Doc . set ( 'version' , ui5 . version ) ; } if ( ui5 . url ) { configurationUi5Doc . set ( 'url' , ui5 . url ) ; } if ( ui5 . directLoad ) { configurationUi5Doc . set ( 'directLoad' , ui5 . directLoad ) ; } } } catch ( e ) { } return this ; } param path returns { UI5Config } memberof public addMockServerMiddleware ( path ? ) { this . document . appendTo ( { path : 'server.customMiddleware' , value : getMockServerMiddlewareConfig ( path ) } ) ; return this ; } param target param app returns { UI5Config } memberof public addAbapDeployTask ( target , app ) { this . document . appendTo ( { path : 'builder.resources' , value : { excludes : [ '/test/**' , '/localService/**' ] } } ) ; this . document . appendTo ( { path : 'builder.customTasks' , value : { name : 'deploy-to-abap' , afterTask : 'generateCachebusterInfo' , configuration : { target , app } } } ) ; return this ; } param name returns { UI5Config } memberof public removeCustomMiddleware ( name ) { this . document . deleteAt ( { path : 'server.customMiddleware' , matcher : { key : 'name' , value : name } } ) ; return this ; } returns { string } memberof public toString ( ) { return this . document . toString ( ) ; } }