import path from "path"; import fs from "fs"; import os from "os"; class Env { private _serverConfig: { agentServer: string; agentKey: string; agentId: string; }; private get serverConfig() { if (this._serverConfig) { return this._serverConfig; } try { const cfgPath = path.resolve( os.homedir(), ".gswl/agent/server.json" ); const str = fs.readFileSync(cfgPath).toString(); console.log("load cfgPath", cfgPath, "content:", str); this._serverConfig = JSON.parse(str); } catch (e) { console.error(e); } return this._serverConfig; } // agent应用的路径 get AgentBasePath() { return path.resolve(__dirname, ".."); } // 插件路径,对agent附加功能 get PluginBasePath() { return ""; } get AgentId() { return this.serverConfig.agentId; } get AgentServer() { return this.serverConfig.agentServer; } } export default new Env();