forked from ddnlink/ddn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
134 lines (112 loc) · 4.1 KB
/
gulpfile.js
File metadata and controls
134 lines (112 loc) · 4.1 KB
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
var path = require('path');
var util = require('util');
var moment = require('moment');
var gulp = require('gulp');
var shell = require('gulp-shell');
var replace = require('gulp-replace');
var webpack = require('webpack');
var nodeExternals = require('webpack-node-externals');
var package = require('./package');
// var UglifyJsPlugin = require('uglifyjs-webpack-plugin')
var format = util.format;
var buildTime = moment().format('HH:mm:ss DD/MM/YYYY');
function build(osName, netVersion, projectName) {
var dir = 'ddn-' + osName + '-' + package.version + '-' + netVersion;
var fullpath = path.join(__dirname, 'build', dir);
return webpack(require('./webpack.config.js')(fullpath), function(){
gulp.src(path.join(fullpath, 'app.js'))
.pipe(replace('localnet', netVersion))
.pipe(replace('development', buildTime))
.pipe(gulp.dest(fullpath))
.pipe(shell(getCmds(osName, netVersion, projectName)));
})
}
function buildSource(netVersion) {
var dir = 'ddn-' + 'linux' + '-' + package.version + '-' + netVersion;
var fullpath = path.join(__dirname, 'build', dir);
return gulp.src('app.js')
.pipe(webpack({
output: {
filename: 'app.js'
},
target: 'node',
context: __dirname,
node: {
__filename: true,
__dirname: true
},
externals: [nodeExternals()],
plugins: [
// new UglifyJsPlugin()
]
}))
.pipe(replace('localnet', netVersion))
.pipe(replace('development', buildTime))
.pipe(gulp.dest(fullpath));
}
function getCmds(osName, netVersion, projectName) {
var dir = 'ddn-' + osName + '-' + package.version + '-' + netVersion;
var fullpath = path.join(__dirname, 'build', dir);
var result = [];
result.push(format('cd %s && mkdir -p public dapps tmp logs bin', fullpath));
result.push(format('cp -r package.json ddnd init protos %s', fullpath));
if (netVersion != 'localnet') {
if (osName == 'mac') {
result.push(format('sed -i "" "s/testnet/%s/g" %s/ddnd', netVersion, fullpath));
} else {
result.push(format('sed -i "s/testnet/%s/g" %s/ddnd', netVersion, fullpath));
}
result.push(format('cp configs/%s/%s.json %s/config.json', projectName, netVersion, fullpath));
result.push(format('cp genesisBlocks/%s/%s.json %s/genesisBlock.json', projectName, netVersion, fullpath));
result.push(format('cp config.database.js %s/config.database.js', fullpath));
result.push(format('cp config.asset.js %s/config.asset.js', fullpath));
result.push(format('cp -r ./src/db/sequelize/models/ %s/', fullpath));
result.push(format('cp -r ./src/schema/format-ext/ %s/', fullpath));
result.push(format('cp -r ./src/schema/ddn-schemas/ %s/', fullpath));
result.push(format('cp -r ./src/network/service/ %s/', fullpath));
} else {
result.push(format('cp config.json %s/', fullpath));
result.push(format('cp genesisBlock.json %s/', fullpath));
result.push(format('cp third_party/sqlite3.exe %s/', fullpath));
}
if (osName !== 'win') {
result.push(format('cp `which node` %s/bin/', fullpath));
}
// result.push(format('cp -r public/dist %s/public/', fullpath));
result.push(format('cd %s && npm install --production', fullpath));
result.push(format('cd %s/.. && tar zcf %s.tar.gz %s', fullpath, dir, dir));
return result
}
const projectName = 'DDN';
gulp.task('build-src-main', function (done) {
buildSource('mainnet');
done();
})
gulp.task('win64-build-local', function (done) {
build('win64', 'localnet', projectName);
done();
});
gulp.task('linux-build-local', function (done) {
build('linux', 'localnet', projectName);
done();
});
gulp.task('win64-build-test', function (done) {
build('win64', 'testnet', projectName);
done();
});
gulp.task('linux-build-test', function (done) {
build('linux', 'testnet', projectName);
done();
});
gulp.task('mac-build-test', function (done) {
build('mac', 'testnet', projectName);
done();
});
gulp.task('win64-build-main', function (done) {
build('win64', 'mainnet', projectName);
done();
});
gulp.task('linux-build-main', function (done) {
build('linux', 'mainnet', projectName);
done();
});