liveperson-functions-cli
Version:
LivePerson Functions CLI
99 lines (97 loc) • 4.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PullView = void 0;
const printer_1 = require("./printer");
const defaultStructure_service_1 = require("../service/defaultStructure.service");
const file_service_1 = require("../service/file.service");
class PullView {
constructor(
/* istanbul ignore next */ { prompt = new printer_1.Prompt(), log = new printer_1.LogMessage(), error = new printer_1.ErrorMessage(), tasklist = new printer_1.TaskList({ concurrent: true }), fileService = new file_service_1.FileService(), defaultStructureService = new defaultStructure_service_1.DefaultStructureService(), chalk = printer_1.chalk, } = {}) {
this.prompt = prompt;
this.log = log;
this.error = error;
this.tasklist = tasklist;
this.chalk = chalk;
this.fileService = fileService;
this.defaultStructureService = defaultStructureService;
}
/**
* Ask for confirmation the passed functions
* @param {ILambda[]} lambdas - lambdas
* @param {string} accountId - accountId
* @returns {Promise<Answers>}
* @memberof PullView
*/
async askForConfirmation(lambdas, accountId) {
lambdas.forEach((lambda) => {
this.prompt.addQuestion({
name: `${lambda.name}`,
type: 'confirm',
message: this.preparePromptMessage(lambda, accountId),
});
});
return this.prompt.run();
}
/**
* Pulls functions from the platform to the local machine
* @param {*} confirmedLambdasToPull - confirmed lambdas to pull
* @param {boolean} [noWatch] - Changes the renderer of the tasklist, so no rendering is displayed in the console
* @returns {Promise<void>}
* @memberof PullView
*/
async showPullProcess({ confirmedLambdasToPull, noWatch = false, }) {
if (noWatch) {
this.tasklist = new printer_1.TaskList({ renderer: 'silent', concurrent: true });
}
else {
this.log.print('\nPulling following functions:\n');
}
confirmedLambdasToPull.forEach((lambda) => {
this.tasklist.addTask({
title: `Pulling ${lambda.name}`,
task: async () => {
this.defaultStructureService.createFunctionsFolder(lambda.name, true);
this.fileService.write(`${this.fileService.getRoot()}/functions/${lambda.name}/config.json`, {
name: lambda.name,
event: lambda.eventId || 'No Event',
description: lambda.description,
input: lambda.samplePayload || {
headers: [],
payload: {},
},
environmentVariables: lambda.implementation.environmentVariables.length > 0
? lambda.implementation.environmentVariables
: [
{
key: '',
value: '',
},
],
});
this.fileService.write(`${this.fileService.getRoot()}/functions/${lambda.name}/index.js`, lambda.implementation.code, false);
},
});
});
await this.tasklist.run();
}
/**
* Shows an error message
* @param {string|PrettyPrintableError} message - message
* @memberof PullView
*/
showErrorMessage(message) {
this.error.print(message);
}
preparePromptMessage(lambda, accountId) {
const message = `Do you want to pull the ${this.chalk.yellow(lambda.name)}?
${this.chalk.red('Caution: Local files will be overwritten!')}
AccountId: ${this.chalk.green(accountId)}
Description: ${lambda.description}
UUID: ${lambda.uuid}
Event: ${lambda.event || 'No Event'}
`;
return message;
}
}
exports.PullView = PullView;
//# sourceMappingURL=pull.view.js.map