2
2
'use strict' ;
3
3
4
4
/**
5
- * Module dependencies.
6
- */
5
+ * Module dependencies.
6
+ */
7
7
8
8
var Concat = require ( 'concat-with-sourcemaps' ) ;
9
9
var through = require ( 'through2' ) ;
@@ -13,16 +13,21 @@ var path = require('path');
13
13
var fs = require ( 'fs' ) ;
14
14
15
15
/**
16
- * gulp-header plugin
17
- */
16
+ * gulp-header plugin
17
+ */
18
18
19
- module . exports = function ( headerText , data ) {
19
+ module . exports = function ( headerText , data ) {
20
20
headerText = headerText || '' ;
21
21
22
22
function TransformStream ( file , enc , cb ) {
23
23
// format template
24
24
var filename = path . basename ( file . path ) ;
25
- var template = data === false ? headerText : lodashTemplate ( headerText ) ( Object . assign ( { } , file . data || { } , { file : file , filename : filename } , data ) ) ;
25
+ var template =
26
+ data === false
27
+ ? headerText
28
+ : lodashTemplate ( headerText ) (
29
+ Object . assign ( { } , file . data || { } , { file : file , filename : filename } , data )
30
+ ) ;
26
31
27
32
if ( file && typeof file === 'string' ) {
28
33
this . push ( template + file ) ;
@@ -38,7 +43,7 @@ module.exports = function (headerText, data) {
38
43
// handle file stream;
39
44
if ( file . isStream ( ) ) {
40
45
var stream = through ( ) ;
41
- stream . write ( new Buffer ( template ) ) ;
46
+ stream . write ( Buffer . from ( template ) ) ;
42
47
stream . on ( 'error' , this . emit . bind ( this , 'error' ) ) ;
43
48
file . contents = file . contents . pipe ( stream ) ;
44
49
this . push ( file ) ;
@@ -49,7 +54,7 @@ module.exports = function (headerText, data) {
49
54
var concat = new Concat ( true , filename ) ;
50
55
51
56
// add template
52
- concat . add ( null , new Buffer ( template ) ) ;
57
+ concat . add ( null , Buffer . from ( template ) ) ;
53
58
54
59
// add sourcemap
55
60
concat . add ( file . relative , file . contents , file . sourceMap ) ;
@@ -75,8 +80,8 @@ module.exports = function (headerText, data) {
75
80
} ;
76
81
77
82
/**
78
- * is stream?
79
- */
83
+ * is stream?
84
+ */
80
85
function isStream ( obj ) {
81
86
return obj instanceof stream . Stream ;
82
87
}
@@ -91,6 +96,6 @@ function isExistingFile(file) {
91
96
if ( file . isStream ( ) ) return true ;
92
97
if ( file . isBuffer ( ) ) return true ;
93
98
if ( typeof file . contents === 'string' ) return true ;
94
- } catch ( err ) { }
99
+ } catch ( err ) { }
95
100
return false ;
96
101
}
0 commit comments