-
Notifications
You must be signed in to change notification settings - Fork 38
/
gulpfile.js
237 lines (195 loc) · 6.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*jslint node: true, for */
'use strict';
let gulp = require('gulp'),
del = require('del'),
renameFile = require("gulp-rename"),
htmlMinifier = require('gulp-htmlmin'),
htmlValidator = require('gulp-html'),
sass = require('gulp-sass'),
sassLint = require('gulp-sass-lint'),
jsLinter = require('gulp-eslint'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
config = require('./config.json'),
colors = config.colors;
gulp.task('minifyHTML', function () {
'use strict';
return gulp.src(['src/options/index.html'])
.pipe(htmlMinifier({
removeComments: true,
collapseWhitespace: true
}))
.pipe(renameFile('options.html'))
.pipe(gulp.dest('extension'));
});
gulp.task('validateHTML', function () {
'use strict';
return gulp.src(['src/options/index.html']).pipe(htmlValidator());
});
gulp.task('lintOptionsSass', function () {
'use strict';
return gulp.src('src/options/main.scss')
.pipe(sassLint({
configFile: './.sass-lint.yml'
}))
.pipe(sassLint.format())
.pipe(sassLint.failOnError());
});
gulp.task('lintContentSass', function () {
'use strict';
return gulp.src('src/content/main.scss')
.pipe(sassLint({
configFile: './.sass-lint.yml'
}))
.pipe(sassLint.format())
.pipe(sassLint.failOnError());
});
gulp.task('lintSass', ['lintOptionsSass', 'lintContentSass']);
gulp.task('compileOptionsCSS', function () {
'use strict';
return gulp.src('src/options/main.scss')
.pipe(sass({
outputStyle: 'compressed',
precision: 10
}).on('error', sass.logError))
.pipe(renameFile('options.css'))
.pipe(gulp.dest('extension'));
});
gulp.task('compileContentCSS', function () {
'use strict';
return gulp.src('src/content/main.scss')
.pipe(sass({
outputStyle: 'compressed',
precision: 10
}).on('error', sass.logError))
.pipe(renameFile('content.css'))
.pipe(gulp.dest('extension'));
});
gulp.task('compileCSS', ['compileOptionsCSS', 'compileContentCSS']);
gulp.task('lintBackgroundJS', function () {
'use strict';
return gulp.src('src/background/main.js')
.pipe(jsLinter({configFile: '.eslintrc.json'}))
.pipe(jsLinter.format())
.pipe(jsLinter.failAfterError())
.pipe(renameFile('background.js'))
.pipe(gulp.dest('extension'));
});
gulp.task('lintContentJS', function () {
'use strict';
return gulp.src('src/content/main.js')
.pipe(jsLinter({configFile: '.eslintrc.json'}))
.pipe(jsLinter.format())
.pipe(jsLinter.failAfterError())
.pipe(renameFile('content.js'))
.pipe(gulp.dest('extension'));
});
gulp.task('lintOptionsJS', function () {
'use strict';
return gulp.src('src/options/main.js')
.pipe(jsLinter({configFile: '.eslintrc.json'}))
.pipe(jsLinter.format())
.pipe(jsLinter.failAfterError())
.pipe(renameFile('options.js'))
.pipe(gulp.dest('extension'));
});
gulp.task('lintJS', ['lintBackgroundJS', 'lintContentJS', 'lintOptionsJS']);
gulp.task('copyRawFilesToExtensionFolder', function () {
'use strict';
return gulp.src([
'src/img/**/*',
'src/_locales/**/*',
'src/fonts/**/*',
'src/manifest.json'
], {base: './src/'}).pipe(gulp.dest('extension'));
});
// TODO: add more files to watch here. For example, none of the files in the common-styles folder is being polled.
gulp.task('serve', [
'validateHTML',
'minifyHTML',
'lintSass',
'compileCSS',
'lintJS',
'copyRawFilesToExtensionFolder'
], function () {
'use strict';
gulp.watch(
['src/options/index.html'],
['validateHTML', 'minifyHTML']
)
.on('change', reload);
gulp.watch(
['src/options/main.js'],
['lintOptionsJS']
)
.on('change', reload);
gulp.watch(
['src/options/main.scss'],
['lintOptionsSass', 'compileOptionsCSS']
)
.on('change', reload);
gulp.watch(
['src/background/main.js'],
['lintBackgroundJS']
)
.on('change', reload);
gulp.watch(
['src/content/main.js'],
['lintContentJS']
)
.on('change', reload);
gulp.watch(
['src/content/main.scss'],
['lintContentSass', 'compileContentCSS']
)
.on('change', reload);
});
gulp.task('build', [
'validateHTML',
'minifyHTML',
'lintSass',
'compileCSS',
'lintJS',
'copyRawFilesToExtensionFolder'
]);
gulp.task('clean', function () {
'use strict';
let fs = require('fs'),
i,
expendableFolders = ['extension'];
for (i = 0; i < expendableFolders.length; i += 1) {
try {
fs.accessSync(expendableFolders[i], fs.F_OK);
process.stdout.write('\n\tThe ' + colors.green + expendableFolders[i] +
colors.default + ' directory was found and ' + colors.green +
'will' + colors.default + ' be deleted.\n');
del(expendableFolders[i]);
} catch (error) {
if (error) {
process.stdout.write('\n\tThe ' + colors.red +
expendableFolders[i] + colors.default +
' directory does ' + colors.red + 'not' + colors.default +
' exist or is ' + colors.red + 'not' + colors.default +
' accessible.\n');
}
}
}
process.stdout.write('\n');
});
gulp.task('default', function () {
'use strict';
let exec = require('child_process').exec;
exec('gulp --tasks', function (error, stdout, stderr) {
if (null !== error) {
process.stdout.write('An error was likely generated when invoking ' +
'the `exec` program in the default task.');
}
if ('' !== stderr) {
process.stdout.write('Content has been written to the stderr stream ' +
'when invoking the `exec` program in the default task.');
}
process.stdout.write('\n\tThis default task does ' + colors.red +
'nothing' + colors.default + ' but generate this message. The ' +
'available tasks are:\n\n' + stdout);
});
});