-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
140 lines (125 loc) · 3.41 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
const gulp = require("gulp");
const buble = require("buble");
const uglifyJS = require("uglify-js");
const composer = require("gulp-uglify/composer");
const uglify = composer(uglifyJS, console);
const replace = require("gulp-replace");
const include = require("gulp-include");
const concat = require("gulp-concat");
const header = require("gulp-header");
const size = require("gulp-size");
const Transform = require("stream").Transform;
const mocha = require("gulp-mocha");
const pkg = require("./package.json");
// Header comment
const comment = `/**
* Trie v${pkg.version}
* Copyright 2017 Léopold Szabatura
* Released under the MIT License
* https://github.com/MetaCorp/trie
*/\r\n`;
// Gulp Buble Plugin
const gulpBuble = function(options) {
return new Transform({
objectMode: true,
transform: function(file, encoding, callback) {
if(!file.isStream()) {
if(options === undefined) {
options = {};
}
let result = null;
try {
result = buble.transform(file.contents.toString(), options);
} catch(e) {
throw new Error("[Buble] Error: " + e);
}
file.contents = new Buffer(result.code);
callback(null, file);
}
}
});
};
const bubleConfig = {
namedFunctionExpressions: false,
transforms: {
arrow: true,
classes: false,
collections: false,
computedProperty: false,
conciseMethodProperty: false,
constLoop: false,
dangerousForOf: false,
dangerousTaggedTemplateString: false,
defaultParameter: false,
destructuring: false,
forOf: false,
generator: false,
letConst: true,
modules: false,
numericLiteral: false,
parameterDestructuring: false,
reservedProperties: false,
spreadRest: false,
stickyRegExp: false,
templateString: true,
unicodeRegExp: false
}
}
gulp.task("transpile", function() {
return gulp.src(["./src/trie.js"])
.pipe(gulpBuble(bubleConfig))
// .pipe(concat("trie.js"))
.pipe(gulp.dest("./dist/"));
});
gulp.task("build", ["transpile"], function() {
return gulp.src(["./src/wrapper.js"])
.pipe(include())
.pipe(concat("trie.js"))
.pipe(header(comment + '\n'))
.pipe(replace("__VERSION__", pkg.version))
.pipe(size())
.pipe(gulp.dest("./dist/"));
});
gulp.task("minify", ["build"], function() {
return gulp.src(["./dist/trie.js"])
.pipe(uglify())
.pipe(header(comment))
.pipe(size())
.pipe(size({
gzip: true
}))
.pipe(concat("trie.min.js"))
.pipe(gulp.dest("./dist/"));
});
gulp.task("transpile1", function () {
return gulp.src(["./src/trie1.js"])
.pipe(gulpBuble(bubleConfig))
// .pipe(concat("trie.js"))
.pipe(gulp.dest("./dist/"));
});
gulp.task("build1", ["transpile1"], function() {
return gulp.src(["./src/wrapper1.js"])
.pipe(include())
.pipe(concat("trie1.js"))
.pipe(header(comment + '\n'))
.pipe(replace("__VERSION__", pkg.version))
.pipe(size())
.pipe(gulp.dest("./dist/"));
});
gulp.task("minify1", ["build1"], function() {
return gulp.src(["./dist/trie1.js"])
.pipe(uglify())
.pipe(header(comment))
.pipe(size())
.pipe(size({
gzip: true
}))
.pipe(concat("trie1.min.js"))
.pipe(gulp.dest("./dist/"));
});
gulp.task("test", function() {
gulp.src("./test/**/*.js")
.pipe(mocha({reporter: "spec"}))
});
// Default task
gulp.task("default", ["build", "minify", "build1", "minify1"]);