-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
195 lines (159 loc) · 4.46 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
var args = require('yargs').argv;
var config = require('./gulp.config')();
var del = require('del');
var gulp = require('gulp');
var $ = require('gulp-load-plugins')({
lazy: true
});
gulp.task('help', $.taskListing);
gulp.task('default', ['help']);
gulp.task('clean', ['azure-cleanup'], cleanTask);
gulp.task('copy-fonts', ['get-source'], copyFontsTask);
gulp.task('get-source', ['clean'], getSourceTask);
gulp.task('lint', ['get-source'], lintTask);
gulp.task('templatecache', ['get-source'], templateCacheTask);
gulp.task('minify', ['templatecache', 'copy-fonts'], minifyTask);
gulp.task('process', ['minify'], buildCleanUpTask);
gulp.task('azure-file-copy', ['minify'], azureFileCopyTask);
gulp.task('azure', ['azure-file-copy'], azureTask);
gulp.task('azure-cleanup', azureCleanupTask);
///////////////
var tempFiles = [
config.tmp,
config.root + 'index.html',
config.root + 'favicon.ico',
config.root + 'web.config',
config.root + 'README.md',
config.root + 'vendor/',
config.root + 'src/'
];
function lintTask() {
log('Analyzing source with JSHint and JSCS');
return gulp
.src(config.alljs)
.pipe($.if(args.verbose, $.print()))
.pipe($.jscs())
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish', {
verbose: true
}))
.pipe($.jshint.reporter('fail'));
}
function azureTask(done) {
log('Cleaning up unnecessary files');
var files = [
config.build,
config.tmp,
config.root + 'README.md',
config.root + 'vendor/',
config.root + 'src/'
];
clean(files, done);
}
function azureCleanupTask(done) {
log('Cleaning up the Azure hosting files');
var files = [
config.root + 'fonts',
config.root + 'js',
config.root + 'styles',
config.root + 'index.html'
];
clean(files, done);
}
function azureFileCopyTask(done) {
log('Copying files from build folder to root for Azure hosting');
return gulp
.src(config.build + '**/*.*')
.pipe(gulp.dest(config.root));
}
function buildCleanUpTask(done) {
log('Cleaning all temp files');
clean(tempFiles, done);
}
function copyFontsTask() {
log('Copying fonts');
return gulp
.src(config.fonts)
.pipe(gulp.dest(config.build + 'fonts'));
}
function templateCacheTask() {
log('Creating AngularJS $templateCache');
return gulp
.src(config.htmltemplates)
.pipe($.minifyHtml({
empty: true
}))
.pipe($.angularTemplatecache(
config.templateCache.file,
config.templateCache.options
))
.pipe(gulp.dest(config.tmp));
}
function minifyTask() {
log('minifying app');
var templateCache = config.tmp + config.templateCache.file;
var assets = $.useref.assets({
searchPath: './'
});
var cssFilter = $.filter(['**/app.css'], {
restore: true
});
var jsFilter = $.filter(['**/app.js'], {
restore: true
});
return gulp
.src(config.index)
.pipe($.plumber())
.pipe($.inject(gulp.src(templateCache, {
read: false
}), {
starttag: '<!-- inject:templates:js -->'
}))
.pipe(assets)
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore)
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore)
.pipe($.rev())
.pipe(assets.restore())
.pipe($.useref())
.pipe($.revReplace())
.pipe(gulp.dest(config.build));
}
function cleanTask(done) {
log('Cleaning build folder');
var files = [
config.build,
config.tmp,
config.root + 'index.html',
config.root + 'favicon.ico',
config.root + 'web.config',
config.root + 'README.md',
config.root + 'vendor/',
config.root + 'src/'
];
clean(files, done);
}
function getSourceTask() {
log('Copying source to build folder');
return gulp
.src(config.origin)
.pipe(gulp.dest(config.root));
}
function log(msg) {
if (typeof (msg) === 'object') {
for (var item in msg) {
if (msg.hasOwnProperty(item)) {
$.util.log($.util.colors.cyan(msg[item]));
}
}
} else {
$.util.log($.util.colors.cyan(msg));
}
}
function clean(path, done) {
log('Cleaning ' + $.util.colors.cyan(path));
del(path, done);
}