forked from klaytn/caver-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
152 lines (138 loc) · 4.29 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
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
#!/usr/bin/env node
const path = require('path')
const del = require('del')
const gulp = require('gulp')
const browserify = require('browserify')
const uglify = require('gulp-uglify')
const babel = require('gulp-babel')
const rename = require('gulp-rename')
const source = require('vinyl-source-stream')
const exorcist = require('exorcist')
const streamify = require('gulp-streamify')
const DEST = path.join(__dirname, 'dist/')
const packages = [
{
fileName: 'caver',
expose: 'Caver',
src: './index.js',
ignore: ['xhr2', 'xmlhttprequest', 'websocket'],
},
{
fileName: 'caver-utils',
expose: 'CaverUtils',
src: './packages/caver-utils/src/index.js',
},
{
fileName: 'caver-klay',
expose: 'CaverKlay',
src: './packages/caver-klay/src/index.js',
},
{
fileName: 'caver-core-helpers',
expose: 'CaverHelpers',
src: './packages/caver-core-helpers/src/index.js',
},
{
fileName: 'caver-middleware',
expose: 'CaverMiddleware',
src: './packages/caver-middleware/src/index.js',
},
{
fileName: 'caver-rtm',
expose: 'CaverRtm',
src: './packages/caver-middleware/src/index.js',
},
{
fileName: 'caver-net',
expose: 'CaverNet',
src: './packages/caver-net/src/index.js',
},
{
fileName: 'caver-core-requestmanager',
expose: 'CaverRequestManager',
src: './packages/caver-core-requestmanager/src/index.js',
ignore: ['xhr2', 'xmlhttprequest', 'websocket'],
},
{
fileName: 'caver-core-subscriptions',
expose: 'CaverSubscriptions',
src: './packages/caver-core-subscriptions/src/index.js',
},
{
fileName: 'caver-core-method',
expose: 'CaverMethod',
src: './packages/caver-core-method/src/index.js',
},
]
const browserifyOptions = {
debug: true,
derequire: true,
insertGlobalVars: false, // jshint ignore:line
detectGlobals: true,
bundleExternal: true,
}
const ugliyOptions = {
compress: {
dead_code: true, // jshint ignore:line
drop_debugger: true, // jshint ignore:line
global_defs: {
// jshint ignore:line
DEBUG: false, // matters for some libraries
},
},
}
gulp.task(
'clean',
gulp.series(function(cb) {
del([DEST]).then(cb.bind(null, null))
})
)
packages.forEach(function(pckg, i) {
const prevPckg = !i ? 'clean' : packages[i - 1].fileName
gulp.task(
pckg.fileName,
gulp.series(prevPckg, function() {
browserifyOptions.standalone = pckg.expose
const pipe = browserify(browserifyOptions)
.require(pckg.src, { expose: pckg.expose })
.require('bn.js', { expose: 'BN' }) // expose it to dapp developers
.add(pckg.src)
if (pckg.ignore) {
pckg.ignore.forEach(function(ignore) {
pipe.ignore(ignore)
})
}
return pipe
.bundle()
.pipe(exorcist(path.join(DEST, `${pckg.fileName}.js.map`)))
.pipe(source(`${pckg.fileName}.js`))
.pipe(
streamify(
babel({
compact: false,
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-runtime'],
})
)
)
.pipe(gulp.dest(DEST))
.pipe(
streamify(
babel({
compact: true,
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-runtime'],
})
)
)
.pipe(streamify(uglify(ugliyOptions)))
.on('error', function(err) {
console.error(err)
})
.pipe(rename(`${pckg.fileName}.min.js`))
.pipe(gulp.dest(DEST))
})
)
})
gulp.task('all', gulp.series('clean', packages[packages.length - 1].fileName))
gulp.task('default', gulp.series('clean', packages[0].fileName))