-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
102 lines (85 loc) · 2.87 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var gulpif = require('gulp-if');
var cssnano = require('gulp-cssnano');
var less = require('gulp-less');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var del = require('del')
var manifest = require('./manifest.json');
var util = require('util');
var zip = require('gulp-zip');
var isToUglify = false;
var unpackagedFolder = 'dist';
var packageFolder = 'release';
gulp.task('uglify_on', function() {
isToUglify = true;
})
gulp.task('scripts', function() {
return gulp.src([
'node_modules/jsuri/Uri.js',
'scripts/*.js'
])
.pipe(gulpif(isToUglify, uglify({
mangle: false
})))
.pipe(gulp.dest(unpackagedFolder + '/scripts'));
});
gulp.task('locales', function() {
return gulp.src(['_locales/**/messages.json'], {
base: './'
})
.pipe(gulp.dest(unpackagedFolder))
});
gulp.task('media', function() {
return gulp.src(['media/**/*.*'], {
base: './'
})
.pipe(gulp.dest(unpackagedFolder))
})
gulp.task('styles', function() {
return gulp.src(['stylesheets/*.less'], {
base: './'
})
.pipe(less())
.pipe(gulpif(isToUglify, cssnano()))
.pipe(gulp.dest(unpackagedFolder));
});
gulp.task('html', function() {
return gulp.src(['html/**/*.html'], {
base: './'
})
.pipe(gulp.dest(unpackagedFolder));
})
gulp.task('manifest', function() {
return gulp.src('manifest.json')
.pipe(gulp.dest(unpackagedFolder));
})
gulp.task('clean', function() {
del.sync(['dist/*']);
});
gulp.task('watch', function() {
var cb = function(event) {
gutil.log(gutil.colors.green('File ' + event.path + ' was ' + event.type + ', running tasks...'));
};
gulp.watch(['node_modules/jsuri/Uri.js', 'scripts/*.js'], ['scripts']).on('change', cb);
gulp.watch('locales/**/messages.json', ['locales']).on('change', cb);
gulp.watch('media/**/*.*', ['media']).on('change', cb);
gulp.watch('stylesheets/*.less', ['styles']).on('change', cb);
gulp.watch('html/**/*.html', ['html']).on('change', cb);
gulp.watch('manifest.json', ['manifest']).on('change', cb);
});
// watches changes and move files to 'unpackagedFolder' folder for the
// extension to be ran as 'unpacked extension' from chrome
gulp.task('default', ['watch']);
// moves all files to 'unpackedFolder'
gulp.task('unpackage', ['clean', 'manifest', 'scripts', 'html', 'media', 'styles', 'locales']);
// same as 'unpackage' but minifies .js and .css files first
gulp.task('unpackage_uglify', ['uglify_on', 'unpackage']);
// moves all files to 'unpackedFolder' folder and creates a .zip package from it on 'packageFolder' folder
// zip file is named after manifest.json version property
gulp.task('package', ['uglify_on', 'unpackage'], function() {
return gulp.src(unpackagedFolder + '/**/*.*')
.pipe(zip('iZoom-' + manifest.version + '.zip'))
.pipe(gulp.dest(packageFolder));
});