-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
73 lines (61 loc) · 2 KB
/
gulpfile.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
'use strict';
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var gutil = require('gulp-util');
var run = require('gulp-run');
var rename = require('gulp-rename');
var gulpMultiProcess = require('gulp-multi-process');
var gls = require('gulp-live-server');
var TestRPC = require('ethereumjs-testrpc');
var Promise = require('bluebird');
var fs = require('fs');
Promise.promisifyAll(fs);
gulp.task('default', function() {
return gulpMultiProcess(['testrpc', 'watch-build', 'watch-mocha']);
});
gulp.task('watch-build', function() {
gulp.watch(['contracts/**'], ['build']);
})
gulp.task('watch-mocha', function() {
gulp.watch(['build/**', 'src/**', 'test/**'], ['mocha']);
});
gulp.task('testrpc', function() {
var server = TestRPC.server(/*{'logger': console}*/)
server.listen(8555, function(err, blockchain) {
if(err) {
console.log(err);
}
});
});
gulp.task('build', function() {
// There's probably some kind of gulp-sorcery to use the npm version of solc here, instead.
// It's beyond me at the moment.
return run('solc contracts/*.sol --combined-json abi,bin').exec()
.pipe(rename('contracts.json'))
.pipe(gulp.dest('./build/'));
})
gulp.task('mocha', function() {
return gulp.src(['test/*.js'], { read: false })
.pipe(mocha({ reporter: 'list' }))
.on('error', gutil.log);
});
gulp.task('deploy', ['build', 'testrpc'], function() {
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8555'));
Promise.promisifyAll(web3.eth);
var u = require('./src/universe')(web3);
return web3.eth.getAccountsAsync()
.then(a => web3.eth.defaultAccount = a[0])
.then(u.createUniverse)
.then(galaxy => {
console.log("galaxy deployed at:", galaxy.address);
return fs.writeFileAsync(
'./build/galaxy-address.js',
'module.exports = "' + galaxy.address + '";'
);
});
});
gulp.task('run', ['deploy', 'testrpc'], function() {
var server = gls.new('server.js');
server.start();
});