1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const extenders_1 = require("./core/config/extenders");
|
4 | const errors_1 = require("./core/errors");
|
5 | const errors_list_1 = require("./core/errors-list");
|
6 | const dsl_1 = require("./core/tasks/dsl");
|
7 | class BuidlerContext {
|
8 | constructor() {
|
9 | this.tasksDSL = new dsl_1.TasksDSL();
|
10 | this.extendersManager = new extenders_1.ExtenderManager();
|
11 | this.loadedPlugins = [];
|
12 | this.configExtenders = [];
|
13 |
|
14 |
|
15 | this.experimentalBuidlerEVMMessageTraceHooks = [];
|
16 | }
|
17 | static isCreated() {
|
18 | const globalWithBuidlerContext = global;
|
19 | return globalWithBuidlerContext.__buidlerContext !== undefined;
|
20 | }
|
21 | static createBuidlerContext() {
|
22 | if (this.isCreated()) {
|
23 | throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_ALREADY_CREATED);
|
24 | }
|
25 | const globalWithBuidlerContext = global;
|
26 | const ctx = new BuidlerContext();
|
27 | globalWithBuidlerContext.__buidlerContext = ctx;
|
28 | return ctx;
|
29 | }
|
30 | static getBuidlerContext() {
|
31 | const globalWithBuidlerContext = global;
|
32 | const ctx = globalWithBuidlerContext.__buidlerContext;
|
33 | if (ctx === undefined) {
|
34 | throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_NOT_CREATED);
|
35 | }
|
36 | return ctx;
|
37 | }
|
38 | static deleteBuidlerContext() {
|
39 | const globalAsAny = global;
|
40 | globalAsAny.__buidlerContext = undefined;
|
41 | }
|
42 | setBuidlerRuntimeEnvironment(env) {
|
43 | if (this.environment !== undefined) {
|
44 | throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_BRE_ALREADY_DEFINED);
|
45 | }
|
46 | this.environment = env;
|
47 | }
|
48 | getBuidlerRuntimeEnvironment() {
|
49 | if (this.environment === undefined) {
|
50 | throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_BRE_NOT_DEFINED);
|
51 | }
|
52 | return this.environment;
|
53 | }
|
54 | setPluginAsLoaded(pluginName) {
|
55 | this.loadedPlugins.push(pluginName);
|
56 | }
|
57 | setConfigPath(configPath) {
|
58 | this._configPath = configPath;
|
59 | }
|
60 | getConfigPath() {
|
61 | if (this._configPath === undefined) {
|
62 | throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_CONFIG_PATH_NOT_SET);
|
63 | }
|
64 | return this._configPath;
|
65 | }
|
66 | }
|
67 | exports.BuidlerContext = BuidlerContext;
|
68 |
|
\ | No newline at end of file |