@sap-ux/generator-adp 1.1.5 → 1.2.1
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 +3 -1
- package/generators/app/headless/cf.d.ts +37 -0
- package/generators/app/headless/cf.js +75 -0
- package/generators/app/index.d.ts +39 -1
- package/generators/app/index.js +141 -19
- package/generators/app/questions/helper/default-values.d.ts +16 -0
- package/generators/app/questions/helper/default-values.js +23 -0
- package/generators/app/questions/helper/validators.d.ts +7 -0
- package/generators/app/questions/helper/validators.js +12 -0
- package/generators/app/types.d.ts +92 -2
- package/generators/translations/generator-adp.i18n.json +4 -0
- package/generators/utils/parse-json-input.d.ts +35 -5
- package/generators/utils/parse-json-input.js +43 -9
- package/generators/utils/type-guards.d.ts +20 -2
- package/generators/utils/type-guards.js +49 -2
- package/package.json +14 -15
package/README.md
CHANGED
|
@@ -14,8 +14,10 @@ The SAPUI5 Adaptation Project generator is included in the [@sap/generator-fiori
|
|
|
14
14
|
|
|
15
15
|
Open the Command Palette in MS Visual Studio Code ( CMD/CTRL + Shift + P ) and execute the `Fiori: Open Adaptation Project Generator` command.
|
|
16
16
|
|
|
17
|
+
For CLI generation, pass the project configuration as a JSON argument. Supplied JSON must be valid and contain the required fields for its target environment; invalid or incomplete input stops generation before CF CLI calls or prompts. Without a JSON argument, the generator opens the interactive wizard.
|
|
18
|
+
|
|
17
19
|
## Keywords
|
|
18
20
|
|
|
19
21
|
SAP Fiori Elements
|
|
20
22
|
Yeoman
|
|
21
|
-
Generator
|
|
23
|
+
Generator
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CfConfig, CfServiceInstanceChoice } from '@sap-ux/adp-tooling';
|
|
2
|
+
import type { ToolsLogger } from '@sap-ux/logger';
|
|
3
|
+
import { MtaMode } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Validates the MTA inputs and resolves the destination project path for the headless CF flow.
|
|
6
|
+
*
|
|
7
|
+
* For `new` MTA mode the folder is created inside `targetFolder` under `mtaId`; for `existing`
|
|
8
|
+
* mode `targetFolder` is the MTA root.
|
|
9
|
+
*
|
|
10
|
+
* @param {MtaMode} mtaMode - The MTA mode.
|
|
11
|
+
* @param {string} targetFolder - The target folder (MTA root for existing, parent for new).
|
|
12
|
+
* @param {ToolsLogger} logger - The logger.
|
|
13
|
+
* @param {CfConfig} cfConfig - The CF configuration.
|
|
14
|
+
* @param {string} [mtaId] - The MTA id/name for new-MTA mode.
|
|
15
|
+
* @returns {string} The resolved absolute project path.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveCfProjectPath(mtaMode: MtaMode, targetFolder: string, logger: ToolsLogger, cfConfig: CfConfig, mtaId?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the target MTA already declares an approuter module. A new MTA never does; for an existing
|
|
20
|
+
* MTA the modules are read from its `mta.yaml`. Mirrors the interactive flow's `detectExistingApprouter`.
|
|
21
|
+
*
|
|
22
|
+
* @param {MtaMode} mtaMode - The MTA mode.
|
|
23
|
+
* @param {string} projectPath - The resolved project/MTA path.
|
|
24
|
+
* @returns {boolean} True if an approuter module already exists.
|
|
25
|
+
*/
|
|
26
|
+
export declare function hasExistingApprouter(mtaMode: MtaMode, projectPath: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Resolves the live CF service instance to bind and extend, matched by name within the current
|
|
29
|
+
* space. Throws when no instance with that name exists.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} serviceInstanceName - The live service instance name.
|
|
32
|
+
* @param {CfConfig} cfConfig - The CF configuration.
|
|
33
|
+
* @param {ToolsLogger} logger - The logger.
|
|
34
|
+
* @returns {Promise<CfServiceInstanceChoice>} The matched service instance.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveCfServiceInstance(serviceInstanceName: string, cfConfig: CfConfig, logger: ToolsLogger): Promise<CfServiceInstanceChoice>;
|
|
37
|
+
//# sourceMappingURL=cf.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveCfProjectPath = resolveCfProjectPath;
|
|
7
|
+
exports.hasExistingApprouter = hasExistingApprouter;
|
|
8
|
+
exports.resolveCfServiceInstance = resolveCfServiceInstance;
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
const adp_tooling_1 = require("@sap-ux/adp-tooling");
|
|
12
|
+
const i18n_js_1 = require("../../utils/i18n.js");
|
|
13
|
+
const types_js_1 = require("../types.js");
|
|
14
|
+
const validators_js_1 = require("../questions/helper/validators.js");
|
|
15
|
+
/**
|
|
16
|
+
* Validates the MTA inputs and resolves the destination project path for the headless CF flow.
|
|
17
|
+
*
|
|
18
|
+
* For `new` MTA mode the folder is created inside `targetFolder` under `mtaId`; for `existing`
|
|
19
|
+
* mode `targetFolder` is the MTA root.
|
|
20
|
+
*
|
|
21
|
+
* @param {MtaMode} mtaMode - The MTA mode.
|
|
22
|
+
* @param {string} targetFolder - The target folder (MTA root for existing, parent for new).
|
|
23
|
+
* @param {ToolsLogger} logger - The logger.
|
|
24
|
+
* @param {CfConfig} cfConfig - The CF configuration.
|
|
25
|
+
* @param {string} [mtaId] - The MTA id/name for new-MTA mode.
|
|
26
|
+
* @returns {string} The resolved absolute project path.
|
|
27
|
+
*/
|
|
28
|
+
function resolveCfProjectPath(mtaMode, targetFolder, logger, cfConfig, mtaId) {
|
|
29
|
+
(0, validators_js_1.assertValidationPassed)((0, validators_js_1.validateProjectPath)(targetFolder, logger, mtaMode, cfConfig));
|
|
30
|
+
if (mtaMode === types_js_1.MtaMode.New) {
|
|
31
|
+
if (!mtaId) {
|
|
32
|
+
throw new Error((0, i18n_js_1.t)('error.mtaIdRequired'));
|
|
33
|
+
}
|
|
34
|
+
(0, validators_js_1.assertValidationPassed)((0, validators_js_1.validateMtaId)(mtaId, targetFolder));
|
|
35
|
+
return (0, node_path_1.join)(targetFolder, mtaId);
|
|
36
|
+
}
|
|
37
|
+
return node_fs_1.default.realpathSync(targetFolder, 'utf-8');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether the target MTA already declares an approuter module. A new MTA never does; for an existing
|
|
41
|
+
* MTA the modules are read from its `mta.yaml`. Mirrors the interactive flow's `detectExistingApprouter`.
|
|
42
|
+
*
|
|
43
|
+
* @param {MtaMode} mtaMode - The MTA mode.
|
|
44
|
+
* @param {string} projectPath - The resolved project/MTA path.
|
|
45
|
+
* @returns {boolean} True if an approuter module already exists.
|
|
46
|
+
*/
|
|
47
|
+
function hasExistingApprouter(mtaMode, projectPath) {
|
|
48
|
+
if (mtaMode === types_js_1.MtaMode.New) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
return (0, adp_tooling_1.hasApprouter)((0, adp_tooling_1.getModuleNames)(projectPath));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Resolves the live CF service instance to bind and extend, matched by name within the current
|
|
60
|
+
* space. Throws when no instance with that name exists.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} serviceInstanceName - The live service instance name.
|
|
63
|
+
* @param {CfConfig} cfConfig - The CF configuration.
|
|
64
|
+
* @param {ToolsLogger} logger - The logger.
|
|
65
|
+
* @returns {Promise<CfServiceInstanceChoice>} The matched service instance.
|
|
66
|
+
*/
|
|
67
|
+
async function resolveCfServiceInstance(serviceInstanceName, cfConfig, logger) {
|
|
68
|
+
const instances = await (0, adp_tooling_1.getAdpServiceInstances)(cfConfig.space.GUID, logger);
|
|
69
|
+
const instance = instances.find((inst) => inst.name === serviceInstanceName);
|
|
70
|
+
if (!instance) {
|
|
71
|
+
throw new Error((0, i18n_js_1.t)('error.serviceInstanceNotFound', { name: serviceInstanceName }));
|
|
72
|
+
}
|
|
73
|
+
return instance;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=cf.js.map
|
|
@@ -53,9 +53,14 @@ export default class extends Generator {
|
|
|
53
53
|
private cfPrompter;
|
|
54
54
|
/**
|
|
55
55
|
* JSON object representing the complete adaptation project configuration,
|
|
56
|
-
* passed as a CLI argument.
|
|
56
|
+
* passed as a CLI argument. Either the ABAP ({@link JsonInput}) or Cloud Foundry
|
|
57
|
+
* ({@link CfJsonInput}) shape, selected by the `targetEnv` discriminator.
|
|
57
58
|
*/
|
|
58
59
|
private readonly jsonInput?;
|
|
60
|
+
/**
|
|
61
|
+
* The reason a supplied CLI JSON argument was rejected, or `undefined` when none was supplied or it was valid.
|
|
62
|
+
*/
|
|
63
|
+
private readonly jsonInputError?;
|
|
59
64
|
/**
|
|
60
65
|
* Parsed `{tmpdir}/{id}.txt` when JSON input includes `id`.
|
|
61
66
|
*/
|
|
@@ -100,6 +105,10 @@ export default class extends Generator {
|
|
|
100
105
|
* CF config.
|
|
101
106
|
*/
|
|
102
107
|
private cfConfig;
|
|
108
|
+
/**
|
|
109
|
+
* Base-app values discovered from CF JSON input; undefined when the interactive prompter supplies them instead.
|
|
110
|
+
*/
|
|
111
|
+
private cfArtifacts?;
|
|
103
112
|
/**
|
|
104
113
|
* Indicates if the current project is an MTA project.
|
|
105
114
|
*/
|
|
@@ -167,8 +176,19 @@ export default class extends Generator {
|
|
|
167
176
|
* @returns {ConfigPrompter} Cached config prompter if going back a page.
|
|
168
177
|
*/
|
|
169
178
|
private _getOrCreatePrompter;
|
|
179
|
+
/**
|
|
180
|
+
* Collects the base-app values the CF writer config needs, sourced from the interactive
|
|
181
|
+
* `cfPrompter`. In the headless (JSON) flow the prompter is absent and `_initFromJsonCf`
|
|
182
|
+
* supplies these values directly; see `_generateAdpProjectArtifactsCF`.
|
|
183
|
+
*
|
|
184
|
+
* @returns {CfArtifactInputs} The base-app values required to build the CF writer config.
|
|
185
|
+
*/
|
|
186
|
+
private _getCfArtifactInputs;
|
|
170
187
|
/**
|
|
171
188
|
* Generates the ADP project artifacts for the CF environment.
|
|
189
|
+
*
|
|
190
|
+
* Base-app values (manifest + derived GUIDs/URLs) are sourced via {@link _getCfArtifactInputs},
|
|
191
|
+
* from either the interactive prompter or the headless JSON discovery.
|
|
172
192
|
*/
|
|
173
193
|
private _generateAdpProjectArtifactsCF;
|
|
174
194
|
/**
|
|
@@ -188,10 +208,28 @@ export default class extends Generator {
|
|
|
188
208
|
* Configures logging for the generator.
|
|
189
209
|
*/
|
|
190
210
|
private _setupLogging;
|
|
211
|
+
/**
|
|
212
|
+
* Dispatches JSON-driven (headless) initialization to the ABAP or Cloud Foundry path based on the
|
|
213
|
+
* JSON shape.
|
|
214
|
+
*
|
|
215
|
+
* @param {JsonInput | CfJsonInput} jsonInput - The parsed JSON input.
|
|
216
|
+
*/
|
|
217
|
+
private _initFromJsonInput;
|
|
191
218
|
/**
|
|
192
219
|
* Initialize the project generator from a json.
|
|
220
|
+
*
|
|
221
|
+
* @param {JsonInput} jsonInput - The parsed ABAP JSON input.
|
|
193
222
|
*/
|
|
194
223
|
private _initFromJson;
|
|
224
|
+
/**
|
|
225
|
+
* Initializes a Cloud Foundry adaptation project from JSON input (headless, no prompts).
|
|
226
|
+
*
|
|
227
|
+
* Validates the CF session, resolves the MTA project path, discovers the business service /
|
|
228
|
+
* service instance and base app, downloads the base app manifest and derives the writer inputs.
|
|
229
|
+
*
|
|
230
|
+
* @param {CfJsonInput} jsonInput - The parsed CF JSON input.
|
|
231
|
+
*/
|
|
232
|
+
private _initFromJsonCf;
|
|
195
233
|
/**
|
|
196
234
|
* Updates the FLP wizard steps in the prompt sequence if the FLP configuration page(s) does not already exist.
|
|
197
235
|
*
|
package/generators/app/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const fiori_generator_shared_1 = require("@sap-ux/fiori-generator-shared");
|
|
|
13
13
|
const logger_1 = require("@sap-ux/logger");
|
|
14
14
|
const axios_extension_1 = require("@sap-ux/axios-extension");
|
|
15
15
|
const feature_toggle_1 = require("@sap-ux/feature-toggle");
|
|
16
|
+
const project_input_validator_1 = require("@sap-ux/project-input-validator");
|
|
16
17
|
const appWizardCache_js_1 = require("../utils/appWizardCache.js");
|
|
17
18
|
const deps_js_1 = require("../utils/deps.js");
|
|
18
19
|
const i18n_js_1 = require("../utils/i18n.js");
|
|
@@ -20,6 +21,7 @@ const json_input_file_js_1 = require("../utils/json-input-file.js");
|
|
|
20
21
|
const logger_js_1 = __importDefault(require("../utils/logger.js"));
|
|
21
22
|
const opts_js_1 = require("../utils/opts.js");
|
|
22
23
|
const parse_json_input_js_1 = require("../utils/parse-json-input.js");
|
|
24
|
+
const type_guards_js_1 = require("../utils/type-guards.js");
|
|
23
25
|
const index_js_1 = require("../telemetry/index.js");
|
|
24
26
|
const steps_js_1 = require("../utils/steps.js");
|
|
25
27
|
const subgenHelpers_js_1 = require("../utils/subgenHelpers.js");
|
|
@@ -35,6 +37,7 @@ const validators_js_1 = require("./questions/helper/validators.js");
|
|
|
35
37
|
const types_js_1 = require("./types.js");
|
|
36
38
|
const target_env_js_1 = require("./questions/target-env.js");
|
|
37
39
|
const key_user_js_1 = require("./questions/key-user.js");
|
|
40
|
+
const cf_js_1 = require("./headless/cf.js");
|
|
38
41
|
const telemetry_1 = require("@sap-ux/telemetry");
|
|
39
42
|
const generatorTitle = 'Adaptation Project';
|
|
40
43
|
/**
|
|
@@ -90,9 +93,14 @@ class default_1 extends yeoman_generator_1.default {
|
|
|
90
93
|
cfPrompter;
|
|
91
94
|
/**
|
|
92
95
|
* JSON object representing the complete adaptation project configuration,
|
|
93
|
-
* passed as a CLI argument.
|
|
96
|
+
* passed as a CLI argument. Either the ABAP ({@link JsonInput}) or Cloud Foundry
|
|
97
|
+
* ({@link CfJsonInput}) shape, selected by the `targetEnv` discriminator.
|
|
94
98
|
*/
|
|
95
99
|
jsonInput;
|
|
100
|
+
/**
|
|
101
|
+
* The reason a supplied CLI JSON argument was rejected, or `undefined` when none was supplied or it was valid.
|
|
102
|
+
*/
|
|
103
|
+
jsonInputError;
|
|
96
104
|
/**
|
|
97
105
|
* Parsed `{tmpdir}/{id}.txt` when JSON input includes `id`.
|
|
98
106
|
*/
|
|
@@ -137,6 +145,10 @@ class default_1 extends yeoman_generator_1.default {
|
|
|
137
145
|
* CF config.
|
|
138
146
|
*/
|
|
139
147
|
cfConfig;
|
|
148
|
+
/**
|
|
149
|
+
* Base-app values discovered from CF JSON input; undefined when the interactive prompter supplies them instead.
|
|
150
|
+
*/
|
|
151
|
+
cfArtifacts;
|
|
140
152
|
/**
|
|
141
153
|
* Indicates if the current project is an MTA project.
|
|
142
154
|
*/
|
|
@@ -177,8 +189,10 @@ class default_1 extends yeoman_generator_1.default {
|
|
|
177
189
|
this.options = opts;
|
|
178
190
|
this.isMtaYamlFound = (0, adp_tooling_1.isMtaProject)(process.cwd());
|
|
179
191
|
const jsonInputString = (0, parse_json_input_js_1.getFirstArg)(args);
|
|
180
|
-
|
|
181
|
-
|
|
192
|
+
const parseResult = (0, parse_json_input_js_1.parseJsonInput)(jsonInputString, this.logger);
|
|
193
|
+
this.jsonInput = parseResult.ok ? parseResult.input : undefined;
|
|
194
|
+
this.jsonInputError = !!jsonInputString && !parseResult.ok ? parseResult.reason : undefined;
|
|
195
|
+
if (!this.jsonInput && !this.jsonInputError) {
|
|
182
196
|
this.env.lookup({
|
|
183
197
|
packagePatterns: ['@sap/generator-fiori', '@bas-dev/generator-extensibility-sub']
|
|
184
198
|
});
|
|
@@ -196,6 +210,9 @@ class default_1 extends yeoman_generator_1.default {
|
|
|
196
210
|
// Force the generator to overwrite existing files without additional prompting
|
|
197
211
|
(0, fiori_generator_shared_1.setYeomanEnvConflicterForce)(this.env, this.options.force);
|
|
198
212
|
await (0, i18n_js_1.initI18n)();
|
|
213
|
+
if (this.jsonInputError) {
|
|
214
|
+
throw new Error((0, parse_json_input_js_1.getInvalidJsonInputMessage)(this.jsonInputError));
|
|
215
|
+
}
|
|
199
216
|
this.isCli = (0, fiori_generator_shared_1.isCli)();
|
|
200
217
|
this.layer = (0, layer_js_1.getFlexLayer)();
|
|
201
218
|
this.isCustomerBase = this.layer === adp_tooling_1.FlexLayer.CUSTOMER_BASE;
|
|
@@ -305,7 +322,7 @@ class default_1 extends yeoman_generator_1.default {
|
|
|
305
322
|
try {
|
|
306
323
|
this.toolsId = (0, uuid_1.v4)();
|
|
307
324
|
if (this.jsonInput) {
|
|
308
|
-
await this.
|
|
325
|
+
await this._initFromJsonInput(this.jsonInput);
|
|
309
326
|
}
|
|
310
327
|
this._collectTelemetryData();
|
|
311
328
|
if (this.isCfEnv) {
|
|
@@ -454,7 +471,8 @@ class default_1 extends yeoman_generator_1.default {
|
|
|
454
471
|
: (this.attributeAnswers?.importKeyUserChanges ?? false)
|
|
455
472
|
};
|
|
456
473
|
if (this.isCfEnv) {
|
|
457
|
-
telemetryData.baseAppTechnicalName =
|
|
474
|
+
telemetryData.baseAppTechnicalName =
|
|
475
|
+
(this.cfArtifacts?.manifest ?? this.cfPrompter?.manifest)?.['sap.app']?.id ?? '';
|
|
458
476
|
telemetryData.projectType = 'cf';
|
|
459
477
|
telemetryData.cfServiceOffering = this.cfServicesAnswers?.serviceInstance?.service ?? '';
|
|
460
478
|
}
|
|
@@ -566,26 +584,46 @@ class default_1 extends yeoman_generator_1.default {
|
|
|
566
584
|
(0, appWizardCache_js_1.cachePut)(this.appWizard, { prompter }, this.logger);
|
|
567
585
|
return prompter;
|
|
568
586
|
}
|
|
587
|
+
/**
|
|
588
|
+
* Collects the base-app values the CF writer config needs, sourced from the interactive
|
|
589
|
+
* `cfPrompter`. In the headless (JSON) flow the prompter is absent and `_initFromJsonCf`
|
|
590
|
+
* supplies these values directly; see `_generateAdpProjectArtifactsCF`.
|
|
591
|
+
*
|
|
592
|
+
* @returns {CfArtifactInputs} The base-app values required to build the CF writer config.
|
|
593
|
+
*/
|
|
594
|
+
_getCfArtifactInputs() {
|
|
595
|
+
if (this.cfArtifacts) {
|
|
596
|
+
return this.cfArtifacts;
|
|
597
|
+
}
|
|
598
|
+
return {
|
|
599
|
+
manifest: this.cfPrompter?.manifest,
|
|
600
|
+
html5RepoRuntimeGuid: this.cfPrompter?.html5RepoRuntimeGuid,
|
|
601
|
+
serviceInstanceGuid: this.cfPrompter?.serviceInstanceGuid,
|
|
602
|
+
backendUrls: this.cfPrompter?.backendUrls,
|
|
603
|
+
oauthPaths: this.cfPrompter?.oauthPaths
|
|
604
|
+
};
|
|
605
|
+
}
|
|
569
606
|
/**
|
|
570
607
|
* Generates the ADP project artifacts for the CF environment.
|
|
608
|
+
*
|
|
609
|
+
* Base-app values (manifest + derived GUIDs/URLs) are sourced via {@link _getCfArtifactInputs},
|
|
610
|
+
* from either the interactive prompter or the headless JSON discovery.
|
|
571
611
|
*/
|
|
572
612
|
async _generateAdpProjectArtifactsCF() {
|
|
573
613
|
const projectPath = this.destinationPath();
|
|
574
614
|
const publicVersions = await (0, adp_tooling_1.fetchPublicVersions)(this.logger);
|
|
575
615
|
this.telemetryCollector.setBatch({ ui5VersionSelected: (0, adp_tooling_1.getLatestVersion)(publicVersions) });
|
|
576
|
-
const manifest = this.
|
|
616
|
+
const { manifest, html5RepoRuntimeGuid, serviceInstanceGuid, backendUrls, oauthPaths } = this._getCfArtifactInputs();
|
|
577
617
|
if (!manifest) {
|
|
578
618
|
throw new Error('Manifest not found for base app.');
|
|
579
619
|
}
|
|
580
|
-
const html5RepoRuntimeGuid = this.cfPrompter.html5RepoRuntimeGuid;
|
|
581
|
-
const serviceInstanceGuid = this.cfPrompter.serviceInstanceGuid;
|
|
582
|
-
const backendUrls = this.cfPrompter.backendUrls;
|
|
583
|
-
const oauthPaths = this.cfPrompter.oauthPaths;
|
|
584
620
|
// In new-MTA / no-existing-service modes the businessService prompt is hidden; use the
|
|
585
621
|
// selected live service instance name to resolve/create the service keys instead.
|
|
586
|
-
const
|
|
622
|
+
const { businessService, serviceInstance } = this.cfServicesAnswers;
|
|
623
|
+
const businessServiceName = businessService?.trim() ? businessService : (serviceInstance?.name ?? '');
|
|
587
624
|
const serviceInfo = await (0, adp_tooling_1.getOrCreateServiceInstanceKeys)({
|
|
588
|
-
names: [businessServiceName]
|
|
625
|
+
names: [businessServiceName],
|
|
626
|
+
spaceGuids: [this.cfConfig.space.GUID]
|
|
589
627
|
}, this.logger);
|
|
590
628
|
const config = (0, adp_tooling_1.getCfConfig)({
|
|
591
629
|
attributeAnswers: this.attributeAnswers,
|
|
@@ -593,7 +631,7 @@ class default_1 extends yeoman_generator_1.default {
|
|
|
593
631
|
cfConfig: this.cfConfig,
|
|
594
632
|
layer: this.layer,
|
|
595
633
|
manifest,
|
|
596
|
-
html5RepoRuntimeGuid,
|
|
634
|
+
html5RepoRuntimeGuid: html5RepoRuntimeGuid ?? '',
|
|
597
635
|
serviceInstanceGuid,
|
|
598
636
|
backendUrls,
|
|
599
637
|
oauthPaths,
|
|
@@ -640,16 +678,28 @@ class default_1 extends yeoman_generator_1.default {
|
|
|
640
678
|
this.logger = logger_js_1.default.logger;
|
|
641
679
|
}
|
|
642
680
|
/**
|
|
643
|
-
*
|
|
681
|
+
* Dispatches JSON-driven (headless) initialization to the ABAP or Cloud Foundry path based on the
|
|
682
|
+
* JSON shape.
|
|
683
|
+
*
|
|
684
|
+
* @param {JsonInput | CfJsonInput} jsonInput - The parsed JSON input.
|
|
644
685
|
*/
|
|
645
|
-
async
|
|
646
|
-
if (
|
|
686
|
+
async _initFromJsonInput(jsonInput) {
|
|
687
|
+
if ((0, type_guards_js_1.isCfJsonInput)(jsonInput)) {
|
|
688
|
+
await this._initFromJsonCf(jsonInput);
|
|
647
689
|
return;
|
|
648
690
|
}
|
|
649
|
-
|
|
650
|
-
|
|
691
|
+
await this._initFromJson(jsonInput);
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Initialize the project generator from a json.
|
|
695
|
+
*
|
|
696
|
+
* @param {JsonInput} jsonInput - The parsed ABAP JSON input.
|
|
697
|
+
*/
|
|
698
|
+
async _initFromJson(jsonInput) {
|
|
699
|
+
if (jsonInput.id) {
|
|
700
|
+
this.jsonInputFile = await (0, json_input_file_js_1.readJsonInputFile)(jsonInput.id);
|
|
651
701
|
}
|
|
652
|
-
const { system, client, username = '', password = '', projectType, application: baseApplicationName, applicationTitle, targetFolder = '/home/user/projects', projectName = (0, adp_tooling_1.getDefaultProjectName)(targetFolder, `${baseApplicationName}.variant`), namespace = (0, default_values_js_1.getDefaultNamespace)(projectName, this.isCustomerBase) } =
|
|
702
|
+
const { system, client, username = '', password = '', projectType, application: baseApplicationName, applicationTitle, targetFolder = '/home/user/projects', projectName = (0, adp_tooling_1.getDefaultProjectName)(targetFolder, `${baseApplicationName}.variant`), namespace = (0, default_values_js_1.getDefaultNamespace)(projectName, this.isCustomerBase) } = jsonInput;
|
|
653
703
|
await (0, validators_js_1.validateJsonInput)(this.systemLookup, this.isCustomerBase, {
|
|
654
704
|
projectName,
|
|
655
705
|
targetFolder,
|
|
@@ -700,6 +750,78 @@ class default_1 extends yeoman_generator_1.default {
|
|
|
700
750
|
enableTypeScript: false
|
|
701
751
|
};
|
|
702
752
|
}
|
|
753
|
+
/**
|
|
754
|
+
* Initializes a Cloud Foundry adaptation project from JSON input (headless, no prompts).
|
|
755
|
+
*
|
|
756
|
+
* Validates the CF session, resolves the MTA project path, discovers the business service /
|
|
757
|
+
* service instance and base app, downloads the base app manifest and derives the writer inputs.
|
|
758
|
+
*
|
|
759
|
+
* @param {CfJsonInput} jsonInput - The parsed CF JSON input.
|
|
760
|
+
*/
|
|
761
|
+
async _initFromJsonCf(jsonInput) {
|
|
762
|
+
this.isCfEnv = true;
|
|
763
|
+
this.targetEnv = types_js_1.TargetEnv.CF;
|
|
764
|
+
if (!this.cfInstalled) {
|
|
765
|
+
throw new Error((0, i18n_js_1.t)('error.cfNotInstalled'));
|
|
766
|
+
}
|
|
767
|
+
this.isCfLoggedIn = await (0, adp_tooling_1.isLoggedInCf)(this.cfConfig, this.logger);
|
|
768
|
+
if (!this.isCfLoggedIn) {
|
|
769
|
+
throw new Error((0, i18n_js_1.t)('error.cfNotLoggedIn'));
|
|
770
|
+
}
|
|
771
|
+
const { application: baseApplicationName, applicationTitle, serviceInstanceName, approuter, businessSolutionName, mtaMode = types_js_1.MtaMode.Existing, mtaId, targetFolder = process.cwd(), projectName: requestedProjectName, namespace: requestedNamespace } = jsonInput;
|
|
772
|
+
const projectPath = (0, cf_js_1.resolveCfProjectPath)(mtaMode, targetFolder, this.logger, this.cfConfig, mtaId);
|
|
773
|
+
this.destinationRoot(projectPath);
|
|
774
|
+
const resolvedApprouter = approuter ?? (mtaMode === types_js_1.MtaMode.Existing ? (0, adp_tooling_1.getApprouterType)(projectPath) : adp_tooling_1.AppRouterType.MANAGED);
|
|
775
|
+
// A managed approuter with no existing router writes destinations keyed on the business solution name.
|
|
776
|
+
let businessSolution = businessSolutionName?.trim() ?? '';
|
|
777
|
+
if (resolvedApprouter === adp_tooling_1.AppRouterType.MANAGED && !(0, cf_js_1.hasExistingApprouter)(mtaMode, projectPath)) {
|
|
778
|
+
if (businessSolution) {
|
|
779
|
+
(0, validators_js_1.assertValidationPassed)((0, validators_js_1.validateBusinessSolutionName)(businessSolution));
|
|
780
|
+
}
|
|
781
|
+
else {
|
|
782
|
+
businessSolution = (0, default_values_js_1.generateBusinessSolutionName)();
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
const serviceInfo = await (0, adp_tooling_1.getBusinessServiceInfo)(serviceInstanceName, this.cfConfig, this.logger);
|
|
786
|
+
if (!serviceInfo) {
|
|
787
|
+
throw new Error((0, i18n_js_1.t)('error.businessServiceDoesNotExist'));
|
|
788
|
+
}
|
|
789
|
+
const serviceInstance = await (0, cf_js_1.resolveCfServiceInstance)(serviceInstanceName, this.cfConfig, this.logger);
|
|
790
|
+
const apps = await (0, adp_tooling_1.getCfApps)(serviceInfo.serviceKeys, this.cfConfig, this.logger);
|
|
791
|
+
const baseApp = apps.find((app) => app.appId === baseApplicationName);
|
|
792
|
+
if (!baseApp) {
|
|
793
|
+
throw new Error((0, i18n_js_1.t)('error.applicationNotFound', { appName: baseApplicationName }));
|
|
794
|
+
}
|
|
795
|
+
const { entries, serviceInstanceGuid, manifest } = await (0, adp_tooling_1.downloadAppContent)(this.cfConfig.space.GUID, baseApp, this.logger);
|
|
796
|
+
await (0, adp_tooling_1.validateSmartTemplateApplication)(manifest);
|
|
797
|
+
await (0, adp_tooling_1.validateODataEndpoints)(entries, serviceInfo.serviceKeys, this.logger);
|
|
798
|
+
this.cfArtifacts = {
|
|
799
|
+
manifest,
|
|
800
|
+
html5RepoRuntimeGuid: serviceInstanceGuid,
|
|
801
|
+
serviceInstanceGuid: serviceInfo.serviceInstance?.guid,
|
|
802
|
+
backendUrls: (0, adp_tooling_1.getBackendUrlsFromServiceKeys)(serviceInfo.serviceKeys),
|
|
803
|
+
oauthPaths: (0, adp_tooling_1.getOAuthPathsFromXsApp)(entries)
|
|
804
|
+
};
|
|
805
|
+
this.cfServicesAnswers = {
|
|
806
|
+
approuter: resolvedApprouter,
|
|
807
|
+
baseApp,
|
|
808
|
+
...(serviceInstance ? { serviceInstance } : {}),
|
|
809
|
+
...(businessSolution ? { businessSolutionName: businessSolution } : {})
|
|
810
|
+
};
|
|
811
|
+
const projectName = (0, default_values_js_1.resolveProjectName)(this.destinationPath(), requestedProjectName);
|
|
812
|
+
const title = applicationTitle ?? manifest['sap.app']?.title ?? (0, i18n_js_1.t)('prompts.appTitleDefault');
|
|
813
|
+
const namespace = requestedNamespace ?? (0, default_values_js_1.getDefaultNamespace)(projectName, this.isCustomerBase);
|
|
814
|
+
(0, validators_js_1.assertValidationPassed)((0, project_input_validator_1.validateProjectName)(projectName, projectPath, this.isCustomerBase, true));
|
|
815
|
+
(0, validators_js_1.assertValidationPassed)((0, project_input_validator_1.validateNamespaceAdp)(namespace, projectName, this.isCustomerBase));
|
|
816
|
+
this.attributeAnswers = {
|
|
817
|
+
projectName,
|
|
818
|
+
title,
|
|
819
|
+
namespace,
|
|
820
|
+
targetFolder: projectPath,
|
|
821
|
+
ui5Version: '',
|
|
822
|
+
enableTypeScript: false
|
|
823
|
+
};
|
|
824
|
+
}
|
|
703
825
|
/**
|
|
704
826
|
* Updates the FLP wizard steps in the prompt sequence if the FLP configuration page(s) does not already exist.
|
|
705
827
|
*
|
|
@@ -14,4 +14,20 @@ export declare function getDefaultNamespace(projectName: string, isCustomerBase:
|
|
|
14
14
|
* @returns {Promise<string>} The valid UI5 version or an empty string if the first version is not valid or if there are no versions.
|
|
15
15
|
*/
|
|
16
16
|
export declare function getDefaultVersion(ui5Versions: string[]): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Generates a unique default business solution name for the headless CF flow when the caller
|
|
19
|
+
* omits one. The `solution-` prefix plus 10 hex characters stays short (the value is written into
|
|
20
|
+
* the CF `sap.cloud.service` destination property) and satisfies the business-solution-name charset.
|
|
21
|
+
*
|
|
22
|
+
* @returns {string} A unique default business solution name, e.g. `solution-a1b2c3d4e5`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function generateBusinessSolutionName(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Derives the project (sub-module) name for the CF flow from JSON input or a default.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} projectPath - The destination path used to derive the default project name.
|
|
29
|
+
* @param {string} [requested] - The explicit project name from JSON input, when provided.
|
|
30
|
+
* @returns {string} The project name.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveProjectName(projectPath: string, requested?: string): string;
|
|
17
33
|
//# sourceMappingURL=default-values.d.ts.map
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDefaultNamespace = getDefaultNamespace;
|
|
4
4
|
exports.getDefaultVersion = getDefaultVersion;
|
|
5
|
+
exports.generateBusinessSolutionName = generateBusinessSolutionName;
|
|
6
|
+
exports.resolveProjectName = resolveProjectName;
|
|
7
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
8
|
const adp_tooling_1 = require("@sap-ux/adp-tooling");
|
|
6
9
|
/**
|
|
7
10
|
* Generates a namespace for a project based on its layer.
|
|
@@ -27,4 +30,24 @@ async function getDefaultVersion(ui5Versions) {
|
|
|
27
30
|
const isValid = await (0, adp_tooling_1.validateUI5VersionExists)(ui5Versions[0]);
|
|
28
31
|
return isValid === true ? ui5Versions[0] : '';
|
|
29
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Generates a unique default business solution name for the headless CF flow when the caller
|
|
35
|
+
* omits one. The `solution-` prefix plus 10 hex characters stays short (the value is written into
|
|
36
|
+
* the CF `sap.cloud.service` destination property) and satisfies the business-solution-name charset.
|
|
37
|
+
*
|
|
38
|
+
* @returns {string} A unique default business solution name, e.g. `solution-a1b2c3d4e5`.
|
|
39
|
+
*/
|
|
40
|
+
function generateBusinessSolutionName() {
|
|
41
|
+
return `solution-${(0, node_crypto_1.randomBytes)(5).toString('hex')}`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Derives the project (sub-module) name for the CF flow from JSON input or a default.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} projectPath - The destination path used to derive the default project name.
|
|
47
|
+
* @param {string} [requested] - The explicit project name from JSON input, when provided.
|
|
48
|
+
* @returns {string} The project name.
|
|
49
|
+
*/
|
|
50
|
+
function resolveProjectName(projectPath, requested) {
|
|
51
|
+
return requested ?? (0, adp_tooling_1.getDefaultProjectName)(projectPath);
|
|
52
|
+
}
|
|
30
53
|
//# sourceMappingURL=default-values.js.map
|
|
@@ -78,6 +78,13 @@ export declare function validateProjectPath(projectPath: string, logger: ToolsLo
|
|
|
78
78
|
* @returns {string | boolean} Returns true if valid, otherwise an error message.
|
|
79
79
|
*/
|
|
80
80
|
export declare function validateMtaId(value: string, parentPath?: string): string | boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Throws the error message of a failed validator result; does nothing when the result is `true`.
|
|
83
|
+
*
|
|
84
|
+
* @param {string | boolean} result - The validator result to assert.
|
|
85
|
+
* @throws {Error} When the result is an error message string.
|
|
86
|
+
*/
|
|
87
|
+
export declare function assertValidationPassed(result: string | boolean): void;
|
|
81
88
|
/**
|
|
82
89
|
* Validate business solution name.
|
|
83
90
|
*
|
|
@@ -8,6 +8,7 @@ exports.validateJsonInput = validateJsonInput;
|
|
|
8
8
|
exports.validateEnvironment = validateEnvironment;
|
|
9
9
|
exports.validateProjectPath = validateProjectPath;
|
|
10
10
|
exports.validateMtaId = validateMtaId;
|
|
11
|
+
exports.assertValidationPassed = assertValidationPassed;
|
|
11
12
|
exports.validateBusinessSolutionName = validateBusinessSolutionName;
|
|
12
13
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
13
14
|
const node_path_1 = require("node:path");
|
|
@@ -151,6 +152,17 @@ function validateMtaId(value, parentPath) {
|
|
|
151
152
|
}
|
|
152
153
|
return true;
|
|
153
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Throws the error message of a failed validator result; does nothing when the result is `true`.
|
|
157
|
+
*
|
|
158
|
+
* @param {string | boolean} result - The validator result to assert.
|
|
159
|
+
* @throws {Error} When the result is an error message string.
|
|
160
|
+
*/
|
|
161
|
+
function assertValidationPassed(result) {
|
|
162
|
+
if ((0, type_guards_js_1.isString)(result)) {
|
|
163
|
+
throw new Error(result);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
154
166
|
/**
|
|
155
167
|
* Validate business solution name.
|
|
156
168
|
*
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type Generator from 'yeoman-generator';
|
|
2
2
|
import type { AppWizard, Prompts as YeomanUiSteps } from '@sap-devx/yeoman-ui-types';
|
|
3
3
|
import type { YUIQuestion } from '@sap-ux/inquirer-common';
|
|
4
|
+
import type { Manifest } from '@sap-ux/project-access';
|
|
4
5
|
import type { TelemetryData } from '@sap-ux/fiori-generator-shared';
|
|
5
6
|
import type { AdaptationDescriptor, AdaptationProjectType, KeyUserChangeContent } from '@sap-ux/axios-extension';
|
|
6
|
-
import type { AttributesAnswers, ConfigAnswers, FlexLayer } from '@sap-ux/adp-tooling';
|
|
7
|
+
import type { AttributesAnswers, ConfigAnswers, FlexLayer, AppRouterType } from '@sap-ux/adp-tooling';
|
|
7
8
|
export interface AdpGeneratorOptions extends Generator.GeneratorOptions {
|
|
8
9
|
/**
|
|
9
10
|
* VSCode instance
|
|
@@ -278,7 +279,7 @@ export interface ExtensionProjectData {
|
|
|
278
279
|
namespace: string;
|
|
279
280
|
}
|
|
280
281
|
/**
|
|
281
|
-
* CLI JSON for the adaptation project generator.
|
|
282
|
+
* CLI JSON for the adaptation project generator (ABAP target).
|
|
282
283
|
*
|
|
283
284
|
* When `id` is set, `{tmpdir}/{id}.txt` may also be loaded (see `readJsonInputFile`).
|
|
284
285
|
*/
|
|
@@ -287,6 +288,10 @@ export interface JsonInput {
|
|
|
287
288
|
* Orchestrator correlation id. Keys the result file and `{tmpdir}/{id}.txt`.
|
|
288
289
|
*/
|
|
289
290
|
id?: string;
|
|
291
|
+
/**
|
|
292
|
+
* Target environment. Absent is treated as `ABAP` for backwards compatibility.
|
|
293
|
+
*/
|
|
294
|
+
targetEnv?: typeof TargetEnv.ABAP;
|
|
290
295
|
system: string;
|
|
291
296
|
client?: string;
|
|
292
297
|
username?: string;
|
|
@@ -298,6 +303,91 @@ export interface JsonInput {
|
|
|
298
303
|
namespace?: string;
|
|
299
304
|
projectType?: AdaptationProjectType;
|
|
300
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* CLI JSON for the adaptation project generator (Cloud Foundry target).
|
|
308
|
+
*
|
|
309
|
+
* Selected by `targetEnv: 'CF'`. The `application` field carries the CF base-app id, matched within
|
|
310
|
+
* the apps discovered for the given service instance. A `serviceInstanceName` is always required.
|
|
311
|
+
*/
|
|
312
|
+
export interface CfJsonInput {
|
|
313
|
+
/**
|
|
314
|
+
* Orchestrator correlation id. Keys the result file.
|
|
315
|
+
*/
|
|
316
|
+
id?: string;
|
|
317
|
+
/**
|
|
318
|
+
* Target environment discriminator. Always `CF` for this shape.
|
|
319
|
+
*/
|
|
320
|
+
targetEnv: typeof TargetEnv.CF;
|
|
321
|
+
/**
|
|
322
|
+
* CF base-app id to adapt. Matched against the apps discovered for the business service.
|
|
323
|
+
*/
|
|
324
|
+
application: string;
|
|
325
|
+
/**
|
|
326
|
+
* Title for the generated adaptation project.
|
|
327
|
+
*/
|
|
328
|
+
applicationTitle?: string;
|
|
329
|
+
/**
|
|
330
|
+
* Name of the live CF service instance to connect to and extend. Always required; identifies the
|
|
331
|
+
* service whose apps are discovered and that is bound into the generated project.
|
|
332
|
+
*/
|
|
333
|
+
serviceInstanceName: string;
|
|
334
|
+
/**
|
|
335
|
+
* Approuter type to configure. When omitted, inherits the existing MTA router type or defaults
|
|
336
|
+
* to the managed HTML5 application runtime for a new MTA.
|
|
337
|
+
*/
|
|
338
|
+
approuter?: AppRouterType;
|
|
339
|
+
/**
|
|
340
|
+
* Optional business solution name (reuse library prefix).
|
|
341
|
+
*/
|
|
342
|
+
businessSolutionName?: string;
|
|
343
|
+
/**
|
|
344
|
+
* Whether to scaffold a new MTA (`new`) or reuse an existing one (`existing`). Defaults to `existing`.
|
|
345
|
+
*/
|
|
346
|
+
mtaMode?: MtaMode;
|
|
347
|
+
/**
|
|
348
|
+
* The MTA project id/name to create (new-MTA mode only).
|
|
349
|
+
*/
|
|
350
|
+
mtaId?: string;
|
|
351
|
+
/**
|
|
352
|
+
* For `existing` MTA mode, the absolute path to the MTA root (the folder containing `mta.yaml`).
|
|
353
|
+
* For `new` MTA mode, the parent folder the new MTA folder is created in.
|
|
354
|
+
*/
|
|
355
|
+
targetFolder?: string;
|
|
356
|
+
/**
|
|
357
|
+
* Name of the generated adaptation project (sub-module) folder.
|
|
358
|
+
*/
|
|
359
|
+
projectName?: string;
|
|
360
|
+
/**
|
|
361
|
+
* Namespace for the generated adaptation project.
|
|
362
|
+
*/
|
|
363
|
+
namespace?: string;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Base-app values required to build the CF writer config, sourced either from the interactive
|
|
367
|
+
* `CFServicesPrompter` or from the headless JSON discovery.
|
|
368
|
+
*/
|
|
369
|
+
export interface CfArtifactInputs {
|
|
370
|
+
/**
|
|
371
|
+
* The base app manifest.
|
|
372
|
+
*/
|
|
373
|
+
manifest?: Manifest;
|
|
374
|
+
/**
|
|
375
|
+
* HTML5 repo runtime service instance GUID.
|
|
376
|
+
*/
|
|
377
|
+
html5RepoRuntimeGuid?: string;
|
|
378
|
+
/**
|
|
379
|
+
* Business service instance GUID.
|
|
380
|
+
*/
|
|
381
|
+
serviceInstanceGuid?: string;
|
|
382
|
+
/**
|
|
383
|
+
* Backend URLs derived from the service keys.
|
|
384
|
+
*/
|
|
385
|
+
backendUrls?: string[];
|
|
386
|
+
/**
|
|
387
|
+
* OAuth paths extracted from the base app's xs-app.json.
|
|
388
|
+
*/
|
|
389
|
+
oauthPaths?: string[];
|
|
390
|
+
}
|
|
301
391
|
/**
|
|
302
392
|
* Extra JSON from `{tmpdir}/{id}.txt`. BAS writes a `.txt` file whose contents are JSON.
|
|
303
393
|
* Currently `keyUserChanges` only; extra fields are allowed.
|
|
@@ -135,6 +135,10 @@
|
|
|
135
135
|
"mtaIdTooLong": "MTA project name must be 20 characters or fewer.",
|
|
136
136
|
"mtaIdAlreadyExists": "A folder with this name already exists in the selected location. Please choose a different MTA project name.",
|
|
137
137
|
"businessServiceDoesNotExist": "The service chosen does not exist in cockpit or the user is not member of the needed space.",
|
|
138
|
+
"mtaIdRequired": "An MTA project name, `mtaId`, is required when creating a new MTA project.",
|
|
139
|
+
"invalidJsonSyntax": "The provided JSON input could not be parsed. Check for syntax errors such as mismatched quotes, commas, or brackets.",
|
|
140
|
+
"invalidJsonInput": "The {{env}} JSON input is invalid or incomplete. Provide valid JSON with the required fields for this target environment.",
|
|
141
|
+
"serviceInstanceNotFound": "The Cloud Foundry service instance '{{name}}' was not found. Provide a valid service instance name.",
|
|
138
142
|
"businessSolutionNameInvalid": "Invalid business solution name. Only lowercase letters, numbers, dots (.), underscores (_), and hyphens (-) are allowed. The name must contain at least one letter or number.",
|
|
139
143
|
"cfLoginCannotBeDetected": "CF Login cannot be detected as an extension in Visual Studio Code. For more information, see (link not yet available).",
|
|
140
144
|
"projectDoesNotExist": "The project does not exist. Please select an MTA project.",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ToolsLogger } from '@sap-ux/logger';
|
|
2
|
-
import type { JsonInput } from '../app/types.js';
|
|
2
|
+
import type { CfJsonInput, JsonInput } from '../app/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Returns the first argument from a list of CLI arguments. If the first argument
|
|
5
5
|
* is not a string and not an array, returns empty string.
|
|
@@ -9,12 +9,42 @@ import type { JsonInput } from '../app/types.js';
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function getFirstArg<T>(args: T | T[]): T | string;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* The reason a JSON input string failed to parse into a valid {@link JsonInput} or {@link CfJsonInput}.
|
|
13
|
+
*
|
|
14
|
+
* - `syntax` — the string is not valid JSON.
|
|
15
|
+
* - `cf-shape` — selects the Cloud Foundry environment (`targetEnv: 'CF'`) but does not satisfy {@link isCfJsonInput}.
|
|
16
|
+
* - `abap-shape` — does not select Cloud Foundry and does not satisfy the ABAP {@link isAbapJsonInput} contract.
|
|
17
|
+
*/
|
|
18
|
+
export type ParseFailure = 'syntax' | 'cf-shape' | 'abap-shape';
|
|
19
|
+
/**
|
|
20
|
+
* Builds the localized error message for a {@link ParseFailure}, keeping the text simple while still
|
|
21
|
+
* naming the target environment (ABAP / Cloud Foundry) for a shape mismatch. A syntax failure has no
|
|
22
|
+
* environment, so it uses its own message.
|
|
23
|
+
*
|
|
24
|
+
* @param {ParseFailure} reason - Why the JSON input was rejected.
|
|
25
|
+
* @returns {string} The localized error message.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getInvalidJsonInputMessage(reason: ParseFailure): string;
|
|
28
|
+
/**
|
|
29
|
+
* Discriminated result of {@link parseJsonInput}: either the parsed input, or the reason it failed.
|
|
30
|
+
*/
|
|
31
|
+
export type ParseJsonResult = {
|
|
32
|
+
ok: true;
|
|
33
|
+
input: JsonInput | CfJsonInput;
|
|
34
|
+
} | {
|
|
35
|
+
ok: false;
|
|
36
|
+
reason: ParseFailure;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Parse a json string as an object conforming to the {@link JsonInput} (ABAP) or {@link CfJsonInput}
|
|
40
|
+
* (Cloud Foundry) interface. Routing is driven by the `targetEnv` discriminator: `'CF'` selects the
|
|
41
|
+
* CF shape, anything else (including an absent `targetEnv`) is treated as ABAP for backwards
|
|
42
|
+
* compatibility.
|
|
13
43
|
*
|
|
14
44
|
* @param {string} jsonString - The json string representation.
|
|
15
45
|
* @param {ToolsLogger} logger - The logger instance.
|
|
16
|
-
* @returns {
|
|
17
|
-
*
|
|
46
|
+
* @returns {ParseJsonResult} `{ ok: true, input }` for a valid input, otherwise `{ ok: false, reason }`
|
|
47
|
+
* describing whether the failure was a JSON syntax error, a CF-shape mismatch or an ABAP-shape mismatch.
|
|
18
48
|
*/
|
|
19
|
-
export declare function parseJsonInput(jsonString: string, logger: ToolsLogger):
|
|
49
|
+
export declare function parseJsonInput(jsonString: string, logger: ToolsLogger): ParseJsonResult;
|
|
20
50
|
//# sourceMappingURL=parse-json-input.d.ts.map
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFirstArg = getFirstArg;
|
|
4
|
+
exports.getInvalidJsonInputMessage = getInvalidJsonInputMessage;
|
|
4
5
|
exports.parseJsonInput = parseJsonInput;
|
|
6
|
+
const types_js_1 = require("../app/types.js");
|
|
5
7
|
const type_guards_js_1 = require("./type-guards.js");
|
|
8
|
+
const i18n_js_1 = require("./i18n.js");
|
|
6
9
|
/**
|
|
7
10
|
* Returns the first argument from a list of CLI arguments. If the first argument
|
|
8
11
|
* is not a string and not an array, returns empty string.
|
|
@@ -20,24 +23,55 @@ function getFirstArg(args) {
|
|
|
20
23
|
return '';
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
|
-
*
|
|
26
|
+
* Builds the localized error message for a {@link ParseFailure}, keeping the text simple while still
|
|
27
|
+
* naming the target environment (ABAP / Cloud Foundry) for a shape mismatch. A syntax failure has no
|
|
28
|
+
* environment, so it uses its own message.
|
|
29
|
+
*
|
|
30
|
+
* @param {ParseFailure} reason - Why the JSON input was rejected.
|
|
31
|
+
* @returns {string} The localized error message.
|
|
32
|
+
*/
|
|
33
|
+
function getInvalidJsonInputMessage(reason) {
|
|
34
|
+
if (reason === 'syntax') {
|
|
35
|
+
return (0, i18n_js_1.t)('error.invalidJsonSyntax');
|
|
36
|
+
}
|
|
37
|
+
const env = reason === 'cf-shape' ? 'Cloud Foundry' : 'ABAP';
|
|
38
|
+
return (0, i18n_js_1.t)('error.invalidJsonInput', { env });
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parse a json string as an object conforming to the {@link JsonInput} (ABAP) or {@link CfJsonInput}
|
|
42
|
+
* (Cloud Foundry) interface. Routing is driven by the `targetEnv` discriminator: `'CF'` selects the
|
|
43
|
+
* CF shape, anything else (including an absent `targetEnv`) is treated as ABAP for backwards
|
|
44
|
+
* compatibility.
|
|
24
45
|
*
|
|
25
46
|
* @param {string} jsonString - The json string representation.
|
|
26
47
|
* @param {ToolsLogger} logger - The logger instance.
|
|
27
|
-
* @returns {
|
|
28
|
-
*
|
|
48
|
+
* @returns {ParseJsonResult} `{ ok: true, input }` for a valid input, otherwise `{ ok: false, reason }`
|
|
49
|
+
* describing whether the failure was a JSON syntax error, a CF-shape mismatch or an ABAP-shape mismatch.
|
|
29
50
|
*/
|
|
30
51
|
function parseJsonInput(jsonString, logger) {
|
|
52
|
+
let parsed;
|
|
31
53
|
try {
|
|
32
|
-
|
|
33
|
-
if (!(0, type_guards_js_1.isJsonInput)(parsed)) {
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
return parsed;
|
|
54
|
+
parsed = JSON.parse(jsonString);
|
|
37
55
|
}
|
|
38
56
|
catch (error) {
|
|
39
57
|
logger.debug(`Failed to parse adp JSON input: ${error.message}`);
|
|
40
|
-
return
|
|
58
|
+
return { ok: false, reason: 'syntax' };
|
|
59
|
+
}
|
|
60
|
+
if (isPlainTargetEnvCf(parsed)) {
|
|
61
|
+
return (0, type_guards_js_1.isCfJsonInput)(parsed) ? { ok: true, input: parsed } : { ok: false, reason: 'cf-shape' };
|
|
41
62
|
}
|
|
63
|
+
if (!(0, type_guards_js_1.isAbapJsonInput)(parsed)) {
|
|
64
|
+
return { ok: false, reason: 'abap-shape' };
|
|
65
|
+
}
|
|
66
|
+
return { ok: true, input: parsed };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Narrow check for whether a parsed json selects the Cloud Foundry target environment.
|
|
70
|
+
*
|
|
71
|
+
* @param {unknown} value - The parsed json value.
|
|
72
|
+
* @returns {boolean} True if the value is an object whose `targetEnv` is `'CF'`.
|
|
73
|
+
*/
|
|
74
|
+
function isPlainTargetEnvCf(value) {
|
|
75
|
+
return typeof value === 'object' && value !== null && value.targetEnv === types_js_1.TargetEnv.CF;
|
|
42
76
|
}
|
|
43
77
|
//# sourceMappingURL=parse-json-input.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { JsonInput, JsonInputFile } from '../app/types.js';
|
|
1
|
+
import type { CfJsonInput, JsonInput, JsonInputFile } from '../app/types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Type guard for a string values.
|
|
4
4
|
*
|
|
@@ -6,13 +6,31 @@ import type { JsonInput, JsonInputFile } from '../app/types.js';
|
|
|
6
6
|
* @returns {boolean} True if the value is of type string.
|
|
7
7
|
*/
|
|
8
8
|
export declare function isString(value: unknown): value is string;
|
|
9
|
+
/**
|
|
10
|
+
* Type guard for a non-empty string (ignoring surrounding whitespace).
|
|
11
|
+
*
|
|
12
|
+
* @param {unknown} value - The value being checked.
|
|
13
|
+
* @returns {boolean} True if the value is a string with non-whitespace content.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isNonEmptyString(value: unknown): value is string;
|
|
9
16
|
/**
|
|
10
17
|
* Type guard for an adaptation project configuration json.
|
|
11
18
|
*
|
|
12
19
|
* @param {unknown} value - The value being checked.
|
|
13
20
|
* @returns {boolean} True if the value conforms to the AdpJsonInput interface.
|
|
14
21
|
*/
|
|
15
|
-
export declare function
|
|
22
|
+
export declare function isAbapJsonInput(value: unknown): value is JsonInput;
|
|
23
|
+
/**
|
|
24
|
+
* Type guard for a Cloud Foundry adaptation project configuration json.
|
|
25
|
+
*
|
|
26
|
+
* Requires `targetEnv === 'CF'`, a non-empty `application` (the CF base-app id) and a non-empty
|
|
27
|
+
* `serviceInstanceName` (the live CF service instance to connect to and extend). All other fields are
|
|
28
|
+
* optional and, when present, must be of the expected type.
|
|
29
|
+
*
|
|
30
|
+
* @param {unknown} value - The value being checked.
|
|
31
|
+
* @returns {boolean} True if the value conforms to the CfJsonInput interface.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isCfJsonInput(value: unknown): value is CfJsonInput;
|
|
16
34
|
/**
|
|
17
35
|
* Type guard for JsonInputFile.
|
|
18
36
|
*
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isString = isString;
|
|
4
|
-
exports.
|
|
4
|
+
exports.isNonEmptyString = isNonEmptyString;
|
|
5
|
+
exports.isAbapJsonInput = isAbapJsonInput;
|
|
6
|
+
exports.isCfJsonInput = isCfJsonInput;
|
|
5
7
|
exports.isJsonInputFile = isJsonInputFile;
|
|
8
|
+
const types_js_1 = require("../app/types.js");
|
|
9
|
+
const adp_tooling_1 = require("@sap-ux/adp-tooling");
|
|
6
10
|
/**
|
|
7
11
|
* Type guard for a string values.
|
|
8
12
|
*
|
|
@@ -12,13 +16,22 @@ exports.isJsonInputFile = isJsonInputFile;
|
|
|
12
16
|
function isString(value) {
|
|
13
17
|
return typeof value === 'string';
|
|
14
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Type guard for a non-empty string (ignoring surrounding whitespace).
|
|
21
|
+
*
|
|
22
|
+
* @param {unknown} value - The value being checked.
|
|
23
|
+
* @returns {boolean} True if the value is a string with non-whitespace content.
|
|
24
|
+
*/
|
|
25
|
+
function isNonEmptyString(value) {
|
|
26
|
+
return isString(value) && value.trim().length > 0;
|
|
27
|
+
}
|
|
15
28
|
/**
|
|
16
29
|
* Type guard for an adaptation project configuration json.
|
|
17
30
|
*
|
|
18
31
|
* @param {unknown} value - The value being checked.
|
|
19
32
|
* @returns {boolean} True if the value conforms to the AdpJsonInput interface.
|
|
20
33
|
*/
|
|
21
|
-
function
|
|
34
|
+
function isAbapJsonInput(value) {
|
|
22
35
|
if (!isPlainObject(value)) {
|
|
23
36
|
return false;
|
|
24
37
|
}
|
|
@@ -33,6 +46,40 @@ function isJsonInput(value) {
|
|
|
33
46
|
isOptionalString(value.projectName) &&
|
|
34
47
|
isOptionalString(value.namespace));
|
|
35
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Type guard for a Cloud Foundry adaptation project configuration json.
|
|
51
|
+
*
|
|
52
|
+
* Requires `targetEnv === 'CF'`, a non-empty `application` (the CF base-app id) and a non-empty
|
|
53
|
+
* `serviceInstanceName` (the live CF service instance to connect to and extend). All other fields are
|
|
54
|
+
* optional and, when present, must be of the expected type.
|
|
55
|
+
*
|
|
56
|
+
* @param {unknown} value - The value being checked.
|
|
57
|
+
* @returns {boolean} True if the value conforms to the CfJsonInput interface.
|
|
58
|
+
*/
|
|
59
|
+
function isCfJsonInput(value) {
|
|
60
|
+
if (!isPlainObject(value)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (value.targetEnv !== types_js_1.TargetEnv.CF || !isNonEmptyString(value.application)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (!isNonEmptyString(value.serviceInstanceName)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const isValidMtaMode = value.mtaMode === undefined || value.mtaMode === types_js_1.MtaMode.New || value.mtaMode === types_js_1.MtaMode.Existing;
|
|
70
|
+
const isValidApprouter = value.approuter === undefined ||
|
|
71
|
+
value.approuter === adp_tooling_1.AppRouterType.MANAGED ||
|
|
72
|
+
value.approuter === adp_tooling_1.AppRouterType.STANDALONE;
|
|
73
|
+
return (isOptionalString(value.id) &&
|
|
74
|
+
isOptionalString(value.applicationTitle) &&
|
|
75
|
+
isOptionalString(value.businessSolutionName) &&
|
|
76
|
+
isOptionalString(value.mtaId) &&
|
|
77
|
+
isOptionalString(value.targetFolder) &&
|
|
78
|
+
isOptionalString(value.projectName) &&
|
|
79
|
+
isOptionalString(value.namespace) &&
|
|
80
|
+
isValidApprouter &&
|
|
81
|
+
isValidMtaMode);
|
|
82
|
+
}
|
|
36
83
|
/**
|
|
37
84
|
* Type guard for a plain javascript object.
|
|
38
85
|
*
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"displayName": "SAPUI5 Adaptation Project",
|
|
4
4
|
"homepage": "https://help.sap.com/viewer/584e0bcbfd4a4aff91c815cefa0bce2d/Cloud/en-US/ada9567b767941aba8d49fdb4fdedea7.html",
|
|
5
5
|
"description": "Adaptation project allows you to create an app variant for an existing SAP Fiori elements-based or SAPUI5 freestyle application, without changing the original application.",
|
|
6
|
-
"version": "1.1
|
|
6
|
+
"version": "1.2.1",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -25,24 +25,24 @@
|
|
|
25
25
|
"yeoman-generator"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sap-devx/yeoman-ui-types": "1.25.1",
|
|
29
28
|
"@sap-devx/feature-toggle-node": "2.1.1",
|
|
29
|
+
"@sap-devx/yeoman-ui-types": "1.25.1",
|
|
30
30
|
"i18next": "26.5.11",
|
|
31
|
+
"uuid": "14.0.3",
|
|
31
32
|
"yeoman-generator": "5.10.0",
|
|
32
|
-
"
|
|
33
|
-
"@sap-ux/
|
|
34
|
-
"@sap-ux/
|
|
33
|
+
"@sap-ux/adp-tooling": "1.2.3",
|
|
34
|
+
"@sap-ux/axios-extension": "2.1.7",
|
|
35
|
+
"@sap-ux/btp-utils": "2.0.9",
|
|
35
36
|
"@sap-ux/feature-toggle": "1.0.5",
|
|
36
|
-
"@sap-ux/
|
|
37
|
-
"@sap-ux/inquirer-common": "1.0.
|
|
38
|
-
"@sap-ux/project-access": "2.3.4",
|
|
37
|
+
"@sap-ux/fiori-generator-shared": "1.4.1",
|
|
38
|
+
"@sap-ux/inquirer-common": "1.0.56",
|
|
39
39
|
"@sap-ux/logger": "1.0.3",
|
|
40
|
+
"@sap-ux/odata-service-writer": "1.0.30",
|
|
41
|
+
"@sap-ux/project-access": "2.3.5",
|
|
42
|
+
"@sap-ux/project-input-validator": "1.0.28",
|
|
40
43
|
"@sap-ux/store": "2.0.8",
|
|
41
|
-
"@sap-ux/
|
|
42
|
-
"@sap-ux/
|
|
43
|
-
"@sap-ux/fiori-generator-shared": "1.4.0",
|
|
44
|
-
"@sap-ux/system-access": "1.0.20",
|
|
45
|
-
"@sap-ux/telemetry": "2.0.15"
|
|
44
|
+
"@sap-ux/system-access": "1.0.21",
|
|
45
|
+
"@sap-ux/telemetry": "2.0.16"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@jest/globals": "30.5.2",
|
|
@@ -53,12 +53,11 @@
|
|
|
53
53
|
"@types/yeoman-environment": "2.10.11",
|
|
54
54
|
"@types/yeoman-generator": "5.2.14",
|
|
55
55
|
"@types/yeoman-test": "4.0.6",
|
|
56
|
-
"@types/uuid": "11.0.0",
|
|
57
56
|
"@vscode-logging/logger": "2.0.10",
|
|
58
57
|
"fs-extra": "11.4.1",
|
|
59
58
|
"rimraf": "6.1.3",
|
|
60
59
|
"yeoman-test": "6.3.0",
|
|
61
|
-
"@sap-ux/deploy-config-sub-generator": "1.0.
|
|
60
|
+
"@sap-ux/deploy-config-sub-generator": "1.0.95"
|
|
62
61
|
},
|
|
63
62
|
"engines": {
|
|
64
63
|
"node": ">=22.x"
|