@hashgraph/hedera-local
Version:
Developer tooling for running Local Hedera Network (Consensus + Mirror Nodes).
44 lines • 1.79 kB
JavaScript
;
// SPDX-License-Identifier: Apache-2.0
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SafeDockerNetworkRemover = void 0;
const shelljs_1 = __importDefault(require("shelljs"));
const constants_1 = require("../constants");
/**
* Checks if the given string is a valid Docker network ID.
* A valid Docker network ID is a 12-character hexadecimal string.
*
* @param {string} id - The string to be validated as a Docker network ID.
* @returns {boolean} - Returns true if the string is a valid Docker network ID, false otherwise.
*
* @example
* const id = "89ded1eca1d5";
* console.log(isCorrectDockerId(id)); // Output: true
*
* @example
* const invalidId = "invalidID123";
* console.log(isCorrectDockerId(invalidId)); // Output: false
*/
const isCorrectDockerId = (id) => id.trim() !== '' && /^[a-f0-9]{12}$/.test(id);
/**
* Provides utility methods for safe networks removal.
*/
class SafeDockerNetworkRemover {
/**
* Removes all the networks started by docker compose. Only networks with the "hedera-" prefix will be affected.
*/
static removeAll() {
const result = shelljs_1.default.exec(`docker network ls --filter name=${constants_1.NETWORK_PREFIX} --format "{{.ID}}"`);
if (!result || result.stderr !== '') {
return;
}
result.stdout.split('\n').filter(isCorrectDockerId).forEach((id) => {
shelljs_1.default.exec(`docker network rm ${id} -f 2>${constants_1.IS_WINDOWS ? 'null' : '/dev/null'}`);
});
}
}
exports.SafeDockerNetworkRemover = SafeDockerNetworkRemover;
//# sourceMappingURL=SafeDockerNetworkRemover.js.map