@sap-ux/create 0.7.19 → 0.7.21

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/README.md CHANGED
@@ -26,6 +26,11 @@ Calling `sap-ux add html` will add html files for local preview and testing to t
26
26
  ```sh
27
27
  sap-ux change add html ui5-test.yaml
28
28
  ```
29
+ ### annotations
30
+ Calling `sap-ux add annotations` allows adding an annotation to the OData Source of the base application in an adaptation project.
31
+ ```sh
32
+ sap-ux add annotations /path/to/adaptation-project
33
+ ```
29
34
 
30
35
  ## change
31
36
  Calling `sap-ux change` allows changing a feature of a project.
@@ -0,0 +1,8 @@
1
+ import type { Command } from 'commander';
2
+ /**
3
+ * Add a new sub-command to add annotations to odata service of an adaptation project to the given command.
4
+ *
5
+ * @param {Command} cmd - The command to add the add annotations-to-odata sub-command to.
6
+ */
7
+ export declare function addAnnotationsToOdataCommand(cmd: Command): void;
8
+ //# sourceMappingURL=annotations-to-odata.d.ts.map
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addAnnotationsToOdataCommand = void 0;
4
+ const adp_tooling_1 = require("@sap-ux/adp-tooling");
5
+ const tracing_1 = require("../../tracing");
6
+ const common_1 = require("../../common");
7
+ const validation_1 = require("../../validation/validation");
8
+ let loginAttempts = 3;
9
+ /**
10
+ * Add a new sub-command to add annotations to odata service of an adaptation project to the given command.
11
+ *
12
+ * @param {Command} cmd - The command to add the add annotations-to-odata sub-command to.
13
+ */
14
+ function addAnnotationsToOdataCommand(cmd) {
15
+ cmd.command('annotations [path]')
16
+ .option('-s, --simulate', 'simulate only do not write or install')
17
+ .option('-c, --config <string>', 'Path to project configuration file in YAML format', 'ui5.yaml')
18
+ .action(async (path, options) => {
19
+ await addAnnotationsToOdata(path, !!options.simulate, options.config);
20
+ });
21
+ }
22
+ exports.addAnnotationsToOdataCommand = addAnnotationsToOdataCommand;
23
+ /**
24
+ * Changes the data source of an adaptation project.
25
+ *
26
+ * @param {string} basePath - The path to the adaptation project.
27
+ * @param {boolean} simulate - If set to true, then no files will be written to the filesystem.
28
+ * @param {string} yamlPath - The path to the project configuration file in YAML format.
29
+ */
30
+ async function addAnnotationsToOdata(basePath, simulate, yamlPath) {
31
+ const logger = (0, tracing_1.getLogger)();
32
+ try {
33
+ if (!basePath) {
34
+ basePath = process.cwd();
35
+ }
36
+ await (0, validation_1.validateAdpProject)(basePath);
37
+ const variant = (0, adp_tooling_1.getVariant)(basePath);
38
+ const adpConfig = await (0, adp_tooling_1.getAdpConfig)(basePath, yamlPath);
39
+ const dataSources = await (0, adp_tooling_1.getManifestDataSources)(variant.reference, adpConfig, logger);
40
+ const answers = await (0, common_1.promptYUIQuestions)((0, adp_tooling_1.getPromptsForAddAnnotationsToOData)(basePath, dataSources), false);
41
+ const fs = await (0, adp_tooling_1.generateChange)(basePath, "appdescr_app_addAnnotationsToOData" /* ChangeType.ADD_ANNOTATIONS_TO_ODATA */, {
42
+ variant,
43
+ answers
44
+ });
45
+ if (!simulate) {
46
+ await new Promise((resolve) => fs.commit(resolve));
47
+ }
48
+ else {
49
+ await (0, tracing_1.traceChanges)(fs);
50
+ }
51
+ }
52
+ catch (error) {
53
+ logger.error(error.message);
54
+ if (error.response?.status === 401 && loginAttempts) {
55
+ loginAttempts--;
56
+ logger.error(`Authentication failed. Please check your credentials. Login attempts left: ${loginAttempts}`);
57
+ await addAnnotationsToOdata(basePath, simulate, yamlPath);
58
+ return;
59
+ }
60
+ logger.debug(error);
61
+ }
62
+ }
63
+ //# sourceMappingURL=annotations-to-odata.js.map
@@ -7,6 +7,7 @@ const smartlinks_config_1 = require("./smartlinks-config");
7
7
  const cds_plugin_ui_1 = require("./cds-plugin-ui");
8
8
  const navigation_config_1 = require("./navigation-config");
9
9
  const cards_editor_1 = require("./cards-editor");
10
+ const annotations_to_odata_1 = require("./annotations-to-odata");
10
11
  const html_1 = require("./html");
