-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgulpfile.js
91 lines (79 loc) · 2.27 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
'use strict';
const extensionName = 'Edit-in-Prose';
const fs = require('fs');
const cleancss = require('gulp-clean-css');
const cleanhtml = require('gulp-cleanhtml');
const crx = require('gulp-crx');
const del = require('del');
const gulp = require('gulp');
const gutil = require('gulp-util');
const vinylpaths = require('vinyl-paths');
const zip = require('gulp-zip');
// Clean build directory
gulp.task('clean', () => {
return gulp.src('build/*')
.pipe(vinylpaths(del));
});
// Copy and compress HTML files
gulp.task('html', () => {
return gulp.src('src/*.html')
.pipe(cleanhtml())
.pipe(gulp.dest('build'));
});
// Copy scripts
gulp.task('scripts', () => {
return gulp.src('src/*.js')
.pipe(gulp.dest('build'));
});
// Copy and minify CSS
gulp.task('styles', () => {
gulp.src('src/**/*.min.css')
.pipe(gulp.dest('build'));
return gulp.src(['src/*.css', '!src/vendor/**/*.css'])
.pipe(cleancss({root: 'src', keepSpecialComments: 0}))
.pipe(gulp.dest('build'));
});
// Copy static files
gulp.task('copy', () => {
gulp.src('src/*.png')
.pipe(gulp.dest('build'));
gulp.src('src/*.mp3')
.pipe(gulp.dest('build'));
gulp.src('src/_locales/**')
.pipe(gulp.dest('build/_locales'));
return gulp.src('src/manifest.json')
.pipe(gulp.dest('build'));
});
// Build
gulp.task('build', ['clean', 'html', 'scripts', 'styles', 'copy']);
// Build ditributable (ZIP)
gulp.task('zip', ['build'], () => {
const manifest = require('./src/manifest.json');
const distFileName = extensionName + '_v' + manifest.version + '.zip';
return gulp.src(['build/**'])
.pipe(zip(distFileName))
.pipe(gulp.dest('dist'));
});
// Build distributable (CRX) extension
gulp.task('crx', ['build'], () => {
const manifest = require('./src/manifest.json');
const crxFileName = extensionName + '_v' + manifest.version + '.crx';
fs.access('./certs/key', err => {
if (err) {
gutil.log(err.message);
return err.code;
}
return gulp.src('build')
.pipe(crx({
privateKey: fs.readFileSync('./certs/key', 'utf8'),
filename: crxFileName
}))
.pipe(gulp.dest('dist'));
});
});
// Build distributable
gulp.task('dist', ['zip']);
// Run build task by default
gulp.task('default', ['clean'], () => {
gulp.start('build');
});