@hashgraph/hedera-local
Version:
Developer tooling for running Local Hedera Network (Consensus + Mirror Nodes).
86 lines • 4.29 kB
JavaScript
;
// SPDX-License-Identifier: Apache-2.0
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StopState = void 0;
const shelljs_1 = __importDefault(require("shelljs"));
const path_1 = require("path");
const LoggerService_1 = require("../services/LoggerService");
const ServiceLocator_1 = require("../services/ServiceLocator");
const EventType_1 = require("../types/EventType");
const constants_1 = require("../constants");
const CLIService_1 = require("../services/CLIService");
const SafeDockerNetworkRemover_1 = require("../utils/SafeDockerNetworkRemover");
class StopState {
/**
* Creates an instance of StopState.
* This class is responsible for initializing the StopState object.
*/
constructor() {
this.stateName = StopState.name;
this.logger = ServiceLocator_1.ServiceLocator.Current.get(LoggerService_1.LoggerService.name);
this.cliOptions = ServiceLocator_1.ServiceLocator.Current.get(CLIService_1.CLIService.name).getCurrentArgv();
this.logger.trace(constants_1.STOP_STATE_INIT_MESSAGE, this.stateName);
}
/**
* Subscribes an observer to the state.
*
* @public
* @param {IOBserver} observer - The observer to subscribe.
*/
subscribe(observer) {
this.observer = observer;
}
/**
* Starts the stop procedure.
* Stops the network, docker containers, and cleans up volumes and temporary files.
* Notifies the observer when the procedure is finished.
* @returns {Promise<void>} A promise that resolves when the procedure is finished.
*/
onStart() {
return __awaiter(this, void 0, void 0, function* () {
var _a;
this.logger.info(constants_1.STOP_STATE_ON_START_MESSAGE, this.stateName);
const nullOutput = this.getNullOutput();
const rootPath = process.cwd();
this.logger.info(constants_1.STOP_STATE_STOPPING_MESSAGE, this.stateName);
shelljs_1.default.cd(__dirname);
shelljs_1.default.cd('../../');
this.logger.trace(constants_1.DOCKER_STOPPING_CONTAINERS_MESSAGE, this.stateName);
shelljs_1.default.exec(`docker compose kill --remove-orphans 2>${nullOutput}`);
shelljs_1.default.exec(`docker compose down -v --remove-orphans 2>${nullOutput}`);
this.logger.trace(constants_1.DOCKER_CLEANING_VOLUMES_MESSAGE, this.stateName);
shelljs_1.default.exec(`rm -rf network-logs/* >${nullOutput} 2>&1`);
this.logger.trace(`Working dir is ${this.cliOptions.workDir}`, this.stateName);
shelljs_1.default.exec(`rm -rf "${(0, path_1.join)(this.cliOptions.workDir, 'network-logs')}" >${nullOutput} 2>&1`);
SafeDockerNetworkRemover_1.SafeDockerNetworkRemover.removeAll();
shelljs_1.default.cd(rootPath);
this.logger.info(constants_1.STOP_STATE_STOPPED_MESSAGE, this.stateName);
(_a = this.observer) === null || _a === void 0 ? void 0 : _a.update(EventType_1.EventType.Finish);
});
}
/**
* Returns the null output path based on the operating system.
* On Windows, it returns "null".
* On other operating systems, it returns "/dev/null".
* @returns {string}
*/
getNullOutput() {
if (constants_1.IS_WINDOWS)
return 'null';
return '/dev/null';
}
}
exports.StopState = StopState;
//# sourceMappingURL=StopState.js.map