@sap-ux/project-input-validator 0.3.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './deploy/validators';
2
2
  export * from './ui5/validators';
3
+ export * from './ui5/project-path-validators';
3
4
  export * from './general/validators';
4
5
  export * from './adp/validators';
5
6
  export * from './flp/validators';
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.addi18nResourceBundle = void 0;
18
18
  __exportStar(require("./deploy/validators"), exports);
19
19
  __exportStar(require("./ui5/validators"), exports);
20
+ __exportStar(require("./ui5/project-path-validators"), exports);
20
21
  __exportStar(require("./general/validators"), exports);
21
22
  __exportStar(require("./adp/validators"), exports);
22
23
  __exportStar(require("./flp/validators"), exports);
@@ -40,7 +40,10 @@
40
40
  "nameContainsSpecialCharacters": "Module name cannot contain special characters (\"~'!()*)",
41
41
  "nameNotUrlFriendly": "Module name can only contain URL-friendly characters",
42
42
  "invalidModuleName": "Invalid module name",
43
- "moduleAlreadyExists": "The module folder named: {{folderName}} already exists at the specified path"
43
+ "moduleAlreadyExists": "The module folder named: {{folderName}} already exists at the specified path",
44
+ "appFolderExistsAtPath": "A module with this name already exists in the folder: {{-path}}",
45
+ "folderContainsFioriApp": "The project folder path already contains an SAP Fiori application in the folder: {{-path}}. Please choose a different folder and try again.",
46
+ "folderContainsCapApp": "The selected project folder is part of an existing CAP project. This application must therefore use the local CAP project as the data source."
44
47
  },
45
48
  "general": {
46
49
  "invalidUrl": "Invalid URL: [{{-input}}]",
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Validates whether the specified target path is suitable for creating a Fiori App project.
3
+ * The function performs the following checks:
4
+ *
5
+ * 1. **CAP Project Check:** If `validateFioriAppFolder` is true, it checks if the target path is part of an existing CAP project.
6
+ * - Uses `findCapProjectRoot()` and `getCapProjectType()` to verify the presence of a CAP project.
7
+ * - Returns an error message if a CAP project is detected.
8
+ *
9
+ * 2. **Fiori App Project Check:** If `validateFioriAppFolder` is true, it checks if the target path contains a Fiori project.
10
+ * - Uses `findRootsForPath()` to determine if a Fiori application root exists.
11
+ * - Returns a success message if a valid Fiori app root is found, otherwise returns true.
12
+ *
13
+ * 3. **General Project Folder Check:**
14
+ * - Uses `validateProjectFolder()` to verify if the provided target path exists.
15
+ * - Ensures the target folder does not already contain a subfolder with the intended project name.
16
+ *
17
+ * @param targetPath - The target directory path where the Fiori app is to be created.
18
+ * @param appName - The application directory name.
19
+ * @param validateFioriAppFolder - If true, validates the target path as a Fiori App project folder.
20
+ * @returns A boolean value `true` if all validations pass; otherwise, an error message.
21
+ */
22
+ export declare function validateFioriAppTargetFolder(targetPath: string, appName: string, validateFioriAppFolder?: boolean): Promise<string | boolean>;
23
+ //# sourceMappingURL=project-path-validators.d.ts.map
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateFioriAppTargetFolder = validateFioriAppTargetFolder;
4
+ const project_access_1 = require("@sap-ux/project-access");
5
+ const validators_1 = require("./validators");
6
+ const i18n_1 = require("../i18n");
7
+ /**
8
+ * Returns true if the specified target path does not contain a Fiori project.
9
+ *
10
+ * @param targetDir the target directory path.
11
+ * @returns true, if not Fiori Project, or string message indicating that the path contains a Fiori project.
12
+ */
13
+ async function validateFioriAppProjectFolder(targetDir) {
14
+ // Check if the target directory contains a CAP project
15
+ if (!!(await (0, project_access_1.findCapProjectRoot)(targetDir, false)) || !!(await (0, project_access_1.getCapProjectType)(targetDir))) {
16
+ return (0, i18n_1.t)('ui5.folderContainsCapApp');
17
+ }
18
+ // Check if the target directory contains a Fiori project
19
+ const appRoot = await (0, project_access_1.findRootsForPath)(targetDir);
20
+ if (appRoot) {
21
+ return (0, i18n_1.t)('ui5.folderContainsFioriApp', { path: appRoot.appRoot });
22
+ }
23
+ else {
24
+ return true;
25
+ }
26
+ }
27
+ /**
28
+ * Validates whether the specified target path is suitable for creating a Fiori App project.
29
+ * The function performs the following checks:
30
+ *
31
+ * 1. **CAP Project Check:** If `validateFioriAppFolder` is true, it checks if the target path is part of an existing CAP project.
32
+ * - Uses `findCapProjectRoot()` and `getCapProjectType()` to verify the presence of a CAP project.
33
+ * - Returns an error message if a CAP project is detected.
34
+ *
35
+ * 2. **Fiori App Project Check:** If `validateFioriAppFolder` is true, it checks if the target path contains a Fiori project.
36
+ * - Uses `findRootsForPath()` to determine if a Fiori application root exists.
37
+ * - Returns a success message if a valid Fiori app root is found, otherwise returns true.
38
+ *
39
+ * 3. **General Project Folder Check:**
40
+ * - Uses `validateProjectFolder()` to verify if the provided target path exists.
41
+ * - Ensures the target folder does not already contain a subfolder with the intended project name.
42
+ *
43
+ * @param targetPath - The target directory path where the Fiori app is to be created.
44
+ * @param appName - The application directory name.
45
+ * @param validateFioriAppFolder - If true, validates the target path as a Fiori App project folder.
46
+ * @returns A boolean value `true` if all validations pass; otherwise, an error message.
47
+ */
48
+ async function validateFioriAppTargetFolder(targetPath, appName, validateFioriAppFolder) {
49
+ if (validateFioriAppFolder === true) {
50
+ const isFioriValid = await validateFioriAppProjectFolder(targetPath);
51
+ if (isFioriValid !== true) {
52
+ return isFioriValid;
53
+ }
54
+ }
55
+ const isProjectValid = (0, validators_1.validateProjectFolder)(targetPath, appName);
56
+ if (isProjectValid !== true) {
57
+ return isProjectValid;
58
+ }
59
+ return true;
60
+ }
61
+ //# sourceMappingURL=project-path-validators.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/project-input-validator",
3
- "version": "0.3.4",
3
+ "version": "0.5.0",
4
4
  "description": "Library to validate Fiori project input formats",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,8 @@
15
15
  "main": "dist/index.js",
16
16
  "dependencies": {
17
17
  "i18next": "23.5.1",
18
- "validate-npm-package-name": "5.0.0"
18
+ "validate-npm-package-name": "5.0.0",
19
+ "@sap-ux/project-access": "1.29.18"
19
20
  },
20
21
  "devDependencies": {
21
22
  "@types/validate-npm-package-name": "4.0.1",