This repository has been archived by the owner on Jan 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
101 lines (85 loc) · 2.8 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
'use strict';
const fs = require('fs');
const browserify = require("browserify");
const gulp = require("gulp");
const through = require('through');
const source = require('vinyl-source-stream');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
function createTransform(transforms, show) {
if (!show) { show = { }; }
function padding(length) {
let pad = '';
while (pad.length < length) { pad += ' '; }
return pad;
}
function transformFile(path) {
for (let pattern in transforms) {
if (path.match(new RegExp('/' + pattern + '$'))) {
return transforms[pattern];
}
}
return null;
}
return function(path, options) {
let data = '';
return through(function(chunk) {
data += chunk;
}, function () {
let transformed = transformFile(path);
let shortPath = path;
if (shortPath.substring(0, __dirname.length) == __dirname) {
shortPath = shortPath.substring(__dirname.length);
}
let size = fs.readFileSync(path).length;
if (transformed != null) {
if (show.transformed) {
console.log('Transformed:', shortPath, padding(70 - shortPath.length), size, padding(6 - String(size).length), '=>', transformed.length);
}
data = transformed;
} else {
if (show.preserved) {
console.log('Preserved: ', shortPath, padding(70 - shortPath.length), size);
}
}
this.queue(data);
this.queue(null);
});
}
}
function taskBundle(name, options) {
let show = options.show || { };
function readShim(filename) {
return fs.readFileSync('./shims/' + filename + '.js').toString();
}
let transforms = {
"ethers/dist/ethers.js": "module.exports = global.ethers;"
};
gulp.task(name, function () {
let result = browserify({
basedir: '.',
debug: false,
entries: [ './index.js' ],
cache: { },
packageCache: {},
standalone: "ENS",
transform: [ [ createTransform(transforms, show), { global: true } ] ],
})
.bundle()
.pipe(source(options.filename))
if (options.minify) {
result = result.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
}
result = result.pipe(gulp.dest(options.dest));
return result;
});
}
taskBundle("default", {
dest: "dist",
filename: "ethers-ens.js",
minify: false,
show: { preserved: true, transformed: true }
});