-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·139 lines (111 loc) · 4.43 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
126
127
128
129
130
131
132
133
134
135
136
137
var gulp = require('gulp'),
buildConfig = require('./config/build.config'),
gutil = require('gulp-util'),
concat = require('gulp-concat'),
del = require('del'),
footer = require('gulp-footer'),
header = require('gulp-header'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
ngAnnotate = require('gulp-ng-annotate'),
templateCache = require('gulp-angular-templatecache'),
karma = require('karma').server,
sass = require('gulp-sass'),
watch = require('gulp-watch'),
useref = require('gulp-useref'),
browserSync = require('browser-sync'),
connect = require('gulp-connect'),
clean = require('gulp-clean');
// presets target mode
gulp.task('dev', function (cb) {
gutil.env.env = 'dev';
return cb()
});
gulp.task('prod', function (cb) {
gutil.env.env = 'prod';
return cb()
});
// based on mode clean JS files either in www or dist
gulp.task('clean-js', function (cb) {
var base = gutil.env.env === 'prod' ? buildConfig.release + '/' : buildConfig.dev + '/';
del(gutil.env.env === 'prod' ? base + buildConfig.cleanJS : base + buildConfig.cleanJS, cb);
});
// based on mode clean CSS files either in www or dist
gulp.task('clean-css', function (cb) {
var files = gutil.env.env === 'prod' ? buildConfig.release + '/' : buildConfig.dev + '/';
files += buildConfig.cleanCSS;
del(files, cb);
});
// Main building task that does several things all based on build.config.js:
// set filename, wrap JS content with self-exec func.block, license, annotates injection,
// check js syntax, if prod then uglify
// why wrap it with self-exec function? There is a good reason which you code will not conflict with anything else.
// if you give you module a name and will have your module inside a variable you can easily share inside the file and you
// not it will not overwrite some other vars from other files. so it is nicely isolated.
gulp.task('build', ['clean-js', 'clean-css'], function () {
return gulp.src(buildConfig.srcJS)
.pipe(concat(buildConfig.filename))
.pipe(header(buildConfig.closureStart))
.pipe(footer(buildConfig.closureEnd))
.pipe(header(buildConfig.banner))
.pipe(ngAnnotate({single_quotes: true}))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(gutil.env.env === 'prod' ? uglify() : gutil.noop())
.pipe(gulp.dest(buildConfig.dev + '/js'))
.pipe(browserSync.stream());
});
// Build css from SASS
gulp.task('sass', function () {
gulp.src(buildConfig.srcCSS)
.pipe(gutil.env.env === 'prod' ? sass({outputStyle: 'compressed'}) : sass())
.pipe(gulp.dest(buildConfig.dev + '/css/'))
.pipe(browserSync.stream());
});
// used for release build, it combines all includes in the index.html into 1 file
gulp.task('useref', ['build', 'templatecache', 'sass'], function (done) {
return gulp.src(buildConfig.combineFiles)
.pipe(useref())
.pipe(gulp.dest(buildConfig.release));
});
// used for release copies resource like images, fonts into DIST
gulp.task('copyRes', function () {
return gulp.src(buildConfig.others, {cwd: 'images/**'})
.pipe(gulp.dest(buildConfig.release));
});
gulp.task('default', ['dev', 'build', 'templatecache', 'sass']);
gulp.task('release', ['prod', 'build', 'templatecache', 'sass', 'useref', 'copyRes']);
gulp.task('serve', ['default', 'server', 'watch'], function () {
});
gulp.task('watch', ['dev', 'build', 'sass'], function () {
gulp.watch(['src/**/*.js', 'src/**/*.scss', 'src/**/*.html'], ['dev', 'build', 'sass', 'templatecache'], browserSync.reload);
});
gulp.task('server', function () {
browserSync({
server: {
baseDir: './www'
}
});
});
// converts all partials into JS template cache
gulp.task('templatecache', function () {
return gulp.src(buildConfig.srcHTML)
.pipe(templateCache('templates.cache.js', {module: 'templatescache', standalone: true}))
.pipe(gulp.dest(buildConfig.dev + '/js'))
.pipe(browserSync.stream());
});
// used to delete all that can be generated using npm install, bower install
gulp.task('reset', function () {
return gulp.src(buildConfig.resetDir, {read: false})
.pipe(clean());
});
/**
* start test
*/
gulp.task('test', function (done) {
karma.start({
configFile: __dirname + '/config/karma.conf.js',
singleRun: true
}, done);
});