-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgulpfile.js
169 lines (137 loc) · 4.33 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
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
//var debug = require('gulp-debug');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var browserify = require('browserify');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var zip = require('gulp-zip');
var bump = require('gulp-bump');
var jeditor = require('gulp-json-editor');
var rename = require('gulp-rename');
var watch = require('gulp-watch');
var livereload = require('gulp-livereload');
var chalk = require('chalk');
var babelify = require('babelify');
var uglify = require('gulp-uglify');
var buffer = require('vinyl-buffer');
gulp.task('browserify', function() {
var bundler = watchify(browserify({
entries: ['./src/js/content/index'],
debug: true
},
watchify.args
).transform(
babelify,
{
presets: ['env'],
plugins: ['transform-runtime']
}
));
// Optionally, you can apply transforms
// and other configuration options on the
// bundler just as you would with browserify
//bundler.transform('brfs');
function rebundle() {
return bundler.bundle()
.on('error', function(e) {
gutil.log(chalk.red('Error: ' + e.message));
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('src/js/dist'))
.pipe(livereload());
}
bundler
.on('update', rebundle);
// log errors if they happen;
return rebundle();
});
gulp.task('browserify-minified', ['manifest'], function() {
var bundler = browserify({
entries: ['./src/js/content/index']
}
).transform(
babelify,
{
presets: ['env'],
plugins: ['transform-runtime']
}
);
// Optionally, you can apply transforms
// and other configuration options on the
// bundler just as you would with browserify
//bundler.transform('brfs');
function rebundle() {
return bundler.bundle()
.on('error', function(e) {
gutil.log(chalk.red('Error: ' + e.message));
})
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('src/js/dist'));
}
bundler
.on('update', rebundle);
// log errors if they happen;
return rebundle();
});
gulp.task('jshint-watch', function(){
return watch([
'gulpfile.js',
'src/**/*.js',
'!src/js/dist/**'
])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('jshint', function(){
return gulp.src(['gulpfile.js',
'src/**/*.js',
'!src/js/dist/**'
])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('zip', ['browserify-minified'], function () {
var pkg = require('./package.json');
return gulp.src(['./src/**'])
.pipe(zip(pkg.name + '-' + pkg.version + '.zip', {compress: true}))
.pipe(gulp.dest('zips'));
});
gulp.task('bump', function(){
return gulp.src('./package.json')
.pipe(bump())
.pipe(gulp.dest('./'));
});
gulp.task('manifest', ['bump'], function(){
return gulp.src('./src/manifest.tmpl.json')
.pipe(jeditor(function(json){
json.version = require('./package.json').version;
return json;
}))
.pipe(rename('manifest.json'))
.pipe(gulp.dest('./src'));
});
gulp.task('manifest-livereload', function(){
return gulp.src('./src/manifest.tmpl.json')
.pipe(jeditor(function(json){
json.version = Math.floor(Math.random() * 1000) + '' + require('./package.json').version;
json.background.scripts.push('js/live-reload.js');
return json;
}))
.pipe(rename('manifest.json'))
.pipe(gulp.dest('./src'));
});
gulp.task('live-reload', livereload.listen);
gulp.task('watch',function() {
watch(['src/**', '!src/js/content/**'], function(files, cb) {
files.pipe(livereload({auto: false}), cb);
});
});
gulp.task('test', ['jshint']);
gulp.task('default', ['live-reload', 'manifest-livereload', 'watch', 'jshint-watch', 'browserify']);
gulp.task('build', ['zip']);
// todo: https://github.com/erikdesjardins/chrome-extension-deploy