Completed
Push — master ( 9fb030...062483 )
by Rain
03:56
created

gulpfile.js ➔ webpackError   A

Complexity

Conditions 4
Paths 9

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
c 0
b 0
f 0
nc 9
dl 0
loc 15
rs 9.2
nop 1
1
/* RainLoop Webmail (c) RainLoop Team | Licensed under AGPL 3 */
2
'use strict';
3
4
var
5
	pkg = require('./package.json'),
6
	head = {
7
		rainloop: '/* RainLoop Webmail (c) RainLoop Team | Licensed under RainLoop Software License */',
8
		agpl: '/* RainLoop Webmail (c) RainLoop Team | Licensed under AGPL v3 */'
9
	},
10
	cfg = {
11
		devVersion: '0.0.0',
12
		releasesPath: 'build/dist/releases',
13
		community: true,
14
		watch: false,
15
		watchInterval: 1000,
16
		googleCompile: false,
17
18
		rainloopBuilded: false,
19
		destPath: '',
20
		cleanPath: '',
21
		zipSrcPath: '',
22
		zipFile: '',
23
24
		paths: {},
25
		uglify: {
26
			mangle: true,
27
			compress: true
28
		}
29
	},
30
31
	_ = require('lodash'),
32
	fs = require('node-fs'),
33
	path = require('path'),
34
	notifier = require('node-notifier'),
35
36
	webpack = require('webpack'),
37
	webpackCfg = require('./webpack.config.js'),
38
39
	gulp = require('gulp'),
40
	concat = require('gulp-concat-util'),
41
	header = require('gulp-header'),
42
	stripbom = require('gulp-stripbom'),
43
	rename = require('gulp-rename'),
44
	replace = require('gulp-replace'),
45
	uglify = require('gulp-uglify'),
46
	notify = require("gulp-notify"),
47
	plumber = require('gulp-plumber'),
48
	gulpif = require('gulp-if'),
49
	eol = require('gulp-eol'),
50
	livereload = require('gulp-livereload'),
51
	eslint = require('gulp-eslint'),
52
	cache = require('gulp-cached'),
53
	gutil = require('gulp-util')
