-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
125 lines (101 loc) · 3.58 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
116
117
118
119
120
121
122
123
124
125
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var ngAnnotate = require('gulp-ng-annotate');
var babel = require('gulp-babel');
var plumber = require('gulp-plumber');
var sourcemaps = require('gulp-sourcemaps');
var eslint = require('gulp-eslint');
var notify = require('gulp-notify');
var livereload = require('gulp-livereload');
var runSeq = require('run-sequence');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var minifyCSS = require('gulp-minify-css');
// Dev Tasks
//-----------------------------------------------------------------------------
// Live reload business.
gulp.task('reload', function () {
livereload.reload();
});
gulp.task('reloadCSS', function () {
return gulp.src('./public/style.css').pipe(livereload());
});
// Linter
gulp.task('lintJS', function () {
return gulp.src(['./browser/**/*.js', './server/**/*.js'])
.pipe(plumber({
errorHandler: notify.onError('Linting FAILED! Check your gulp process.')
}))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
// Build scripts
gulp.task('buildJS', ['lintJS'], function() {
return gulp.src(['browser/app/app.js', 'browser/**/*.js'])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(concat('main.js'))
.pipe(babel())
.pipe(sourcemaps.write())
.pipe(gulp.dest('dest/scripts'));
});
gulp.task('buildCSS', function () {
var sassCompilation = sass();
sassCompilation.on('error', console.error.bind(console));
return gulp.src('./browser/main.scss')
.pipe(plumber({
errorHandler: notify.onError('SASS processing failed! Check your gulp process.')
}))
.pipe(sassCompilation)
.pipe(rename('style.css'))
.pipe(gulp.dest('./dest/styles'));
});
// Productions Tasks
//-----------------------------------------------------------------------------
gulp.task('buildJSProduction', function() {
return gulp.src(['browser/app/app.js', 'browser/**/*.js'])
.pipe(concat('main.js'))
.pipe(babel())
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(gulp.dest('dest/scripts'));
});
gulp.task('buildCSSProduction', function () {
return gulp.src('./browser/main.scss')
.pipe(sass())
.pipe(rename('style.css'))
.pipe(minifyCSS())
.pipe(gulp.dest('./dest/styles'))
});
// Composed tasks
//-----------------------------------------------------------------------------
gulp.task('build', function() {
if(process.env.NODE_ENV === 'production') {
console.log('PRODUCTION ENVIRONMENT: ', process.env.NODE_ENV);
runSeq(['buildJSProduction', 'buildCSSProduction']);
} else {
console.log('DEVELOPMENT ENVIRONMENT: ', process.env.NODE_ENV);
runSeq(['buildJS', 'buildCSS']);
}
});
gulp.task('default', function () {
gulp.start('build');
// Run when anything inside of browser/ changes.
gulp.watch('browser/**', function () {
runSeq('buildJS', 'reload');
});
// Run when anything inside of browser/scss changes.
gulp.watch('browser/**', function () {
runSeq('buildCSS', 'reloadCSS');
});
gulp.watch('server/**/*.js', ['lintJS']);
// Reload when a template (.html) file changes.
gulp.watch(['browser/**/*.html', '*.html'], ['reload']);
// Run server tests when a server file or server test file changes.
// gulp.watch(['tests/server/**/*.js'], ['testServerJS']);
// Run browser testing when a browser test file changes.
// gulp.watch('tests/browser/**/*', ['testBrowserJS']);
livereload.listen();
});