UNPKG

893 Btext/coffeescriptView Raw
1
2{ LineEndingCorrector } = require 'line-ending-corrector'
3
4PluginError = require 'plugin-error'
5
6through = require 'through2'
7
8module.exports = (opt) ->
9
10 transform = (file, enc, cb) ->
11
12 return cb null, file if file.isNull()
13
14 return cb (new PluginError 'gulp-line-ending-corrector', 'Streaming not supported') if file.isStream()
15
16 data = undefined
17
18 str = file.contents.toString('utf8')
19
20 dest = file.path
21
22 try
23
24 [ wasAltered, output ] = LineEndingCorrector.correctSync str, opt
25
26 if typeof opt is 'object' and 'verbose' of opt and opt.verbose
27
28 console.log "lec #{dest} : #{wasAltered}"
29
30
31
32 catch err
33
34 return cb (new PluginError 'gulp-line-ending-corrector', err)
35
36 file.contents = new Buffer output
37
38 file.path = dest
39
40 cb null, file
41
42 return
43
44 through.obj transform
45