11
12
  /**
12
13
  * Return 'create-fiori add *' commands. Commands include also the handler action.
@@ -25,6 +26,8 @@ function getAddCommands() {
25
26
  (0, navigation_config_1.addInboundNavigationConfigCommand)(addCommands);
26
27
  // create-fiori add cards-editor
27
28
  (0, cards_editor_1.addCardsEditorConfigCommand)(addCommands);
29
+ // create-fiori add annotations-to-odata
30
+ (0, annotations_to_odata_1.addAnnotationsToOdataCommand)(addCommands);
28
31
  // create-fiori add html
29
32
  (0, html_1.addAddHtmlFilesCmd)(addCommands);
30
33
  return addCommands;
@@ -3,11 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addChangeDataSourceCommand = void 0;
4
4
  const adp_tooling_1 = require("@sap-ux/adp-tooling");
5
5
  const tracing_1 = require("../../tracing");
6
- const fs_1 = require("fs");
7
- const path_1 = require("path");
8
- const ui5_config_1 = require("@sap-ux/ui5-config");
9
6
  const common_1 = require("../../common");
10
- const project_access_1 = require("@sap-ux/project-access");
7
+ const validation_1 = require("../../validation/validation");
11
8
  let loginAttempts = 3;
12
9
  /**
13
10
  * Add a new sub-command to change the data source of an adaptation project to the given command.
@@ -19,7 +16,7 @@ function addChangeDataSourceCommand(cmd) {
19
16
  .option('-s, --simulate', 'simulate only do not write or install')
20
17
  .option('-c, --config <string>', 'Path to project configuration file in YAML format', 'ui5.yaml')
21
18
  .action(async (path, options) => {
22
- await changeDataSource(path, { ...options }, !!options.simulate, options.config);
19
+ await changeDataSource(path, !!options.simulate, options.config);
23
20
  });
24
21
  }
25
22
  exports.addChangeDataSourceCommand = addChangeDataSourceCommand;
@@ -27,34 +24,19 @@ exports.addChangeDataSourceCommand = addChangeDataSourceCommand;
27
24
  * Changes the data source of an adaptation project.
28
25
  *
29
26
  * @param {string} basePath - The path to the adaptation project.
30
- * @param {PromptDefaults} defaults - The default values for the prompts.
31
27
  * @param {boolean} simulate - If set to true, then no files will be written to the filesystem.
32
28
  * @param {string} yamlPath - The path to the project configuration file in YAML format.
33
29
  */
