Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
100 lines (86 loc) · 2.77 KB
/
Copy pathgulpfile.js
File metadata and controls
100 lines (86 loc) · 2.77 KB
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
const gulp = require('gulp');
const ts = require("gulp-typescript");
const merge2 = require("merge2");
const amdclean = require("gulp-amdclean");
const Server = require('karma').Server;
const webserver = require("gulp-webserver");
const replace = require('gulp-replace');
const fs = require('fs');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const rename = require("gulp-rename");
const sparkMd5 = fs.readFileSync('sparkMd5.js');
gulp.task('build-commonjs', () => {
// Build CommonJS library.
const tsProject = ts.createProject("tsconfig.json", {
module: "commonjs"
});
const tsResult = tsProject.src().pipe(tsProject());
return merge2([
tsResult.js.pipe(replace(/__SPARK_MD5__/g, sparkMd5)).pipe(gulp.dest("dist/commonjs")),
tsResult.dts.pipe(gulp.dest("dist/commonjs"))
]);
});
gulp.task("build-amd", function () {
// Build CommonJS library.
var tsProject = ts.createProject("tsconfig.json", {
module: "amd",
outFile: "md5-webworker.js"
});
var tsResult = tsProject.src().pipe(tsProject());
return merge2([
tsResult.js.pipe(replace(/__SPARK_MD5__/g, sparkMd5)).pipe(gulp.dest("dist/amd")),
tsResult.dts.pipe(gulp.dest("dist/amd"))
]);
});
gulp.task("build-browser-single", ["build-amd"], function () {
// Build library for browser.
return gulp
.src(["dist/amd/md5-webworker.js"])
.pipe(amdclean.gulp({
prefixMode: "standard",
wrap: {
// This string is prepended to the file
start: ";(function(global, file_worker) {\n",
// This string is appended to the file
end: "\nglobal.md5_webworker=src_index.default;}(window, {default: FileWorker}));"
}
}))
.pipe(gulp.dest("dist/browser-single"));
});
gulp.task("build-browser", ["build-browser-single"], function () {
return gulp.src(["node_modules/file-worker/dist/browser/FileWorker.js", "dist/browser-single/md5-webworker.js"])
.pipe(concat('md5-webworker.js'))
.pipe(gulp.dest("dist/browser"));
});
gulp.task("build-browser-minify", ["build-browser"], () => {
// Build library for browser.
return gulp
.src(["dist/browser/md5-webworker.js"])
.pipe(uglify())
.pipe(rename('md5-webworker.min.js'))
.pipe(gulp.dest("dist/browser"));
});
gulp.task('test', function (done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function() {
done();
}).start();
});
gulp.task('test-watch', (done) => {
new Server({
configFile: __dirname + '/karma.conf.js'
}, () => done()).start();
});
gulp.task("webserver", () => {
gulp.src(".")
.pipe(webserver({
livereload: true,
directoryListing: true,
open: true
}));
});
gulp.task('build', ['build-commonjs', 'build-browser', 'build-browser-minify']);
gulp.task('default', ['build']);