This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
gulpfile.js
94 lines (83 loc) · 2.87 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
var gulp = require('gulp');
var pipe = require('pipe/gulp');
var clean = require('gulp-clean');
var connect = require('gulp-connect');
var traceur = require('gulp-traceur');
var runSequence = require('run-sequence');
var mergeStreams = require('event-stream').merge;
var path = {
src: ['./src/**/*.js'],
srcCopy: ['./src/**/*.html', './src/**/*.css'],
test: ['./test/**/*.js'],
deps: {
'watchtower': './node_modules/watchtower/src/**/*.js',
'expressionist': './node_modules/expressionist/src/**/*.js',
'di': './node_modules/di/src/**/*.js',
'rtts-assert': './node_modules/rtts-assert/src/**/*.js',
'templating': './node_modules/templating/src/lib/**/*.js',
'router': './node_modules/router/src/**/*.js'
},
depsCopy: [
'./bower_components/platform/platform.js',
'./node_modules/es6-shim/es6-shim.js',
'./node_modules/zone.js/zone.js',
'./node_modules/traceur/bin/traceur-runtime.js',
'./node_modules/requirejs/require.js',
'./node_modules/route-recognizer/dist/route-recognizer.amd.js'
],
output: 'dist',
outputTest: 'dist_test'
};
gulp.task('clean', function() {
return gulp.src([path.output, path.outputTest], {read: false})
.pipe(clean());
});
gulp.task('build_source', function() {
var assetStream = gulp.src(path.srcCopy)
.pipe(gulp.dest(path.output));
var sourceStream = gulp.src(path.src)
.pipe(traceur(pipe.traceur()))
.pipe(gulp.dest(path.output));
return mergeStreams(sourceStream, assetStream);
});
gulp.task('build_test', function() {
return gulp.src(path.test)
.pipe(traceur(pipe.traceur({modules: 'inline', asyncFunctions: true})))
.pipe(gulp.dest(path.outputTest));
});
var createDepStream = function(prop) {
return gulp.src(path.deps[prop])
.pipe(traceur(pipe.traceur()))
.pipe(gulp.dest(path.output+'/lib/' + prop));
};
gulp.task('build_deps', function() {
var assetStream = gulp.src(path.depsCopy)
.pipe(gulp.dest(path.output+'/lib/'));
var depStreams = Object.keys(path.deps).map(createDepStream);
var streams = depStreams.concat(assetStream);
return mergeStreams.apply(null, streams);
});
gulp.task('build', function(done) {
// By using runSequence here we are decoupling the cleaning from the rest of the build tasks
// Otherwise, we have to add clean as a dependency on every task to ensure that it completes
// before they begin.
runSequence(
'clean',
['build_source', 'build_deps', 'build_test'],
done
);
});
// WATCH FILES FOR CHANGES
gulp.task('watch', function() {
gulp.watch([path.src, path.srcCopy], ['build_source']);
gulp.watch([path.test], ['build_test']);
var deps = Object.keys(path.deps).map(function(key) { return path.deps[key]; });
gulp.watch([deps], ['build_deps']);
});
// WEB SERVER
gulp.task('serve', connect.server({
root: [__dirname+'/'+path.output],
port: 8000,
livereload: false,
open: false
}));