@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.
88 lines • 4.19 kB
JavaScript
"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_tooling_1 = require("@sap-ux/adp-tooling");
const adp_common_1 = require("@sap/adp-common");
const AdaptationProjectGeneratorBase_1 = __importDefault(require("../common/generator/AdaptationProjectGeneratorBase"));
let projectPath = null;
class AddNewModelGenerator extends AdaptationProjectGeneratorBase_1.default {
constructor(args, opts) {
super(args, opts, adp_common_1.GeneratorTypes.ADD_NEW_MODEL);
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);
// TODO: the appdescr file has already been read in the constructor, it should be refactored to be read only once
this.variant = adp_common_1.Workspace.getManifestAppdescrFile(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 = yield this.prompt((0, adp_tooling_1.getPromptsForNewModel)(projectPath, this.variant.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 OData Service and SAPUI5 Model", description: "Select OData Service and SAPUI5 Model" }]);
}
createNewModelData() {
const { name, uri, modelName, version, modelSettings, addAnnotationMode } = this.answers;
return Object.assign({ variant: this.variant, service: {
name,
uri,
modelName,
version,
modelSettings
} }, (addAnnotationMode && {
annotation: {
dataSourceName: this.answers.dataSourceName,
dataSourceURI: this.answers.dataSourceURI,
settings: this.answers.annotationSettings
}
}));
}
writing() {
return __awaiter(this, void 0, void 0, function* () {
yield (0, adp_tooling_1.generateChange)(projectPath, "appdescr_ui5_addNewModel" /* ChangeType.ADD_NEW_MODEL */, this.createNewModelData(),
// @ts-ignore
this.fs);
this.logger.log("Change written to changes folder");
});
}
end() {
this.logger.log("Successfully created change!");
}
}
module.exports = AddNewModelGenerator;
//# sourceMappingURL=index.js.map