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.

86 lines 4.01 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 adp_common_1 = require("@sap/adp-common"); const AdaptationProjectGeneratorBase_1 = __importDefault(require("../common/generator/AdaptationProjectGeneratorBase")); const adp_tooling_1 = require("@sap-ux/adp-tooling"); let projectPath = null; class AddComponentUsagesGenerator extends AdaptationProjectGeneratorBase_1.default { constructor(args, opts) { super(args, opts, adp_common_1.GeneratorTypes.ADD_COMPONENT_USAGES); if (opts.data) { projectPath = opts.data.path; } this.setPrompts(); } initializing() { return __awaiter(this, void 0, void 0, function* () { try { this.projectData = adp_common_1.Workspace.project(projectPath); this.logger.log(adp_common_1.Messages.SUCCESSFULLY_RETRIEVED_PROJECT_DATA(JSON.stringify(this.projectData, null, 2))); } catch (e) { this.appWizard.showError(e.message, yeoman_ui_types_1.MessageType.notification); this.validationError = e; } }); } prompting() { return __awaiter(this, void 0, void 0, function* () { if (this.validationError) { yield this.handleRuntimeCrash(this.validationError.message); } this.answers = Object.assign(yield this.prompt((0, adp_tooling_1.getPromptsForAddComponentUsages)(projectPath, this.projectData.layer))); this.logger.log(adp_common_1.Messages.CURRENT_ANSWERS(JSON.stringify(this.answers, null, 2))); }); } setPrompts() { this.setPromptsCallback = (fn) => { // setPromptsCallback gets called only in Yeoman UI. Thus we can use it to know the running context. if (this.prompts) { this.prompts.setCallback(fn); } }; this.prompts = new yeoman_ui_types_1.Prompts([{ name: "Add SAPUI5 Component Usages", description: "Select SAPUI5 Component Usages" }]); } createComponentUsageData() { const variant = adp_common_1.Workspace.getManifestAppdescrFile(projectPath); const { usageId, data, settings, isLazy, name, shouldAddLibrary } = this.answers; return Object.assign({ variant, component: { data, usageId, settings, isLazy, name } }, (shouldAddLibrary && { library: { reference: this.answers.library, referenceIsLazy: this.answers.libraryIsLazy } })); } writing() { return __awaiter(this, void 0, void 0, function* () { yield (0, adp_tooling_1.generateChange)(projectPath, "appdescr_ui5_addComponentUsages" /* ChangeType.ADD_COMPONENT_USAGES */, this.createComponentUsageData(), // @ts-ignore this.fs); this.logger.log(`Changes written to changes folder`); }); } end() { this.logger.log("Successfully created change!"); } } module.exports = AddComponentUsagesGenerator; //# sourceMappingURL=index.js.map