-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.coffee
46 lines (33 loc) · 1.11 KB
/
index.coffee
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
'use strict'
PLUGIN_NAME = 'gulp-livingstyleguide'
fs = require 'fs'
exec = require('child_process').exec
gutil = require 'gulp-util'
through = require 'through2'
module.exports = (options = {}) ->
transform = (file, enc, callback) ->
if file.isStream()
error = new gutil.PluginError PLUGIN_NAME, 'Streaming not supported'
@emit 'error', error
return callback()
exec "bundle exec livingstyleguide compile #{file.path}", (error) =>
if error
error = new gutil.PluginError PLUGIN_NAME, error
@emit 'error', error
return callback()
styleguideFilePath = file.path.replace /\..*$/g, ''
styleguideHtmlFilePath = "#{styleguideFilePath}.html"
file.path = styleguideHtmlFilePath
styleguide = fs.readFileSync styleguideHtmlFilePath
fs.unlink styleguideHtmlFilePath
try
file.contents = new Buffer styleguide
catch error
err = new gutil.PluginError PLUGIN_NAME, error
@emit 'error', err
return callback()
@push file
callback()
flush = (callback) ->
callback()
through.obj transform, flush