-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·219 lines (187 loc) · 7.45 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
var gulp = require('gulp');
var args = require('yargs').argv;
var del = require('del');
//var sprity = require('sprity');
var config = require('./gulp.config')();
var $ = require('gulp-load-plugins')({ lazy: true });
var series = require('stream-series');
gulp.task('fonts', ['glyphs'], function () {
log('Copying fonts');
return gulp
.src(config.input.fonts)
.pipe(gulp.dest(config.build.fonts));
});
gulp.task('glyphs', function () {
log('Copying glyphs');
return gulp
.src(config.input.glyphicons)
.pipe(gulp.dest(config.build.glyphs));
});
gulp.task('less-watcher', function () {
gulp.watch([config.input.less], ['styles']);
});
gulp.task('styles', ['clean-styles'], function () {
log('Compiling Less --> CSS');
return gulp
.src(config.input.less)
.pipe($.plumber())
.pipe($.less())
.pipe($.autoprefixer({ browsers: ['last 2 version', '> 5%'] }))
.pipe(gulp.dest(config.build.temp));
});
gulp.task('copyIndex', function () {
log('Copy Index to site root');
return gulp
.src(config.input.index)
.pipe(gulp.dest(config.siteRoot));
});
gulp.task('wiredepDev', ['copyIndex'], function () {
log('Wire up the bower css js and our app js into the html');
var options = config.getWiredepDefaultOptions();
var wiredep = require('wiredep').stream;
var appJs = gulp.src(config.appJs, { read: false });
var appJsShared = gulp.src(config.appJsShared, { read: false });
var appHeadJs = gulp.src(config.appHeadJs, { read: false });
var othersJs = gulp.src(config.othersJs, { read: false });
var appThirdPartyJs = gulp.src(config.appThirdPartyJs, { read: false });
return gulp
.src('index.html')
.pipe(wiredep(options))
.pipe($.inject(appHeadJs, { starttag: '<!-- inject:head:js -->', addRootSlash: false }))
.pipe($.inject(othersJs, { starttag: '<!-- inject:others:js -->', addRootSlash: false }))
.pipe($.inject(appThirdPartyJs, { starttag: '<!-- inject:thirdParty:js -->', addRootSlash: false }))
.pipe($.inject(appJsShared, { starttag: '<!-- inject:shared:js -->', addRootSlash: false }))
.pipe($.inject(series(appJs), { addRootSlash: false }))
.pipe(gulp.dest(config.siteRoot));
});
gulp.task('injectDev', ['wiredepDev', 'styles'], function () {
log('Wire up the app css into the html, and call wiredep ');
var compiledBoostrapCss = gulp.src(config.build.temp + 'lla.custom.boostrap.css', { read: false });
var compiledCss = gulp.src([config.buildCssTemp, '!' + config.build.temp + 'lla.custom.boostrap.css'], { read: false });
var appThirdPartyCss = gulp.src(config.appThirdPartyCss, { read: false });
return gulp
.src('index.html')
.pipe($.inject(compiledBoostrapCss, { starttag: '<!-- inject:boostrap:css -->', addRootSlash: false }))
.pipe($.inject(appThirdPartyCss, { starttag: '<!-- inject:thirdParty:css -->', addRootSlash: false }))
.pipe($.inject(series(compiledCss), { addRootSlash: false }))
.pipe(gulp.dest(config.siteRoot));
});
gulp.task('templatecache', function () {
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.build.temp));
});
gulp.task('templatecacheShared', function () {
log('Creating AngularJS $templateCache');
return gulp
.src(config.htmltemplatesShared)
.pipe($.minifyHtml({ empty: true }))
.pipe($.angularTemplatecache(
config.templateCacheShared.file,
config.templateCacheShared.options
))
.pipe(gulp.dest(config.build.temp));
});
gulp.task('injectRelease', ['injectDev', 'templatecache', 'templatecacheShared', 'clean-code'], function () {
log('Preparing css and js files to optimize, obtimizing html and cleaning js/css build folder');
});
gulp.task('optimize', ['injectRelease'], function () {
log('Optimizing the javascript, css, injecting html templates');
var assets = $.useref.assets();
var cssFilter = $.filter('**/*.css', { restore: true });
var jsHeadFilter = $.filter('**/' + config.optimized.head, { restore: true });
var jsLibFilter = $.filter('**/' + config.optimized.lib, { restore: true });
var jsthirdPartyFilter = $.filter('**/' + config.optimized.thirdParty, { restore: true });
var jsSharedFilter = $.filter('**/' + config.optimized.shared, { restore: true });
var jsAppFilter = $.filter('**/' + config.optimized.app, { restore: true });
return gulp
.src('index.html')
.pipe($.plumber())
.pipe($.inject(
gulp.src(config.build.temp + 'templates.js', { read: false }), {
starttag: '<!-- inject:templates:js -->'
}))
.pipe($.inject(
gulp.src(config.build.temp + 'templates1.js', { read: false }), {
starttag: '<!-- inject:templates1:js -->'
}))
.pipe(assets)
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore)
.pipe(jsHeadFilter)
.pipe($.uglify())
.pipe(jsHeadFilter.restore)
.pipe(jsLibFilter)
.pipe($.uglify())
.pipe(jsLibFilter.restore)
.pipe(jsthirdPartyFilter)
.pipe($.uglify())
.pipe(jsthirdPartyFilter.restore)
.pipe(jsSharedFilter)
.pipe($.ngAnnotate())
.pipe($.uglify())
.pipe(jsSharedFilter.restore)
.pipe(jsAppFilter)
.pipe($.ngAnnotate())
.pipe($.uglify())
.pipe(jsAppFilter.restore)
.pipe(assets.restore())
.pipe($.useref())
.pipe(gulp.dest(config.siteRoot));
});
gulp.task('buildDev', ['injectDev'], function () {
log('Create build for Develop');
return gulp
.src('index.html')
.pipe($.replace('./shared/', '/shared/'))
.pipe(gulp.dest(config.siteRoot));
});
gulp.task('buildRelease', ['optimize'], function (done) {
log('Performing cleaning temp files after build');
var delconfig = [].concat(config.build.temp);
del(delconfig, done);
});
gulp.task('clean-temp', function (done) {
var delconfig = [].concat(config.build.temp);
del(delconfig, done);
});
gulp.task('clean-styles', function (done) {
var files = config.build.css + '**/*.css';
clean(files, done);
});
gulp.task('clean-code', function (done) {
var files = [].concat(
config.build.js + '**/*.js',
config.build.css + '**/*.css'
);
clean(files, done);
});
gulp.task('clean', ['clean-code', 'clean-styles', 'clean-temp']);
gulp.task('clean-images', function (done) {
clean(config.build.img + '**/*.*', done);
});
gulp.task('clean-fonts', function (done) {
clean(config.build.fonts + '**/*.*', done);
});
function clean(path, done) {
log('Cleaning: ' + $.util.colors.blue(path));
del(path, done);
}
function log(msg) {
if (typeof (msg) === 'object') {
for (var item in msg) {
if (msg.hasOwnProperty(item)) {
$.util.log($.util.colors.blue(msg[item]));
}
}
} else {
$.util.log($.util.colors.blue(msg));
}
}