-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
122 lines (105 loc) · 3.48 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
(function() {
"use strict";
//
// Imports
//
var fs = require("fs");
var gulp = require("gulp");
var eslint = require("gulp-eslint");
var uglify = require("gulp-uglify");
var mocha = require("gulp-spawn-mocha");
var rename = require("gulp-rename");
var Server = require("karma").Server;
var path = require("path");
var jsoncombine = require("gulp-jsoncombine");
var bower = require("gulp-bower");
var replace = require("gulp-replace");
var sourceFiles = [
"*.js",
"src/**/*.js",
"test/*.js",
"cli/*.js"
];
//
// Task Definitions
//
gulp.task("lint", function() {
gulp.src(sourceFiles)
.pipe(eslint())
.pipe(eslint.format());
});
gulp.task("lint:build", function() {
return gulp.src(sourceFiles)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.format("checkstyle", fs.createWriteStream("eslint.xml")));
});
gulp.task("compress", function() {
gulp.src([
"!dist/*.min.*",
"dist/*.js"
])
.pipe(rename({
suffix: ".min"
}))
.pipe(uglify({ mangle: true }))
.pipe(gulp.dest("dist"));
});
gulp.task("build", function() {
[
{ "file": "usertiming-compression", "name": "UserTimingCompression" },
{ "file": "usertiming-decompression", "name": "UserTimingDecompression" }
].forEach(function(o) {
var vanillaJs = fs.readFileSync("./src/shared/vanilla.js", "utf8").replace(/__name__/g, o.name);
var detectJs = fs.readFileSync("./src/shared/detect.js", "utf8").replace(/__name__/g, o.name);
gulp.src("./src/" + o.file + ".js")
.pipe(replace(/[^\n]*__module__;.*/g, detectJs))
.pipe(rename(o.file + ".js"))
.pipe(gulp.dest("./dist"));
gulp.src("./src/" + o.file + ".js")
.pipe(replace(/[^\n]*__module__;.*/g, vanillaJs))
.pipe(rename(o.file + ".vanilla.js"))
.pipe(gulp.dest("./dist"));
});
});
gulp.task("build-test", function() {
gulp.src("test/data/*.json")
.pipe(jsoncombine("data.js", function(data) {
var out = "window.TEST_DATA = ";
out += JSON.stringify(data);
out += ";";
return new Buffer(out);
}))
.pipe(gulp.dest("./test/build"));
});
gulp.task("mocha", ["build-test"], function() {
return gulp.src("test/test-*.js",
{
read: false
})
.pipe(mocha());
});
gulp.task("mocha-tap", ["mocha"], function() {
return gulp.src("test/test-*.js",
{
read: false
})
.pipe(mocha({
reporter: "tap",
output: "./test/mocha.tap"
}));
});
gulp.task("bower", function() {
return bower();
});
gulp.task("karma", ["bower", "build-test", "mocha", "mocha-tap"], function(done) {
new Server({
configFile: path.join(__dirname, "karma.config.js"),
singleRun: true
}, done).start();
});
gulp.task("all", ["default"]);
gulp.task("test", ["mocha", "mocha-tap", "karma"]);
gulp.task("default", ["bower", "lint", "lint:build", "compress", "test"]);
gulp.task("travis", ["default"]);
}());