1
- /* jshint node: true */
2
- 'use strict' ;
3
-
4
1
/**
5
2
* Module dependencies.
6
3
*/
7
4
8
- var Concat = require ( 'concat-with-sourcemaps' ) ;
9
- var through = require ( 'through2' ) ;
10
- var lodashTemplate = require ( 'lodash.template' ) ;
11
- var stream = require ( 'stream' ) ;
12
- var path = require ( 'path' ) ;
13
- var fs = require ( 'fs' ) ;
5
+ const Concat = require ( 'concat-with-sourcemaps' ) ;
6
+ const through = require ( 'through2' ) ;
7
+ const lodashTemplate = require ( 'lodash.template' ) ;
8
+ const stream = require ( 'stream' ) ;
9
+ const path = require ( 'path' ) ;
14
10
15
11
/**
16
12
* gulp-header plugin
17
13
*/
18
14
19
- module . exports = function ( headerText , data ) {
15
+ module . exports = ( headerText , data ) => {
20
16
headerText = headerText || '' ;
21
17
22
18
function TransformStream ( file , enc , cb ) {
23
19
// format template
24
- var filename = path . basename ( file . path ) ;
25
- var template =
26
- data === false
27
- ? headerText
20
+ const filename = path . basename ( file . path ) ;
21
+ const template =
22
+ data === false ?
23
+ headerText
28
24
: lodashTemplate ( headerText ) (
29
25
Object . assign ( { } , file . data || { } , { file : file , filename : filename } , data )
30
26
) ;
@@ -42,7 +38,7 @@ module.exports = function(headerText, data) {
42
38
43
39
// handle file stream;
44
40
if ( file . isStream ( ) ) {
45
- var stream = through ( ) ;
41
+ const stream = through ( ) ;
46
42
stream . write ( Buffer . from ( template ) ) ;
47
43
stream . on ( 'error' , this . emit . bind ( this , 'error' ) ) ;
48
44
file . contents = file . contents . pipe ( stream ) ;
@@ -51,7 +47,7 @@ module.exports = function(headerText, data) {
51
47
}
52
48
53
49
// variables to handle direct file content manipulation
54
- var concat = new Concat ( true , filename ) ;
50
+ const concat = new Concat ( true , filename ) ;
55
51
56
52
// add template
57
53
concat . add ( null , Buffer . from ( template ) ) ;
@@ -82,14 +78,14 @@ module.exports = function(headerText, data) {
82
78
/**
83
79
* is stream?
84
80
*/
85
- function isStream ( obj ) {
81
+ const isStream = ( obj ) => {
86
82
return obj instanceof stream . Stream ;
87
- }
83
+ } ;
88
84
89
85
/**
90
86
* Is File, and Exists
91
87
*/
92
- function isExistingFile ( file ) {
88
+ const isExistingFile = ( file ) => {
93
89
try {
94
90
if ( ! ( file && typeof file === 'object' ) ) return false ;
95
91
if ( file . isDirectory ( ) ) return false ;
@@ -98,4 +94,4 @@ function isExistingFile(file) {
98
94
if ( typeof file . contents === 'string' ) return true ;
99
95
} catch ( err ) { }
100
96
return false ;
101
- }
97
+ } ;
0 commit comments