UNPKG

@amplience/dc-cli

Version:
76 lines (75 loc) 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IndexCloneStep = void 0; const clone_hub_step_1 = require("../model/clone-hub-step"); const path_1 = require("path"); const export_1 = require("../../search-index/export"); const import_1 = require("../../search-index/import"); const fs_1 = require("fs"); class IndexCloneStep { getId() { return clone_hub_step_1.CloneHubStepId.Index; } getName() { return 'Clone Indexes'; } async run(state) { try { state.logFile.appendLine(`Exporting existing indexes from destination.`); await (0, export_1.handler)({ dir: (0, path_1.join)(state.path, 'oldIndex'), force: true, logFile: state.logFile, ...state.to }); } catch (e) { state.logFile.appendLine(`ERROR: Could not export existing indexes. \n${e}`); return false; } try { state.logFile.appendLine(`Exporting indexes from source.`); await (0, export_1.handler)({ dir: (0, path_1.join)(state.path, 'index'), force: true, logFile: state.logFile, ...state.from }); } catch (e) { state.logFile.appendLine(`ERROR: Could not export indexes. \n${e}`); return false; } try { await (0, import_1.handler)({ dir: (0, path_1.join)(state.path, 'index'), logFile: state.logFile, webhooks: true, ...state.to }); } catch (e) { state.logFile.appendLine(`ERROR: Could not import indexes. \n${e}`); return false; } return true; } async revert(state) { const toUpdate = state.revertLog.getData('UPDATE', this.getName()); if (toUpdate.length > 0 && (0, fs_1.existsSync)((0, path_1.join)(state.path, 'oldIndex'))) { try { await (0, import_1.handler)({ dir: (0, path_1.join)(state.path, 'oldIndex'), logFile: state.logFile, ...state.to }, toUpdate.map(item => item.split(' ')[0])); } catch (e) { state.logFile.appendLine(`ERROR: Could not import old indexes. \n${e}`); return false; } } return true; } } exports.IndexCloneStep = IndexCloneStep;