forked from outaTiME/gulp-replace-task
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·54 lines (39 loc) · 1.02 KB
/
index.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
/*
* gulp-replace-task
*
* Copyright (c) 2015 outaTiME
* Licensed under the MIT license.
* https://github.com/outaTiME/gulp-replace-task/blob/master/LICENSE-MIT
*/
'use strict';
// dependencies
var through2 = require('through2');
var PluginError = require('plugin-error');
var Applause = require('next-applause');
// constants
var PLUGIN_NAME = 'gulp-replace-task';
// plugin
module.exports = function (opts) {
return through2.obj(function (file, enc, cb) {
if (file.isNull()) {
this.push(file);
return cb();
}
if (file.isStream()) {
this.emit('error', new PluginError(PLUGIN_NAME,
'Streaming not supported'));
return cb();
}
var options = opts || {};
var contents = file.contents.toString();
var applause = Applause.create(options);
var result = applause.replace(contents);
if (result && result.count > 0) {
file.contents = Buffer.from(result.content);
} else {
// preserve original file
}
this.push(file);
cb();
});
};