This repository has been 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
/
revReplace.js
74 lines (64 loc) · 2.02 KB
/
revReplace.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
import BaseRecipe from './baseRecipe'
import Preset from './preset'
import extend from 'extend'
import debug from 'gulp-debug'
import gulpif from 'gulp-if'
import revReplace from 'gulp-rev-replace'
export const Default = {
debug: false,
presetType: 'postProcessor',
task: {
name: 'rev:replace'
},
watch: false,
source: { // cwd/ignore defaulted from preset set in constructor
glob: '**'
},
manifest: 'rev-manifest.json', // file name only
options: {}
}
const RevReplace = 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) {
let resolvedPreset = Preset.resolveConfig(preset, Default, ...configs)
super(gulp, preset,
Default,
{
source: {
options: { // replace everything in the postProcessor dest folder (except manifest)
cwd: resolvedPreset.dest,
ignore: [`**/${resolvedPreset.manifest}`]
}
}
},
...configs)
}
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)
// options.manifest has to originate from gulp.src
let options = extend(true, {},
{
// full path to the manifest file
manifest: this.gulp.src(`${this.config.dest}/${this.config.manifest}`)
},
this.config.options
)
this.debugDump(`revReplace options`, options)
return this.gulp.src(this.config.source.glob, this.config.source.options)
.pipe(gulpif(this.config.debug, debug(this.debugOptions())))
.pipe(revReplace(options))
.pipe(this.gulp.dest(this.config.dest))
.on('error', (error) => {
this.notifyError(error, done, watching)
})
}
}
export default RevReplace