54
;
55
56
// webpack
57
if (webpackCfg && webpackCfg.output)
58
{
59
	webpackCfg.output.publicPath = cfg.paths.staticJS;
60
}
61
62
if (webpackCfg && webpackCfg.plugins)
63
{
64
	webpackCfg.plugins.push(new webpack.DefinePlugin({
65
		'RL_COMMUNITY': !!cfg.community,
66
		'process.env': {
67
			NODE_ENV: '"production"'
68
		}
69
	}));
70
}
71
72
function webpackError(err) {
73
	if (err)
74
	{
75
		gutil.log('[webpack]', '---');
76
		gutil.log('[webpack]', err.error ? err.error.toString() : '');
77
		gutil.log('[webpack]', err.message || '');
78
		gutil.log('[webpack]', '---');
79
80
		notifier.notify({
81
			'sound': true,
82
			'title': 'webpack',
83
			'message': err.error ? err.error.toString() : err.message
84
		});
85
	}
86
}
87
88
function getHead()
89
{
90
	return !cfg.community ? head.rainloop : head.agpl;
91
}
92
93
function regOtherMinTask(sName, sPath, sInc, sOut, sHeader)
94
{
95
	gulp.task(sName, function() {
96
		return gulp.src(sPath + sInc)
97
			.pipe(uglify())
98
			.pipe(header(sHeader || ''))
99
			.pipe(rename(sOut))
100
			.pipe(eol('\n', true))
101
			.pipe(gulp.dest(sPath));
102
	});
103
}
104
105
function zipDir(sSrcDir, sDestDir, sFileName)
106
{
107
	return gulp.src(sSrcDir + '**/*')
108
		.pipe(require('gulp-zip')(sFileName))
109
		.pipe(gulp.dest(sDestDir));
110
}
111
112
function cleanDir(sDir)
113
{
114
	return gulp.src(sDir, {read: false})
115
		.pipe(require('gulp-rimraf')());
116
}
117
118
function renameFileWithMd5Hash(sFile, callback)
119
{
120
	var sHash = require('crypto').createHash('md5').update(fs.readFileSync(sFile)).digest('hex');
121
	cfg.lastMd5File = sFile.replace(/\.zip$/, '-' + sHash + '.zip');
122
	fs.renameSync(sFile, cfg.lastMd5File);
123
	callback();
124
}
125
126
function copyFile(sFile, sNewFile, callback)
127
{
128
	fs.writeFileSync(sNewFile, fs.readFileSync(sFile));
129
	callback();
130
}
131
132
cfg.paths.globjs = 'dev/**/*.{js,jsx,html,css}';
133
cfg.paths.globjsonly = 'dev/**/*.js';
134
cfg.paths.globjsxonly = 'dev/**/*.jsx';
135
cfg.paths.globjsall = 'dev/**/*.{js,jsx}';
136
cfg.paths.globtsonly = 'dev/**/*.ts';
137
cfg.paths.static = 'rainloop/v/' + cfg.devVersion + '/static/';
138
cfg.paths.staticJS = 'rainloop/v/' + cfg.devVersion + '/static/js/';
139
cfg.paths.staticMinJS = 'rainloop/v/' + cfg.devVersion + '/static/js/min/';
140
cfg.paths.staticCSS = 'rainloop/v/' + cfg.devVersion + '/static/css/';
141
cfg.paths.momentLocales = 'rainloop/v/' + cfg.devVersion + '/app/localization/moment/';
142
143
cfg.paths.less = {
144
	main: {
145
		name: 'less.css',
146
		src: 'dev/Styles/@Main.less',
147
		watch: ['dev/Styles/*.less'],
148
		options: {
149
			paths: [
150
				path.join(__dirname, 'dev', 'Styles'),
151
				path.join(__dirname, 'vendors', 'bootstrap', 'less')
152
			]
153
		}
154
	}
155
};
156
157
cfg.paths.css = {
158
	main: {
159
		name: 'app.css',
160
		src: [
161
			'node_modules/normalize.css/normalize.css',
162
			'vendors/jquery-ui/css/smoothness/jquery-ui-1.10.3.custom.css',
163
			'vendors/fontastic/styles.css',
164
			'vendors/jquery-nanoscroller/nanoscroller.css',
165
			'vendors/jquery-letterfx/jquery-letterfx.min.css',
166
			'vendors/inputosaurus/inputosaurus.css',
167
			'vendors/flags/flags-fixed.css',
168
			'node_modules/opentip/css/opentip.css',
169
			'node_modules/pikaday/css/pikaday.css',
170
			'node_modules/lightgallery/dist/css/lightgallery.min.css',
171
			'node_modules/lightgallery/dist/css/lg-transitions.min.css',
172
			'node_modules/Progress.js/minified/progressjs.min.css',
173
			'dev/Styles/_progressjs.css',
174
			cfg.paths.staticCSS + cfg.paths.less.main.name
175
		]
176
	},
177
	social: {
178
		name: 'social.css',
179
		src: [
180
			'vendors/fontastic/styles.css',
181
			'dev/Styles/_social.css'
182
		]
183
	}
184
};
185
186
cfg.paths.js = {
187
	openpgp: {
188
		name: 'openpgp.min.js',
189
		src: [
190
			'node_modules/openpgp/dist/openpgp.min.js'
191
		]
192
	},
193
	openpgpworker: {
194
		name: 'openpgp.worker.min.js',
195
		src: [
196
			'node_modules/openpgp/dist/openpgp.worker.min.js'
197
		]
198
	},
199
	moment: {
200
		locales: [
201
			'node_modules/moment/locale/*.js'
202
		]
203
	},
204
	libs: {
205
		name: 'libs.js',
206
		src: [
207
			'node_modules/jquery/dist/jquery.min.js',
208
			'node_modules/jquery-mousewheel/jquery.mousewheel.js',
209
			'node_modules/jquery-scrollstop/jquery.scrollstop.js',
210
			'node_modules/jquery-lazyload/jquery.lazyload.js ',
211
			'node_modules/jquery.backstretch/jquery.backstretch.min.js',
212
			'vendors/jquery-ui/js/jquery-ui-1.10.3.custom.min.js', // custom
213
			'vendors/jquery-nanoscroller/jquery.nanoscroller.js', // custom (modified)
214
			'vendors/jquery-wakeup/jquery.wakeup.js', // no-npm
215
			'vendors/jquery-letterfx/jquery-letterfx.min.js', // no-npm
216
			'vendors/inputosaurus/inputosaurus.js', // custom (modified)
217
			'vendors/routes/signals.min.js', // fixed
218
			'vendors/routes/hasher.min.js', // fixed
219
			'vendors/routes/crossroads.min.js', // fixed
220
			'vendors/jua/jua.min.js', // custom
221
			'vendors/keymaster/keymaster.js', // custom (modified)
222
			'vendors/qr.js/qr.min.js', // fixed
223
			'vendors/bootstrap/js/bootstrap.min.js', // fixed
224
			'node_modules/underscore/underscore-min.js',
225
			'node_modules/moment/min/moment.min.js',
226
			'node_modules/tinycon/tinycon.min.js',
227
			'node_modules/knockout/build/output/knockout-latest.js',
228
			'node_modules/knockout-projections/dist/knockout-projections.min.js',
229
			'node_modules/knockout-sortable/build/knockout-sortable.min.js ',
230
			'node_modules/matchmedia-polyfill/matchMedia.js',
231
			'node_modules/matchmedia-polyfill/matchMedia.addListener.js',
232
			'node_modules/simplestatemanager/dist/ssm.min.js',
233
			'node_modules/autolinker/dist/Autolinker.min.js',
234
			'node_modules/opentip/lib/opentip.js',
235
			'node_modules/opentip/lib/adapter-jquery.js',
236
			'node_modules/lightgallery/dist/js/lightgallery.min.js',
237
			'node_modules/lightgallery/dist/js/lg-fullscreen.min.js',
238
			'node_modules/lightgallery/dist/js/lg-thumbnail.min.js',
239
			'node_modules/lightgallery/dist/js/lg-zoom.min.js',
240
			'node_modules/lightgallery/dist/js/lg-autoplay.min.js',
241
			'node_modules/ifvisible.js/src/ifvisible.min.js'
242
		]
243
	},
244
	app: {
245
		name: 'app.js'
246
	},
247
	admin: {
248
		name: 'admin.js'
249
	}
250
};
251
252
// CSS
253
gulp.task('less:main', function() {
254
	var less = require('gulp-less');
255
256
	return gulp.src(cfg.paths.less.main.src)
257
		.pipe(gulpif(cfg.watch, plumber({errorHandler: notify.onError("Error: <%= error.message %>")})))
258
		.pipe(less({
259
			'paths': cfg.paths.less.main.options.paths
260
		}))
261
		.pipe(rename(cfg.paths.less.main.name))
262
		.pipe(eol('\n', true))
263
		.pipe(gulp.dest(cfg.paths.staticCSS))
264
		.on('error', gutil.log);
265
});
266
267
gulp.task('css:social', function() {
268
	var autoprefixer = require('gulp-autoprefixer');
269
	return gulp.src(cfg.paths.css.social.src)
270
		.pipe(concat(cfg.paths.css.social.name))
271
		.pipe(autoprefixer('last 3 versions', '> 1%', 'ie 9', 'Firefox ESR', 'Opera 12.1'))
272
		.pipe(replace(/\.\.\/(img|images|fonts|svg)\//g, '$1/'))
273
		.pipe(eol('\n', true))
274
		.pipe(gulp.dest(cfg.paths.staticCSS));
275
});
276
277
gulp.task('css:main-begin', ['less:main', 'css:social'], function() {
278
	var autoprefixer = require('gulp-autoprefixer');
279
	return gulp.src(cfg.paths.css.main.src)
280
		.pipe(concat(cfg.paths.css.main.name))
281
		.pipe(autoprefixer('last 3 versions', '> 1%', 'ie 9', 'Firefox ESR', 'Opera 12.1'))
282
		.pipe(replace(/\.\.\/(img|images|fonts|svg)\//g, '$1/'))
283
		.pipe(eol('\n', true))
284
		.pipe(gulp.dest(cfg.paths.staticCSS))
285
		.pipe(livereload());
286
});
287
288
gulp.task('package:community-on', function() {
289
	cfg.community = true;
290
	return true;
291
});
292
293
gulp.task('package:community-off', function() {
294
	cfg.community = false;
295
	return true;
296
});
297
298
gulp.task('css:clear-less', ['css:main-begin'], function() {
299
	return gulp.src(cfg.paths.staticCSS + cfg.paths.less.main.name, {read: false})
300
		.pipe(require('gulp-rimraf')());
301
});
302
303
gulp.task('css:main', ['css:clear-less']);
304
305
gulp.task('css:main:min', ['css:main'], function() {
306
	var cleanCSS = require('gulp-clean-css');
307
	return gulp.src(cfg.paths.staticCSS + cfg.paths.css.main.name)
308
		.pipe(cleanCSS())
309
		.pipe(rename({suffix: '.min'}))
310
		.pipe(eol('\n', true))
311
		.pipe(gulp.dest(cfg.paths.staticCSS));
312
});
313
314
gulp.task('css:social:min', ['css:social'], function() {
315
	var cleanCSS = require('gulp-clean-css');
316
	return gulp.src(cfg.paths.staticCSS + cfg.paths.css.social.name)
317
		.pipe(cleanCSS())
318
		.pipe(rename({suffix: '.min'}))
319
		.pipe(eol('\n', true))
320
		.pipe(gulp.dest(cfg.paths.staticCSS));
321
});
322
323
gulp.task('css:min', ['css:main:min', 'css:social:min']);
324
325
// JS
326
gulp.task('js:openpgp', function() {
327
	return gulp.src(cfg.paths.js.openpgp.src)
328
		.pipe(rename(cfg.paths.js.openpgp.name))
329
		.pipe(eol('\n', true))
330
		.pipe(gulp.dest(cfg.paths.staticMinJS));
331
});
332
333
gulp.task('js:openpgpworker', function() {
334
	return gulp.src(cfg.paths.js.openpgpworker.src)
335
		.pipe(rename(cfg.paths.js.openpgpworker.name))
336
		.pipe(eol('\n', true))
337
		.pipe(gulp.dest(cfg.paths.staticMinJS));
338
});
339
340
gulp.task('js:moment:locales-clear', function() {
341
	return cleanDir('rainloop/v/' + cfg.devVersion + '/app/localization/moment/*.js');
342
});
343
344
gulp.task('js:moment:locales', ['js:moment:locales-clear'], function() {
345
	return gulp.src(cfg.paths.js.moment.locales)
346
		.pipe(gulp.dest(cfg.paths.momentLocales));
347
});
348
349
gulp.task('js:libs', function() {
350
	return gulp.src(cfg.paths.js.libs.src)
351
		.pipe(concat(cfg.paths.js.libs.name, {separator: '\n\n'}))
352
		.pipe(eol('\n', true))
353
		.pipe(replace(/sourceMappingURL=[a-z0-9\.\-_]{1,20}\.map/ig, ''))
354
		.pipe(gulp.dest(cfg.paths.staticJS));
355
});
356
357
gulp.task('js:ckeditor:beautify', function() {
358
	var beautify = require('gulp-beautify');
359
	return gulp.src(cfg.paths.static + 'ckeditor/ckeditor.js')
360
		.pipe(beautify({
361
			'indentSize': 2
362
		}))
363
		.pipe(rename('ckeditor.beautify.js'))
364
		.pipe(eol('\n', true))
365
		.pipe(gulp.dest(cfg.paths.static + 'ckeditor/'));
366
});
367
368
gulp.task('js:webpack', function(callback) {
369
	webpack(webpackCfg, function(err, stats) {
370
371
		if (err)
372
		{
373
			if (cfg.watch)
374
			{
375
				webpackError(err);
376
			}
377
			else
378
			{
379
				throw new gutil.PluginError('webpack', err);
380
			}
381
		}
382
		else if (stats && stats.compilation && stats.compilation.errors && stats.compilation.errors[0])
383
		{
384
			if (cfg.watch)
385
			{
386
				_.each(stats.compilation.errors, webpackError);
387
			}
388
			else
389
			{
390
				throw new gutil.PluginError('webpack', stats.compilation.errors[0]);
391
			}
392
		}
393
394
        callback();
395
    });
396
});
397
398
gulp.task('js:app', ['js:webpack'], function() {
399
	return gulp.src(cfg.paths.staticJS + cfg.paths.js.app.name)
400
		.pipe(header(getHead() + '\n'))
401
		.pipe(eol('\n', true))
402
		.pipe(gulp.dest(cfg.paths.staticJS))
403
		.on('error', gutil.log);
404
});
405
406
gulp.task('js:admin', ['js:webpack'], function() {
407
	return gulp.src(cfg.paths.staticJS + cfg.paths.js.admin.name)
408
		.pipe(header(getHead() + '\n'))
409
		.pipe(eol('\n', true))
410
		.pipe(gulp.dest(cfg.paths.staticJS))
411
		.on('error', gutil.log);
412
});
413
414
// - min
415
gulp.task('js:min', ['js:app', 'js:admin', 'js:validate'], function() {
416
	return gulp.src(cfg.paths.staticJS + '*.js')
417
		.pipe(replace(/"rainloop\/v\/([^\/]+)\/static\/js\/"/g, '"rainloop/v/$1/static/js/min/"'))
418
		.pipe(uglify(cfg.uglify))
419
		.pipe(eol('\n', true))
420
		.pipe(gulp.dest(cfg.paths.staticMinJS))
421
		.on('error', gutil.log);
422
});
423
424
// lint
425
gulp.task('js:eslint', function() {
426
	return gulp.src(cfg.paths.globjsall)
427
		.pipe(cache('eslint'))
428
		.pipe(eslint())
429
		.pipe(gulpif(cfg.watch, plumber({errorHandler: notify.onError("Error: <%= error.message %>")})))
430
		.pipe(eslint.format())
431
		.pipe(eslint.failAfterError());
432
});
433
434
gulp.task('js:validate', ['js:eslint']);
435
436
// OTHER
437
gulp.task('lightgallery-fonts:clear', function() {
438
	return cleanDir('rainloop/v/' + cfg.devVersion + '/static/css/fonts/lg.*');
439
});
440
441
gulp.task('fontastic-fonts:clear', function() {
442
	return cleanDir('rainloop/v/' + cfg.devVersion + '/static/css/fonts/rainloop.*');
443
});
444
445
gulp.task('fontastic-svg:clear', function() {
446
	return cleanDir('rainloop/v/' + cfg.devVersion + '/static/css/svg/*.svg');
447
});
448
449
gulp.task('lightgallery-fonts:copy', ['lightgallery-fonts:clear'], function() {
450
	return gulp.src('node_modules/lightgallery/dist/fonts/lg.*')
451
		.pipe(gulp.dest('rainloop/v/' + cfg.devVersion + '/static/css/fonts'));
452
});
453
454
gulp.task('fontastic-fonts:copy', ['fontastic-fonts:clear'], function() {
455
	return gulp.src('vendors/fontastic/fonts/rainloop.*')
456
		.pipe(gulp.dest('rainloop/v/' + cfg.devVersion + '/static/css/fonts'));
457
});
458
459
gulp.task('fontastic-svg:copy', ['fontastic-svg:clear'], function() {
460
	return gulp.src('vendors/fontastic/svg/*.svg')
461
		.pipe(gulp.dest('rainloop/v/' + cfg.devVersion + '/static/css/svg'));
462
});
463
464
gulp.task('lightgallery', ['lightgallery-fonts:copy']);
465
gulp.task('fontastic', ['fontastic-fonts:copy', 'fontastic-svg:copy']);
466
467
gulp.task('ckeditor:clear', function() {
468
	return cleanDir('rainloop/v/' + cfg.devVersion + '/static/ckeditor');
469
});
470
471
gulp.task('ckeditor:copy', ['ckeditor:clear'], function() {
472
	return gulp.src(['vendors/ckeditor/**/*', 'vendors/ckeditor/.gitempty', '!vendors/ckeditor/samples{,/**}', '!vendors/ckeditor/adapters{,/**}', '!vendors/ckeditor/*.md'])
473
		.pipe(gulp.dest('rainloop/v/' + cfg.devVersion + '/static/ckeditor'));
474
});
475
476
gulp.task('ckeditor:copy-plugins', ['ckeditor:copy'], function() {
477
	return gulp.src('vendors/ckeditor-plugins/**/*')
478
		.pipe(gulp.dest('rainloop/v/' + cfg.devVersion + '/static/ckeditor/plugins'));
479
});
480
481
gulp.task('ckeditor', ['ckeditor:copy-plugins'], function () {
482
	return gulp.src('rainloop/v/' + cfg.devVersion + '/static/ckeditor/*.js')
483
		.pipe(stripbom())
484
		.pipe(header("\uFEFF")) // BOM
485
		.pipe(gulp.dest('rainloop/v/' + cfg.devVersion + '/static/ckeditor'));
486
});
487
488
// BUILD (RainLoop)
489
gulp.task('rainloop:copy', ['default'], function() {
490
491
	var
492
		versionFull = pkg.version + '.' + parseInt(pkg.release, 10),
493
		dist = cfg.releasesPath + '/webmail/' + versionFull + '/src/'
494
	;
495
496
	fs.mkdirSync(dist, '0777', true);
497
	fs.mkdirSync(dist + 'data');
498
	fs.mkdirSync(dist + 'rainloop/v/' + versionFull, '0777', true);
499
500
	return gulp.src('rainloop/v/' + cfg.devVersion + '/**/*', {base: 'rainloop/v/' + cfg.devVersion})
501
		.pipe(gulp.dest(dist + 'rainloop/v/' + versionFull));
502
});
503
504
gulp.task('rainloop:setup', ['rainloop:copy'], function() {
505
506
	var
507
		versionFull = pkg.version + '.' + parseInt(pkg.release, 10),
508
		dist = cfg.releasesPath + '/webmail/' + versionFull + '/src/'
509
	;
510
511
	fs.writeFileSync(dist + 'data/VERSION', versionFull);
512
	fs.writeFileSync(dist + 'data/EMPTY', versionFull);
513
514
	fs.writeFileSync(dist + 'index.php',
515
		fs.readFileSync('index.php', 'utf8').replace('\'APP_VERSION\', \'0.0.0\'', '\'APP_VERSION\', \'' + versionFull + '\''));
516
517
	fs.writeFileSync(dist + 'rainloop/v/' + versionFull + '/index.php.root', fs.readFileSync(dist + 'index.php'));
518
519
	if (cfg.community)
520
	{
521
		require('rimraf').sync(dist + 'rainloop/v/' + versionFull + '/app/libraries/RainLoop/Prem/');
522
	}
523
524
	cfg.destPath = cfg.releasesPath + '/webmail/' + versionFull + '/';
525
	cfg.cleanPath = dist;
526
	cfg.zipSrcPath = dist;
527
	cfg.zipFile = 'rainloop-' + (cfg.community ? 'community-' : '') + versionFull + '.zip';
528
	cfg.md5File = cfg.zipFile;
529
	cfg.lastMd5File = '';
530
531
	cfg.rainloopBuilded = true;
532
});
533
534
gulp.task('rainloop:zip', ['rainloop:copy', 'rainloop:setup'], function() {
535
	return (cfg.destPath && cfg.zipSrcPath && cfg.zipFile) ?
536
		zipDir(cfg.zipSrcPath, cfg.destPath, cfg.zipFile) : false;
537
});
538
539
gulp.task('rainloop:md5', ['rainloop:zip'], function(callback) {
540
	renameFileWithMd5Hash(cfg.destPath + cfg.md5File, callback);
541
});
542
543
gulp.task('rainloop:clean', ['rainloop:copy', 'rainloop:setup', 'rainloop:zip'], function() {
544
	return (cfg.cleanPath) ? cleanDir(cfg.cleanPath) : false;
545
});
546
547
gulp.task('rainloop:shortname', ['rainloop:md5'], function(callback) {
548
	copyFile(cfg.lastMd5File, cfg.destPath +
549
		'rainloop' + (cfg.community ? '-community' : '') + '-latest.zip', callback);
550
});
551
552
// BUILD (OwnCloud)
553
gulp.task('rainloop:owncloud:copy', function() {
554
555
	var
556
		versionFull = pkg.ownCloudPackageVersion,
557
		dist = cfg.releasesPath + '/owncloud/' + versionFull + '/src/'
558
	;
559
560
	fs.mkdirSync(dist, '0777', true);
561
	fs.mkdirSync(dist + 'rainloop', '0777', true);
562
563
	return gulp.src('build/owncloud/rainloop-app/**/*', {base: 'build/owncloud/rainloop-app/'})
564
		.pipe(gulp.dest(dist + 'rainloop'));
565
});
566
567
gulp.task('rainloop:owncloud:copy-rainloop', ['rainloop:start', 'rainloop:owncloud:copy'], function() {
568
569
	var
570
		versionFull = pkg.ownCloudPackageVersion,
571
		dist = cfg.releasesPath + '/owncloud/' + versionFull + '/src/rainloop/'
572
	;
573
574
	if (cfg.rainloopBuilded && cfg.destPath)
575
	{
576
		return gulp.src(cfg.destPath + '/src/**/*', {base: cfg.destPath + '/src/'})
577
			.pipe(gulp.dest(dist + 'app/'));
578
	}
579
580
	return true;
581
});
582
583
gulp.task('rainloop:owncloud:copy-rainloop:clean', ['rainloop:owncloud:copy-rainloop'], function() {
584
	return (cfg.cleanPath) ? cleanDir(cfg.cleanPath) : false;
585
});
586
587
gulp.task('rainloop:owncloud:setup', ['rainloop:owncloud:copy',
588
	'rainloop:owncloud:copy-rainloop'], function() {
589
590
	var
591
		versionFull = pkg.ownCloudPackageVersion,
592
		dist = cfg.releasesPath + '/owncloud/' + versionFull + '/src/'
593
	;
594
595
	fs.writeFileSync(dist + 'rainloop/appinfo/info.xml',
596
		fs.readFileSync(dist + 'rainloop/appinfo/info.xml', 'utf8')
597
			.replace('<version>0.0</version>', '<version>' + versionFull + '</version>')
598
			.replace('<licence></licence>', '<licence>' + (cfg.community ? 'AGPLv3' : 'RainLoop Software License') + '</licence>')
599
		);
600
601
	fs.writeFileSync(dist + 'rainloop/appinfo/version', versionFull);
602
	fs.writeFileSync(dist + 'rainloop/VERSION', versionFull);
603
604
	cfg.destPath = cfg.releasesPath + '/owncloud/' + versionFull + '/';
605
	cfg.cleanPath = dist;
606
	cfg.zipSrcPath = dist;
607
	cfg.zipFile = 'rainloop-owncloud-app-' + (cfg.community ? '' : 'standard-') + versionFull + '.zip';
608
	cfg.md5File = cfg.zipFile;
609
610
});
611
612
gulp.task('rainloop:owncloud:zip', ['rainloop:owncloud:copy', 'rainloop:owncloud:setup'], function() {
613
	return (cfg.destPath && cfg.zipSrcPath && cfg.zipFile) ?
614
		zipDir(cfg.zipSrcPath, cfg.destPath, cfg.zipFile) : false;
615
});
616
617
gulp.task('rainloop:owncloud:md5', ['rainloop:owncloud:zip'], function(callback) {
618
	renameFileWithMd5Hash(cfg.destPath +  cfg.md5File, callback);
619
});
620
621
gulp.task('rainloop:owncloud:clean', ['rainloop:owncloud:copy', 'rainloop:owncloud:setup', 'rainloop:owncloud:zip'], function() {
622
	return (cfg.cleanPath) ? cleanDir(cfg.cleanPath) : false;
623
});
624
625
gulp.task('rainloop:owncloud:shortname', ['rainloop:owncloud:md5'], function(callback) {
626
	copyFile(cfg.lastMd5File, cfg.destPath +
627
		'rainloop' + (cfg.community ? '' : '-standard') + '.zip', callback);
628
});
629
630
// MAIN
631
gulp.task('js:pgp', ['js:openpgp', 'js:openpgpworker']);
632
gulp.task('js:moment', ['js:moment:locales']);
633
634
gulp.task('default', ['js:libs', 'js:pgp', 'js:moment', 'js:min', 'css:min', 'ckeditor', 'fontastic', 'lightgallery']);
635
gulp.task('default+', ['package:community-off', 'default']);
636
gulp.task('fast-', ['js:app', 'js:admin', 'css:main']);
637
638
gulp.task('fast', ['package:community-on', 'fast-']);
639
gulp.task('fast+', ['package:community-off', 'fast-']);
640
641
gulp.task('rainloop:start', ['rainloop:copy', 'rainloop:setup']);
642
643
gulp.task('rainloop-', ['rainloop:start', 'rainloop:zip', 'rainloop:md5', 'rainloop:clean', 'rainloop:shortname']);
644
645
gulp.task('rainloop', ['package:community-on', 'rainloop-']);
646
gulp.task('rainloop+', ['package:community-off', 'rainloop-']);
647
648
gulp.task('owncloud-', ['rainloop:owncloud:copy',
649
	'rainloop:owncloud:copy-rainloop', 'rainloop:owncloud:copy-rainloop:clean',
650
	'rainloop:owncloud:setup', 'rainloop:owncloud:zip', 'rainloop:owncloud:md5', 'rainloop:owncloud:clean', 'rainloop:owncloud:shortname']);
651
652
gulp.task('owncloud', ['package:community-on', 'owncloud-']);
653
gulp.task('owncloud+', ['package:community-off', 'owncloud-']);
654
655
//WATCH
656
gulp.task('watch', ['fast'], function() {
657
	cfg.watch = true;
658
	livereload.listen();
659
	gulp.watch(cfg.paths.globjs, {interval: cfg.watchInterval}, ['js:app', 'js:admin']);
660
	gulp.watch(cfg.paths.globjsall, {interval: cfg.watchInterval}, ['js:validate']);
661
	gulp.watch(cfg.paths.less.main.watch, {interval: cfg.watchInterval}, ['css:main']);
662
});
663
664
gulp.task('watch+', ['fast+'], function() {
665
	cfg.watch = true;
666
	livereload.listen();
667
	gulp.watch(cfg.paths.globjs, {interval: cfg.watchInterval}, ['js:app', 'js:admin']);
668
	gulp.watch(cfg.paths.globjsall, {interval: cfg.watchInterval}, ['js:validate']);
669
	gulp.watch(cfg.paths.less.main.watch, {interval: cfg.watchInterval}, ['css:main']);
670
});
671
672
// ALIASES
673
gulp.task('build', ['rainloop']);
674
gulp.task('build+', ['rainloop+']);
675
676
gulp.task('js:v', ['js:validate']);
677
gulp.task('v', ['js:v']);
678
679
gulp.task('d', ['default']);
680
gulp.task('d+', ['default+']);
681
gulp.task('w', ['watch']);
682
gulp.task('w+', ['watch+']);
683
gulp.task('f', ['fast']);
684
gulp.task('f+', ['fast+']);
685
686
gulp.task('b', ['build']);
687
gulp.task('b+', ['build+']);
688
689
gulp.task('o', ['owncloud']);
690
gulp.task('o+', ['owncloud+']);
691