This repository has been archived by the owner on May 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.babel.js
79 lines (69 loc) · 2.24 KB
/
gulpfile.babel.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
//
// gulpfile.babel.js
// calder-gl
//
import babel from "gulp-babel";
import gulp from "gulp";
import changed from "gulp-changed";
import merge from "merge2";
import typescript from "gulp-typescript";
import browserify from "browserify";
import uglify from "gulp-uglify";
import sourcemaps from "gulp-sourcemaps";
import source from "vinyl-source-stream";
import buffer from 'vinyl-buffer';
import gutil from 'gulp-util';
const src = ["./src/**/*.ts"];
const test = ["./test/**/*.js"]
const sample = ["./sample/**/*.js"]
const out = "./build";
const babelConf = { presets: ["es2015"] };
const project = typescript.createProject("tsconfig.json", {
outDir: out,
typescript: require("typescript")
});
// Gulp task to build changed Typescript and tests
gulp.task("build", function () {
const sourceDestination = `${out}/js/src`;
const testDestination = `${out}/js/test`;
const sampleDestination = `${out}/js/sample`;
const result = gulp.src(src)
.pipe(changed(sourceDestination))
.pipe(typescript(project));
return merge([
result.dts.pipe(gulp.dest(`${out}/definitions`)),
result.js
.pipe(babel(babelConf))
.pipe(gulp.dest(sourceDestination)),
gulp.src(test)
.pipe(changed(testDestination))
.pipe(babel(babelConf))
.pipe(gulp.dest(testDestination)),
gulp.src(sample)
.pipe(changed(sampleDestination))
.pipe(babel(babelConf))
.pipe(gulp.dest(sampleDestination))
]);
});
gulp.task("browser", function() {
// set up the browserify instance on a task basis
var b = browserify({
entries: `${out}/js/sample/index.js`,
debug: true
});
return b.bundle()
.pipe(source(`index.js`))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
// Add transformation tasks to the pipeline here.
.pipe(uglify())
.on('error', gutil.log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${out}/js/browser`));
});
// Gulp task to watch for changes to .ts files, and build on change
gulp.task("watch", ["build"], function () {
gulp.watch([src, test], ["build"]);
});
// Set default gulp task as 'build' task
gulp.task("default", ["build"]);