@sap-ux/app-config-writer 1.0.10 → 1.1.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.
@@ -3,14 +3,17 @@ import type { ToolsLogger } from '@sap-ux/logger';
3
3
  /**
4
4
  * Enables the card generator configuration for the given application.
5
5
  *
6
- * This function updates the `ui5.yaml` file to include the necessary middlewares for the card generator
6
+ * This function validates that the project meets the minimum UI5 version requirements,
7
+ * then updates the `ui5.yaml` file to include the necessary middlewares for the card generator
7
8
  * and modifies the `package.json` file to add a script for starting the card generator.
8
9
  *
9
10
  * @param {string} basePath - The path to the project root.
10
11
  * @param {string} [yamlPath] - Optional path to the `ui5.yaml` configuration file.
11
12
  * @param {ToolsLogger} [logger] - Optional logger instance for logging messages.
12
13
  * @param {Editor} [fs] - Optional `mem-fs-editor` instance for file system operations. If not provided, a new instance will be created.
14
+ * @param {boolean} [updatePackage] - Optional flag to update the `package.json` file. Defaults to true.
13
15
  * @returns {Promise<Editor>} A promise that resolves to the updated `mem-fs-editor` instance.
16
+ * @throws {Error} If minimum UI5 version requirement is not met (EDMX: ≥1.121.0, CAP: ≥1.149.0).
14
17
  */
15
- export declare function enableCardGeneratorConfig(basePath: string, yamlPath?: string, logger?: ToolsLogger, fs?: Editor): Promise<Editor>;
18
+ export declare function enableCardGeneratorConfig(basePath: string, yamlPath?: string, logger?: ToolsLogger, fs?: Editor, updatePackage?: boolean): Promise<Editor>;
16
19
  //# sourceMappingURL=index.d.ts.map
@@ -4,6 +4,7 @@ import { create } from 'mem-fs-editor';
4
4
  import { getPreviewMiddleware, getIntentFromPreviewConfig, getCLIForPreview } from '../common/utils.js';
5
5
  import { FileName, readUi5Yaml } from '@sap-ux/project-access';
6
6
  import { updateMiddlewaresForPreview } from '../common/ui5-yaml.js';
7
+ import { ensureMinUI5Version } from './prerequisites.js';
7
8
  const DEPENDENCY_NAME = '@sap-ux/cards-editor-middleware';
8
9
  const CARDS_GENERATOR_MIDDLEWARE = 'sap-cards-generator';
9
10
  /**
@@ -76,20 +77,27 @@ async function updatePackageJson(basePath, fs, yamlPath, logger) {
76
77
  /**
77
78
  * Enables the card generator configuration for the given application.
78
79
  *
79
- * This function updates the `ui5.yaml` file to include the necessary middlewares for the card generator
80
+ * This function validates that the project meets the minimum UI5 version requirements,
81
+ * then updates the `ui5.yaml` file to include the necessary middlewares for the card generator
80
82
  * and modifies the `package.json` file to add a script for starting the card generator.
81
83
  *
82
84
  * @param {string} basePath - The path to the project root.
83
85
  * @param {string} [yamlPath] - Optional path to the `ui5.yaml` configuration file.
84
86
  * @param {ToolsLogger} [logger] - Optional logger instance for logging messages.
85
87
  * @param {Editor} [fs] - Optional `mem-fs-editor` instance for file system operations. If not provided, a new instance will be created.
88
+ * @param {boolean} [updatePackage] - Optional flag to update the `package.json` file. Defaults to true.
86
89
  * @returns {Promise<Editor>} A promise that resolves to the updated `mem-fs-editor` instance.
90
+ * @throws {Error} If minimum UI5 version requirement is not met (EDMX: ≥1.121.0, CAP: ≥1.149.0).
87
91
  */
