UNPKG

secret-polar

Version:

Polar is a development environment to compile, deploy, test, run scrt contracts on different networks.

58 lines (57 loc) 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PolarContext = void 0; const extenders_1 = require("./core/config/extenders"); const errors_1 = require("./core/errors"); const errors_list_1 = require("./core/errors-list"); const dsl_1 = require("./core/tasks/dsl"); class PolarContext { constructor() { this.tasksDSL = new dsl_1.TasksDSL(); this.extendersManager = new extenders_1.ExtenderManager(); this.loadedPlugins = []; this.configExtenders = []; } static isCreated() { const globalWithPolarContext = global; return globalWithPolarContext.__polarContext !== undefined; } static createPolarContext() { if (this.isCreated()) { throw new errors_1.PolarError(errors_list_1.ERRORS.GENERAL.CONTEXT_ALREADY_CREATED); } const globalWithPolarContext = global; const ctx = new PolarContext(); globalWithPolarContext.__polarContext = ctx; return ctx; } static getPolarContext() { const globalWithPolarContext = global; const ctx = globalWithPolarContext.__polarContext; if (ctx === undefined) { throw new errors_1.PolarError(errors_list_1.ERRORS.GENERAL.CONTEXT_NOT_CREATED); } return ctx; } static deletePolarContext() { // eslint-disable-next-line const globalAsAny = global; globalAsAny.__polarContext = undefined; } setRuntimeEnv(env) { if (this.environment !== undefined) { throw new errors_1.PolarError(errors_list_1.ERRORS.GENERAL.CONTEXT_PRE_ALREADY_DEFINED); } this.environment = env; } getRuntimeEnv() { if (this.environment === undefined) { throw new errors_1.PolarError(errors_list_1.ERRORS.GENERAL.CONTEXT_PRE_NOT_DEFINED); } return this.environment; } setPluginAsLoaded(pluginName) { this.loadedPlugins.push(pluginName); } } exports.PolarContext = PolarContext;