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

Revise launch config #2347

Merged
merged 21 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tidy-papayas-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sap-ux/launch-config': minor
---

Reverted the use of Node.js `fs` modules and replaced them with `mem-fs` for writing launch config files & Removed `writeApplicationInfoSettings()` from `@sap-ux/launch-config`
Refactoring create launch config functionalities.
2 changes: 0 additions & 2 deletions packages/launch-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
"@sap-ux/project-access": "workspace:*",
"@sap-ux/ui5-config": "workspace:*",
"@sap-ux/ui5-info": "workspace:*",
"@sap-ux/odata-service-inquirer": "workspace:*",
"@sap-ux/store": "workspace:*",
"i18next": "23.5.1",
"jsonc-parser": "3.2.0",
"mem-fs": "2.1.0",
Expand Down
30 changes: 14 additions & 16 deletions packages/launch-config/src/debug-config/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { DatasourceType, OdataVersion } from '@sap-ux/odata-service-inquirer';
import { basename } from 'path';
import { getLaunchConfig } from '../launch-config-crud/utils';
import type { LaunchConfig, LaunchJSON, DebugOptions, LaunchConfigEnv } from '../types';
import { FIORI_TOOLS_LAUNCH_CONFIG_HANDLER_ID } from '../types';
import { FIORI_TOOLS_LAUNCH_CONFIG_HANDLER_ID, ProjectDataSourceType } from '../types';

// debug constants
const testFlpSandboxHtml = 'test/flpSandbox.html';
Expand All @@ -27,7 +26,7 @@ function getEnvUrlParams(sapClientParam: string): string {
}

