UNPKG

8.8 kBJavaScriptView Raw
1"use strict";
2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 if (k2 === undefined) k2 = k;
4 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5}) : (function(o, m, k, k2) {
6 if (k2 === undefined) k2 = k;
7 o[k2] = m[k];
8}));
9var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10 Object.defineProperty(o, "default", { enumerable: true, value: v });
11}) : function(o, v) {
12 o["default"] = v;
13});
14var __importStar = (this && this.__importStar) || function (mod) {
15 if (mod && mod.__esModule) return mod;
16 var result = {};
17 if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18 __setModuleDefault(result, mod);
19 return result;
20};
21var __importDefault = (this && this.__importDefault) || function (mod) {
22 return (mod && mod.__esModule) ? mod : { "default": mod };
23};
24Object.defineProperty(exports, "__esModule", { value: true });
25exports.configProps = exports.getInitialConfig = void 0;
26const lodash_assignin_1 = __importDefault(require("lodash.assignin"));
27const path = __importStar(require("path"));
28const provider_1 = __importDefault(require("@truffle/provider"));
29exports.getInitialConfig = ({ truffleDirectory, workingDirectory, network }) => {
30 const truffle_directory = truffleDirectory || path.resolve(path.join(__dirname, "../"));
31 const working_directory = workingDirectory || process.cwd();
32 return {
33 truffle_directory,
34 working_directory,
35 network,
36 networks: {},
37 verboseRpc: false,
38 gas: null,
39 gasPrice: null,
40 from: null,
41 confirmations: 0,
42 timeoutBlocks: 0,
43 production: false,
44 skipDryRun: false,
45 build: null,
46 resolver: null,
47 artifactor: null,
48 ethpm: {
49 ipfs_host: "ipfs.infura.io",
50 ipfs_protocol: "https",
51 registry: "0x8011df4830b4f696cd81393997e5371b93338878",
52 install_provider_uri: "https://ropsten.infura.io/v3/26e88e46be924823983710becd929f36"
53 },
54 ens: {
55 enabled: false,
56 registryAddress: null
57 },
58 compilers: {
59 solc: {
60 settings: {
61 optimizer: {
62 enabled: false,
63 runs: 200
64 },
65 remappings: []
66 }
67 },
68 vyper: {}
69 },
70 logger: console
71 };
72};
73exports.configProps = ({ configObject }) => {
74 const resolveDirectory = (value) => path.resolve(configObject.working_directory, value);
75 const defaultTXValues = {
76 gas: 6721975,
77 gasPrice: 20000000000,
78 from: null
79 };
80 return {
81 // These are already set.
82 truffle_directory() { },
83 working_directory() { },
84 network() { },
85 networks() { },
86 verboseRpc() { },
87 build() { },
88 resolver() { },
89 artifactor() { },
90 ethpm() { },
91 logger() { },
92 compilers() { },
93 ens() { },
94 build_directory: {
95 default: () => path.join(configObject.working_directory, "build"),
96 transform: resolveDirectory
97 },
98 contracts_directory: {
99 default: () => path.join(configObject.working_directory, "contracts"),
100 transform: resolveDirectory
101 },
102 contracts_build_directory: {
103 default: () => path.join(configObject.build_directory, "contracts"),
104 transform: resolveDirectory
105 },
106 migrations_directory: {
107 default: () => path.join(configObject.working_directory, "migrations"),
108 transform: resolveDirectory
109 },
110 migrations_file_extension_regexp() {
111 return /^\.(js|es6?)$/;
112 },
113 test_directory: {
114 default: () => path.join(configObject.working_directory, "test"),
115 transform: resolveDirectory
116 },
117 test_file_extension_regexp() {
118 return /.*\.(js|ts|es|es6|jsx|sol)$/;
119 },
120 example_project_directory: {
121 default: () => path.join(configObject.truffle_directory, "example"),
122 transform: resolveDirectory
123 },
124 network_id: {
125 get() {
126 try {
127 return configObject.network_config.network_id;
128 }
129 catch (e) {
130 return null;
131 }
132 },
133 set() {
134 throw new Error("Do not set config.network_id. Instead, set config.networks and then config.networks[<network name>].network_id");
135 }
136 },
137 network_config: {
138 get() {
139 const network = configObject.network;
140 if (network === null || network === undefined) {
141 throw new Error("Network not set. Cannot determine network to use.");
142 }
143 let config = configObject.networks[network];
144 if (config === null || config === undefined) {
145 config = {};
146 }
147 config = lodash_assignin_1.default({}, defaultTXValues, config);
148 return config;
149 },
150 set() {
151 throw new Error("Don't set config.network_config. Instead, set config.networks with the desired values.");
152 }
153 },
154 from: {
155 get() {
156 try {
157 return configObject.network_config.from;
158 }
159 catch (e) {
160 return defaultTXValues.from;
161 }
162 },
163 set() {
164 throw new Error("Don't set config.from directly. Instead, set config.networks and then config.networks[<network name>].from");
165 }
166 },
167 gas: {
168 get() {
169 try {
170 return configObject.network_config.gas;
171 }
172 catch (e) {
173 return defaultTXValues.gas;
174 }
175 },
176 set() {
177 throw new Error("Don't set config.gas directly. Instead, set config.networks and then config.networks[<network name>].gas");
178 }
179 },
180 gasPrice: {
181 get() {
182 try {
183 return configObject.network_config.gasPrice;
184 }
185 catch (e) {
186 return defaultTXValues.gasPrice;
187 }
188 },
189 set() {
190 throw new Error("Don't set config.gasPrice directly. Instead, set config.networks and then config.networks[<network name>].gasPrice");
191 }
192 },
193 provider: {
194 get() {
195 if (!configObject.network) {
196 return null;
197 }
198 const options = configObject.network_config;
199 options.verboseRpc = configObject.verboseRpc;
200 return provider_1.default.create(options);
201 },
202 set() {
203 throw new Error("Don't set config.provider directly. Instead, set config.networks and then set config.networks[<network name>].provider");
204 }
205 },
206 confirmations: {
207 get() {
208 try {
209 return configObject.network_config.confirmations;
210 }
211 catch (e) {
212 return 0;
213 }
214 },
215 set() {
216 throw new Error("Don't set config.confirmations directly. Instead, set config.networks and then config.networks[<network name>].confirmations");
217 }
218 },
219 production: {
220 get() {
221 try {
222 return configObject.network_config.production;
223 }
224 catch (e) {
225 return false;
226 }
227 },
228 set() {
229 throw new Error("Don't set config.production directly. Instead, set config.networks and then config.networks[<network name>].production");
230 }
231 },
232 timeoutBlocks: {
233 get() {
234 try {
235 return configObject.network_config.timeoutBlocks;
236 }
237 catch (e) {
238 return 0;
239 }
240 },
241 set() {
242 throw new Error("Don't set config.timeoutBlocks directly. Instead, set config.networks and then config.networks[<network name>].timeoutBlocks");
243 }
244 }
245 };
246};
247//# sourceMappingURL=configDefaults.js.map
\No newline at end of file