ColemanGariety / gulp-nodemon

gulp + nodemon + convenience
526 stars 76 forks source link

piping gulp nodemon output through Bunyan (or whatever) #103

Open ORESoftware opened 8 years ago

ORESoftware commented 8 years ago

I am a big fan of gulp-nodemon, but I cannot figure out how to pipe it through Bunyan

I have to do this:

$ gulp nodemon | bunyan -l debug -o short

but I would rather do something like this:

$ gulp nodemon

with " | bunyan -l debug -o short" as some sort of argument using this:

gulp.task('nodemon', ['metagen:all', 'watch:hot-reload-front-end'], function () {

    nodemon({

        script: 'bin/www.js',
        ext: 'js',
        ignore: ['public/*', '*.git/*', '*.idea/*', 'routes/*', 'gulpfile.js'],
        args: ['--use_socket_serverX', '--use_hot_reloader', ' | bunyan -o short'],  // <<<< this bunyan call doesn't work
        nodeArgs: [],
        env: {
            NODE_ENV: 'development'
        }

    }).on('restart', []);

});

I am just being stoopid and not using the right command or is there something else wrong?

ColemanGariety commented 8 years ago

Try this solution contributed by @markstos:

gulp.task('run', ['default', 'watch'], function() {
    var nodemon = require('gulp-nodemon'),
        spawn   = require('child_process').spawn,
        bunyan

    nodemon({
        script: paths.server,
        ext:    'js json',
        ignore: [
            'var/',
            'node_modules/'
        ],
        watch:    [paths.etc, paths.src],
        stdout:   false,
        readable: false
    })
    .on('readable', function() {

        // free memory
        bunyan && bunyan.kill()

        bunyan = spawn('./node_modules/bunyan/bin/bunyan', [
            '--output', 'short',
            '--color'
        ])

        bunyan.stdout.pipe(process.stdout)
        bunyan.stderr.pipe(process.stderr)

        this.stdout.pipe(bunyan.stdin)
        this.stderr.pipe(bunyan.stdin)
    });
})
ColemanGariety commented 8 years ago

But that is way too complicated. It would be nice to be able to do something like this:

nodemon().pipe(bunyan.stream)

EDIT: tagged 'enhancement'

ORESoftware commented 8 years ago

ok thanks, yeah I have been struggling with it