-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
295 lines (256 loc) · 8.34 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
var gulp = require('gulp'),
del = require('del'),
args = require('yargs').argv,
config = require('./gulp.config')(),
gulpLoadPlugins = require('gulp-load-plugins'),
urlAdjuster = require('gulp-css-url-adjuster'),
rebaseUrls = require('gulp-css-rebase-urls'),
$ = gulpLoadPlugins({lazy: true});
/**
* Remove all files from the build, temp, and reports folders
* @param {Function} done - callback when complete
*/
gulp.task('clean', function(done) {
var delconfig = [].concat(config.build);
log('Cleaning: ' + $.util.colors.blue(delconfig));
del(delconfig, done);
});
gulp.task('sort', function() {
var js = ['app.js', 'src/**/*.js'];
return gulp
.src(js)
.pipe($.print())
.pipe($.angularFilesort())
.pipe($.print())
});
gulp.task('vet', function() {
var js = ['app.js', 'src/**/*.js'];
return gulp
.src(js)
.pipe($.if(args.verbose, $.print()))
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish', {verbose: true}))
.pipe($.jshint.reporter('fail'))
.pipe($.jscs());
});
gulp.task('default', function() {
var wiredep = require('wiredep').stream;
var jsSources = gulp.src(['./src/**/*.js', '!./src/dashboard/**/*.*', '!./src/**/weboffice/generic/**/*.js', '!./src/ueditor/**/*.*']);
var cssSources = gulp.src(['./src/**/*.css', '!./src/ueditor/**/*.*', '!./src/dashboard/**/*.*']);
return gulp
.src('src/index.html')
.pipe($.print())
.pipe(wiredep({
bowerJson: require('./bower.json'),
directory: './bower_components/'
}))
.pipe($.inject(jsSources.pipe($.angularFilesort()), {relative: true}))
.pipe($.inject(cssSources, {relative: true}))
.pipe($.print())
.pipe(gulp.dest('src/'));
});
gulp.task('build', ['optimize', 'fonts','fonts2', 'xls', 'images', 'images2', 'svg'], function() {
var date = new Date();
gulp
.src(config.build + '**/*.css')
//.pipe($.cssSpriter({
// // The path and file name of where we will save the sprite sheet
// 'spriteSheet': './build/images/spritesheet.png',
// // Because we don't know where you will end up saving the CSS file at this point in the pipe,
// // we need a litle help identifying where it will be.
// 'pathToSpriteSheetFromCSS': '../images/spritesheet.png'
//}))
//.pipe(rebaseUrls())
//.pipe(rebaseUrls())
.pipe($.if('**/*app*.css', urlAdjuster({
//replace: ['img/','images/'],
append: '?version='+date.getTime(),
})))
.pipe($.sourcemaps.init())
.pipe($.minifyCss())
.pipe(getHeader())
.pipe($.sourcemaps.write('maps'))
.pipe(gulp.dest(config.build));
});
gulp.task('fonts', function() {
return gulp
.src(config.fonts)
.pipe(gulp.dest(config.build + '/font/'));
});
gulp.task('fonts2',function(){
return gulp
.src(config.fonts2)
.pipe(gulp.dest( config.build + '/styles/fonts/'));
});
gulp.task('xls',function(){
return gulp
.src(config.xls)
.pipe(gulp.dest( config.build ));
});
gulp.task('images', function() {
return gulp
.src(config.images)
//.pipe($.imagemin({optimizationLevel: 4}))
//.pipe($.rename({
// dirname: "/"
//}))
//.pipe(gulp.dest(config.build + 'images/'));
.pipe(gulp.dest(config.build))
.pipe($.rename(function(path) {
//console.log(path.dirname, path.dirname.replace(/(\.\.\/)*/, ''));
path.dirname = path.dirname.replace(/.*\\images(.*)/, 'images$1');
path.dirname = path.dirname.replace(/.*\\img(.*)/, 'img$1');
}))
.pipe(gulp.dest(config.build + 'styles/'))
.pipe(gulp.dest(config.build));
});
gulp.task('images2', function() {
return gulp
.src(['./src/**/*.png', './src/**/*.jpg', './src/**/*.gif'])
.pipe(gulp.dest(config.build));
});
gulp.task('dashboard', function() {
return gulp
.src(['./src/**/*.*'])
.pipe(gulp.dest(config.build));
});
gulp.task('svg', function() {
return gulp
.src(config.svg)
.pipe(gulp.dest(config.build));
});
gulp.task('wiredep', ['ueditor', 'weboffice'], function() {
var wiredep = require('wiredep').stream;
var options = {
bowerJson: require('./bower.json'),
directory: './bower_components/'
};
var js = ['app.js', 'src/**/*.js', '!./src/**/weboffice/generic/**/*.js', '!./src/ueditor/**/*.*', '!./src/dashboard/**/*.*'];
return gulp
.src(config.index)
.pipe(wiredep(options))
.pipe($.inject(gulp
.src(js)
.pipe($.angularFilesort())
.pipe($.print())))
.pipe(gulp.dest('./'));
});
gulp.task('templatecache', ['dashboard'], function() {
log('Creating an AngularJS $templateCache');
del(config.build + 'js/'+config.templateCache.file);
gulp
.src(config.htmltemplates)
.pipe($.minifyHtml({empty: true}))
.pipe(gulp.dest(config.build + '/modules/'));
//.pipe($.angularTemplatecache(
// config.templateCache.file,
// config.templateCache.options
//))
//.pipe(gulp.dest(config.build + 'js'));
return gulp
.src(config.client + 'directives/**/*.html')
.pipe($.minifyHtml({empty: true}))
.pipe(gulp.dest(config.build + '/directives/'));
//.pipe($.angularTemplatecache(
// config.templateCache.file,
// config.templateCache.options
//))
//.pipe(gulp.dest(config.build + 'js'));
});
gulp.task('inject', ['wiredep', 'templatecache'], function() {
var css = [config.client+'**/*.css', '!./src/ueditor/**/*.*', '!./src/dashboard/**/*.*'];
return gulp
.src(config.index)
.pipe(inject(css, ''))
.pipe(gulp.dest('./'));
});
gulp.task('optimize', ['inject'], function() {
var templateCache = config.build + 'js/' + config.templateCache.file;
var filter = $.filter,
jsFilter = filter('**/*.js', {restore: true}),
cssFilter = filter('**/*.css', {restore: true});
return gulp
.src(config.index)
.pipe(inject(templateCache, 'templates'))
.pipe($.plumber())
.pipe($.useref())
.pipe($.if('js/app.js', $.ngAnnotate()))
.pipe(jsFilter)
.pipe($.sourcemaps.init())
.pipe($.uglify())
.pipe($.rev())
.pipe($.sourcemaps.write('maps'))
.pipe(jsFilter.restore)
.pipe(cssFilter)
.pipe($.rev())
.pipe(cssFilter.restore)
.pipe($.revReplace())
.pipe(gulp.dest(config.build));
});
gulp.task('ueditor', function() {
return gulp.src(config.client + 'ueditor/**/*.*')
.pipe(gulp.dest(config.build + '/ueditor/'));
});
gulp.task('weboffice', function() {
return gulp.src(config.client + 'modules/commons/weboffice/generic/**/*.*')
.pipe(gulp.dest(config.build + '/modules/commons/weboffice/generic/'));
});
/**
* Inject files in a sorted sequence at a specified inject label
* @param {Array} src glob pattern for source files
* @param {String} label The label name
* @param {Array} order glob pattern for sort order of the files
* @returns {Stream} The stream
*/
function inject(src, label, order) {
var options = {read: false, relative: true};
if (label) {
options.name = 'inject:' + label;
}
return $.inject(orderSrc(src, order), options);
}
/** Order a stream
* @param {Stream} src The gulp.src stream
* @param {Array} order Glob array pattern
* @returns {Stream} The ordered stream
*/
function orderSrc (src, order) {
//order = order || ['**/*'];
return gulp
.src(src)
.pipe($.if(order, $.order(order)));
}
/**
* Log a message or series of messages using chalk's blue color.
* Can pass in a string, object or array.
*/
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));
}
}
/**
* Format and return the header for files
* @return {String} Formatted file header
*/
function getHeader() {
var pkg = require('./package.json');
var template = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @authors <%= pkg.authors %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''
].join('\n');
return $.header(template, {
pkg: pkg
});
}