This repository was archived by the owner on Mar 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrev.js
84 lines (72 loc) · 2.21 KB
/
rev.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
import BaseRecipe from './baseRecipe'
import BrowserSync from 'browser-sync'
import debug from 'gulp-debug'
import extend from 'extend'
import gulpif from 'gulp-if'
import rev from 'gulp-rev'
export const Default = {
debug: false,
presetType: 'postProcessor',
task: {
name: 'rev'
},
watch: {
glob: '**',
options: {
//cwd: ** resolved from preset **
ignore: ['**/digest', '**/digest/**', '**/*.map']
}
},
source: {
glob: '**',
options: {
//cwd: ** resolved from preset **
ignore: ['**/digest', '**/digest/**', '**/*.map']
}
},
options: {
merge: true,
path: 'rev-manifest.json'
}
}
const Rev = class extends BaseRecipe {
/**
*
* @param gulp - gulp instance
* @param preset - base preset configuration - either one from preset.js or a custom hash
* @param configs - customized overrides for this recipe
*/
constructor(gulp, preset, ...configs) {
super(gulp, preset, Default, ...configs)
this.browserSync = BrowserSync.create()
}
createDescription() {
return `Adds revision digest to assets from ${this.config.source.options.cwd}/${this.config.source.glob}`
}
run(done, watching = false) {
this.debugDump(`gulp.src ${this.config.source.glob}`, this.config.source.options)
// base is not working https://github.com/sindresorhus/gulp-rev/issues/150
//let manifestOptions = extend(true, {}, {base: this.config.dest}, this.config.options)
// workaround
let manifestOptions = extend(true, {},
this.config.options,
{
base: this.config.dest,
path: `${this.config.dest}/${this.config.options.path}`
}
)
this.debugDump(`manifestOptions`, manifestOptions)
return this.gulp.src(this.config.source.glob, this.config.source.options)
.pipe(gulpif(this.config.debug, debug(this.debugOptions())))
.pipe(rev(this.config.options))
.pipe(this.gulp.dest(this.config.dest))
// Merge with an existing unless merge == false
.pipe(rev.manifest(manifestOptions))
.pipe(this.gulp.dest(this.config.dest))
.on('error', (error) => {
this.notifyError(error, done, watching)
})
.pipe(this.browserSync.stream())
}
}
export default Rev