-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulp-hologram.js
46 lines (40 loc) · 1.05 KB
/
gulp-hologram.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
/** @format */
'use strict';
/*
Adapted from https://gist.github.com/jchild3rs/470be49a4bc4caf3ca8a
// Usage:
gulp.task('docs', function(cb) {
gulp.src('path/to/your/src')
.pipe(hologram(cb));
});
*/
import log from 'fancy-log';
import PluginError from 'plugin-error';
import map from 'map-stream';
import { spawn } from 'child_process';
/**
* Facade/Plugin for compiling Hologram as a stream
* @param task
* @param taskCallback
* @returns {*}
*/
export default function(taskCallback) {
// (child-process.spawn implementation)
return map(file => {
const args = ['./hologram_config.yml'];
const hologram = spawn('hologram', args, { stdio: 'inherit' });
hologram
// Print hologram stdout to log.
.on('data', data => log(data.toString().trim()))
// Handle end of command execution.
.on('close', code => {
let error;
if (code && 0 !== code) {
error = new PluginError('hologram', 'Hologram failed with error code: ' + code);
}
if (typeof taskCallback === 'function') {
taskCallback(error, file);
}
});
});
}