forked from saul-jb/js-untar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
103 lines (95 loc) · 2.91 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
var gulp = require("gulp"),
umd = require("gulp-umd"),
sourcemaps = require("gulp-sourcemaps"),
uglify = require("gulp-uglify"),
insert = require("gulp-insert"),
addSrc = require("gulp-add-src"),
concat = require("gulp-concat"),
jshint = require("gulp-jshint"),
KarmaServer = require('karma').Server,
path = require("path"),
filter = require("gulp-filter"),
webserver = require('gulp-webserver');
gulp.task("build:dev", function() {
var f = filter(['*', '!untar-worker.js'], { restore: true });
return gulp.src(["src/untar.js"])
.pipe(sourcemaps.init())
.pipe(insert.append("\nworkerScriptUri = '/base/build/dev/untar-worker.js';"))
.pipe(addSrc(["src/ProgressivePromise.js", "src/untar-worker.js"]))
.pipe(jshint())
.pipe(jshint.reporter("default"))
.pipe(jshint.reporter("fail"))
.pipe(insert.prepend('"use strict";\n'))
.pipe(f)
.pipe(umd({
dependencies: function(file) {
if (path.basename(file.path) === "untar.js") {
return ["ProgressivePromise"];
} else {
return [];
}
},
exports: function(file) {
return path.basename(file.path, path.extname(file.path));
},
namespace: function(file) {
return path.basename(file.path, path.extname(file.path));
}
}))
.pipe(f.restore)
.pipe(sourcemaps.write())
.pipe(gulp.dest("build/dev"));
});
gulp.task("build:dist", function() {
return gulp.src("src/untar-worker.js")
.pipe(sourcemaps.init())
.pipe(jshint())
.pipe(jshint.reporter("default"))
.pipe(jshint.reporter("fail"))
.pipe(insert.prepend('"use strict";\n'))
.pipe(uglify())
.pipe(insert.transform(function(contents, file) {
var str = ['\nworkerScriptUri = (window||this).URL.createObjectURL(new Blob(["'];
str.push(contents.replace(/\\/g, "\\\\").replace(/"/g, '\\"'));
str.push('"]));');
return str.join("");
}))
.pipe(addSrc(["src/ProgressivePromise.js", "src/untar.js"]))
.pipe(jshint())
.pipe(jshint.reporter("default"))
.pipe(jshint.reporter("fail"))
.pipe(concat("untar.js"))
.pipe(insert.prepend('"use strict";\n'))
.pipe(umd({
exports: function() { return "untar"; },
namespace: function() { return "untar"; }
}))
.pipe(uglify())
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("build/dist"));
});
gulp.task("jshint:specs", function() {
return gulp.src("spec/**/*.js")
.pipe(jshint())
.pipe(jshint.reporter("default"))
.pipe(jshint.reporter("fail"));
});
gulp.task("default", ["build:dev", "build:dist"]);
gulp.task("test", ["jshint:specs", "build:dev", "build:dist"], function(done) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
gulp.task("example", ["build:dev"], function() {
gulp.src("./")
.pipe(webserver({
directoryListing: false,
livereload: true,
open: "example/",
proxies: [
{ source: "/base", target: "http://localhost:8000/"}
],
port: 8000
}));
});