This repository has been archived by the owner on Jun 11, 2019. It is now read-only.
/
pipelines.js
159 lines (133 loc) · 4.55 KB
/
pipelines.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
'use strict';
// Lazy load things we might not need this run.
var req = require('lazreq')({
buffer: 'vinyl-buffer',
gutil: 'gulp-util',
vinyl: 'vinyl-fs'
});
var _ = require('lodash');
var Combine = require('stream-combiner');
var filter = require('gulp-filter');
var loggers = require('../lib/loggers.js');
var streams = require('../lib/streams');
var Workspace = require('../lib/workspace.js');
var Web3Factory = require('dapple-core/web3Factory');
var Web3Interface = require('dapple-core/web3Interface');
var deasync = require('deasync');
// This file contains collections of streams that have been packaged up into
// discreet "pipelines" which are ultimately themselves streams. This helps keep
// `main.js` clean and easy to read.
var _fillOptionDefaults = function (opts) {
if (!opts) opts = {};
var mapAwareLogger = new loggers.MapAwareLogger();
var defaults = {
deployData: true,
globalVar: false,
errorHandler: mapAwareLogger.getErrorHandler(),
logger: new loggers.Logger(),
mapAwareLogger: mapAwareLogger,
packageRoot: Workspace.findPackageRoot() || process.cwd(),
preprocessorVars: {},
web3: 'internal',
confirmationBlocks: 1
};
var _opts = _.assign(defaults, opts);
return _opts;
};
// This pipeline gathers together all the raw source files that go into a
// given package.
var SourcePipeline = function (opts) {
// Defaults
opts = _fillOptionDefaults(opts);
var injectedSources = _.values(opts.modules)
.filter(m => 'inject' in m)
.map(m => m.inject(opts))
.concat([streams.inject_virtual_contracts()]);
var injected = Combine.apply(this, injectedSources);
// Grab all the files relevant to the package.
return Combine(
streams.package_stream(opts.packageRoot),
// Extendable preprocessor
streams.xpreprocess(opts),
injected,
// Lodash.template is the default preprocessor.
streams.preprocess(opts.preprocessorVars));
};
// Returns raw output of `solc`.
var BuildPipeline = function (opts) {
// Defaults
opts = _fillOptionDefaults(opts);
if (!opts.name) {
var workspace = Workspace.atPackageRoot(opts.packageRoot);
opts.name = workspace.dappfile.name;
}
var solidityFilter = filter(['*.sol', '**/*.sol'], {restore: true});
var buildFilter = new streams.PackageBuildFilter();
return Combine(
SourcePipeline(opts),
opts.subpackages ? req.gutil.noop() : buildFilter.seed(),
streams.linker(),
streams.linker_filter.exclude(),
opts.mapAwareLogger.seedStream(),
solidityFilter,
streams.build(opts),
solidityFilter.restore,
opts.subpackages ? req.gutil.noop() : buildFilter.filter());
};
// Builds JS-specific output.
var JSBuildPipeline = function (opts) {
// Defaults
opts = _fillOptionDefaults(opts);
return Combine(BuildPipeline(opts), streams.js_postprocess(opts));
};
// Grabs pre-built contracts from build directory.
var BuiltClassesPipeline = function (opts) {
opts = _fillOptionDefaults(opts);
var buildFilter = new streams.PackageBuildFilter();
streams.package_stream(opts.packageRoot)
.pipe(buildFilter.seed());
return Combine(
req.vinyl.src([opts.buildRoot + '/classes.json']),
opts.subpackage ? req.gutil.noop() : buildFilter.filter(),
req.buffer());
};
// Takes built contracts and deploys and runs any test
// contracts among them, emitting the results to the CLI
// and passing them downstream as File objects.
var TestPipeline = function (opts) {
// Defaults
opts = _fillOptionDefaults(opts);
var chainenv = opts.state.state.pointers[opts.state.state.head];
var web3Interface = new Web3Interface(_.assign({type: 'tmp', chainenv, db: opts.state.db}, opts));
web3Interface._web3.currentProvider.manager.blockchain.setGasLimit(900000000);
opts.web3 = web3Interface._web3
// Setup internal web3
// TestPipeline only supports internal ethersim
// opts.web3 = deasync(Web3Factory.EVM.bind(Web3Factory.EVM, {
// packageRoot: opts.packageRoot,
// mode: opts.mode,
// state: opts.state,
// db: opts.state.db,
// chainenv
// }))();
return Combine(
streams.linkLibraries(opts),
streams.test(opts), streams.cli_out(),
streams.test_summarizer(), streams.cli_out());
};
// Takes built contracts and runs the deployscript
var PublishPipeline = function (opts) {
// Defaults
opts = _fillOptionDefaults(opts);
return Combine(
streams.publish(opts)
);
};
module.exports = {
BuildPipeline: BuildPipeline,
BuiltClassesPipeline: BuiltClassesPipeline,
JSBuildPipeline: JSBuildPipeline,
SourcePipeline: SourcePipeline,
TestPipeline: TestPipeline,
PublishPipeline
};