-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
140 lines (119 loc) · 3.96 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
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')({
rename: {
'gulp-if': 'gulpif',
'gulp-tag-version': 'tag_version'
}
});
var argv = require('yargs')
.default('env', 'local')
.argv;
var del = require('del');
var merge = require('merge-stream');
var semver = require('semver');
// Define some variables
var prod = argv.env == 'prod' ? true : false;
var local = argv.env == 'local' ? true : false;
// allow to force prod-like behavior (minifying mostly)
prod = argv.prod ? true : prod;
// Get the current version for zimlet
var p = require('./package.json');
var git = require('git-rev-sync');
var zimlet_version = local === true ? 'local' : p.version;
var zimlet_commit = git.short();
var sentry_dsn = 'https://[email protected]/8';
var dist = 'dist/' + argv.env + '/zimlet/';
var zip_name = 'com_crunchmail_zimlet.zip';
var zip_subdir = argv.env == 'prod' ? zimlet_version + '/' : '';
var zip_dest = 'dist/' + argv.env + '/' + zip_subdir;
// Validate JS
gulp.task('jshint', function() {
return gulp.src('src/**/*.js')
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('default'));
});
// Cleanup
gulp.task('clean', function() {
return del([
dist+'**/*',
zip_dest + zip_name
]);
});
// Build
gulp.task('dist', ['clean', 'jshint'], function() {
var bundle = gulp.src([
'bower_components/humps/humps.js',
'bower_components/raven-js/dist/raven.js'
])
// we minify our dependencies otherwise Zimbra might have
// problems compiling them
.pipe(plugins.sourcemaps.init())
.pipe(plugins.concat('bundle.js'))
.pipe(plugins.uglify({mangle: true}))
.pipe(plugins.sourcemaps.write())
.pipe(gulp.dest(dist));
var xml = gulp.src('src/com_crunchmail_zimlet.xml')
.pipe(plugins.replace('VERSION', zimlet_version))
.pipe(gulp.dest(dist));
var js = gulp.src([
'src/js/logger.module.js',
'src/js/main.js',
'src/js/soap.js',
'src/js/*',
])
.pipe(plugins.sourcemaps.init())
.pipe(plugins.concat('crunchmail_zimlet.js'))
// only minify for production (a lot faster)
.pipe(plugins.gulpif(prod, plugins.uglify({mangle: true})))
.pipe(plugins.gulpif(prod, plugins.sourcemaps.write()))
.pipe(gulp.dest(dist));
gulp.src('src/' + argv.env + '-config_template.xml')
.pipe(plugins.rename('config_template.xml'))
.pipe(plugins.replace('VERSION', zimlet_version))
.pipe(plugins.replace('COMMIT', zimlet_commit))
.pipe(plugins.replace('ENVIRONMENT', argv.env))
.pipe(plugins.replace('SENTRY_DSN', sentry_dsn))
.pipe(gulp.dest(dist));
var properties = gulp.src('src/*.properties')
// Zimbra wants ISO-8859 files, but we write in UTF-8
.pipe(plugins.iconv({encoding: 'ISO-8859-1'}))
.pipe(gulp.dest(dist));
var css = gulp.src(['src/*.css'])
.pipe(plugins.concat('bundle.css'))
.pipe(gulp.dest(dist));
var other = gulp.src([
'src/**',
'!src/*.properties',
'!src/*.css',
'!src/com_crunchmail_zimlet.xml',
'!src/*-config_template.xml',
'!src/js/', '!src/js/**'
])
.pipe(gulp.dest(dist));
// we need to merge so we can return and correctly wait for
// completion before building the zip (next task)
return merge(xml, js, properties, css, other);
});
// Zip
gulp.task('zip', ['dist'], function() {
return gulp.src(dist + '**')
.pipe(plugins.zip(zip_name))
.pipe(gulp.dest(zip_dest))
.pipe(plugins.notify({ message: 'Zimlet ZIP available at: ' + zip_dest + zip_name }));
});
gulp.task('default', function() {
gulp.start('zip');
});
function bump(importance) {
var version = semver.inc(require('./package.json').version, importance);
// get all the files to bump version in
return gulp.src(['./package.json', './bower.json'])
.pipe(plugins.bump({type: importance}))
.pipe(gulp.dest('./'))
.pipe(plugins.git.commit('bump version v'+version))
.pipe(plugins.filter('package.json'))
.pipe(plugins.tag_version());
}
gulp.task('patch', function() { return bump('patch'); });
gulp.task('minor', function() { return bump('minor'); });
gulp.task('major', function() { return bump('major'); });