UNPKG

@dlillyatx/dc-cli

Version:
76 lines (75 loc) 2.52 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 export_1.handler({ dir: 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 export_1.handler({ dir: 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 import_1.handler({ dir: 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 && fs_1.existsSync(path_1.join(state.path, 'oldIndex'))) { try { await import_1.handler({ dir: 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;