-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
72 lines (62 loc) · 2.1 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
'use strict'
const gulp = require('gulp')
const path = require('path')
const pkg = require('./package.json')
const colors = require('colors/safe')
const zip = require('gulp-zip')
const imagemin = require('gulp-imagemin')
const jsonEditor = require('gulp-json-editor')
const cheerio = require('gulp-cheerio')
const gulpIf = require('gulp-if')
const { exec } = require('child_process')
colors.setTheme({
error: 'red'
})
function logMessage (message) {
console.log(`${message}`)
}
gulp.task('update-version', function (cb) {
const manifestPath = path.join(__dirname, 'src', 'manifest.json')
const manifest = require(manifestPath)
const version = manifest.version
return gulp.src('./package.json')
.pipe(jsonEditor({ version }))
.pipe(gulp.dest('./'))
.on('end', function () {
exec('npm install', { cwd: './' }, function (error) {
if (error) {
logMessage(colors.error('Error running npm install: ' + error))
return
}
cb()
})
})
.on('error', function (err) {
logMessage(colors.error('Error updating version in package.json: ' + err.toString()))
})
})
gulp.task('build-chrome', function () {
const manifestPath = path.join(__dirname, 'src', 'manifest.json')
const manifest = require(manifestPath)
const version = manifest.version
return gulp.src(['src/**'])
.pipe(imagemin([imagemin.optipng({ optimizationLevel: 5 })]))
.pipe(gulpIf('*.html', cheerio(($) => {
$('body').addClass('chrome')
})))
.pipe(zip(`${pkg.name}-v${version}-chrome.zip`))
.pipe(gulp.dest('build'))
})
gulp.task('build-edge', function () {
const manifestPath = path.join(__dirname, 'src', 'manifest.json')
const manifest = require(manifestPath)
const version = manifest.version
return gulp.src(['src/**'])
.pipe(imagemin([imagemin.optipng({ optimizationLevel: 5 })]))
.pipe(gulpIf('*.html', cheerio(($) => {
$('body').addClass('edge')
})))
.pipe(zip(`${pkg.name}-v${version}-edge.zip`))
.pipe(gulp.dest('build'))
})
gulp.task('build', gulp.series('update-version', gulp.parallel('build-chrome', 'build-edge')))