gulp-append

Append a file the easy way

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
gulp-append
030.3.46 years ago7 years agoMinified + gzip package size for gulp-append in KB

Readme

gulp-append Build Status
An gulp plugin for writing .pipe 'data' to a file.

Install

$ npm install --save-dev gulp-append

Usage

Default usage

var gulp = require('gulp');
var append = require('gulp-append');

gulp.task('default', function () {
	return gulp.src('src/file.json')
		.pipe(append());
});

Using a custom destination

var gulp = require('gulp');
var append = require('gulp-append');

gulp.task('default', function () {
	return gulp.src('src/file.json')
		.pipe(append('some/path/appended-file.json'));
});

Using tranform

var gulp = require('gulp');
var append = require('gulp-append');
var nameFromPath = require('name-from-path');

gulp.task('append:transform', () => {
  return gulp.src(
    'README.md'
  ).pipe(append({
      transform: {
        path: function(file) {
          return String(file.path)
        },
        name: function(file) {
          return nameFromPath(file, true);
        }
      }
    }
  ));
});

Wrapping it all together

var gulp = require('gulp');
var append = require('gulp-append');
var nameFromPath = require('name-from-path');

gulp.task('append:transform', () => {
  return gulp.src(
    'README.md'
  ).pipe(append('some/path/to/file.json', {
    transform: {
      path: function(file) {
        return String(file.path)
      },
      name: function(file) {
        return nameFromPath(file, true);
      }
    }
  }));
});

API

options

append(destination)

Type: string
Default: appended.json
The destination to write to.
append('some-file.json');

append(opts) - json

Type: boolean
Default: false
Wether or not the destination should be handled as json.
append({json: true});

append(opts) - named

Type: boolean
Default: false
Wether or not to name the items.
creates an named object when true (checkout the transform option to learn how to set an custom name)
append({named: true});

append(opts) - transform

Type: object
Default: undefined
Transform the file to your likes.
append({
	transform: {
	  path: function(file) {
			return String(file.path);
	  },
		info: function(file) {
			return 'some info ...';
		}
	}
});

License

MIT © Glenn Vandeuren