UNPKG

zksync-cli

Version:

CLI tool that simplifies the process of developing applications and interacting with the ZKsync network

85 lines 2.48 kB
import fs from "fs"; import path from "path"; import { fileOrDirExists, getLocalPath, writeFile } from "../../../utils/files.js"; import Logger from "../../../utils/logger.js"; export var ModuleCategory; (function (ModuleCategory) { ModuleCategory["Node"] = "node"; ModuleCategory["Dapp"] = "dapp"; ModuleCategory["Explorer"] = "explorer"; ModuleCategory["Service"] = "service"; ModuleCategory["Other"] = "other"; })(ModuleCategory || (ModuleCategory = {})); export const modulesPath = getLocalPath("modules"); export const createModulesFolder = () => { if (fileOrDirExists(modulesPath)) { return; } fs.mkdirSync(modulesPath, { recursive: true }); }; class Module { // eslint-disable-next-line @typescript-eslint/no-unused-vars isNodeSupported(_) { return true; } get startAfterNode() { return false; } getStartupInfo() { return []; } async getLogs() { } get version() { return; } async getLatestVersion() { return; } async update() { } get dataDirPath() { return path.join(modulesPath, this.package.name); } get configPath() { return path.join(this.dataDirPath, "config.json"); } get moduleConfig() { if (!fileOrDirExists(this.configPath)) { return {}; } else { try { return JSON.parse(fs.readFileSync(this.configPath, { encoding: "utf-8" })); } catch { Logger.error(`There was an error while reading config file for module "${this.name}":`); return {}; } } } setModuleConfig(config) { writeFile(this.configPath, JSON.stringify(config, null, 2)); } removeDataDir() { if (fileOrDirExists(this.dataDirPath)) { fs.rmSync(this.dataDirPath, { recursive: true }); } } constructor(data, configHandler) { this.package = { name: "", version: "", symlinked: false, }; this.name = data.name; this.description = data.description; this.category = data.category; this.configHandler = configHandler; } } export default Module; export class ModuleNode extends Module { constructor(data, modulesConfigHandler) { super({ ...data, category: ModuleCategory.Node }, modulesConfigHandler); } } //# sourceMappingURL=Module.js.map