UNPKG

@sap/generator-adaptation-project

Version:

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.

91 lines 4.96 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; const yeoman_ui_types_1 = require("@sap-devx/yeoman-ui-types"); const uxToolsWrapper_1 = __importDefault(require("../common/uxToolsWrapper")); const adp_common_1 = require("@sap/adp-common"); const logger_1 = require("@sap-ux/logger"); const path_1 = require("path"); const SubGeneratorWithAuthBase_1 = __importDefault(require("../common/generator/SubGeneratorWithAuthBase")); class AddAnnotationsToDataGenerator extends SubGeneratorWithAuthBase_1.default { constructor(args, opts) { super(args, opts, adp_common_1.GeneratorTypes.ADD_ANNOTATIONS_TO_DATA); } initializing() { return __awaiter(this, void 0, void 0, function* () { yield this.onInit(); }); } prompting() { var _a; return __awaiter(this, void 0, void 0, function* () { try { this.variant = yield uxToolsWrapper_1.default.getVariant(this.projectPath); const yamlPath = (0, path_1.join)(this.projectPath, "ui5.yaml"); if (this.isCFEnv) { yield this.getManifest(); } else { const adpConfig = yield uxToolsWrapper_1.default.getAdpConfig(this.projectPath, yamlPath); yield this._fetchManifest(adpConfig); } this.answers = yield this.prompt(uxToolsWrapper_1.default.getPromptsForAddAnnotationsToOData(this.projectPath, (_a = this.manifest["sap.app"].dataSources) !== null && _a !== void 0 ? _a : {})); this.logger.log(adp_common_1.Messages.CURRENT_ODATA_SERVICES(JSON.stringify(this.answers, null, 2))); } catch (error) { yield this.handleRuntimeCrash(error.message, this.isCFEnv); } }); } writing() { return __awaiter(this, void 0, void 0, function* () { const changeData = { variant: this.variant, isCommand: true, annotation: { dataSource: this.answers.id, filePath: this.answers.filePath, serviceUrl: this.manifest["sap.app"].dataSources[this.answers.id].uri } }; if (!this.isCFEnv && !this.answers.filePath) { const metadata = yield this.manifestService.getDataSourceMetadata(this.answers.id); changeData.annotation["namespaces"] = uxToolsWrapper_1.default.getAnnotationNamespaces({ metadata }); } yield uxToolsWrapper_1.default.generateChange(this.projectPath, "appdescr_app_addAnnotationsToOData" /* ChangeType.ADD_ANNOTATIONS_TO_ODATA */, changeData, // @ts-ignore this.fs); this.logger.log(`Change written to changes folder`); if (this.answers.fileSelectOption === 2 /* AnnotationFileSelectType.NewEmptyFile */) { this.appWizard.showInformation(adp_common_1.Messages.EMPTY_ANNOTATION_FILE_INFO, yeoman_ui_types_1.MessageType.notification); } }); } end() { this.logger.log("Successfully created annotation file!"); } _fetchManifest({ target, ignoreCertErrors = false }) { return __awaiter(this, void 0, void 0, function* () { let requestOptions; if (this.requiresAuthentication) { const credentials = (yield this.prompt(this.getABAPCredentialsPrompts(this.projectData))); requestOptions = { auth: { username: credentials.username, password: credentials.password } }; } const provider = yield uxToolsWrapper_1.default.createAbapServiceProvider(target, Object.assign(Object.assign({}, requestOptions), { ignoreCertErrors }), false, new logger_1.ToolsLogger()); this.manifestService = yield uxToolsWrapper_1.default.ManifestService.initMergedManifest(provider, this.projectPath, this.variant, new logger_1.ToolsLogger()); this.manifest = this.manifestService.getManifest(); }); } } module.exports = AddAnnotationsToDataGenerator; //# sourceMappingURL=index.js.map