-
Notifications
You must be signed in to change notification settings - Fork 60
/
gulpfile.js
109 lines (98 loc) · 2.74 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
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 = `/**
* Wade v${pkg.version}
* Copyright 2017-2018 Kabir Shah
* Released under the MIT License
* https://github.com/kbrsh/wade
*/\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);
}
}
});
};
gulp.task("transpile", function() {
return gulp.src(["./src/index.js"])
.pipe(gulpBuble({
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
}
}))
.pipe(concat("wade.js"))
.pipe(gulp.dest("./dist/"));
});
gulp.task("build", ["transpile"], function() {
return gulp.src(["./src/wrapper.js"])
.pipe(include())
.pipe(concat("wade.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/wade.js"])
.pipe(uglify())
.pipe(header(comment))
.pipe(size())
.pipe(size({
gzip: true
}))
.pipe(concat("wade.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"]);