This repository has been archived by the owner on Aug 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
115 lines (106 loc) · 3.75 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
var gulp = require('gulp')
var del = require('del')
var clip = require('gulp-clip-empty-files')
var sourcemaps = require('gulp-sourcemaps')
var concat = require('gulp-concat')
var uglify = require('gulp-uglify')
var minifyCSS = require('gulp-minify-css')
var ngAnnotate = require('gulp-ng-annotate')
var templateCache = require('gulp-angular-templatecache')
var changed = require('gulp-changed')
var gulpif = require('gulp-if')
var server = require('gulp-server-livereload')
var paths = {
src: {
base: './src/frontend',
js: [
'./bower_components/lodash/lodash.js',
'./bower_components/angular/angular.js',
'./bower_components/angular-route/angular-route.js',
'./bower_components/angular-local-storage/dist/angular-local-storage.js',
'./bower_components/angular-recursion/angular-recursion.js',
'./bower_components/angular-sanitize/angular-sanitize.js',
'./src/frontend/app.js',
'./src/frontend/**/*.js'
],
css: './src/frontend/**/*.css',
html: [
'./src/frontend/**/*.html',
'!./src/frontend/index.html'
],
static_content: [
'./src/frontend/index.html',
'./src/frontend/favicon.ico',
'./src/frontend/images/**'
]
},
dist: {
root: './build-frontend',
backendRoot: './build-backend',
bundleName: 'bundle.js',
coverage: './coverage'
}
}
// clean up old build
gulp.task('clean', function clean(callback) {
return del([paths.dist.root, paths.dist.coverage, paths.dist.backendRoot], callback)
})
// copy over html
gulp.task('build-html', function() {
return gulp.src(paths.src.html)
.pipe(clip())
.pipe(templateCache({ module: 'chatty'}))
.pipe(changed(paths.dist.root, {hasChanged: changed.compareSha1Digest}))
.pipe(gulp.dest(paths.dist.root))
})
// copy over html
gulp.task('build-static', function() {
return gulp.src(paths.src.static_content, { base: paths.src.base })
.pipe(clip())
.pipe(changed(paths.dist.root, {hasChanged: changed.compareSha1Digest}))
.pipe(gulp.dest(paths.dist.root))
})
// minify and concat all js
gulp.task('build-js', buildJs(false))
gulp.task('build-js-debug', buildJs(true))
function buildJs(debug) {
return function() {
var jspaths = paths.src.js
return gulp.src(jspaths)
.pipe(clip())
.pipe(gulpif(!debug, sourcemaps.init()))
.pipe(ngAnnotate())
.pipe(gulpif(!debug, uglify()))
.pipe(concat(paths.dist.bundleName))
.pipe(changed(paths.dist.root, {hasChanged: changed.compareSha1Digest}))
.pipe(gulpif(!debug,sourcemaps.write('.')))
.pipe(gulp.dest(paths.dist.root))
}
}
// minify and concat all css
gulp.task('build-css', function() {
return gulp.src(paths.src.css)
.pipe(clip())
.pipe(minifyCSS())
.pipe(concat('bundle.css'))
.pipe(changed(paths.dist.root, {hasChanged: changed.compareSha1Digest}))
.pipe(gulp.dest(paths.dist.root))
})
// rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch(paths.src.static_content, ['build-static'])
gulp.watch(paths.src.html, ['build-html'])
gulp.watch(paths.src.js, ['build-js-debug'])
gulp.watch(paths.src.css, ['build-css'])
})
gulp.task('server', function() {
gulp.src(paths.dist.root)
.pipe(server({
port: 3000,
livereload: true,
directoryListing: false,
open: true
}))
})
gulp.task('default', ['server', 'watch', 'build-html', 'build-js-debug', 'build-css', 'build-static'])
gulp.task('build', ['build-html', 'build-js', 'build-css', 'build-static'])