@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.
868 lines • 41.5 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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 Generator = require("yeoman-generator");
const types = __importStar(require("@sap-devx/yeoman-ui-types"));
const validator_1 = require("../common/questions/validator");
const adp_common_1 = require("@sap/adp-common");
const adp_abap_1 = require("@sap/adp-abap");
const deploy_config_1 = require("../common/questions/prompts/deploy-config");
const flp_config_1 = require("../common/questions/prompts/flp-config");
const config_1 = require("../common/utils/config");
const uxToolsWrapper_1 = __importDefault(require("../common/uxToolsWrapper"));
class DeploymentGenerator extends Generator {
constructor(args, opts) {
super(args, opts);
const wizard = types.AppWizard.create(opts);
this.logger = {
info: function (message) {
wizard.showInformation(message, types.MessageType.notification);
},
error: function (message) {
wizard.showError(message, types.MessageType.notification);
},
log: (message) => {
this.log(`↪ ${message}`);
}
};
adp_common_1.Logger.setLogger = this.logger;
adp_common_1.Workspace.setGeneratorHeaderTitle(opts, this.resolved, adp_common_1.GeneratorTypes.DEPLOYMENT_WIZARD);
this.setPromptsCallback = (fn) => {
this.prompts.setCallback(fn);
};
this.answers = {};
this.generatorOptions = opts.data;
this.isRunningIsBAS = adp_common_1.EnvironmentUtils.isRunningInBAS();
this.localDestinationService = new adp_abap_1.LocalDestinationService();
this.projectPath = this.generatorOptions.path;
this.prompts = new types.Prompts([]);
this.hasDeployConfig = false;
this.hasFlpConfig = false;
this.shouldAddConfigs = false;
}
_setPages() {
if (!this.isCloudProject) {
this.prompts.splice(this.requiresAuth ? 1 : 0, this.requiresAuth ? 1 : 0, [
{
name: "System",
description: `Source system is selected by default.`
},
{
name: "Package",
description: ""
},
{
name: adp_common_1.Messages.TRANSPORT_REQUEST_NUMBER,
description: ""
}
]);
}
else {
const pages = !this.shouldAddConfigs
? [
{
name: "Deployment Summary",
description: "Selected properties to be used for the next deployment"
}
]
: [
{ name: adp_common_1.Messages.FLP_CONFIGURATION_STEP, description: adp_common_1.Messages.FLP_CONFIGURATION_STEP_DESCRIPTION },
{ name: adp_common_1.Messages.DEPLOY_CONFIG_STET, description: adp_common_1.Messages.DEPLOY_CONFIG_STEP_DESCRIPTION }
];
this.prompts.splice(this.requiresAuth ? 1 : 0, this.requiresAuth ? 1 : 0, pages);
}
}
initializing() {
return __awaiter(this, void 0, void 0, function* () {
if (!adp_common_1.Workspace.isDeploymentAllowed(this.projectPath)) {
this.prompts.splice(0, 3, [{ name: "Deployment Wizard", description: "" }]);
yield this.prompt(this._getDeploymentNotAllowedPrompt());
}
//When package.json is modified YUI automatically opens a new page with prompt which notes how the changes should be reflected e.g (overwrite or not overwrite).
//Setting this property to true overides this default behaviour of YUI.
if (this.env.conflicter) {
this.env.conflicter.force = true;
}
this.projectData = adp_common_1.Workspace.project(this.projectPath);
this.endPointsManager = yield adp_common_1.EndpointsManager.getInstance();
this.abapProvider = new adp_abap_1.AbapProvider(this.endPointsManager);
this.abapService = new adp_abap_1.AbapService(this.abapProvider, true);
this.requiresAuth = yield this.endPointsManager.getSystemRequiresAuth(this.projectData.sourceSystem);
if (!this.requiresAuth) {
yield this.abapProvider.setProvider(this.projectData.sourceSystem, this.projectData.client);
this.isCloudProject = yield this.abapService.isAbapCloud();
if (this.isCloudProject) {
this.hasDeployConfig = adp_common_1.Workspace.hasDeployConfig(this.projectPath);
this.hasFlpConfig = yield uxToolsWrapper_1.default.flpConfigurationExists(this.projectPath);
this.shouldAddConfigs = !this.hasDeployConfig || !this.hasFlpConfig;
}
this._setPages();
}
else {
this.prompts.splice(0, 0, [
{
name: "Credentials",
description: `Enter credentials for your adaptation project's system (${this.projectData.sourceSystem})`
},
{
name: "Configuration",
description: "Configuration"
}
]);
}
});
}
_getBasicCredentialsPrompts() {
return [
{
type: "input",
name: "username",
message: adp_common_1.Messages.USERNAME,
validate: (value) => {
return (0, validator_1.validateForEmptyValue)(value, adp_common_1.Messages.USERNAME);
},
guiOptions: {
mandatory: true
},
store: false
},
{
type: "password",
guiType: "login",
name: "password",
message: adp_common_1.Messages.PASSWORD,
mask: "*",
validate: (value, answers) => __awaiter(this, void 0, void 0, function* () {
if (value.length <= 0) {
return adp_common_1.Messages.INPUT_CANNOT_BE_EMPTY_ERROR(adp_common_1.Messages.PASSWORD);
}
if (!answers.username) {
return adp_common_1.Messages.ERROR_MISSING_REQUIRED_DATA;
}
try {
yield this.abapProvider.setProvider(this.projectData.sourceSystem, this.projectData.client, answers.username, value);
this.isCloudProject = yield this.abapService.isAbapCloud();
if (!this.isCloudProject) {
const project = new adp_abap_1.DeploymentManager(this.projectData, {
url: `https://${this.projectData.sourceSystem}.dest`,
auth: {
username: answers.username,
password: value
}
});
this.deploymentData = yield project.deploymentData();
this.logger.log(`Successfull login to ${this.projectData.sourceSystem}`);
this.project = project;
}
else {
this.hasDeployConfig = adp_common_1.Workspace.hasDeployConfig(this.projectPath);
this.hasFlpConfig = yield uxToolsWrapper_1.default.flpConfigurationExists(this.projectPath);
this.shouldAddConfigs = !this.hasDeployConfig || !this.hasFlpConfig;
}
return true;
}
catch (e) {
return e.message;
}
}),
guiOptions: {
mandatory: true
},
store: false
}
];
}
prompting() {
return __awaiter(this, void 0, void 0, function* () {
try {
if (this.requiresAuth) {
this.credentials = (yield this.prompt(this._getBasicCredentialsPrompts()));
this._setPages();
}
if (this.isRunningIsBAS) {
this.destinations = yield adp_abap_1.DestinationService.destinations();
}
else {
// Running in VSCode Native
// Prompt for Username, Password
if (this.projectData.client && !this.localDestinationService.getIsExtensionInstalled()) {
this.answers = yield this.prompt(yield this._getCredentialsPrompt());
}
else {
if (!this.isCloudProject) {
this.answers = yield this.prompt(yield this._getLocalDestinationsPrompt());
}
}
}
}
catch (error) {
this.logger.error(`Error: ${error === null || error === void 0 ? void 0 : error.message}`);
yield this.prompt([
{
type: "input",
name: "errorMessagePrompt",
message: adp_common_1.Messages.CRASH_MESSAGE_ABAP,
guiOptions: {
type: "label",
hint: error.message
},
validate: () => false
}
]);
}
if (!this.isCloudProject) {
yield this._getAbapOnPremisePrompts();
}
else {
yield this._collectAbapCloudAnswers();
}
});
}
_collectAbapCloudAnswers() {
return __awaiter(this, void 0, void 0, function* () {
if (this.shouldAddConfigs) {
this.flpConfigAnswers = (yield this.prompt(yield this._getFlpPrompts()));
Object.assign(this.answers, this.flpConfigAnswers);
this.logger.log(`Flp Config answers: ${JSON.stringify(this.flpConfigAnswers, null, 2)}`);
this.deployConfigAnwers = (yield this.prompt(yield this._getDeployConfigPrompts()));
Object.assign(this.answers, this.flpConfigAnswers);
this.logger.log(`Deploy Config answers: ${JSON.stringify(this.deployConfigAnwers, null, 2)}`);
}
else {
this.answers = yield this.prompt((0, deploy_config_1.getDeploySummaryPrompts)(this.projectPath));
}
});
}
_getFlpPrompts() {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const adpManifest = adp_common_1.Workspace.getManifestAppdescrFile(this.projectPath);
const manifestManager = new adp_abap_1.ManifestManager(this.abapProvider);
const appManifest = yield manifestManager.getManifest(adpManifest.reference);
const appID = ((_b = (_a = appManifest["sap.fiori"]) === null || _a === void 0 ? void 0 : _a.registrationIds) === null || _b === void 0 ? void 0 : _b.length) ? appManifest["sap.fiori"].registrationIds[0] : "";
const inboundIds = adp_abap_1.ManifestServiceABAP.getManifestInboundIds(appManifest);
const existingFlpConfig = yield adp_abap_1.ManifestServiceABAP.getFlpConfig(this.projectPath);
const flpConfig = {
appID: appID,
inboundIds: inboundIds,
isCloudProject: this.isCloudProject,
system: this.projectData.sourceSystem,
flpConfig: existingFlpConfig
};
return (0, flp_config_1.getFlpConfigurationPrompts)(flpConfig);
});
}
_getDeployConfigPrompts() {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const deployApp = yield adp_common_1.Workspace.getDeployTaskApp(this.projectPath);
const deployConfig = {
abapService: this.abapService,
abapServiceConfig: {
system: this.projectData.sourceSystem,
client: this.projectData.client,
password: (_a = this.credentials) === null || _a === void 0 ? void 0 : _a.password,
username: (_b = this.credentials) === null || _b === void 0 ? void 0 : _b.username
},
deployApp: deployApp
};
return yield (0, deploy_config_1.getDeployConfigurationPrompts)(deployConfig);
});
}
_getAbapOnPremisePrompts() {
return __awaiter(this, void 0, void 0, function* () {
if (this.isRunningIsBAS) {
this.answers = yield this.prompt(yield this._getInitialDataPrompts());
}
this.logger.log(`project: ${this.projectData.title}`);
this.logger.log(`destination: ${this.answers.destination}`);
yield this._getProjectService();
yield this._getDeploymentData();
if (this.deploymentData.isDeployed) {
this.prompts.splice(1, 1, [
{
name: "Operation",
description: `Adaptation project with this namespace already exists in the system.
${this.deploymentData.isUndeploymentSupported ? "You can either update it or undeploy it." : ""}`
}
]);
}
this.answers = Object.assign({}, this.answers, yield this.prompt(yield this._getPackageDataPrompts()));
let showTransportPrompt;
if (this.deploymentData.isDeployed) {
this.logger.log(`operation: ${this.answers.action}`);
showTransportPrompt = this.deploymentData.package !== "$TMP";
}
else {
this.packageName = this.answers.packageInputChoice === adp_common_1.InputChoice.ENTER_MANUALLY ? this.answers.packageManual : this.answers.packageAutoComplete;
this.logger.log(`package: ${this.packageName}`);
showTransportPrompt = this.packageName.trim().toUpperCase() !== "$TMP";
}
if (showTransportPrompt) {
this.answers = Object.assign({}, this.answers, yield this.prompt(yield this._getOptionsDataPrompts(showTransportPrompt)));
this.logger.log(`transport request number: ${this.answers.transportRequestNumber}`);
}
});
}
_getProjectService() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.project && this.answers.username && this.answers.password) {
const url = this.isRunningIsBAS ? `https://${this.answers.destination}.dest` : this.answers.systemUrl;
const client = this.isRunningIsBAS ? "" : this.answers.client;
this.project = this._createProject(this.projectData, url, client, this.answers.username, this.answers.password);
}
if (!this.project) {
if (this.isRunningIsBAS) {
this.project = this._createProject(this.projectData, `https://${this.answers.destination}.dest`);
}
else {
if (this.projectData.client && !this.localDestinationService.getIsExtensionInstalled()) {
this.project = this._createProject(this.projectData, this.answers.systemUrl, this.answers.client, this.answers.username, this.answers.password);
}
else {
const destinationAuthDetails = yield this.localDestinationService.getSystemAuthDetails(this.answers.destination);
this.project = this._createProject(this.projectData, destinationAuthDetails.url, destinationAuthDetails.client, destinationAuthDetails.username, destinationAuthDetails.password);
}
}
}
});
}
_createProject(projectData, url, client, username, password) {
return new adp_abap_1.DeploymentManager(projectData, {
url: url,
client: client,
auth: {
username: username,
password: password
}
});
}
_getDeploymentData() {
return __awaiter(this, void 0, void 0, function* () {
try {
this.deploymentData = this.deploymentData || (yield this.project.deploymentData());
this.logger.log(`isDeployed: ${this.deploymentData.isDeployed}`);
this.logger.log(`package: ${this.deploymentData.package || "N/A"}`);
this.logger.log(`transport request number: ${this.deploymentData.transport || "N/A"}`);
}
catch (error) {
this.logger.error(`Unknown project status: ${error === null || error === void 0 ? void 0 : error.message}`);
throw new Error(`Unknown project status: ${error === null || error === void 0 ? void 0 : error.message}`);
}
});
}
_getDeploymentNotAllowedPrompt() {
return [
{
type: "input",
name: "deploymentNotAllowed",
message: "This deployment generator is meant to be used only by external developers. " +
"If you are internal developer you should use Maven based standard deployment procedure. " +
"The Adaptation project you want to deploy is created from an internal template used by SAP Fiori developers. " +
"It is an internal Maven project that has server-side build configurations. As such, the project should not be deployed " +
"using Adaptation Project tooling because it lacks the Maven build process. If you are an SAP Fiori developer, your project must go through a " +
"regular release build and then be deployed from Nexus. " +
"For more information see:",
guiOptions: {
type: "label",
mandatory: false,
link: {
text: "https://wiki.one.int.sap/wiki/display/fiorisuite/Development+Process",
url: "https://wiki.one.int.sap/wiki/display/fiorisuite/Development+Process"
}
},
//If we return false YEOMAN UI is rendering error message, which we don`t want to see
//String.fromCharCode(160) returns ' ', it it used because of formatter
validate: () => String.fromCharCode(160)
}
];
}
_getLocalDestinationsPrompt() {
return __awaiter(this, void 0, void 0, function* () {
return [
{
type: "list",
name: "destination",
message: "System",
choices: () => __awaiter(this, void 0, void 0, function* () { return yield this.localDestinationService.getDestinationNames(); }),
store: false,
guiOptions: {
applyDefaultWhenDirty: true,
hint: adp_common_1.Messages.SYSTEM_DEPLOY_TOOLTIP
},
default: yield this.localDestinationService.getSystemNameByUrl(this.projectData.sourceSystem),
validate: (value) => __awaiter(this, void 0, void 0, function* () {
return yield (0, validator_1.validateEmptyInput)(value, "System");
})
}
];
});
}
_getCredentialsPrompt() {
return __awaiter(this, void 0, void 0, function* () {
return [
{
type: "input",
name: "systemUrl",
message: adp_common_1.Messages.SYSTEM_URL,
default: this.projectData.sourceSystem,
validate: (value) => {
return (0, validator_1.validateForEmptyValue)(value, adp_common_1.Messages.SYSTEM_URL);
},
guiOptions: {
mandatory: true
},
store: false
},
{
type: "input",
name: "client",
message: adp_common_1.Messages.CLIENT,
default: this.projectData.client,
validate: (value) => {
return (0, validator_1.validateForEmptyValue)(value, adp_common_1.Messages.CLIENT);
},
guiOptions: {
mandatory: true
},
store: false
},
{
type: "input",
name: "username",
message: adp_common_1.Messages.USERNAME,
validate: (value) => {
return (0, validator_1.validateForEmptyValue)(value, adp_common_1.Messages.USERNAME);
},
guiOptions: {
mandatory: true
},
store: false
},
{
type: "password",
guiType: "login",
name: "password",
message: adp_common_1.Messages.PASSWORD,
mask: "*",
validate: (value, answers) => __awaiter(this, void 0, void 0, function* () {
if (value.length <= 0) {
return adp_common_1.Messages.INPUT_CANNOT_BE_EMPTY_ERROR(adp_common_1.Messages.PASSWORD);
}
if (!answers.username) {
return adp_common_1.Messages.ERROR_MISSING_REQUIRED_DATA;
}
try {
yield this.abapService.connectToSystem(answers.systemUrl, answers.client, answers.username, value);
// Check if credentials are correct by trying to get ui5 version of the system
yield this.abapService.getSystemUI5Version();
return true;
}
catch (e) {
return e.message;
}
}),
guiOptions: {
mandatory: true
},
store: false
}
];
});
}
_getInitialDataPrompts() {
return __awaiter(this, void 0, void 0, function* () {
return [
{
type: "input",
name: "project",
message: `Project path: ${this.generatorOptions.path}`,
guiOptions: {
type: "label"
}
},
{
type: "list",
name: "destination",
message: "System",
choices: this.destinations,
store: false,
guiOptions: {
applyDefaultWhenDirty: true,
hint: adp_common_1.Messages.SYSTEM_DEPLOY_TOOLTIP
},
default: (yield this._validateSystem(this.projectData.sourceSystem)) === true ? this.projectData.sourceSystem : "",
validate: (value) => __awaiter(this, void 0, void 0, function* () { return yield this._validateSystem(value); })
},
{
type: "input",
name: "username",
message: "Username",
store: false,
guiOptions: {
applyDefaultWhenDirty: true,
mandatory: true
},
when: (answers) => {
var _a;
return !((_a = this.destinations.find((destination) => destination.name === answers.destination)) === null || _a === void 0 ? void 0 : _a.authenticated) &&
!this.abapProvider.isConnected() &&
this.abapProvider.getSystem() !== answers.destination;
},
validate: (value) => {
return value.length > 0 ? true : adp_common_1.Messages.MANDATORY_FIELD;
},
default: ""
},
{
type: "password",
name: "password",
message: "Password",
store: false,
guiOptions: {
type: "login",
applyDefaultWhenDirty: true,
mandatory: true
},
mask: "*",
when: (answers) => {
var _a;
return !((_a = this.destinations.find((destination) => destination.name === answers.destination)) === null || _a === void 0 ? void 0 : _a.authenticated) &&
!this.abapProvider.isConnected() &&
this.abapProvider.getSystem() !== answers.destination;
},
validate: (value, answers) => __awaiter(this, void 0, void 0, function* () {
if (answers.username.length <= 0) {
return true;
}
if (value.length > 0) {
const project = new adp_abap_1.DeploymentManager(this.projectData, {
url: `https://${answers.destination}.dest`,
auth: {
username: answers.username,
password: value
}
});
try {
this.deploymentData = yield project.deploymentData();
this.logger.log(`Successfull login to ${answers.destination}`);
this.project = project;
return true;
}
catch (error) {
return error.message;
}
}
else {
return adp_common_1.Messages.MANDATORY_FIELD;
}
}),
default: ""
}
];
});
}
_validateSystem(value) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const isAuthenticated = (_a = this.destinations.find((destination) => destination.name === value)) === null || _a === void 0 ? void 0 : _a.authenticated;
if (isAuthenticated) {
if (value.length > 0) {
const project = new adp_abap_1.DeploymentManager(this.projectData, {
url: `https://${value}.dest`
});
try {
this.deploymentData = yield project.deploymentData();
this.logger.log(`Successfull login to ${value}`);
this.project = project;
return true;
}
catch (error) {
this.logger.log(error);
return error.message;
}
}
else {
return adp_common_1.Messages.MANDATORY_FIELD;
}
}
else {
return true;
}
});
}
_validatePackage(value) {
if (!value) {
return adp_common_1.Messages.MANDATORY_FIELD;
}
if (value.trim().toUpperCase() === "$TMP") {
this.prompts.splice(2, 1, null);
}
else {
this.prompts.splice(2, 1, [
{
name: adp_common_1.Messages.TRANSPORT_REQUEST_NUMBER,
description: ""
}
]);
}
return true;
}
_getSystemForTransportAndPackageLists() {
const system = !this.isRunningIsBAS && !this.localDestinationService.getIsExtensionInstalled() ? this.answers.systemUrl : this.answers.destination;
return system;
}
_getPackageDataPrompts() {
return __awaiter(this, void 0, void 0, function* () {
yield this.abapService.connectToSystem(this._getSystemForTransportAndPackageLists(), this.answers.client, this.answers.username, this.answers.password);
let morePackageResultsMsg = "";
return [
{
type: "list",
name: "packageInputChoice",
message: adp_common_1.Messages.PACKAGE_INPUT_CHOICE,
choices: [
{ name: adp_common_1.InputChoice.ENTER_MANUALLY, value: adp_common_1.InputChoice.ENTER_MANUALLY },
{ name: adp_common_1.InputChoice.CHOOSE_FROM_EXISTING, value: adp_common_1.InputChoice.CHOOSE_FROM_EXISTING }
],
default: adp_common_1.InputChoice.ENTER_MANUALLY,
guiOptions: {
mandatory: true
},
when: !this.deploymentData.isDeployed,
validate: (value) => __awaiter(this, void 0, void 0, function* () { return yield (0, validator_1.validatePackageChoiceInput)(value, this.abapService); })
},
{
type: "autocomplete",
name: "packageAutoComplete",
message: "Package",
store: false,
guiOptions: {
mandatory: true,
hint: adp_common_1.Messages.PACKAGE_TOOLTIP
},
source: (answers, input) => __awaiter(this, void 0, void 0, function* () {
const packages = yield this.abapService.listPackages(input);
morePackageResultsMsg =
packages && packages.length === adp_abap_1.ABAP_PACKAGE_SEARCH_MAX_RESULTS ? adp_common_1.Messages.INFO_MESSAGE_MORE_SEARCH_RESULTS(packages.length) : "";
return packages;
}),
additionalInfo: () => morePackageResultsMsg,
validate: (value) => this._validatePackage(value),
when: (answers) => !this.deploymentData.isDeployed && answers.packageInputChoice === adp_common_1.InputChoice.CHOOSE_FROM_EXISTING
},
{
type: "input",
name: "packageManual",
message: "Package",
store: false,
guiOptions: {
mandatory: true,
hint: adp_common_1.Messages.PACKAGE_TOOLTIP
},
validate: (value) => this._validatePackage(value),
when: (answers) => !this.deploymentData.isDeployed && answers.packageInputChoice === adp_common_1.InputChoice.ENTER_MANUALLY
},
{
type: "list",
name: "action",
message: "Operation",
choices: [adp_common_1.DeploymentOperations.UPDATE, adp_common_1.DeploymentOperations.UNDEPLOY],
store: false,
guiOptions: {
mandatory: false,
hint: adp_common_1.Messages.OPERATION_TOOLTIP
},
validate: (value) => {
if (value === adp_common_1.DeploymentOperations.UNDEPLOY && !this.deploymentData.isUndeploymentSupported) {
return adp_common_1.Messages.ERROR_NEWER_SAP_UI_NEEDED;
}
if (this.deploymentData.package === "$TMP") {
this.prompts.splice(2, 1, null);
}
else {
this.prompts.splice(2, 1, [
{
name: adp_common_1.Messages.TRANSPORT_REQUEST_NUMBER,
description: ""
}
]);
}
return true;
},
when: this.deploymentData.isDeployed,
default: adp_common_1.DeploymentOperations.UPDATE
}
];
});
}
_getOptionsDataPrompts(showTransportPrompt) {
return __awaiter(this, void 0, void 0, function* () {
return [
{
type: "input",
name: "transportRequestNumber",
message: "Transport request number",
store: false,
guiOptions: {
mandatory: true,
applyDefaultWhenDirty: true,
hint: adp_common_1.Messages.TRANSPORT_TOOLTIP
},
validate: (value) => {
return value.length > 0 ? true : adp_common_1.Messages.MANDATORY_FIELD;
},
when: showTransportPrompt,
default: this.deploymentData.transport
}
];
});
}
_projectDeploy() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield this.project.deploy(this.packageName, this.answers.transportRequestNumber);
this.logger.info("Project deployed successfully!");
}
catch (error) {
this.logger.error(`Error deploying project: ${error.message}`);
error.response && this.logger.error(`Error deploying project details: ${error.response.data}`);
}
});
}
_projectUpdate() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield this.project.deploy(this.deploymentData.package, this.answers.transportRequestNumber);
this.logger.info("Project updated successfully!");
}
catch (error) {
this.logger.error(`Error updating project: ${error.message}`);
error.response && this.logger.error(`Error updating project details: ${error.response.data}`);
}
});
}
_projectUndeploy() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield this.project.undeploy(this.answers.transportRequestNumber);
this.logger.info("Project undeployed successfully!");
}
catch (error) {
this.logger.error(`Error undeploying project: ${error.message}`);
error.response && this.logger.error(`Error undeploying project details: ${error.response.data}`);
}
});
}
_abapActions() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.generatorOptions || !this.deploymentData) {
return;
}
if (this.deploymentData.isDeployed) {
switch (this.answers.action) {
case adp_common_1.DeploymentOperations.UPDATE:
this._projectUpdate();
break;
case adp_common_1.DeploymentOperations.UNDEPLOY:
this._projectUndeploy();
break;
default:
break;
}
}
else {
this._projectDeploy();
}
});
}
_cloudReadyActions() {
var _a, _b, _c, _d, _e, _f;
return __awaiter(this, void 0, void 0, function* () {
const scriptName = (_b = (_a = this.answers) === null || _a === void 0 ? void 0 : _a.action) !== null && _b !== void 0 ? _b : "deploy";
try {
const vscode = adp_common_1.ModuleResolver.resolve("vscode");
const terminal = (_c = vscode === null || vscode === void 0 ? void 0 : vscode.window) === null || _c === void 0 ? void 0 : _c.createTerminal("Adaptation Project Deployment Wizard");
if (terminal) {
terminal.show();
terminal.sendText(`cd "${this.projectPath}"`);
if (this.shouldAddConfigs) {
yield this._generateConfigs();
terminal.sendText("npm install");
}
(_d = adp_common_1.Logger.getLogger) === null || _d === void 0 ? void 0 : _d.info(`Starting project ${scriptName}!`);
terminal.sendText(`echo y | npm run ${scriptName}`);
}
else {
(_e = adp_common_1.Logger.getLogger) === null || _e === void 0 ? void 0 : _e.error(`Could not start project ${scriptName}. Reason: could not open terminal!`);
}
}
catch (e) {
(_f = adp_common_1.Logger.getLogger) === null || _f === void 0 ? void 0 : _f.error(`Error during project ${scriptName} project: ${e.message}`);
}
});
}
_generateConfigs() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
if (this.hasDeployConfig) {
adp_common_1.Workspace.deleteFile(this.projectPath, "ui5-deploy.yaml");
}
yield (0, config_1.generateDeployConfig)(this.projectPath, this.projectData, this.deployConfigAnwers, this.fs);
if (this.hasFlpConfig) {
yield adp_common_1.Workspace.removeFlpConfig(this.projectPath);
}
yield (0, config_1.generateFlpConfig)(this.projectPath, this.flpConfigAnswers, this.fs);
}
catch (error) {
(_a = adp_common_1.Logger.getLogger) === null || _a === void 0 ? void 0 : _a.error(`Error occured while generating deploy config: ${error.message}`);
}
});
}
default() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.isCloudProject) {
this._abapActions();
}
else {
yield this._cloudReadyActions();
}
});
}
}
module.exports = DeploymentGenerator;
//# sourceMappingURL=index.js.map