Skip to content

Commit

Permalink
If networks directory did not exist, there was an error. Migrations i…
Browse files Browse the repository at this point in the history
…gnored the first migration, made it migrate if there are more than zero.
  • Loading branch information
asselstine committed Apr 11, 2018
1 parent e5d110b commit 04a6ee9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
36 changes: 21 additions & 15 deletions lib/truffle-migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,26 @@ function updateAllContractNetworks(options) {
// NOTE: Some networks may have a different ABI. We need a different structure to store these.
var contractsCache = {}

fs.readdirSync(options.networks_directory).forEach(function (networkJsonFilename) {
var networkJson = readNetworkJSON(path.join(options.networks_directory, networkJsonFilename))
var networkId = path.basename(networkJsonFilename, '.json')

// the last contract will be the one recorded
networkJson.contracts.forEach(function (networkContract) {
var contract = contractsCache[networkContract.contractName] || options.resolver.require(networkContract.contractName)
contract.networks[networkId] = contract.networks[networkId] || {
events: {},
links: {}
}
contract.networks[networkId].address = networkContract.address
contractsCache[networkContract.contractName] = contract
})
mkdirp(options.networks_directory, function (err) {
if (err) {
console.error(err)
} else {
fs.readdirSync(options.networks_directory).forEach(function (networkJsonFilename) {
var networkJson = readNetworkJSON(path.join(options.networks_directory, networkJsonFilename))
var networkId = path.basename(networkJsonFilename, '.json')

// the last contract will be the one recorded
networkJson.contracts.forEach(function (networkContract) {
var contract = contractsCache[networkContract.contractName] || options.resolver.require(networkContract.contractName)
contract.networks[networkId] = contract.networks[networkId] || {
events: {},
links: {}
}
contract.networks[networkId].address = networkContract.address
contractsCache[networkContract.contractName] = contract
})
})
}
})

options.artifactor.saveAll(_.values(contractsCache));
Expand Down Expand Up @@ -359,7 +365,7 @@ var Migrate = {
migrations.shift();
}

callback(null, migrations.length > 1);
callback(null, migrations.length > 0);
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "truffle-migrate-off-chain",
"version": "0.1.0",
"version": "0.1.1",
"description": "Off-chain migrations for Truffle",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 04a6ee9

Please sign in to comment.