Skip to content

Commit

Permalink
v2.0. Preprocessor and more
Browse files Browse the repository at this point in the history
  • Loading branch information
nourharidy committed Oct 10, 2018
1 parent 642fe63 commit dc93a1a
Show file tree
Hide file tree
Showing 21 changed files with 843 additions and 239 deletions.
39 changes: 39 additions & 0 deletions addressbook/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var jsonfile = require('jsonfile');

module.exports = {
get: function() {
return jsonfile.readFileSync(process.cwd() + '/addressbook.json');
},
add: function(contracts) {
if(contracts[Object.keys(contracts)[0]].currentProvider.ganache === undefined) {
const assign = require('assign-deep');
for (var contract in contracts) {
var host = contracts[contract].currentProvider.host
var network = /(?<=https:\/\/).*?(?=.infura.io)/.exec(host)
const file = process.cwd() + '/addressbook.json';
var book = jsonfile.readFileSync(file)
if(network === null){
var obj = {
[host]:{
[contract]:contracts[contract].options.address
}
}
}else {
var obj = {
[network]:{
[contract]:contracts[contract].options.address
}
}
var result = assign(book, obj) }
jsonfile.writeFileSync(file, result, { spaces:2 })
}
}
},
checkNetwork: function(network) {
var book = require(process.cwd()+'/addressbook.json');
if(typeof book[network] === "undefined") {
console.log(("There are no contracts registered for this network in your address book. Please make sure you deploy your contracts to " + network + " first").red)
process.exit()
}
}
}
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion example/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion example/addressbook.json

This file was deleted.

38 changes: 0 additions & 38 deletions example/contracts/Token.sol

This file was deleted.

1 change: 0 additions & 1 deletion example/docs/README.md

This file was deleted.

46 changes: 0 additions & 46 deletions example/parasol.js

This file was deleted.

7 changes: 0 additions & 7 deletions example/tests/Token.js

This file was deleted.

77 changes: 77 additions & 0 deletions hooks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module.exports = {
onCompiled: function (context, callback) {
if(typeof this.compiled[context.source] === "array") {
this.compiled[context.source].push(callback);
} else {
this.compiled[context.source] = [callback];
}
},
compiled: {},
executeCompiled(compiledFileName) {
for (fileName in this.compiled) {
if (compiledFileName.startsWith(fileName)) {
for (var i = 0; i < this.compiled[fileName].length; i++) {
this.compiled[fileName][i](compiledFileName)
}
}
}
},
onDeployed: function (context, callback) {
if(typeof this.deployed[context.source] === "array") {
this.deployed[context.source].push(callback);
} else {
this.deployed[context.source] = [callback];
}
},
deployed: {},
executeDeployed(contracts) {
this.executeAllDeployed(contracts)
for (contractName in contracts) {
for (fileName in this.deployed) {
if (contractName.startsWith(fileName)) {
for (var i = 0; i < this.deployed[fileName].length; i++) {
this.deployed[fileName][i](contracts[contractName], contractName)
}

}
}
}
},
onAllDeployed: function (callback) {
this.allDeployed.push(callback)
},
allDeployed: [],
executeAllDeployed: function(contracts){
for (var i = 0; i < this.allDeployed.length; i++) {
this.allDeployed[i](contracts)
}
},
onError: function (context, callback) {
if(typeof this.errors[context.source] === "array") {
this.errors[context.source].push(callback);
} else {
this.errors[context.source] = [callback];
}
},
errors: {},
executeErrors: function(errors) {
var self = this;
errors.forEach(function(error) {
for (fileName in self.errors) {
if (error.includes(fileName)) {
for (var i = 0; i < self.errors[fileName].length; i++) {
self.errors[fileName][i](error)
}
}
}
})
},
tests:{},
onTest: function (context, description, callback) {
if(typeof this.tests[context.source] != "object") {
this.tests[context.source] = {[description]: callback}
} else {
this.tests[context.source][description] = callback
}
},
}
Loading

0 comments on commit dc93a1a

Please sign in to comment.