Skip to content
This repository was archived by the owner on Apr 22, 2021. It is now read-only.

Commit 9ecb399

Browse files
committed
Support networks.js
1 parent a415fd8 commit 9ecb399

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/config.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require('path');
12
const truffleConfig = require('truffle-config');
23
const findUp = require('find-up');
34

@@ -8,21 +9,34 @@ async function getTruffleConfig(opts) {
89
return file;
910
}
1011

12+
async function getNetworksConfig(opts) {
13+
const file = await findUp('networks.js', opts);
14+
return file;
15+
}
16+
1117
// Extracts artifacts directory from Tuffle and OpenZeppelin configs
1218
async function getBuildDir({ network, cwd }) {
1319
if (!network) {
1420
throw new Error('You must specify the network name to deploy to.');
1521
}
1622

1723
let config;
24+
25+
// Look for networks.js
26+
const networksConfig = await getNetworksConfig({ cwd });
27+
if (networksConfig) {
28+
// At that moment networks.js always use /build/contracts as a build folder
29+
// but that may change in the future
30+
return path.resolve(cwd, './build/contracts');
31+
}
32+
1833
const truffleConfigPath = await getTruffleConfig({ cwd });
1934
if (truffleConfigPath) {
2035
config = truffleConfig.load(truffleConfigPath, { network });
21-
} else {
22-
throw new Error('No Truffle Config file found!');
36+
return config.contracts_build_directory;
2337
}
2438

25-
return config.contracts_build_directory;
39+
throw new Error('No Truffle or Networks.js Config file found!');
2640
}
2741

2842
module.exports = {

0 commit comments

Comments
 (0)