Gulp how to save output to file

I am using gulp

and gulp-shell

. How do I save the output to a file (created gulp

)?

return gulp.src('.')
    .pipe(shell([
        'composer install --prefer-source'
    ]));

      

+3


source to share


4 answers


For this I use gulp-exec

.



gulp.task("git_log", [], function(){
    var options = {
        continueOnError: false, // default = false, true means don't emit error event
        pipeStdout: true, // default = false, true means stdout is written to file.contents
        customTemplatingThing: "test" // content passed to gutil.template()
    };
    var reportOptions = {
        err: false, // default = true, false means don't write err
        stderr: true, // default = true, false means don't write stderr
        stdout: false // default = true, false means don't write stdout
    };
    return gulp.src("somefile.txt")
        .pipe(exec("pwd", options))
        .pipe(exec.reporter(reportOptions))
        .pipe(gulp.dest('build/'));
});

      

+2


source


continue with .pipe(gulp.dest('output.file'))

.



0


source


Gulp Shell transfers files not the output of the commands it runs.

A quick and dirty solution not compatible with Windows and gulp is to simply pipe the output of a shell command to a file inside the command itself:

return gulp.src('.')
  .pipe(shell([
    'composer install --prefer-source > composer-log.txt'
  ]));

      

This is obviously only suitable for * nix environments and doesn't scale enough to collect the output of multiple commands (although you can just add the output from all of those commands to the same file).

0


source


You can use run for this.

gulp.task 'run',->
run ("echo Hello!")
.exec()
.pipe (gulp.dest "G:\\new.txt")

      

Install the necessary plugins for this type of gulp-run and gulp-exec.

-1


source







All Articles