liveperson-functions-cli
Version:
LivePerson Functions CLI
69 lines • 2.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InitView = void 0;
const child_process_1 = require("child_process");
const defaultStructure_service_1 = require("../service/defaultStructure.service");
const printer_1 = require("./printer");
class InitView {
constructor({ error = new printer_1.ErrorMessage(), tasklist = new printer_1.TaskList({ concurrent: true, exitOnError: false }), exec = child_process_1.exec, defaultStructureService = new defaultStructure_service_1.DefaultStructureService(), } = {}) {
this.error = error;
this.tasklist = tasklist;
this.exec = exec;
this.defaultStructureService = defaultStructureService;
}
/**
* Shows an error message
* @param {string|PrettyPrintableError} message - message
* @memberof InitView
*/
showErrorMessage(message) {
this.error.print(message);
}
/**
* Runs the tasklist which initialise all folder and files
* @param { packageManager, needDependencyInstallation, functionNames } - Passes the used package manager, if an installation is required and functions to initialize.
* @returns {Promise<void>}
* @memberof InitView
*/
async showInitialiseTaskList({ packageManager, needDependencyInstallation, functionNames, update = false, }) {
if (functionNames === null || functionNames === void 0 ? void 0 : functionNames.length) {
functionNames.forEach((functionName) => {
this.tasklist.addTask({
title: `Initialise ${functionName}`,
task: async () => {
this.defaultStructureService.create(functionName);
},
});
});
}
else {
this.tasklist.addTask({
title: `${update ? 'Update files' : 'Initializing structure'}`,
task: async () => {
this.defaultStructureService.create(undefined, update);
},
});
}
/* istanbul ignore else */
if (needDependencyInstallation) {
this.tasklist.addTask({
title: 'Install packages',
task: async (ctx, task) => {
const command = `cd bin/lp-faas-toolbelt && ${ctx.packageManager === 'npm' ? 'npm i' : 'yarn -i'}`;
/* istanbul ignore next */
return new Promise((resolve) => {
this.exec(command, (error) => {
if (error) {
task.skip(error.message);
}
resolve();
});
});
},
});
}
await this.tasklist.run({ context: { packageManager } });
}
}
exports.InitView = InitView;
//# sourceMappingURL=init.view.js.map