Skip to content

Commit

Permalink
Add multiExt option
Browse files Browse the repository at this point in the history
Closes #16.
  • Loading branch information
TheDancingCode committed May 15, 2018
1 parent 165949e commit eda8133
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
var Stream = require('stream');
var Path = require('path');

function gulpRename(obj) {
function gulpRename(obj, options) {

options = options || {};

var stream = new Stream.Transform({objectMode: true});

function parsePath(path) {
var extname = Path.extname(path);
var extname = options.multiExt ? Path.basename(path).slice(Path.basename(path).indexOf('.')) : Path.extname(path);
return {
dirname: Path.dirname(path),
basename: Path.basename(path, extname),
Expand Down
11 changes: 11 additions & 0 deletions test/path-parsing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,15 @@ describe('gulp-rename path parsing', function () {
helper(srcPattern, obj, null, done);
});
});

describe('multiExt option', function () {
it('includes multiple extensions in extname', function (done) {
var srcPattern = 'test/fixtures/hello.min.txt';
var obj = function (path) {
path.extname.should.equal('.min.txt');
path.basename.should.equal('hello');
};
helper(srcPattern, obj, null, done, { multiExt: true });
});
});
});
4 changes: 2 additions & 2 deletions test/spec-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ var Path = require('path'),
gulp = require('gulp'),
rename = require('../');

global.helper = function (srcArgs, obj, expectedPath, done) {
global.helper = function (srcArgs, obj, expectedPath, done, options) {
var srcPattern = srcArgs.pattern || srcArgs;
var srcOptions = srcArgs.options || {};
var stream = gulp.src(srcPattern, srcOptions).pipe(rename(obj));
var stream = gulp.src(srcPattern, srcOptions).pipe(rename(obj, options));
var count = 0;
stream.on('error', done);
stream.on('data', function () {
Expand Down

0 comments on commit eda8133

Please sign in to comment.