-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin-template.js
More file actions
41 lines (32 loc) · 1000 Bytes
/
plugin-template.js
File metadata and controls
41 lines (32 loc) · 1000 Bytes
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
var through = require('through2');
var PluginError = require('gulp-util').PluginError;
var PLUGIN_NAME = 'プラグイン名';
module.exports = function() {
/**
* @this {Transform}
*/
var transform = function(file, encoding, callback) {
if (file.isNull()) {
// 何もしない
return callback(null, file);
}
if (file.isStream()) {
// ストリームはサポートしない
this.emit('error', new PluginError(PLUGIN_NAME, 'Streams not supported!'));
}
// プラグインの処理本体
if (file.isBuffer()) {
// ファイルの内容をcontentsに読み込み
var contents = String(file.contents);
// 同じ内容を繰り返す(サンプル)
contents = contents + contents;
// 編集した内容を出力
file.contents = new Buffer(contents);
// 処理の完了を通知
return callback(null, file);
}
this.push(file);
callback();
};
return through.obj(transform);
};