forked from trufflesuite/truffle-deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
84 lines (68 loc) · 2.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var expect = require("truffle-expect");
var DeferredChain = require("./src/deferredchain");
var deploy = require("./src/actions/deploy");
var deployMany = require("./src/actions/deploymany");
var link = require("./src/actions/link");
var create = require("./src/actions/new");
function Deployer(options) {
var self = this;
options = options || {};
expect.options(options, [
"provider",
"network",
"network_id"
]);
this.chain = new DeferredChain();
this.logger = options.logger || {log: function() {}};
this.known_contracts = {};
(options.contracts || []).forEach(function(contract) {
self.known_contracts[contract.contract_name] = contract;
});
this.network = options.network;
this.network_id = options.network_id;
this.provider = options.provider;
this.basePath = options.basePath || process.cwd();
};
// Note: In all code below we overwrite this.chain every time .then() is used
// in order to ensure proper error processing.
Deployer.prototype.start = function() {
return this.chain.start();
};
Deployer.prototype.link = function(library, destinations) {
return this.queueOrExec(link(library, destinations, this));
};
Deployer.prototype.deploy = function() {
var args = Array.prototype.slice.call(arguments);
var contract = args.shift();
if (Array.isArray(contract)) {
return this.queueOrExec(deployMany(contract, this));
} else {
return this.queueOrExec(deploy(contract, args, this));
}
};
Deployer.prototype.new = function() {
var args = Array.prototype.slice.call(arguments);
var contract = args.shift();
return this.queueOrExec(create(contract, args, this));
};
Deployer.prototype.exec = function(file) {
throw new Error("deployer.exec() has been deprecated; please seen the truffle-require package for integration.")
};
Deployer.prototype.then = function(fn) {
var self = this;
return this.queueOrExec(function() {
self.logger.log("Running step...");
return fn(this);
});
};
Deployer.prototype.queueOrExec = function(fn) {
var self = this;
if (this.chain.started == true) {
return new Promise(function(accept, reject) {
accept();
}).then(fn);
} else {
return this.chain.then(fn);
}
};
module.exports = Deployer;