@sap-ux/app-config-writer 0.7.5 → 1.0.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.
Files changed (46) hide show
  1. package/dist/cards-config/index.js +19 -22
  2. package/dist/common/package-json.js +19 -30
  3. package/dist/common/ui5-yaml.d.ts +2 -2
  4. package/dist/common/ui5-yaml.js +37 -48
  5. package/dist/common/utils.d.ts +1 -1
  6. package/dist/common/utils.js +13 -20
  7. package/dist/eslint-config/add.js +13 -16
  8. package/dist/eslint-config/convert.js +29 -35
  9. package/dist/eslint-config/index.d.ts +2 -2
  10. package/dist/eslint-config/index.js +2 -7
  11. package/dist/flp-embedded-config/index.js +11 -15
  12. package/dist/i18n.js +15 -25
  13. package/dist/index.d.ts +8 -8
  14. package/dist/index.js +8 -24
  15. package/dist/navigation-config/index.js +14 -18
  16. package/dist/preview-config/index.js +15 -18
  17. package/dist/preview-config/package-json.js +12 -16
  18. package/dist/preview-config/prerequisites.js +14 -17
  19. package/dist/preview-config/preview-files.js +28 -34
  20. package/dist/preview-config/ui5-yaml.d.ts +1 -1
  21. package/dist/preview-config/ui5-yaml.js +35 -40
  22. package/dist/prompt/index.d.ts +2 -2
  23. package/dist/prompt/index.js +2 -21
  24. package/dist/prompt/preview-config.js +6 -9
  25. package/dist/prompt/smartlinks-config.d.ts +1 -1
  26. package/dist/prompt/smartlinks-config.js +46 -49
  27. package/dist/smartlinks-config/generateSmartLinks.d.ts +1 -1
  28. package/dist/smartlinks-config/generateSmartLinks.js +6 -9
  29. package/dist/smartlinks-config/index.d.ts +2 -2
  30. package/dist/smartlinks-config/index.js +2 -21
  31. package/dist/smartlinks-config/ui5-yaml.d.ts +1 -1
  32. package/dist/smartlinks-config/ui5-yaml.js +14 -18
  33. package/dist/smartlinks-config/utils.d.ts +1 -1
  34. package/dist/smartlinks-config/utils.js +33 -40
  35. package/dist/templates.js +5 -6
  36. package/dist/types/index.d.ts +3 -3
  37. package/dist/types/index.js +3 -19
  38. package/dist/types/navigation.js +1 -2
  39. package/dist/types/smartLinks.js +4 -7
  40. package/dist/types/variantsConfig.js +2 -5
  41. package/dist/variants-config/generateVariantsConfig.js +8 -11
  42. package/dist/variants-config/index.d.ts +1 -1
  43. package/dist/variants-config/index.js +1 -17
  44. package/dist/variants-config/package-json.js +10 -13
  45. package/dist/variants-config/utils.js +13 -17
  46. package/package.json +13 -11
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.enableCardGeneratorConfig = enableCardGeneratorConfig;
4
- const node_path_1 = require("node:path");
5
- const mem_fs_1 = require("mem-fs");
6
- const mem_fs_editor_1 = require("mem-fs-editor");
7
- const utils_1 = require("../common/utils");
8
- const project_access_1 = require("@sap-ux/project-access");
9
- const ui5_yaml_1 = require("../common/ui5-yaml");
1
+ import { join, basename } from 'node:path';
2
+ import { create as createStorage } from 'mem-fs';
3
+ import { create } from 'mem-fs-editor';
4
+ import { getPreviewMiddleware, getIntentFromPreviewConfig, getCLIForPreview } from '../common/utils.js';
5
+ import { FileName, readUi5Yaml } from '@sap-ux/project-access';
6
+ import { updateMiddlewaresForPreview } from '../common/ui5-yaml.js';
10
7
  const DEPENDENCY_NAME = '@sap-ux/cards-editor-middleware';
11
8
  const CARDS_GENERATOR_MIDDLEWARE = 'sap-cards-generator';
12
9
  /**
@@ -20,8 +17,8 @@ const CARDS_GENERATOR_MIDDLEWARE = 'sap-cards-generator';
20
17
  * @returns {Promise<void>} A promise that resolves when the `ui5.yaml` file has been successfully updated.
21
18
  */
