Skip to content

Commit

Permalink
Merge 25a7c33 into 2c0d3cd
Browse files Browse the repository at this point in the history
  • Loading branch information
stevelacy committed Sep 16, 2014
2 parents 2c0d3cd + 25a7c33 commit 7a5c79c
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions docs/writing-a-plugin/guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;

// consts
// Consts
const PLUGIN_NAME = 'gulp-prefixer';

function prefixStream(prefixText) {
Expand All @@ -65,37 +65,33 @@ function prefixStream(prefixText) {
return stream;
}

// plugin level function (dealing with files)
// Plugin level function(dealing with files)
function gulpPrefixer(prefixText) {

if (!prefixText) {
throw new PluginError(PLUGIN_NAME, 'Missing prefix text!');
}

prefixText = new Buffer(prefixText); // allocate ahead of time

// creating a stream through which each file will pass
var stream = through.obj(function(file, enc, cb) {
// Creating a stream through which each file will pass
return through.obj(function(file, enc, callback) {
if (file.isNull()) {
// do nothing if no contents
// return empty file
return callback(null, file);
}

if (file.isBuffer()) {
file.contents = Buffer.concat([prefixText, file.contents]);
file.contents = Buffer.concat([prefixText, file.contents]);
}

if (file.isStream()) {
file.contents = file.contents.pipe(prefixStream(prefixText));
file.contents = file.contents.pipe(prefixStream(prefixText));
}

this.push(file);
return callback(null, file);

return cb();
});

// returning the file stream
return stream;
};

// exporting the plugin main function
// Exporting the plugin main function
module.exports = gulpPrefixer;
```

0 comments on commit 7a5c79c

Please sign in to comment.