-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
86 lines (70 loc) · 1.73 KB
/
index.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var through = require('through2');
var defaults = require('lodash.defaults');
var exec = require('child_process').exec;
var PLUGIN_NAME = 'gulp-styledocco';
module.exports = function (options) {
'use strict';
var firstFile = null;
var opts = defaults(options || {}, {
out: 'docs',
name: 'Styledocco',
include: null,
preprocessor: null
});
var count = 0;
function transform (file, encoding, cb) {
if (file.isNull()) {
this.push(file);
return cb();
}
if (file.isStream()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'Streaming not supported'));
return cb();
}
count++;
if (!firstFile) {
firstFile = file;
}
cb();
}
function flush (cb) {
var bin = 'styledocco ';
var args = [];
args.push('--out', opts.out);
if (opts.name !== null) {
args.push('--name', '"' + opts.name + '"');
}
if (opts.preprocessor !== null) {
args.push('--preprocessor', opts.preprocessor);
}
if (opts.include !== null) {
opts.include.forEach(function (value) {
return args.push('--include', value);
});
}
if (opts.verbose) {
args.push('--verbose', opts.verbose);
}
if (opts['no-minify']) {
args.push('--no-minify');
}
if (count > 1) {
args.push(firstFile.base);
} else {
args.push(firstFile.path);
}
exec(bin + args.join(' '), function (error, stdout, stderr) {
if (stderr) {
gutil.log(stderr);
}
if (stdout) {
stdout = stdout.trim();
gutil.log(stdout);
}
cb(error);
});
}
return through.obj(transform, flush);
};