22
19
  async function updateMiddlewareConfigWithGeneratorPath(fs, basePath, yamlPath, logger) {
23
- const ui5YamlFile = yamlPath ? (0, node_path_1.basename)(yamlPath) : project_access_1.FileName.Ui5Yaml;
24
- const ui5YamlConfig = await (0, project_access_1.readUi5Yaml)(basePath, ui5YamlFile, fs);
20
+ const ui5YamlFile = yamlPath ? basename(yamlPath) : FileName.Ui5Yaml;
21
+ const ui5YamlConfig = await readUi5Yaml(basePath, ui5YamlFile, fs);
25
22
  if (ui5YamlConfig.findCustomMiddleware(CARDS_GENERATOR_MIDDLEWARE)) {
26
23
  try {
27
24
  ui5YamlConfig.removeCustomMiddleware(CARDS_GENERATOR_MIDDLEWARE);
@@ -31,7 +28,7 @@ async function updateMiddlewareConfigWithGeneratorPath(fs, basePath, yamlPath, l
31
28
  logger?.warn(`Failed to remove '${CARDS_GENERATOR_MIDDLEWARE}' middleware: ${error.message}`);
32
29
  }
33
30
  }
34
- const previewMiddleware = await (0, utils_1.getPreviewMiddleware)(ui5YamlConfig, basePath, yamlPath, fs);
31
+ const previewMiddleware = await getPreviewMiddleware(ui5YamlConfig, basePath, yamlPath, fs);
35
32
  if (previewMiddleware) {
36
33
  previewMiddleware.configuration ??= {};
37
34
  const middlewareConfig = previewMiddleware.configuration;
@@ -41,7 +38,7 @@ async function updateMiddlewareConfigWithGeneratorPath(fs, basePath, yamlPath, l
41
38
  path: cardGeneratorPath
42
39
  };
43
40
  ui5YamlConfig.updateCustomMiddleware(previewMiddleware);
44
- fs.write((0, node_path_1.join)(basePath, ui5YamlFile), ui5YamlConfig.toString());
41
+ fs.write(join(basePath, ui5YamlFile), ui5YamlConfig.toString());
45
42
  logger?.debug(`Updated preview middleware in ${ui5YamlFile}.`);
46
43
  }
47
44
  }
@@ -56,18 +53,18 @@ async function updateMiddlewareConfigWithGeneratorPath(fs, basePath, yamlPath, l
56
53
  * @returns {Promise<void>} A promise that resolves when the `package.json` file has been successfully updated.
57
54
  */
58
55
  async function updatePackageJson(basePath, fs, yamlPath, logger) {
59
- const packageJsonPath = (0, node_path_1.join)(basePath, 'package.json');
56
+ const packageJsonPath = join(basePath, 'package.json');
60
57
  if (!fs.exists(packageJsonPath)) {
61
58
  throw new Error('package.json not found');
62
59
  }
63
60
  const packageJson = (fs.readJSON(packageJsonPath) ?? {});
64
- const ui5YamlFile = yamlPath ? (0, node_path_1.basename)(yamlPath) : project_access_1.FileName.Ui5Yaml;
65
- const ui5YamlConfig = await (0, project_access_1.readUi5Yaml)(basePath, ui5YamlFile, fs);
66
- const previewMiddleware = await (0, utils_1.getPreviewMiddleware)(ui5YamlConfig, basePath, ui5YamlFile, fs);
67
- const intent = (0, utils_1.getIntentFromPreviewConfig)(previewMiddleware?.configuration) ?? '#app-preview';
61
+ const ui5YamlFile = yamlPath ? basename(yamlPath) : FileName.Ui5Yaml;
62
+ const ui5YamlConfig = await readUi5Yaml(basePath, ui5YamlFile, fs);
63
+ const previewMiddleware = await getPreviewMiddleware(ui5YamlConfig, basePath, ui5YamlFile, fs);
64
+ const intent = getIntentFromPreviewConfig(previewMiddleware?.configuration) ?? '#app-preview';
68
65
  const cardGeneratorPath = previewMiddleware?.configuration?.editors?.cardGenerator?.path ??
69
66
  '/test/flpCardGeneratorSandbox.html';
70
- const cliForPreview = await (0, utils_1.getCLIForPreview)(basePath, ui5YamlFile, fs);
67
+ const cliForPreview = await getCLIForPreview(basePath, ui5YamlFile, fs);
71
68
  packageJson.scripts ??= {};
72
69
  packageJson.scripts['start-cards-generator'] = `${cliForPreview} --open "${cardGeneratorPath}${intent}"`;
73
70
  if (packageJson.devDependencies?.[DEPENDENCY_NAME]) {
@@ -88,9 +85,9 @@ async function updatePackageJson(basePath, fs, yamlPath, logger) {
88
85
  * @param {Editor} [fs] - Optional `mem-fs-editor` instance for file system operations. If not provided, a new instance will be created.
89
86
  * @returns {Promise<Editor>} A promise that resolves to the updated `mem-fs-editor` instance.
90
87
  */
91
- async function enableCardGeneratorConfig(basePath, yamlPath, logger, fs) {
92
- fs = fs ?? (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
93
- await (0, ui5_yaml_1.updateMiddlewaresForPreview)(fs, basePath, yamlPath, logger);
88
+ export async function enableCardGeneratorConfig(basePath, yamlPath, logger, fs) {
89
+ fs = fs ?? create(createStorage());
90
+ await updateMiddlewaresForPreview(fs, basePath, yamlPath, logger);
94
91
  await updateMiddlewareConfigWithGeneratorPath(fs, basePath, yamlPath, logger);
95
92
  await updatePackageJson(basePath, fs, yamlPath, logger);
96
93
  return fs;
@@ -1,17 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getScriptsFromPackageJson = getScriptsFromPackageJson;
4
- exports.extractUrlDetails = extractUrlDetails;
5
- exports.isValidPreviewScript = isValidPreviewScript;
6
- exports.getRunScriptForYamlConfig = getRunScriptForYamlConfig;
7
- exports.extractYamlConfigFileName = extractYamlConfigFileName;
8
- exports.isTestPath = isTestPath;
9
- exports.isFlpPath = isFlpPath;
10
- exports.getTestPathForUi5TestRunner = getTestPathForUi5TestRunner;
11
- exports.isLowerThanMinimalVersion = isLowerThanMinimalVersion;
12
- const node_path_1 = require("node:path");
13
- const project_access_1 = require("@sap-ux/project-access");
14
- const semver_1 = require("semver");
1
+ import { join } from 'node:path';
2
+ import { FileName } from '@sap-ux/project-access';
3
+ import { satisfies, valid, validRange, outside } from 'semver';
15
4
  /**
16
5
  * Map of scripts from the package.json file.
17
6
  */
@@ -24,8 +13,8 @@ const scriptsFromPackageJson = new Map();
24
13
  * @param basePath - base path to be used for the conversion
25
14
  * @returns the scripts from the package.json file
26
15
  */
27
- function getScriptsFromPackageJson(fs, basePath) {
28
- const packageJsonPath = (0, node_path_1.join)(basePath, 'package.json');
16
+ export function getScriptsFromPackageJson(fs, basePath) {
17
+ const packageJsonPath = join(basePath, 'package.json');
29
18
  const packageJson = fs.readJSON(packageJsonPath);
30
19
  scriptsFromPackageJson.clear();
31
20
  Object.entries(packageJson?.scripts ?? {}).forEach(([scriptName, scriptContent]) => {
@@ -41,7 +30,7 @@ function getScriptsFromPackageJson(fs, basePath) {
41
30
  * @param script - the content of the script
42
31
  * @returns the URL details
43
32
  */
44
- function extractUrlDetails(script) {
33
+ export function extractUrlDetails(script) {
45
34
  //extract the URL from the 'open' command of the script
46
35
  let url = / (?:--open|-o|--o) (\S*)/.exec(script)?.[1] ?? undefined;
47
36
  //delete double or single quotes from the URL
@@ -77,7 +66,7 @@ function extractUrlDetails(script) {
77
66
  * @param convertTests - indicator if test suite and test runner should be included in the conversion (default: false)
78
67
  * @returns indicator if the script is valid
79
68
  */
80
- function isValidPreviewScript(script, convertTests = false) {
69
+ export function isValidPreviewScript(script, convertTests = false) {
81
70
  const isValidScriptName = script.name != 'start-variants-management' &&
82
71
  script.name != 'start-control-property-editor' &&
83
72
  script.name != 'start-cards-generator';
@@ -96,8 +85,8 @@ function isValidPreviewScript(script, convertTests = false) {
96
85
  * @param basePath - path to project root, where package.json is
97
86
  * @returns the run script or undefined
98
87
  */
99
- function getRunScriptForYamlConfig(yamlConfigName, fs, basePath) {
100
- const packageJsonPath = (0, node_path_1.join)(basePath, 'package.json');
88
+ export function getRunScriptForYamlConfig(yamlConfigName, fs, basePath) {
89
+ const packageJsonPath = join(basePath, 'package.json');
101
90
  const packageJson = fs.readJSON(packageJsonPath);
102
91
  if (!packageJson) {
103
92
  return undefined;
@@ -119,8 +108,8 @@ function getRunScriptForYamlConfig(yamlConfigName, fs, basePath) {
119
108
  * @param script - the content of the script from the package.json file
120
109
  * @returns the UI5 yaml configuration file name or 'ui5.yaml' as default
121
110
  */
122
- function extractYamlConfigFileName(script) {
123
- return / (?:--config|-c) (\S*)/.exec(script)?.[1] ?? project_access_1.FileName.Ui5Yaml;
111
+ export function extractYamlConfigFileName(script) {
112
+ return / (?:--config|-c) (\S*)/.exec(script)?.[1] ?? FileName.Ui5Yaml;
124
113
  }
125
114
  /**
126
115
  * Check if the path is a test path.
@@ -131,7 +120,7 @@ function extractYamlConfigFileName(script) {
131
120
  * @param configuration - the preview configuration
132
121
  * @returns indicator if the path is a test path
133
122
  */
134
- function isTestPath(script, configuration) {
123
+ export function isTestPath(script, configuration) {
135
124
  const { path } = extractUrlDetails(script.value);
136
125
  if (!path) {
137
126
  return !!getTestPathForUi5TestRunner(script.name);
@@ -148,7 +137,7 @@ function isTestPath(script, configuration) {
148
137
  * @param configuration - the preview configuration
149
138
  * @returns indicator if the path is an FLP path
150
139
  */
151
- function isFlpPath(script, configuration) {
140
+ export function isFlpPath(script, configuration) {
152
141
  const { path } = extractUrlDetails(script.value);
153
142
  if (!path) {
154
143
  return false;
@@ -173,7 +162,7 @@ function isFlpPath(script, configuration) {
173
162
  * @param scriptName - the name of the script from the package.json file
174
163
  * @returns the related test path
175
164
  */
176
- function getTestPathForUi5TestRunner(scriptName) {
165
+ export function getTestPathForUi5TestRunner(scriptName) {
177
166
  const TEST_RUNNER_COMMAND = 'ui5-test-runner';
178
167
  const extractUrl = (script) => {
179
168
  return / (?:--url|-u|--testsuite) (\S*)/.exec(script)?.[1] ?? undefined;
@@ -207,7 +196,7 @@ function getTestPathForUi5TestRunner(scriptName) {
207
196
  * @param mandatory - (default true) if the existence of the dependency is mandatory
208
197
  * @returns indicator if the version is lower than the minimal version
209
198
  */
210
- function isLowerThanMinimalVersion(packageJson, dependencyName, minVersionInfo, mandatory = true) {
199
+ export function isLowerThanMinimalVersion(packageJson, dependencyName, minVersionInfo, mandatory = true) {
211
200
  let versionInfo = packageJson?.devDependencies?.[dependencyName] ?? packageJson?.dependencies?.[dependencyName];
212
201
  if (!versionInfo) {
213
202
  // In case no dependency is found we assume the minimal version is not met depending on the mandatory flag
@@ -217,14 +206,14 @@ function isLowerThanMinimalVersion(packageJson, dependencyName, minVersionInfo,
217
206
  // In case of 'latest' we know the minimal version is met
218
207
  return false;
219
208
  }
220
- if ((0, semver_1.validRange)(versionInfo)) {
209
+ if (validRange(versionInfo)) {
221
210
  // In case of a valid range the minimal version must not be outside the range in high direction
222
- return (0, semver_1.outside)(minVersionInfo, versionInfo, '>');
211
+ return outside(minVersionInfo, versionInfo, '>');
223
212
  }
224
- if ((0, semver_1.valid)(versionInfo)) {
213
+ if (valid(versionInfo)) {
225
214
  // In case of a valid version we add a prefix to make it a range
226
215
  versionInfo = `<=${versionInfo}`;
227
216
  }
228
- return !(0, semver_1.satisfies)(minVersionInfo, versionInfo);
217
+ return !satisfies(minVersionInfo, versionInfo);
229
218
  }
230
219
  //# sourceMappingURL=package-json.js.map
@@ -1,9 +1,9 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
2
  import type { ToolsLogger } from '@sap-ux/logger';
3
- import type { PreviewConfigOptions } from '../types';
3
+ import type { PreviewConfigOptions } from '../types/index.js';
4
4
  import type { CustomMiddleware, FioriAppReloadConfig, UI5Config } from '@sap-ux/ui5-config';
5
5
  import { type DefaultFlpPath, type MiddlewareConfig as PreviewConfig, type TestConfig, type RtaConfig } from '@sap-ux/preview-middleware';
6
- import { type Script } from './package-json';
6
+ import { type Script } from './package-json.js';
7
7
  type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType[number];
8
8
  type PreviewTestConfig = ArrayElement<Required<PreviewConfig>['test']>;
9
9
  export declare const DEFAULT_FLP_PATH: DefaultFlpPath;
@@ -1,25 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TEST_CONFIG_DEFAULTS = exports.DEFAULT_FLP_PATH = void 0;
4
- exports.sanitizeRtaConfig = sanitizeRtaConfig;
5
- exports.getEnhancedReloadMiddleware = getEnhancedReloadMiddleware;
6
- exports.createPreviewMiddlewareConfig = createPreviewMiddlewareConfig;
7
- exports.updateMiddlewaresForPreview = updateMiddlewaresForPreview;
8
- exports.sanitizePreviewMiddleware = sanitizePreviewMiddleware;
9
- exports.updatePreviewMiddlewareConfig = updatePreviewMiddlewareConfig;
10
- exports.updateTestConfig = updateTestConfig;
11
- exports.sanitizeTestScript = sanitizeTestScript;
12
- const node_path_1 = require("node:path");
13
- const types_1 = require("../types");
14
- const project_access_1 = require("@sap-ux/project-access");
15
- const utils_1 = require("./utils");
16
- const package_json_1 = require("./package-json");
1
+ import { basename, join } from 'node:path';
2
+ import { MiddlewareConfigs } from '../types/index.js';
3
+ import { FileName, readUi5Yaml, getWebappPath } from '@sap-ux/project-access';
4
+ import { getPreviewMiddleware, isFioriToolsDeprecatedPreviewConfig, deleteFiles } from './utils.js';
5
+ import { getRunScriptForYamlConfig, getTestPathForUi5TestRunner, extractUrlDetails, isTestPath, isFlpPath } from './package-json.js';
17
6
  const DEFAULT_INTENT = {
18
7
  object: 'app',
19
8
  action: 'preview'
20
9
  };
21
- exports.DEFAULT_FLP_PATH = '/test/flp.html';
22
- exports.TEST_CONFIG_DEFAULTS = {
10
+ export const DEFAULT_FLP_PATH = '/test/flp.html';
11
+ export const TEST_CONFIG_DEFAULTS = {
23
12
  qunit: {
24
13
  path: '/test/unitTests.qunit.html',
25
14
  framework: 'QUnit'
@@ -41,7 +30,7 @@ exports.TEST_CONFIG_DEFAULTS = {
41
30
  * @returns sanitized RTA configuration
42
31
  */
43
32
  //prettier-ignore
44
- function sanitizeRtaConfig(deprecatedRtaConfig, logger) {
33
+ export function sanitizeRtaConfig(deprecatedRtaConfig, logger) {
45
34
  let rtaConfig;
46
35
  if (deprecatedRtaConfig) {
47
36
  const { editors, ...rta } = deprecatedRtaConfig;
@@ -58,9 +47,9 @@ function sanitizeRtaConfig(deprecatedRtaConfig, logger) {
58
47
  * @param yamlConfig - the yaml configuration to use
59
48
  * @returns reload middleware configuration if found or undefined
60
49
  */
61
- async function getEnhancedReloadMiddleware(yamlConfig) {
62
- const reloadMiddleware = yamlConfig.findCustomMiddleware(types_1.MiddlewareConfigs.FioriToolsAppreload) ??
63
- yamlConfig.findCustomMiddleware(types_1.MiddlewareConfigs.ReloadMiddleware);
50
+ export async function getEnhancedReloadMiddleware(yamlConfig) {
51
+ const reloadMiddleware = yamlConfig.findCustomMiddleware(MiddlewareConfigs.FioriToolsAppreload) ??
52
+ yamlConfig.findCustomMiddleware(MiddlewareConfigs.ReloadMiddleware);
64
53
  if (!reloadMiddleware) {
65
54
  return undefined;
66
55
  }
@@ -76,13 +65,13 @@ async function getEnhancedReloadMiddleware(yamlConfig) {
76
65
  * @param basePath - path to project root, where package.json and ui5.yaml is
77
66
  * @returns 'fiori-tools-preview' or 'preview-middleware' configuration
78
67
  */
79
- function createPreviewMiddlewareConfig(fs, basePath) {
80
- const packageJsonPath = (0, node_path_1.join)(basePath, 'package.json');
68
+ export function createPreviewMiddlewareConfig(fs, basePath) {
69
+ const packageJsonPath = join(basePath, 'package.json');
81
70
  const packageJson = fs.readJSON(packageJsonPath);
82
71
  return {
83
72
  name: packageJson?.devDependencies?.['@sap/ux-ui5-tooling']
84
- ? types_1.MiddlewareConfigs.FioriToolsPreview
85
- : types_1.MiddlewareConfigs.PreviewMiddleware,
73
+ ? MiddlewareConfigs.FioriToolsPreview
74
+ : MiddlewareConfigs.PreviewMiddleware,
86
75
  afterMiddleware: 'compression'
87
76
  };
88
77
  }
@@ -95,16 +84,16 @@ function createPreviewMiddlewareConfig(fs, basePath) {
95
84
  * @param yamlPath - path to the ui5*.yaml file passed by cli
96
85
  * @param logger - logger
97
86
  */
98
- async function updateMiddlewaresForPreview(fs, basePath, yamlPath, logger) {
99
- const ui5YamlFile = yamlPath ? (0, node_path_1.basename)(yamlPath) : project_access_1.FileName.Ui5Yaml;
100
- const ui5YamlConfig = await (0, project_access_1.readUi5Yaml)(basePath, ui5YamlFile, fs);
101
- let previewMiddleware = await (0, utils_1.getPreviewMiddleware)(ui5YamlConfig);
87
+ export async function updateMiddlewaresForPreview(fs, basePath, yamlPath, logger) {
88
+ const ui5YamlFile = yamlPath ? basename(yamlPath) : FileName.Ui5Yaml;
89
+ const ui5YamlConfig = await readUi5Yaml(basePath, ui5YamlFile, fs);
90
+ let previewMiddleware = await getPreviewMiddleware(ui5YamlConfig);
102
91
  if (!previewMiddleware) {
103
92
  logger?.warn(`No preview middleware found in ${ui5YamlFile}. Preview middleware will be added.`);
104
93
  previewMiddleware = createPreviewMiddlewareConfig(fs, basePath);
105
94
  }
106
95
  else {
107
- const script = (0, package_json_1.getRunScriptForYamlConfig)(ui5YamlFile, fs, basePath);
96
+ const script = getRunScriptForYamlConfig(ui5YamlFile, fs, basePath);
108
97
  if (script) {
109
98
  previewMiddleware = await updatePreviewMiddlewareConfig(previewMiddleware, script, basePath, fs, logger);
110
99
  }
@@ -120,7 +109,7 @@ async function updateMiddlewaresForPreview(fs, basePath, yamlPath, logger) {
120
109
  logger?.debug(`Updated reload middleware in ${ui5YamlFile}.`);
121
110
  }
122
111
  ui5YamlConfig.updateCustomMiddleware(previewMiddleware);
123
- fs.write((0, node_path_1.join)(basePath, ui5YamlFile), ui5YamlConfig.toString());
112
+ fs.write(join(basePath, ui5YamlFile), ui5YamlConfig.toString());
124
113
  logger?.debug(`Updated preview middleware in ${ui5YamlFile}.`);
125
114
  }
126
115
  /**
@@ -135,7 +124,7 @@ async function updateMiddlewaresForPreview(fs, basePath, yamlPath, logger) {
135
124
  * @param logger - logger to report info to the user
136
125
  * @returns the sanitized preview middleware
137
126
  */
138
- function sanitizePreviewMiddleware(previewMiddleware, logger) {
127
+ export function sanitizePreviewMiddleware(previewMiddleware, logger) {
139
128
  if (!previewMiddleware.configuration) {
140
129
  return previewMiddleware;
141
130
  }
@@ -146,7 +135,7 @@ function sanitizePreviewMiddleware(previewMiddleware, logger) {
146
135
  previewMiddleware.configuration.editors ??= {};
147
136
  previewMiddleware.configuration.editors.rta = rtaConfig;
148
137
  }
149
- if (!(0, utils_1.isFioriToolsDeprecatedPreviewConfig)(previewMiddleware.configuration)) {
138
+ if (!isFioriToolsDeprecatedPreviewConfig(previewMiddleware.configuration)) {
150
139
  return previewMiddleware;
151
140
  }
152
141
  const ui5Theme = previewMiddleware.configuration.ui5Theme;
@@ -172,16 +161,16 @@ function sanitizePreviewMiddleware(previewMiddleware, logger) {
172
161
  * @param logger logger to report info to the user
173
162
  * @returns the preview middleware configuration
174
163
  */
175
- async function updatePreviewMiddlewareConfig(previewMiddleware, script, basePath, fs, logger) {
176
- const { path, intent } = (0, package_json_1.extractUrlDetails)(script.value);
164
+ export async function updatePreviewMiddlewareConfig(previewMiddleware, script, basePath, fs, logger) {
165
+ const { path, intent } = extractUrlDetails(script.value);
177
166
  const defaultIntent = `${DEFAULT_INTENT.object}-${DEFAULT_INTENT.action}`;
178
167
  const newMiddlewareConfig = sanitizePreviewMiddleware(previewMiddleware, logger);
179
168
  //copy of configuration to avoid ending up with an empty configuration object in some cases
180
169
  const configuration = { ...newMiddlewareConfig.configuration };
181
170
  let writeConfig = false;
182
- if ((0, package_json_1.isFlpPath)(script, configuration)) {
171
+ if (isFlpPath(script, configuration)) {
183
172
  //adjust path but respect defaults
184
- if (!path?.includes(exports.DEFAULT_FLP_PATH)) {
173
+ if (!path?.includes(DEFAULT_FLP_PATH)) {
185
174
  configuration.flp = configuration.flp ?? {};
186
175
  configuration.flp.path = path;
187
176
  writeConfig = true;
@@ -196,12 +185,12 @@ async function updatePreviewMiddlewareConfig(previewMiddleware, script, basePath
196
185
  writeConfig = true;
197
186
  }
198
187
  }
199
- else if (path && (0, package_json_1.isTestPath)(script, configuration)) {
188
+ else if (path && isTestPath(script, configuration)) {
200
189
  configuration.test = await updateTestConfig(configuration.test, path, basePath, fs, logger);
201
190
  writeConfig = true;
202
191
  }
203
192
  else if (!path) {
204
- const ui5TestRunnerPath = (0, package_json_1.getTestPathForUi5TestRunner)(script.name);
193
+ const ui5TestRunnerPath = getTestPathForUi5TestRunner(script.name);
205
194
  if (ui5TestRunnerPath) {
206
195
  configuration.test = await updateTestConfig(configuration.test, ui5TestRunnerPath, basePath, fs);
207
196
  writeConfig = true;
@@ -222,7 +211,7 @@ async function updatePreviewMiddlewareConfig(previewMiddleware, script, basePath
222
211
  * @param logger logger to report info to the user
223
212
  * @returns the updated test configuration
224
213
  */
225
- async function updateTestConfig(testConfiguration, path, basePath, fs, logger) {
214
+ export async function updateTestConfig(testConfiguration, path, basePath, fs, logger) {
226
215
  const hasTestsuite = (config) => {
227
216
  return config?.some((test) => test.framework === 'Testsuite') ?? false;
228
217
  };
@@ -240,7 +229,7 @@ async function updateTestConfig(testConfiguration, path, basePath, fs, logger) {
240
229
  if (!framework) {
241
230
  return testConfiguration;
242
231
  }
243
- const defaultPath = exports.TEST_CONFIG_DEFAULTS[framework.toLowerCase()].path;
232
+ const defaultPath = TEST_CONFIG_DEFAULTS[framework.toLowerCase()].path;
244
233
  const testConfig = testConfiguration.find((test) => test.framework === framework);
245
234
  if (testConfig) {
246
235
  testConfig.path = path;
@@ -274,9 +263,9 @@ async function updateTestConfig(testConfiguration, path, basePath, fs, logger) {
274
263
  * @param newConfig - the new test configuration
275
264
  * @param logger logger to report info to the user
276
265
  */
277
- async function sanitizeTestScript(fs, basePath, path, newConfig, logger) {
278
- const jsTestScriptPath = (0, node_path_1.join)(await (0, project_access_1.getWebappPath)(basePath), path.replace('.html', '.js'));
279
- const tsTestScriptPath = (0, node_path_1.join)(await (0, project_access_1.getWebappPath)(basePath), path.replace('.html', '.ts'));
266
+ export async function sanitizeTestScript(fs, basePath, path, newConfig, logger) {
267
+ const jsTestScriptPath = join(await getWebappPath(basePath), path.replace('.html', '.js'));
268
+ const tsTestScriptPath = join(await getWebappPath(basePath), path.replace('.html', '.ts'));
280
269
  const testScriptPath = fs.exists(jsTestScriptPath) ? jsTestScriptPath : tsTestScriptPath;
281
270
  if (fs.exists(testScriptPath)) {
282
271
  const file = fs.read(testScriptPath);
@@ -284,11 +273,11 @@ async function sanitizeTestScript(fs, basePath, path, newConfig, logger) {
284
273
  if (usesJourneyRunner) {
285
274
  const filePathRenamed = testScriptPath.replace(/(\.([jt])s)$/, '.custom$1');
286
275
  fs.move(testScriptPath, filePathRenamed);
287
- newConfig.pattern = `/test/**/${(0, node_path_1.basename)(filePathRenamed)}`;
288
- logger?.info(`Renamed '${(0, node_path_1.basename)(testScriptPath)}' to '${(0, node_path_1.basename)(filePathRenamed)}'. This file creates the JourneyRunner for OPA5 tests. As the handling of journey runners is not part of the virtual OPA5 test runner endpoint, this file has been renamed and added to the respective UI5 YAML configuration.`);
276
+ newConfig.pattern = `/test/**/${basename(filePathRenamed)}`;
277
+ logger?.info(`Renamed '${basename(testScriptPath)}' to '${basename(filePathRenamed)}'. This file creates the JourneyRunner for OPA5 tests. As the handling of journey runners is not part of the virtual OPA5 test runner endpoint, this file has been renamed and added to the respective UI5 YAML configuration.`);
289
278
  }
290
279
  else {
291
- await (0, utils_1.deleteFiles)(fs, [testScriptPath]);
280
+ await deleteFiles(fs, [testScriptPath]);
292
281
  }
293
282
  }
294
283
  }
@@ -1,5 +1,5 @@
1
1
  import type { CustomMiddleware, UI5Config } from '@sap-ux/ui5-config';
2
- import type { PreviewConfigOptions, FioriToolsDeprecatedPreviewConfig } from '../types';
2
+ import type { PreviewConfigOptions, FioriToolsDeprecatedPreviewConfig } from '../types/index.js';
3
3
  import type { Editor } from 'mem-fs-editor';
4
4
  import type { ToolsLogger } from '@sap-ux/logger';
5
5
  /**
@@ -1,20 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFioriToolsDeprecatedPreviewConfig = isFioriToolsDeprecatedPreviewConfig;
4
- exports.getPreviewMiddleware = getPreviewMiddleware;
5
- exports.getIntentFromPreviewConfig = getIntentFromPreviewConfig;
6
- exports.getCLIForPreview = getCLIForPreview;
7
- exports.deleteFiles = deleteFiles;
8
- const project_access_1 = require("@sap-ux/project-access");
9
- const types_1 = require("../types");
10
- const node_path_1 = require("node:path");
1
+ import { FileName, readUi5Yaml } from '@sap-ux/project-access';
2
+ import { MiddlewareConfigs } from '../types/index.js';
3
+ import { basename } from 'node:path';
11
4
  /**
12
5
  * Type guard to check if the given configuration is a deprecated preview middleware configuration.
13
6
  *
14
7
  * @param configuration preview middleware configuration
15
8
  * @returns true, if a preview middleware configuration is deprecated
16
9
  */
17
- function isFioriToolsDeprecatedPreviewConfig(configuration) {
10
+ export function isFioriToolsDeprecatedPreviewConfig(configuration) {
18
11
  return configuration?.component !== undefined;
19
12
  }
20
13
  /**
@@ -28,13 +21,13 @@ function isFioriToolsDeprecatedPreviewConfig(configuration) {
28
21
  * @returns preview middleware configuration if found
29
22
  * Rejects if neither yamlConfig nor basePath is provided or if the file can't be read
30
23
  */
31
- async function getPreviewMiddleware(yamlConfig, basePath, filename = project_access_1.FileName.Ui5Yaml, fs) {
24
+ export async function getPreviewMiddleware(yamlConfig, basePath, filename = FileName.Ui5Yaml, fs) {
32
25
  if (!basePath && !yamlConfig) {
33
26
  throw new Error('Either base path or yaml config must be provided.');
34
27
  }
35
- yamlConfig = yamlConfig ?? (await (0, project_access_1.readUi5Yaml)(basePath, filename, fs));
36
- return (yamlConfig.findCustomMiddleware(types_1.MiddlewareConfigs.FioriToolsPreview) ??
37
- yamlConfig.findCustomMiddleware(types_1.MiddlewareConfigs.PreviewMiddleware));
28
+ yamlConfig = yamlConfig ?? (await readUi5Yaml(basePath, filename, fs));
29
+ return (yamlConfig.findCustomMiddleware(MiddlewareConfigs.FioriToolsPreview) ??
30
+ yamlConfig.findCustomMiddleware(MiddlewareConfigs.PreviewMiddleware));
38
31
  }
39
32
  /**
40
33
  * Returns the intent of the preview middleware configuration from the ui5.yaml file, if given.
@@ -42,7 +35,7 @@ async function getPreviewMiddleware(yamlConfig, basePath, filename = project_acc
42
35
  * @param previewMiddlewareConfig - configuration of the preview middleware
43
36
  * @returns - preview intent or undefined
44
37
  */
45
- function getIntentFromPreviewConfig(previewMiddlewareConfig) {
38
+ export function getIntentFromPreviewConfig(previewMiddlewareConfig) {
46
39
  if (isFioriToolsDeprecatedPreviewConfig(previewMiddlewareConfig)) {
47
40
  return undefined;
48
41
  }
@@ -59,9 +52,9 @@ function getIntentFromPreviewConfig(previewMiddlewareConfig) {
59
52
  * @param fs - the memfs editor instance
60
53
  * @returns - preview serve or undefined
61
54
  */
62
- async function getCLIForPreview(basePath, yamlFileName, fs) {
55
+ export async function getCLIForPreview(basePath, yamlFileName, fs) {
63
56
  const previewMiddleware = await getPreviewMiddleware(undefined, basePath, yamlFileName, fs);
64
- return previewMiddleware?.name === types_1.MiddlewareConfigs.PreviewMiddleware ? 'ui5 serve' : 'fiori run';
57
+ return previewMiddleware?.name === MiddlewareConfigs.PreviewMiddleware ? 'ui5 serve' : 'fiori run';
65
58
  }
66
59
  /**
67
60
  * Deletes the given file.
@@ -70,11 +63,11 @@ async function getCLIForPreview(basePath, yamlFileName, fs) {
70
63
  * @param files - files to be deleted
71
64
  * @param logger logger to report info to the user
72
65
  */
73
- async function deleteFiles(fs, files, logger) {
66
+ export async function deleteFiles(fs, files, logger) {
74
67
  files.forEach((path) => {
75
68
  if (fs.exists(path)) {
76
69
  fs.delete(path);
77
- logger?.info(`Deleted the '${(0, node_path_1.basename)(path)}' file. This file is no longer needed for the virtual endpoints.`);
70
+ logger?.info(`Deleted the '${basename(path)}' file. This file is no longer needed for the virtual endpoints.`);
78
71
  }
79
72
  });
80
73
  }
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateEslintConfig = generateEslintConfig;
4
- const mem_fs_1 = require("mem-fs");
5
- const mem_fs_editor_1 = require("mem-fs-editor");
6
- const project_access_1 = require("@sap-ux/project-access");
7
- const node_path_1 = require("node:path");
8
- const ui5_application_writer_1 = require("@sap-ux/ui5-application-writer");
1
+ import { create as createStorage } from 'mem-fs';
2
+ import { create } from 'mem-fs-editor';
3
+ import { hasDependency, FileName } from '@sap-ux/project-access';
4
+ import { join } from 'node:path';
5
+ import { addEslintFeature } from '@sap-ux/ui5-application-writer';
9
6
  /**
10
7
  * Adds eslint configuration to the project.
11
8
  *
@@ -19,8 +16,8 @@ const ui5_application_writer_1 = require("@sap-ux/ui5-application-writer");
19
16
  * @param options.config - the name of the SAP Fiori tools eslint plugin config to be used
20
17
  * @returns file system reference
21
18
  */
22
- async function generateEslintConfig(basePath, options) {
23
- const fs = options.fs ?? (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
19
+ export async function generateEslintConfig(basePath, options) {
20
+ const fs = options.fs ?? create(createStorage());
24
21
  const logger = options.logger;
25
22
  if (!(await checkPrerequisites(basePath, fs, logger))) {
26
23
  throw new Error('The prerequisites are not met. For more information, see the log messages above.');
@@ -37,17 +34,17 @@ async function generateEslintConfig(basePath, options) {
37
34
  * @returns true if the prerequisites are met, false otherwise
38
35
  */
39
36
  async function checkPrerequisites(basePath, fs, logger) {
40
- const packageJsonPath = (0, node_path_1.join)(basePath, project_access_1.FileName.Package);
37
+ const packageJsonPath = join(basePath, FileName.Package);
41
38
  const packageJson = fs.readJSON(packageJsonPath);
42
39
  if (!packageJson) {
43
40
  logger?.error(`No package.json found at path '${packageJsonPath}'`);
44
41
  return false;
45
42
  }
46
- if ((0, project_access_1.hasDependency)(packageJson, 'eslint')) {
43
+ if (hasDependency(packageJson, 'eslint')) {
47
44
  logger?.error(`EsLint already exists in this project. Found 'eslint' dependency in package.json at path '${packageJsonPath}'`);
48
45
  return false;
49
46
  }
50
- const eslintConfigFilePath = (0, node_path_1.join)(basePath, 'eslint.config.mjs');
47
+ const eslintConfigFilePath = join(basePath, 'eslint.config.mjs');
51
48
  if (fs.exists(eslintConfigFilePath)) {
52
49
  logger?.error(`An ESLint configuration file already exists at path '${eslintConfigFilePath}'`);
53
50
  return false;
@@ -62,12 +59,12 @@ async function checkPrerequisites(basePath, fs, logger) {
62
59
  * @param config - the name of the SAP Fiori tools eslint plugin config to be used
63
60
  */
64
61
  async function addEslintConfig(basePath, fs, config = 'recommended') {
65
- await (0, ui5_application_writer_1.addEslintFeature)(basePath, fs);
62
+ await addEslintFeature(basePath, fs);
66
63
  if (config === 'recommended-for-s4hana') {
67
- const eslintConfigPath = (0, node_path_1.join)(basePath, 'eslint.config.mjs');
64
+ const eslintConfigPath = join(basePath, 'eslint.config.mjs');
68
65
  let eslintConfigContent = fs.read(eslintConfigPath);
69
66
  eslintConfigContent = eslintConfigContent.replace('...fioriTools.configs.recommended', "...fioriTools.configs['recommended-for-s4hana']");
70
- await fs.write((0, node_path_1.join)(basePath, 'eslint.config.mjs'), eslintConfigContent);
67
+ await fs.write(join(basePath, 'eslint.config.mjs'), eslintConfigContent);
71
68
  }
72
69
  }
73
70
  //# sourceMappingURL=add.js.map