@sap-ux/create 0.5.112 → 0.5.114
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 +11 -1
- package/dist/cli/change/change-data-source.d.ts +8 -0
- package/dist/cli/change/change-data-source.js +117 -0
- package/dist/cli/change/index.d.ts +8 -0
- package/dist/cli/change/index.js +18 -0
- package/dist/cli/index.js +3 -0
- package/dist/common/prompts.js +19 -1
- package/package.json +13 -8
package/README.md
CHANGED
|
@@ -21,6 +21,16 @@ npx sap-ux
|
|
|
21
21
|
## add
|
|
22
22
|
Calling `sap-ux add` allows adding a feature to a project.
|
|
23
23
|
|
|
24
|
+
## change
|
|
25
|
+
Calling `sap-ux change` allows changing a feature of a project.
|
|
26
|
+
|
|
27
|
+
### data-source
|
|
28
|
+
Calling `sap-ux change data-source` allows replacing the OData Source of the base application in an adaptation project.
|
|
29
|
+
```sh
|
|
30
|
+
sap-ux change data-source /path/to/adaptation-project
|
|
31
|
+
```
|
|
32
|
+
If the project path is not provided, the current working directory will be used.
|
|
33
|
+
|
|
24
34
|
## remove
|
|
25
35
|
Calling `sap-ux remove` allows removing a feature to a project.
|
|
26
36
|
|
|
@@ -32,4 +42,4 @@ Calling `sap-ux generate adaptation-project` allows generating a new adaptation
|
|
|
32
42
|
```sh
|
|
33
43
|
sap-ux generate adaptation-project --id my.adp --reference the.original.app --url http://my.sapsystem.example
|
|
34
44
|
```
|
|
35
|
-
Additional options are `--skip-install` to skip running `npm install` after the project generation and `--simulate` to only simulate the files that would be generated instead of writing them to the file system.
|
|
45
|
+
Additional options are `--skip-install` to skip running `npm install` after the project generation and `--simulate` to only simulate the files that would be generated instead of writing them to the file system.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* Add a new sub-command to change the data source of an adaptation project to the given command.
|
|
4
|
+
*
|
|
5
|
+
* @param {Command} cmd - The command to add the change data-source sub-command to.
|
|
6
|
+
*/
|
|
7
|
+
export declare function addChangeDataSourceCommand(cmd: Command): void;
|
|
8
|
+
//# sourceMappingURL=change-data-source.d.ts.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addChangeDataSourceCommand = void 0;
|
|
13
|
+
const adp_tooling_1 = require("@sap-ux/adp-tooling");
|
|
14
|
+
const tracing_1 = require("../../tracing");
|
|
15
|
+
const fs_1 = require("fs");
|
|
16
|
+
const path_1 = require("path");
|
|
17
|
+
const ui5_config_1 = require("@sap-ux/ui5-config");
|
|
18
|
+
const common_1 = require("../../common");
|
|
19
|
+
const project_access_1 = require("@sap-ux/project-access");
|
|
20
|
+
let loginAttempts = 3;
|
|
21
|
+
/**
|
|
22
|
+
* Add a new sub-command to change the data source of an adaptation project to the given command.
|
|
23
|
+
*
|
|
24
|
+
* @param {Command} cmd - The command to add the change data-source sub-command to.
|
|
25
|
+
*/
|
|
26
|
+
function addChangeDataSourceCommand(cmd) {
|
|
27
|
+
cmd.command('data-source [path]')
|
|
28
|
+
.option('-s, --simulate', 'simulate only do not write or install')
|
|
29
|
+
.option('-c, --config <string>', 'Path to project configuration file in YAML format', 'ui5.yaml')
|
|
30
|
+
.action((path, options) => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
yield changeDataSource(path, Object.assign({}, options), !!options.simulate, options.config);
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
exports.addChangeDataSourceCommand = addChangeDataSourceCommand;
|
|
35
|
+
/**
|
|
36
|
+
* Changes the data source of an adaptation project.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} basePath - The path to the adaptation project.
|
|
39
|
+
* @param {PromptDefaults} defaults - The default values for the prompts.
|
|
40
|
+
* @param {boolean} simulate - If set to true, then no files will be written to the filesystem.
|
|
41
|
+
* @param {string} yamlPath - The path to the project configuration file in YAML format.
|
|
42
|
+
*/
|
|
43
|
+
function changeDataSource(basePath, defaults, simulate, yamlPath) {
|
|
44
|
+
var _a, _b, _c;
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const logger = (0, tracing_1.getLogger)();
|
|
47
|
+
try {
|
|
48
|
+
if (!basePath) {
|
|
49
|
+
basePath = process.cwd();
|
|
50
|
+
}
|
|
51
|
+
if ((yield (0, project_access_1.getAppType)(basePath)) !== 'Fiori Adaptation') {
|
|
52
|
+
throw new Error('This command can only be used for an Adaptation Project');
|
|
53
|
+
}
|
|
54
|
+
checkEnvironment(basePath);
|
|
55
|
+
const variant = getVariant(basePath);
|
|
56
|
+
const ui5ConfigPath = (0, path_1.isAbsolute)(yamlPath) ? yamlPath : (0, path_1.join)(basePath, yamlPath);
|
|
57
|
+
const ui5Conf = yield ui5_config_1.UI5Config.newInstance((0, fs_1.readFileSync)(ui5ConfigPath, 'utf-8'));
|
|
58
|
+
const customMiddlerware = (_a = ui5Conf.findCustomMiddleware('fiori-tools-preview')) !== null && _a !== void 0 ? _a : ui5Conf.findCustomMiddleware('preview-middleware');
|
|
59
|
+
const adp = (_b = customMiddlerware === null || customMiddlerware === void 0 ? void 0 : customMiddlerware.configuration) === null || _b === void 0 ? void 0 : _b.adp;
|
|
60
|
+
if (!adp) {
|
|
61
|
+
throw new Error('No system configuration found in ui5.yaml');
|
|
62
|
+
}
|
|
63
|
+
const manifest = yield (0, adp_tooling_1.getManifest)(variant.reference, adp, logger);
|
|
64
|
+
const dataSources = manifest['sap.app'].dataSources;
|
|
65
|
+
if (!dataSources) {
|
|
66
|
+
throw new Error('No data sources found in the manifest');
|
|
67
|
+
}
|
|
68
|
+
const answers = yield (0, common_1.promptYUIQuestions)((0, adp_tooling_1.getPromptsForChangeDataSource)(dataSources), false);
|
|
69
|
+
const fs = yield (0, adp_tooling_1.generateChange)(basePath, "appdescr_app_changeDataSource" /* ChangeType.CHANGE_DATA_SOURCE */, {
|
|
70
|
+
variant,
|
|
71
|
+
dataSources,
|
|
72
|
+
answers
|
|
73
|
+
});
|
|
74
|
+
if (!simulate) {
|
|
75
|
+
yield new Promise((resolve) => fs.commit(resolve));
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
yield (0, tracing_1.traceChanges)(fs);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
logger.error(error.message);
|
|
83
|
+
if (((_c = error.response) === null || _c === void 0 ? void 0 : _c.status) === 401 && loginAttempts) {
|
|
84
|
+
loginAttempts--;
|
|
85
|
+
logger.error(`Authentication failed. Please check your credentials. Login attempts left: ${loginAttempts}`);
|
|
86
|
+
yield changeDataSource(basePath, defaults, simulate, yamlPath);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
logger.debug(error);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the app descriptor variant.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} basePath - The path to the adaptation project.
|
|
97
|
+
* @returns {DescriptorVariant} The app descriptor variant.
|
|
98
|
+
*/
|
|
99
|
+
function getVariant(basePath) {
|
|
100
|
+
return JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(basePath, 'webapp', 'manifest.appdescr_variant'), 'utf-8'));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Check if the project is a CF project.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} basePath - The path to the adaptation project.
|
|
106
|
+
* @throws {Error} If the project is a CF project.
|
|
107
|
+
*/
|
|
108
|
+
function checkEnvironment(basePath) {
|
|
109
|
+
const configJsonPath = (0, path_1.join)(basePath, '.adp', 'config.json');
|
|
110
|
+
if ((0, fs_1.existsSync)(configJsonPath)) {
|
|
111
|
+
const config = JSON.parse((0, fs_1.readFileSync)(configJsonPath, 'utf-8'));
|
|
112
|
+
if (config.environment === 'CF') {
|
|
113
|
+
throw new Error('Changing data source is not supported for CF projects.');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=change-data-source.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* Return 'create-fiori change *' commands. Commands include also the handler action.
|
|
4
|
+
*
|
|
5
|
+
* @returns - commander command containing change <feature> commands
|
|
6
|
+
*/
|
|
7
|
+
export declare function getChangeCommands(): Command;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getChangeCommands = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const change_data_source_1 = require("./change-data-source");
|
|
6
|
+
/**
|
|
7
|
+
* Return 'create-fiori change *' commands. Commands include also the handler action.
|
|
8
|
+
*
|
|
9
|
+
* @returns - commander command containing change <feature> commands
|
|
10
|
+
*/
|
|
11
|
+
function getChangeCommands() {
|
|
12
|
+
const addCommands = new commander_1.Command('change');
|
|
13
|
+
// create-fiori change data-source
|
|
14
|
+
(0, change_data_source_1.addChangeDataSourceCommand)(addCommands);
|
|
15
|
+
return addCommands;
|
|
16
|
+
}
|
|
17
|
+
exports.getChangeCommands = getChangeCommands;
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
package/dist/cli/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const tracing_1 = require("../tracing");
|
|
|
8
8
|
const add_1 = require("./add");
|
|
9
9
|
const remove_1 = require("./remove");
|
|
10
10
|
const generate_1 = require("./generate");
|
|
11
|
+
const change_1 = require("./change");
|
|
11
12
|
/*
|
|
12
13
|
* We've chosen 'commander' over 'minimist' and 'yargs' for this CLI implementation. Reasons:
|
|
13
14
|
* (if it still up: https://npmtrends.com/commander-vs-minimist-vs-yargs)
|
|
@@ -51,6 +52,8 @@ function getCommanderProgram() {
|
|
|
51
52
|
program.addCommand((0, add_1.getAddCommands)());
|
|
52
53
|
// Handler for create-fiori remove <feature> ..
|
|
53
54
|
program.addCommand((0, remove_1.getRemoveCommands)());
|
|
55
|
+
// Handler for create-fiori change <feature> ..
|
|
56
|
+
program.addCommand((0, change_1.getChangeCommands)());
|
|
54
57
|
// Override exit so calling this command without arguments does not result in an exit code 1, which causes an error message when running from npm init
|
|
55
58
|
program.exitOverride();
|
|
56
59
|
return program;
|
package/dist/common/prompts.js
CHANGED
|
@@ -50,6 +50,24 @@ function enhanceListQuestion(listQuestion, prompt, answers) {
|
|
|
50
50
|
: mapppedChoices.findIndex((choice) => choice.value === initialValue);
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Indicates if the question is optional.
|
|
55
|
+
*
|
|
56
|
+
* @param question question to be checked
|
|
57
|
+
* @param answers rpeviously given answers
|
|
58
|
+
* @returns message of the question
|
|
59
|
+
*/
|
|
60
|
+
function extractMessage(question, answers) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const message = isFunction(question.message) ? yield question.message(answers) : question.message;
|
|
63
|
+
if (question.guiOptions && !question.guiOptions.mandatory) {
|
|
64
|
+
return `${message} (optional)`;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return message;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
53
71
|
/**
|
|
54
72
|
* Converts a YUI question to a simple prompts question.
|
|
55
73
|
*
|
|
@@ -63,7 +81,7 @@ function convertQuestion(question, answers) {
|
|
|
63
81
|
const prompt = {
|
|
64
82
|
type: (_b = QUESTION_TYPE_MAP[(_a = question.type) !== null && _a !== void 0 ? _a : 'input']) !== null && _b !== void 0 ? _b : question.type,
|
|
65
83
|
name: question.name,
|
|
66
|
-
message:
|
|
84
|
+
message: yield extractMessage(question, answers),
|
|
67
85
|
validate: (value) => __awaiter(this, void 0, void 0, function* () { var _c; return isFunction(question.validate) ? yield question.validate(value, answers) : (_c = question.validate) !== null && _c !== void 0 ? _c : true; }),
|
|
68
86
|
initial: () => (isFunction(question.default) ? question.default(answers) : question.default)
|
|
69
87
|
};
|
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.5.
|
|
4
|
+
"version": "0.5.114",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -27,14 +27,19 @@
|
|
|
27
27
|
"chalk": "4.1.2",
|
|
28
28
|
"commander": "9.4.0",
|
|
29
29
|
"diff": "5.1.0",
|
|
30
|
+
"mem-fs": "2.1.0",
|
|
31
|
+
"mem-fs-editor": "9.4.0",
|
|
30
32
|
"prompts": "2.4.2",
|
|
31
|
-
"@sap-ux/adp-tooling": "0.11.
|
|
32
|
-
"@sap-ux/app-config-writer": "0.3.
|
|
33
|
-
"@sap-ux/cap-config-writer": "0.5.
|
|
34
|
-
"@sap-ux/cards-editor-config-writer": "0.3.
|
|
33
|
+
"@sap-ux/adp-tooling": "0.11.7",
|
|
34
|
+
"@sap-ux/app-config-writer": "0.3.81",
|
|
35
|
+
"@sap-ux/cap-config-writer": "0.5.4",
|
|
36
|
+
"@sap-ux/cards-editor-config-writer": "0.3.9",
|
|
37
|
+
"@sap-ux/inquirer-common": "0.3.1",
|
|
35
38
|
"@sap-ux/logger": "0.5.1",
|
|
36
|
-
"@sap-ux/mockserver-config-writer": "0.5.
|
|
37
|
-
"@sap-ux/project-access": "1.22.
|
|
39
|
+
"@sap-ux/mockserver-config-writer": "0.5.8",
|
|
40
|
+
"@sap-ux/project-access": "1.22.3",
|
|
41
|
+
"@sap-ux/system-access": "0.4.5",
|
|
42
|
+
"@sap-ux/ui5-config": "0.22.10"
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {
|
|
40
45
|
"@types/diff": "5.0.9",
|
|
@@ -42,7 +47,7 @@
|
|
|
42
47
|
"@types/mem-fs": "1.1.2",
|
|
43
48
|
"@types/mem-fs-editor": "7.0.1",
|
|
44
49
|
"@types/prompts": "2.4.4",
|
|
45
|
-
"@sap-ux/inquirer-common": "0.3.
|
|
50
|
+
"@sap-ux/inquirer-common": "0.3.1",
|
|
46
51
|
"@sap-ux/store": "0.6.0"
|
|
47
52
|
},
|
|
48
53
|
"scripts": {
|