This repository has been archived by the owner on Aug 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
178 lines (156 loc) · 4.57 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import del from 'del';
import runSequence from 'run-sequence';
import {stream as wiredep} from 'wiredep';
const $ = gulpLoadPlugins();
gulp.task('extras', () => {
return gulp.src([
'app/*.*',
'app/_locales/**',
'app/scripts.vendor/**',
'app/scripts/mutation-observers.js',
'!app/scripts.babel',
'!app/*.json',
'!app/*.html',
'!app/styles.scss'
], {
base: 'app',
dot: true
}).pipe(gulp.dest('dist'));
});
gulp.task('lint', () => {
return gulp.src('app/scripts.babel/**/*.js')
.pipe($.eslint())
.pipe($.eslint.format());
});
gulp.task('images', () => {
return gulp.src('app/images/**/*')
.pipe($.if($.if.isFile, $.cache($.imagemin({
progressive: true,
interlaced: true,
// don't remove IDs from SVGs, they are often used
// as hooks for embedding and styling
svgoPlugins: [{cleanupIDs: false}]
}))
.on('error', (err) => {
console.log(err);
this.end();
})))
.pipe(gulp.dest('dist/images'));
});
gulp.task('styles', () => {
return gulp.src('app/styles.scss/**/*.scss')
.pipe($.plumber())
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['.']
}).on('error', $.sass.logError))
.pipe(gulp.dest('app/styles'));
});
gulp.task('html', ['styles'], () => {
return gulp.src('app/*.html')
.pipe($.useref({searchPath: ['.tmp', 'app', '.']}))
// .pipe($.sourcemaps.init())
// .pipe($.if('*.js', $.uglify()))
.pipe($.if('*.css', $.cleanCss({compatibility: '*'})))
// .pipe($.sourcemaps.write())
.pipe($.if('*.html', $.htmlmin({
collapseWhitespace: false,
minifyCSS: false,
minifyJS: false,
removeComments: true
})))
.pipe(gulp.dest('dist'));
});
gulp.task('chromeManifest', () => {
return gulp.src('app/manifest.json')
.pipe($.chromeManifest({
buildnumber: require('./package.json').version,
background: {
target: 'scripts/background.js',
exclude: [
'scripts/live-reload.js'
]
}
}))
.pipe($.if('*.css', $.cleanCss({compatibility: '*'})))
// .pipe($.if('*.js', $.sourcemaps.init()))
// .pipe($.if('*.js', $.uglify()))
// .pipe($.if('*.js', $.sourcemaps.write('.')))
.pipe(gulp.dest('dist'));
});
gulp.task('devChromeManifest', () => {
return gulp.src('app/manifest.json')
.pipe($.chromeManifest({
buildnumber: require('./package.json').version
}))
.pipe(gulp.dest('app'));
});
gulp.task('firefox-extra-permissions', () => {
return gulp.src('dist/manifest.json')
.pipe($.jsonTransform((data, file) => {
data.permissions.push('tabs');
return data;
}, "\t"))
.pipe(gulp.dest('dist'));
});
gulp.task('babel', () => {
return gulp.src('app/scripts.babel/**/*.js')
.pipe($.babel())
.pipe(gulp.dest('app/scripts'));
});
gulp.task('clean', del.bind(null, ['.tmp', 'dist']));
gulp.task('watch', ['devChromeManifest', 'lint', 'babel', 'styles'], () => {
$.livereload.listen();
gulp.watch([
'app/*.html',
'app/scripts/**/*.js',
'app/images/**/*',
'app/styles/**/*',
'app/_locales/**/*.json'
]).on('change', $.livereload.reload);
gulp.watch('app/scripts.babel/**/*.js', ['lint', 'babel']);
gulp.watch('app/styles.scss/**/*.scss', ['styles']);
gulp.watch('bower.json', ['wiredep']);
});
gulp.task('size', () => {
return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
});
gulp.task('wiredep', () => {
gulp.src('app/*.html')
.pipe(wiredep({
ignorePath: /^(\.\.\/)*\.\./
}))
.pipe(gulp.dest('app'));
});
gulp.task('package-chrome', ['build-chrome'], () => {
var manifest = require('./dist/manifest.json');
return gulp.src('dist/**')
.pipe($.zip('Chrome-Netflix-Tweaked-' + manifest.version + '.zip'))
.pipe(gulp.dest('package'));
});
gulp.task('package-firefox', ['build-firefox'], () => {
var manifest = require('./dist/manifest.json');
return gulp.src('dist/**')
.pipe($.zip('Firefox-Netflix-Tweaked-' + manifest.version + '.zip'))
.pipe(gulp.dest('package'));
});
gulp.task('build-chrome', ['clean'], (cb) => {
runSequence(
'lint', 'babel', 'chromeManifest',
['html', 'images', 'extras'],
'size', cb);
});
gulp.task('build-firefox', ['clean'], (cb) => {
runSequence(
'lint', 'babel', 'chromeManifest',
['html', 'images', 'extras'],
'firefox-extra-permissions',
'size', cb);
});
gulp.task('package', (cb) => {
runSequence('package-chrome', 'package-firefox', cb);
});
gulp.task('default', ['watch']);