@hashgraph/hedera-local
Version:
Developer tooling for running Local Hedera Network (Consensus + Mirror Nodes).
68 lines • 3.15 kB
JavaScript
;
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileSystemUtils = void 0;
const os_1 = require("os");
const path_1 = require("path");
const fs_1 = require("fs");
const LoggerService_1 = require("../services/LoggerService");
const ServiceLocator_1 = require("../services/ServiceLocator");
class FileSystemUtils {
static copyPaths(directories) {
const logger = ServiceLocator_1.ServiceLocator.Current.get(LoggerService_1.LoggerService.name);
Object.entries(directories).forEach(([srcPath, destPath]) => {
if (!(0, fs_1.existsSync)(srcPath)) {
logger.error(`Path ${srcPath} doesn't exist`, FileSystemUtils.name);
return;
}
try {
(0, fs_1.cpSync)(srcPath, destPath, { recursive: true });
}
catch (error) {
logger.error(error.message);
}
});
}
static ensureDirectoryExists(dirPath) {
const logger = ServiceLocator_1.ServiceLocator.Current.get(LoggerService_1.LoggerService.name);
if (!(0, fs_1.existsSync)(dirPath)) {
(0, fs_1.mkdirSync)(dirPath, { recursive: true });
logger.trace(`Directory created: ${dirPath}`, FileSystemUtils.name);
}
else {
logger.trace(`Directory already exists: ${dirPath}`, FileSystemUtils.name);
}
}
static getPlatformSpecificAppDataPath(name) {
if (process.platform === 'darwin') {
return (0, path_1.join)((0, os_1.homedir)(), 'Library', 'Application Support', name);
}
if (process.platform === 'win32') {
return (0, path_1.join)(process.env.LOCALAPPDATA || (0, path_1.join)((0, os_1.homedir)(), 'AppData', 'Local'), name);
}
// else it's Linux
return (0, path_1.join)(process.env.XDG_DATA_HOME || (0, path_1.join)((0, os_1.homedir)(), '.local', 'share'), name);
}
static createEphemeralDirectories(workDir) {
const directories = [
workDir,
(0, path_1.join)(workDir, 'network-logs', 'node', 'accountBalances', 'balance0.0.3'),
(0, path_1.join)(workDir, 'network-logs', 'node', 'recordStreams', 'record0.0.3', 'sidecar'),
(0, path_1.join)(workDir, 'network-logs', 'node', 'logs'),
(0, path_1.join)(workDir, 'network-logs', 'node', 'stats'),
];
directories.forEach(dir => FileSystemUtils.ensureDirectoryExists(dir)); // creating those directories ensures we'll have permissions to delete them on cleanup
}
static parseWorkDir(workdir) {
let workdirPath = workdir;
if (workdirPath.startsWith('~')) {
workdirPath = (0, path_1.join)((0, os_1.homedir)(), workdirPath.slice(1));
}
if (workdirPath !== this.getPlatformSpecificAppDataPath('hedera-local')) {
workdirPath = (0, path_1.join)(workdirPath, 'hedera-local');
}
return (0, path_1.resolve)(workdirPath);
}
}
exports.FileSystemUtils = FileSystemUtils;
//# sourceMappingURL=FileSystemUtils.js.map