88
- export async function enableCardGeneratorConfig(basePath, yamlPath, logger, fs) {
92
+ export async function enableCardGeneratorConfig(basePath, yamlPath, logger, fs, updatePackage = true) {
89
93
  fs = fs ?? create(createStorage());
94
+ // asserts minimum UI5 version requirement before proceeding
95
+ await ensureMinUI5Version(basePath, fs);
90
96
  await updateMiddlewaresForPreview(fs, basePath, yamlPath, logger);
91
97
  await updateMiddlewareConfigWithGeneratorPath(fs, basePath, yamlPath, logger);
92
- await updatePackageJson(basePath, fs, yamlPath, logger);
98
+ if (updatePackage) {
99
+ await updatePackageJson(basePath, fs, yamlPath, logger);
100
+ }
93
101
  return fs;
94
102
  }
95
103
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ /**
3
+ * Ensures the minimum UI5 version requirement for card generator is met.
4
+ * - For EDMX projects: UI5 version 1.121.0 or higher is required.
5
+ * - For CAP projects: UI5 version 1.149.0 or higher is required.
6
+ *
7
+ * @param basePath - base path to be used for the check
8
+ * @param fs - file system reference
9
+ * @throws {Error} if the minimum UI5 version requirement is not met
10
+ */
11
+ export declare function ensureMinUI5Version(basePath: string, fs: Editor): Promise<void>;
12
+ //# sourceMappingURL=prerequisites.d.ts.map
@@ -0,0 +1,26 @@
1
+ import { getMinimumUI5Version, getProjectType, findProjectRoot } from '@sap-ux/project-access';
2
+ import { gte } from 'semver';
3
+ import { readManifest } from '../common/utils.js';
4
+ const MIN_UI5_VERSION_EDMX = '1.121.0';
5
+ const MIN_UI5_VERSION_CAP = '1.149.0';
6
+ /**
7
+ * Ensures the minimum UI5 version requirement for card generator is met.
8
+ * - For EDMX projects: UI5 version 1.121.0 or higher is required.
9
+ * - For CAP projects: UI5 version 1.149.0 or higher is required.
10
+ *
11
+ * @param basePath - base path to be used for the check
12
+ * @param fs - file system reference
13
+ * @throws {Error} if the minimum UI5 version requirement is not met
14
+ */
15
+ export async function ensureMinUI5Version(basePath, fs) {
16
+ const { manifest } = await readManifest(basePath, fs);
17
+ const minUI5Version = getMinimumUI5Version(manifest);
18
+ const projectRoot = await findProjectRoot(basePath, true, true, fs);
19
+ const isEdmx = (await getProjectType(projectRoot)) === 'EDMXBackend';
20
+ const featureVersion = isEdmx ? MIN_UI5_VERSION_EDMX : MIN_UI5_VERSION_CAP;
21
+ // No or invalid sap.ui5.minUi5Version property value will lead to the check being passed
22
+ if (minUI5Version && !gte(minUI5Version, featureVersion)) {
23
+ throw new Error(`The card generator is only supported for projects with a minimum SAPUI5 version of ${featureVersion} or higher. The detected minimum SAPUI5 version is ${minUI5Version}. Update the sap.ui5.minUI5Version property in the manifest.json file and ensure the SAPUI5 version used is ${featureVersion} or higher.`);
24
+ }
25
+ }
26
+ //# sourceMappingURL=prerequisites.js.map
@@ -1,3 +1,4 @@
1
+ import { type Manifest } from '@sap-ux/project-access';
1
2
  import type { CustomMiddleware, UI5Config } from '@sap-ux/ui5-config';
2
3
  import type { PreviewConfigOptions, FioriToolsDeprecatedPreviewConfig } from '../types/index.js';
3
4
  import type { Editor } from 'mem-fs-editor';
@@ -47,4 +48,16 @@ export declare function getCLIForPreview(basePath: string, yamlFileName: string,
47
48
  * @param logger logger to report info to the user
48
49
  */
49
50
  export declare function deleteFiles(fs: Editor, files: string[], logger?: ToolsLogger): Promise<void>;
51
+ /**
52
+ * Reads the manifest.json file from the application path.
53
+ *
54
+ * @param appPath - path to the application root
55
+ * @param fs - file system reference
56
+ * @returns object containing the parsed manifest and its file path
57
+ * @throws {Error} if manifest.json is not found or sap.app section is missing
58
+ */
59
+ export declare function readManifest(appPath: string, fs: Editor): Promise<{
60
+ manifest: Manifest;
61
+ manifestPath: string;
62
+ }>;
50
63
  //# sourceMappingURL=utils.d.ts.map
@@ -1,6 +1,6 @@
1
- import { FileName, readUi5Yaml } from '@sap-ux/project-access';
1
+ import { FileName, readUi5Yaml, getWebappPath } from '@sap-ux/project-access';
2
2
  import { MiddlewareConfigs } from '../types/index.js';
3
- import { basename } from 'node:path';
3
+ import { basename, join } from 'node:path';
4
4
  /**
5
5
  * Type guard to check if the given configuration is a deprecated preview middleware configuration.
6
6
  *
@@ -71,4 +71,26 @@ export async function deleteFiles(fs, files, logger) {
71
71
  }
72
72
  });
73
73
  }
74
+ /**
75
+ * Reads the manifest.json file from the application path.
76
+ *
77
+ * @param appPath - path to the application root
78
+ * @param fs - file system reference
79
+ * @returns object containing the parsed manifest and its file path
80
+ * @throws {Error} if manifest.json is not found or sap.app section is missing
81
+ */
82
+ export async function readManifest(appPath, fs) {
83
+ const manifestPath = join(await getWebappPath(appPath, fs), FileName.Manifest);
84
+ const manifest = fs.readJSON(manifestPath);
85
+ if (!manifest) {
86
+ throw new Error(`The \`manifest.json\` file was not found at path: ${manifestPath}. Check the file exists.`);
87
+ }
88
+ if (!manifest['sap.app']) {
89
+ throw new Error(`The \`manifest.json\` file is missing the \`sap.app\` required section.`);
90
+ }
91
+ return {
92
+ manifest,
93
+ manifestPath
94
+ };
95
+ }
74
96
  //# sourceMappingURL=utils.js.map
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export { getSmartLinksTargetFromPrompt, simulatePrompt, includeTestRunnersPrompt } from './prompt/index.js';
2
2
  export { generateSmartLinksConfig } from './smartlinks-config/index.js';
3
3
  export { generateEslintConfig, convertEslintConfig } from './eslint-config/index.js';
4
- export { generateInboundNavigationConfig, readManifest } from './navigation-config/index.js';
4
+ export { generateInboundNavigationConfig } from './navigation-config/index.js';
5
+ export { readManifest } from './common/utils.js';
5
6
  export { generateVariantsConfig } from './variants-config/index.js';
6
7
  export { convertToVirtualPreview } from './preview-config/index.js';
7
8
  export { enableCardGeneratorConfig } from './cards-config/index.js';
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  export { getSmartLinksTargetFromPrompt, simulatePrompt, includeTestRunnersPrompt } from './prompt/index.js';
2
2
  export { generateSmartLinksConfig } from './smartlinks-config/index.js';
3
3
  export { generateEslintConfig, convertEslintConfig } from './eslint-config/index.js';
4
- export { generateInboundNavigationConfig, readManifest } from './navigation-config/index.js';
4
+ export { generateInboundNavigationConfig } from './navigation-config/index.js';
5
+ export { readManifest } from './common/utils.js';
5
6
  export { generateVariantsConfig } from './variants-config/index.js';
6
7
  export { convertToVirtualPreview } from './preview-config/index.js';
7
8
  export { enableCardGeneratorConfig } from './cards-config/index.js';
@@ -1,4 +1,4 @@
1
- import type { Manifest, ManifestNamespace } from '@sap-ux/project-access';
1
+ import type { ManifestNamespace } from '@sap-ux/project-access';
2
2
  import type { Editor } from 'mem-fs-editor';
3
3
  /**
4
4
  * Adds a basic inbound navigation configuration to the application manifest.
@@ -14,16 +14,4 @@ import type { Editor } from 'mem-fs-editor';
14
14
  * @returns file system reference
15
15
  */
16
16
  export declare function generateInboundNavigationConfig(appRootPath: string, { semanticObject, action, title, subTitle }: ManifestNamespace.Inbound[string], overwrite?: boolean, fs?: Editor): Promise<Editor>;
17
- /**
18
- * Validates the basic manifest structure and existence required for inbound navigation addition.
19
- *
20
- * @param appPath path to the application
21
- * @param fs Editor instance
22
- * @throws an error specifiying the validation failure
23
- * @returns the manifest object and manifest path
24
- */
25
- export declare function readManifest(appPath: string, fs: Editor): Promise<{
26
- manifest: Manifest;
27
- manifestPath: string;
28
- }>;
29
17
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,8 @@
1
- import { FileName, getWebappPath } from '@sap-ux/project-access';
2
1
  import { create as createStorage } from 'mem-fs';
3
2
  import { create } from 'mem-fs-editor';
4
3
  import { mergeObjects } from '@sap-ux/ui5-config';
5
- import { join } from 'node:path';
6
4
  import { NAV_CONFIG_NS, t } from '../i18n.js';
5
+ import { readManifest } from '../common/utils.js';
7
6
  /**
8
7
  * Adds a basic inbound navigation configuration to the application manifest.
9
8
  *
@@ -44,26 +43,4 @@ export async function generateInboundNavigationConfig(appRootPath, { semanticObj
44
43
  fs.extendJSON(manifestPath, { 'sap.app': Object.assign(manifest['sap.app'], { crossNavigation }) });
45
44
  return fs;
46
45
  }
47
- /**
48
- * Validates the basic manifest structure and existence required for inbound navigation addition.
49
- *
50
- * @param appPath path to the application
51
- * @param fs Editor instance
52
- * @throws an error specifiying the validation failure
53
- * @returns the manifest object and manifest path
54
- */
55
- export async function readManifest(appPath, fs) {
56
- const manifestPath = join(await getWebappPath(appPath, fs), FileName.Manifest);
57
- const manifest = fs.readJSON(manifestPath);
58
- if (!manifest) {
59
- throw Error(t('error.manifestNotFound', { path: manifestPath, ns: NAV_CONFIG_NS }));
60
- }
61
- if (!manifest['sap.app']) {
62
- throw Error(t('error.sapAppNotDefined', { ns: NAV_CONFIG_NS }));
63
- }
64
- return {
65
- manifest,
66
- manifestPath
67
- };
68
- }
69
46
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/app-config-writer",
3
3
  "description": "Add or update configuration for SAP Fiori tools application",
4
- "version": "1.0.10",
4
+ "version": "1.1.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -13,6 +13,16 @@
13
13
  },
14
14
  "license": "Apache-2.0",
15
15
  "main": "dist/index.js",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "./cards-config": {
22
+ "types": "./dist/cards-config/index.d.ts",
23
+ "default": "./dist/cards-config/index.js"
24
+ }
25
+ },
16
26
  "files": [
17
27
  "LICENSE",
18
28
  "dist",
@@ -29,8 +39,8 @@
29
39
  "prompts": "2.4.2",
30
40
  "semver": "7.7.4",
31
41
  "cross-spawn": "7.0.6",
32
- "@sap-ux/axios-extension": "2.0.3",
33
42
  "@sap-ux/ui5-application-writer": "2.0.4",
43
+ "@sap-ux/axios-extension": "2.0.3",
34
44
  "@sap-ux/btp-utils": "2.0.2",
35
45
  "@sap-ux/logger": "1.0.1",
36
46
  "@sap-ux/project-access": "2.1.2",
@@ -47,7 +57,7 @@
47
57
  "@types/cross-spawn": "6.0.6",
48
58
  "axios": "1.16.0",
49
59
  "nock": "14.0.11",
50
- "@sap-ux/preview-middleware": "1.0.17"
60
+ "@sap-ux/preview-middleware": "1.0.26"
51
61
  },
52
62
  "engines": {
53
63
  "node": ">=22.x"