Skip to content

Commit

Permalink
fix(cf-deploy-config-writer): fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
longieirl committed Jan 24, 2025
1 parent 808ffd3 commit 7f781fe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
38 changes: 18 additions & 20 deletions packages/cf-deploy-config-writer/src/cf-writer/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ import {
import LoggerHelper from '../logger-helper';
import { t } from '../i18n';
import { type Logger } from '@sap-ux/logger';
import type { XSAppDocument } from '../types';
import { ApiHubType, type CFAppConfig, type CFConfig, type MTABaseConfig } from '../types';
import { type XSAppDocument, ApiHubType, type CFAppConfig, type CFConfig, type MTABaseConfig } from '../types';

/**
* Add a managed approuter configuration to an existing HTML5 application.
Expand Down Expand Up @@ -277,27 +276,26 @@ async function updateMtaConfig(cfConfig: CFConfig, fs: Editor): Promise<void> {
cfConfig.destinationAuthentication = Authentication.NO_AUTHENTICATION;
}
}
cleanupStandaloneRoutes(cfConfig, mtaInstance, fs);
await saveMta(cfConfig, mtaInstance);
cfConfig.cloudServiceName = mtaInstance.cloudServiceName;
}
}

// Cleanup standalone xs-app.json to reflect new application
const appRouterPath = mtaInstance.standaloneRouterPath;
if (appRouterPath) {
try {
const xsAppPath = join(appRouterPath, XSAppFile);
const appRouterXsAppObj = fs.readJSON(join(cfConfig.rootPath, xsAppPath)) as unknown as XSAppDocument;
if (
(appRouterXsAppObj && !appRouterXsAppObj?.[WelcomeFile]) ||
appRouterXsAppObj?.[WelcomeFile] === '/'
) {
appRouterXsAppObj[WelcomeFile] = `/${cfConfig.appId}`;
fs.writeJSON(join(cfConfig.rootPath, xsAppPath), appRouterXsAppObj);
}
} catch (error) {
LoggerHelper.logger?.error(t('error.cannotUpdateRouterXSApp', { error }));
function cleanupStandaloneRoutes({ rootPath, appId }: CFConfig, mtaInstance: MtaConfig, fs: Editor): void {
// Cleanup standalone xs-app.json to reflect new application
const appRouterPath = mtaInstance.standaloneRouterPath;
if (appRouterPath) {
try {
const xsAppPath = join(appRouterPath, XSAppFile);
const appRouterXsAppObj = fs.readJSON(join(rootPath, xsAppPath)) as unknown as XSAppDocument;
if ((appRouterXsAppObj && !appRouterXsAppObj?.[WelcomeFile]) || appRouterXsAppObj?.[WelcomeFile] === '/') {
appRouterXsAppObj[WelcomeFile] = `/${appId}`;
fs.writeJSON(join(rootPath, xsAppPath), appRouterXsAppObj);
}
} catch (error) {
LoggerHelper.logger?.error(t('error.cannotUpdateRouterXSApp', { error }));
}

await saveMta(cfConfig, mtaInstance);
cfConfig.cloudServiceName = mtaInstance.cloudServiceName;
}
}

Expand Down
27 changes: 13 additions & 14 deletions packages/cf-deploy-config-writer/src/mta-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@ import { join } from 'path';
import { render } from 'ejs';
import { MtaConfig } from './mta';
import { getTemplatePath, setMtaDefaults, validateVersion } from '../utils';
import { MTAYamlFile, MTAVersion, MTADescription, deployMode, enableParallelDeployments } from '../constants';
import {
MTAYamlFile,
MTAVersion,
MTADescription,
deployMode,
enableParallelDeployments,
CDSAddMtaParams,
CDSBinNotFound,
CDSExecutable,
MTABinNotFound,
MTAExecutable
} from '../constants';
import type { mta } from '@sap/mta-lib';
import { type MTABaseConfig, type CFBaseConfig } from '../types';
import LoggerHelper from '../logger-helper';
import { sync } from 'hasbin';
import { CDSAddMtaParams, CDSBinNotFound, CDSExecutable, MTABinNotFound, MTAExecutable } from '../constants';
import { spawnSync } from 'child_process';
import type { Editor } from 'mem-fs-editor';
import { t } from '../i18n';
Expand Down Expand Up @@ -121,18 +131,7 @@ export function doesCDSBinaryExist(): void {
}

/**
*
* @param cwd
* @param options
*/
export function addCAMtaServices(cwd: string, options?: string[]): void {
const result = spawnSync(CDSExecutable, [...CDSAddMtaParams, ...(options ?? [])], { cwd });
if (result.error) {
throw new Error(CDSBinNotFound);
}
}

/**
* Create MTA using `cds` binary to add mta and any optional services.
*
* @param cwd
* @param options
Expand Down

0 comments on commit 7f781fe

Please sign in to comment.