34
- async function changeDataSource(basePath, defaults, simulate, yamlPath) {
30
+ async function changeDataSource(basePath, simulate, yamlPath) {
35
31
  const logger = (0, tracing_1.getLogger)();
36
32
  try {
37
33
  if (!basePath) {
38
34
  basePath = process.cwd();
39
35
  }
40
- if ((await (0, project_access_1.getAppType)(basePath)) !== 'Fiori Adaptation') {
41
- throw new Error('This command can only be used for an Adaptation Project');
42
- }
43
- checkEnvironment(basePath);
44
- const variant = getVariant(basePath);
45
- const ui5ConfigPath = (0, path_1.isAbsolute)(yamlPath) ? yamlPath : (0, path_1.join)(basePath, yamlPath);
46
- const ui5Conf = await ui5_config_1.UI5Config.newInstance((0, fs_1.readFileSync)(ui5ConfigPath, 'utf-8'));
47
- const customMiddlerware = ui5Conf.findCustomMiddleware('fiori-tools-preview') ??
48
- ui5Conf.findCustomMiddleware('preview-middleware');
49
- const adp = customMiddlerware?.configuration?.adp;
50
- if (!adp) {
51
- throw new Error('No system configuration found in ui5.yaml');
52
- }
53
- const manifest = await (0, adp_tooling_1.getManifest)(variant.reference, adp, logger);
54
- const dataSources = manifest['sap.app'].dataSources;
55
- if (!dataSources) {
56
- throw new Error('No data sources found in the manifest');
57
- }
36
+ await (0, validation_1.validateAdpProject)(basePath);
37
+ const variant = (0, adp_tooling_1.getVariant)(basePath);
38
+ const adpConfig = await (0, adp_tooling_1.getAdpConfig)(basePath, yamlPath);
39
+ const dataSources = await (0, adp_tooling_1.getManifestDataSources)(variant.reference, adpConfig, logger);
58
40
  const answers = await (0, common_1.promptYUIQuestions)((0, adp_tooling_1.getPromptsForChangeDataSource)(dataSources), false);
59
41
  const fs = await (0, adp_tooling_1.generateChange)(basePath, "appdescr_app_changeDataSource" /* ChangeType.CHANGE_DATA_SOURCE */, {
60
42
  variant,
@@ -73,34 +55,10 @@ async function changeDataSource(basePath, defaults, simulate, yamlPath) {
73
55
  if (error.response?.status === 401 && loginAttempts) {
74
56
  loginAttempts--;
75
57
  logger.error(`Authentication failed. Please check your credentials. Login attempts left: ${loginAttempts}`);
76
- await changeDataSource(basePath, defaults, simulate, yamlPath);
58
+ await changeDataSource(basePath, simulate, yamlPath);
77
59
  return;
78
60
  }
79
61
  logger.debug(error);
80
62
  }
81
63
  }
82
- /**
83
- * Get the app descriptor variant.
84
- *
85
- * @param {string} basePath - The path to the adaptation project.
86
- * @returns {DescriptorVariant} The app descriptor variant.
87
- */
88
- function getVariant(basePath) {
89
- return JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(basePath, 'webapp', 'manifest.appdescr_variant'), 'utf-8'));
90
- }
91
- /**
92
- * Check if the project is a CF project.
93
- *
94
- * @param {string} basePath - The path to the adaptation project.
95
- * @throws {Error} If the project is a CF project.
96
- */
97
- function checkEnvironment(basePath) {
98
- const configJsonPath = (0, path_1.join)(basePath, '.adp', 'config.json');
99
- if ((0, fs_1.existsSync)(configJsonPath)) {
100
- const config = JSON.parse((0, fs_1.readFileSync)(configJsonPath, 'utf-8'));
101
- if (config.environment === 'CF') {
102
- throw new Error('Changing data source is not supported for CF projects.');
103
- }
104
- }
105
- }
106
64
  //# sourceMappingURL=change-data-source.js.map
@@ -13,4 +13,10 @@ export declare function validateBasePath(basePath: string, ui5YamlPath?: string)
13
13
  * @returns - true if fs contains deletions; false otherwise
14
14
  */
15
15
  export declare function hasFileDeletes(fs: Editor): boolean;
16
+ /**
17
+ * Validate if adaptation project is supported for command, throws an error if not supported.
18
+ *
19
+ * @param basePath - path to the adaptation project
20
+ */
21
+ export declare function validateAdpProject(basePath: string): Promise<void>;
16
22
  //# sourceMappingURL=validation.d.ts.map
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasFileDeletes = exports.validateBasePath = void 0;
3
+ exports.validateAdpProject = exports.hasFileDeletes = exports.validateBasePath = void 0;
4
4
  const project_access_1 = require("@sap-ux/project-access");
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = require("path");
7
+ const adp_tooling_1 = require("@sap-ux/adp-tooling");
7
8
  /**
8
9
  * Validate base path of app, throw error if file is missing.
9
10
  *
@@ -33,4 +34,18 @@ function hasFileDeletes(fs) {
33
34
  return !!Object.keys(changedFiles).find((fileName) => changedFiles[fileName].state === 'deleted');
34
35
  }
35
36
  exports.hasFileDeletes = hasFileDeletes;
37
+ /**
38
+ * Validate if adaptation project is supported for command, throws an error if not supported.
39
+ *
40
+ * @param basePath - path to the adaptation project
41
+ */
42
+ async function validateAdpProject(basePath) {
43
+ if ((await (0, project_access_1.getAppType)(basePath)) !== 'Fiori Adaptation') {
44
+ throw new Error('This command can only be used for an adaptation project');
45
+ }
46
+ if ((0, adp_tooling_1.isCFEnvironment)(basePath)) {
47
+ throw new Error('This command is not supported for CF projects.');
48
+ }
49
+ }
50
+ exports.validateAdpProject = validateAdpProject;
36
51
  //# sourceMappingURL=validation.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/create",
3
3
  "description": "SAP Fiori tools module to add or remove features",
4
- "version": "0.7.19",
4
+ "version": "0.7.21",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -30,15 +30,15 @@
30
30
  "mem-fs": "2.1.0",
31
31
  "mem-fs-editor": "9.4.0",
32
32
  "prompts": "2.4.2",
33
- "@sap-ux/adp-tooling": "0.12.12",
34
- "@sap-ux/app-config-writer": "0.4.9",
35
- "@sap-ux/cap-config-writer": "0.7.0",
36
- "@sap-ux/inquirer-common": "0.4.1",
33
+ "@sap-ux/adp-tooling": "0.12.14",
34
+ "@sap-ux/app-config-writer": "0.4.10",
35
+ "@sap-ux/cap-config-writer": "0.7.1",
37
36
  "@sap-ux/cards-editor-config-writer": "0.4.1",
37
+ "@sap-ux/inquirer-common": "0.4.1",
38
38
  "@sap-ux/logger": "0.6.0",
39
39
  "@sap-ux/mockserver-config-writer": "0.6.1",
40
- "@sap-ux/preview-middleware": "0.16.18",
41
- "@sap-ux/project-access": "1.25.5",
40
+ "@sap-ux/preview-middleware": "0.16.20",
41
+ "@sap-ux/project-access": "1.25.6",
42
42
  "@sap-ux/system-access": "0.5.2",
43
43
  "@sap-ux/ui5-config": "0.23.1"
44
44
  },