generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 54
tbi(odata-service-inq): improve detection of local CAP roots on CLI #3960
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
50989af
feat: implement automatic detection of local CAP roots and enhance pa…
mikicvi-SAP 4e2fe0b
Linting auto fix commit
github-actions[bot] 76ff09d
fix: path sep for windows test
mikicvi-SAP b662ee8
feat: questions filter tests for cap path
mikicvi-SAP 1de0015
fix: test under windows scenario
mikicvi-SAP 4eb618f
fix: platform agnostic path
mikicvi-SAP a1be19b
tbi: refactor to address sonar issues
mikicvi-SAP 94a19f2
Merge branch 'main' into tbi/3959/cap-root-detection-cli
mikicvi-SAP 14d12bc
tbi: fix lint issue
mikicvi-SAP 1635d6c
tbi: refactor to use existing project access implementation
mikicvi-SAP 6f9bdd6
tbi: translations feedback
mikicvi-SAP 973313a
tbi: replace strings with translations
mikicvi-SAP 84a652d
refactor: simplify implementation, handle relative paths
mikicvi-SAP 1de7c72
tbi: revert relative path support, add autocomplete for cap project s…
mikicvi-SAP 7b4bc99
Merge branch 'main' into tbi/3959/cap-root-detection-cli
mikicvi-SAP f564eb9
tbi: use separator for test
mikicvi-SAP a7f28a2
tbi: address feedback, simplify detection
mikicvi-SAP 7ccab1f
tbi: add more tests
mikicvi-SAP e4123bd
Linting auto fix commit
github-actions[bot] 7c5b03e
Merge branch 'main' into tbi/3959/cap-root-detection-cli
mikicvi-SAP b2c9659
Merge branch 'main' into tbi/3959/cap-root-detection-cli
mikicvi-SAP 0238e5f
Merge branch 'main' into tbi/3959/cap-root-detection-cli
mikicvi-SAP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@sap-ux/odata-service-inquirer': minor | ||
| --- | ||
|
|
||
| Automatic detection of local CAP roots, allow relative path usage for manual selection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 32 additions & 6 deletions
38
packages/odata-service-inquirer/src/prompts/datasources/cap-project/validators.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,45 @@ | ||
| import { getCapProjectType } from '@sap-ux/project-access'; | ||
| import { t } from '../../../i18n'; | ||
| import { resolveRelativeCliPath } from './cap-helpers'; | ||
|
|
||
| /** | ||
| * Ensure the path specified is a valid CAP project. | ||
| * Now supports relative paths like "../my-cap-project" by resolving them properly. | ||
| * | ||
| * @param capProjectPath - The path to the CAP project | ||
| * @param capProjectPath - The path to the CAP project (can be relative or absolute) | ||
| * @returns A boolean indicating if the path is a valid CAP project or an error message | ||
| */ | ||
| export async function validateCapPath(capProjectPath: string): Promise<boolean | string> { | ||
| if (capProjectPath) { | ||
| try { | ||
| return !!(await getCapProjectType(capProjectPath)) || t('prompts.validationMessages.capProjectNotFound'); | ||
| } catch (err) { | ||
| // Handle undefined/null case (when validate is called without parameters) - return false for backwards compatibility | ||
| if (capProjectPath === undefined || capProjectPath === null) { | ||
| return false; | ||
| } | ||
|
|
||
| // Empty path after filter means auto-detection failed or not in CLI mode | ||
| if (capProjectPath.trim() === '') { | ||
| return t('prompts.validationMessages.capProjectNotFound'); | ||
| } | ||
|
|
||
| try { | ||
| // Validate the resolved path | ||
| const resolvedPath = resolveRelativeCliPath(capProjectPath); | ||
| const capProjectType = await getCapProjectType(resolvedPath); | ||
|
|
||
| if (capProjectType) { | ||
| return true; | ||
| } else { | ||
| return t('prompts.validationMessages.capProjectNotFound'); | ||
| } | ||
| } catch (err) { | ||
| // Provide more specific error message for common issues | ||
| const errorMessage = err instanceof Error ? err.message : String(err); | ||
|
|
||
| if (errorMessage.includes('ENOENT') || errorMessage.includes('no such file or directory')) { | ||
| return t('prompts.validationMessages.capProjectNotFound'); | ||
| } else if (errorMessage.includes('EACCES') || errorMessage.includes('permission denied')) { | ||
| return t('prompts.validationMessages.permissionDenied'); | ||
| } else { | ||
| return t('prompts.validationMessages.capProjectNotFound'); | ||
| } | ||
| } | ||
| return false; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.