/**
* Creates a launch configuration.
* Gets launch configuration.
*
* @param {string} name - The name of the configuration.
* @param {string} cwd - The current working directory.
Expand All @@ -37,7 +36,7 @@ function getEnvUrlParams(sapClientParam: string): string {
* @param {string} [runConfig] - The optional run configuration for AppStudio.
* @returns {LaunchConfig} The launch configuration object.
*/
function createLaunchConfig(
function configureLaunchConfig(
name: string,
cwd: string,
runtimeArgs: string[],
Expand All @@ -56,13 +55,13 @@ function createLaunchConfig(
/**
* Configures the launch.json file based on provided options.
*
* @param rootFolder - The root folder path where the app will be generated.
* @param {string} cwd - The current working directory.
* @param {DebugOptions} configOpts - Configuration options for the launch.json file.
* @returns {LaunchJSON} The configured launch.json object.
*/
export function configureLaunchJsonFile(cwd: string, configOpts: DebugOptions): LaunchJSON {
export function configureLaunchJsonFile(rootFolder: string, cwd: string, configOpts: DebugOptions): LaunchJSON {
const {
projectPath,
isAppStudio,
datasourceType,
flpAppId,
Expand All @@ -73,24 +72,23 @@ export function configureLaunchJsonFile(cwd: string, configOpts: DebugOptions):
isFioriElement,
migratorMockIntent
} = configOpts;

const projectName = basename(projectPath);
const projectName = basename(rootFolder);
const flpAppIdWithHash = flpAppId && !flpAppId.startsWith('#') ? `#${flpAppId}` : flpAppId;
const startHtmlFile = flpSandboxAvailable ? testFlpSandboxHtml : indexHtml;
const runConfig = isAppStudio
? JSON.stringify({
handlerId: FIORI_TOOLS_LAUNCH_CONFIG_HANDLER_ID,
runnableId: projectPath
runnableId: rootFolder
})
: undefined;
const envUrlParam = getEnvUrlParams(sapClientParam);

const launchFile: LaunchJSON = { version: '0.2.0', configurations: [] };

// Add live configuration if the datasource is not from a metadata file
if (datasourceType !== DatasourceType.metadataFile) {
if (datasourceType !== ProjectDataSourceType.metadataFile) {
const startCommand = `${startHtmlFile}${flpAppIdWithHash}`;
const liveConfig = createLaunchConfig(
const liveConfig = configureLaunchConfig(
`Start ${projectName}`,
cwd,
['fiori', 'run'],
Expand All @@ -102,13 +100,13 @@ export function configureLaunchJsonFile(cwd: string, configOpts: DebugOptions):
}

// Add mock configuration for OData V2 or V4
if (odataVersion && [OdataVersion.v2, OdataVersion.v4].includes(odataVersion)) {
if (odataVersion && ['2.0', '4.0'].includes(odataVersion)) {
const params = `${flpAppIdWithHash ?? ''}`;
const mockCmdArgs =
isMigrator && odataVersion === OdataVersion.v2
isMigrator && odataVersion === '2.0'
? ['--open', `${testFlpSandboxMockServerHtml}${params}`]
kjose90 marked this conversation as resolved.
Show resolved Hide resolved
: ['--config', './ui5-mock.yaml', '--open', `${testFlpSandboxHtml}${params}`];
const mockConfig = createLaunchConfig(
const mockConfig = configureLaunchConfig(
`Start ${projectName} Mock`,
cwd,
['fiori', 'run'],
Expand All @@ -120,12 +118,12 @@ export function configureLaunchJsonFile(cwd: string, configOpts: DebugOptions):
}

// Add local configuration
const shouldUseMockServer = isFioriElement && odataVersion === OdataVersion.v2 && isMigrator;
const shouldUseMockServer = isFioriElement && odataVersion === '2.0' && isMigrator;
const localHtmlFile = shouldUseMockServer ? testFlpSandboxMockServerHtml : startHtmlFile;
const startLocalCommand = `${localHtmlFile}${
migratorMockIntent ? `#${migratorMockIntent.replace('#', '')}` : flpAppIdWithHash
}`;
const localConfig = createLaunchConfig(
const localConfig = configureLaunchConfig(
`Start ${projectName} Local`,
cwd,
['fiori', 'run'],
Expand Down
25 changes: 13 additions & 12 deletions packages/launch-config/src/debug-config/workspaceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { formatCwd, getLaunchJsonPath, isFolderInWorkspace, handleAppsNotInWorks
* @param {any} vscode - The VS Code API object.
* @returns {WorkspaceHandlerInfo} An object containing the path to the `launch.json` configuration file and the cwd for the launch configuration.
*/
export function handleUnsavedWorkspace(projectPath: string, vscode: any): WorkspaceHandlerInfo {
function handleUnsavedWorkspace(projectPath: string, vscode: any): WorkspaceHandlerInfo {
const workspace = vscode.workspace;
const wsFolder = workspace.getWorkspaceFolder(vscode.Uri.file(projectPath))?.uri?.fsPath;
const nestedFolder = relative(wsFolder ?? projectPath, projectPath);
Expand All @@ -31,7 +31,7 @@ export function handleUnsavedWorkspace(projectPath: string, vscode: any): Worksp
* @param {any} vscode - The VS Code API object.
* @returns {WorkspaceHandlerInfo} An object containing the path to the `launch.json` configuration file and the cwd for the launch configuration.
*/
export function handleSavedWorkspace(
function handleSavedWorkspace(
projectPath: string,
projectName: string,
targetFolder: string,
Expand All @@ -58,7 +58,7 @@ export function handleSavedWorkspace(
* @param {any} vscode - The VS Code API object.
* @returns {WorkspaceHandlerInfo} An object containing the path to the `launch.json` configuration file and the cwd for the launch configuration.
*/
export function handleOpenFolderButNoWorkspaceFile(
function handleOpenFolderButNoWorkspaceFile(
projectPath: string,
targetFolder: string,
isAppStudio: boolean,
Expand All @@ -83,37 +83,38 @@ export function handleOpenFolderButNoWorkspaceFile(
* This function handles different scenarios depending on whether a workspace is open,
* whether the project is inside or outside of a workspace, and other factors.
*
* @param rootFolder - The root folder path where the app will be generated.
* @param {DebugOptions} options - The options used to determine how to manage the workspace configuration.
* @param {string} options.projectPath -The project's path including project name.
* @param {boolean} [options.isAppStudio] - A boolean indicating whether the current environment is BAS.
* @param {boolean} [options.writeToAppOnly] - If true, write the launch configuration directly to the app folder, ignoring workspace settings.
* @param {any} options.vscode - The VS Code API object.
* @returns {WorkspaceHandlerInfo} An object containing the path to the `launch.json` configuration file, the cwd command, workspaceFolderUri if provided will enable reload.
*/
export function handleWorkspaceConfig(options: DebugOptions): WorkspaceHandlerInfo {
const { projectPath, isAppStudio = false, writeToAppOnly = false, vscode } = options;
export function handleWorkspaceConfig(rootFolder: string, options: DebugOptions): WorkspaceHandlerInfo {
const { isAppStudio = false, writeToAppOnly = false, vscode } = options;

const projectName = basename(projectPath);
const targetFolder = dirname(projectPath);
const projectName = basename(rootFolder);
const targetFolder = dirname(rootFolder);

// Directly handle the case where we ignore workspace settings
if (writeToAppOnly) {
return handleAppsNotInWorkspace(projectPath, isAppStudio, vscode);
return handleAppsNotInWorkspace(rootFolder, isAppStudio, vscode);
}
const workspace = vscode.workspace;
const workspaceFile = workspace?.workspaceFile;
// Handles the scenario where no workspace or folder is open in VS Code.
if (!workspace) {
return handleAppsNotInWorkspace(projectPath, isAppStudio, vscode);
return handleAppsNotInWorkspace(rootFolder, isAppStudio, vscode);
}
// Handle case where a folder is open, but not a workspace file
if (!workspaceFile) {
return handleOpenFolderButNoWorkspaceFile(projectPath, targetFolder, isAppStudio, vscode);
return handleOpenFolderButNoWorkspaceFile(rootFolder, targetFolder, isAppStudio, vscode);
}
// Handles the case where a previously saved workspace is open
if (workspaceFile.scheme === 'file') {
return handleSavedWorkspace(projectPath, projectName, targetFolder, isAppStudio, vscode);
return handleSavedWorkspace(rootFolder, projectName, targetFolder, isAppStudio, vscode);
}
// Handles the case where an unsaved workspace is open
return handleUnsavedWorkspace(projectPath, vscode);
return handleUnsavedWorkspace(rootFolder, vscode);
}
2 changes: 1 addition & 1 deletion packages/launch-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './types';
export { createLaunchConfig, configureLaunchConfig } from './launch-config-crud/create';
export { createLaunchConfig } from './launch-config-crud/create';
export { deleteLaunchConfig } from './launch-config-crud/delete';
export { convertOldLaunchConfigToFioriRun } from './launch-config-crud/modify';
export { getLaunchConfigs, getLaunchConfigByName } from './launch-config-crud/read';
Expand Down
Loading
Loading