trm-core
Version:
TRM (Transport Request Manager) Core
140 lines (139 loc) • 6.99 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.setCustomizingTransports = void 0;
const trm_commons_1 = require("trm-commons");
const transport_1 = require("../../transport");
exports.setCustomizingTransports = {
name: 'set-customizing-transports',
filter: (context) => __awaiter(void 0, void 0, void 0, function* () {
if (context.rawInput.publishData.skipCustomizingTransports) {
trm_commons_1.Logger.log(`Skipping customizing transports publish (user input)`, true);
return false;
}
else {
return true;
}
}),
run: (context) => __awaiter(void 0, void 0, void 0, function* () {
trm_commons_1.Logger.log('Set customizing transports step', true);
var customizingTransports = context.rawInput.publishData.customizingTransports;
customizingTransports = Object.values(customizingTransports.reduce((acc, t) => {
acc[t.trkorr] = t;
return acc;
}, {}));
if (!context.rawInput.contextData.noInquirer) {
const addCust = (yield trm_commons_1.Inquirer.prompt({
message: customizingTransports.length > 0 ? `Do you want to add more customizing transports?` : `Do you want to add customizing transports?`,
name: 'continue',
type: 'confirm',
default: customizingTransports.length > 0
})).continue;
if (addCust) {
var option;
do {
var options = [];
for (const transport of customizingTransports) {
var description;
try {
description = yield transport.getDescription();
}
catch (_a) {
description = '';
}
options.push({
name: `- ${transport_1.Transport.getTransportIcon()} ${transport.trkorr} ${description}`.trim(),
value: transport
});
}
options.push({
name: `+ Add`,
value: 1
});
options.push({
name: `x Done`,
value: 2
});
option = (yield trm_commons_1.Inquirer.prompt({
message: 'Select option',
name: 'option',
type: 'list',
choices: options,
default: 1
})).option;
if (option === 1) {
const trkorr = (yield trm_commons_1.Inquirer.prompt({
message: 'Input customizing transport request',
name: 'trkorr',
type: 'input',
validate: (input) => __awaiter(void 0, void 0, void 0, function* () {
try {
if (customizingTransports.find(o => o.trkorr === input.trim())) {
return 'Already added';
}
const trFunction = (yield (new transport_1.Transport(input.trim())).getE070()).trfunction;
if (trFunction !== 'W') {
return 'Transport request must be of type customizing';
}
else {
return true;
}
}
catch (_a) {
return 'Invalid transport request';
}
})
})).trkorr;
customizingTransports.push(new transport_1.Transport(trkorr.trim()));
}
else if (option instanceof transport_1.Transport) {
customizingTransports = customizingTransports.filter(o => o.trkorr !== option.trkorr);
}
} while (option !== 2);
}
const maxDescLength = 60 - `@X1@TRM: ${context.rawInput.packageData.name} v${context.rawInput.packageData.version} (C) `.length;
for (const transport of customizingTransports) {
try {
const e070 = yield transport.getE070();
if (e070.trfunction !== 'W') {
trm_commons_1.Logger.warning(`Transport ${transport.trkorr} is not of type customizing`);
throw new Error();
}
const tasks = yield transport.getTasks();
var desc = yield transport.getDescription();
if (!context.rawInput.contextData.noInquirer) {
desc = (yield trm_commons_1.Inquirer.prompt({
message: `Description of ${transport.trkorr}`,
type: 'input',
name: 'desc',
default: desc,
validate: (input) => {
if (input.length > maxDescLength) {
return `Description cannot exceede ${maxDescLength} characters`;
}
else {
return true;
}
}
})).desc || desc;
}
context.runtime.systemData.originCustomizing.push({
transports: [transport].concat(tasks),
description: desc
});
}
catch (_b) {
trm_commons_1.Logger.warning(`Invalid transport ${transport.trkorr}, ignored`);
}
}
}
})
};