Skip to content

Commit 056b298

Browse files
committed
chore: release v2.0.0
1 parent ca50853 commit 056b298

File tree

11 files changed

+160
-189
lines changed

11 files changed

+160
-189
lines changed

.jscsrc

Lines changed: 0 additions & 13 deletions
This file was deleted.

.jshintrc

Lines changed: 0 additions & 21 deletions
This file was deleted.

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
language: node_js
22
node_js:
3+
- '12'
4+
- '11'
35
- '10'
46
- '9'
57
- '8'

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# v2.0.0
2+
3+
#### Breaking
4+
5+
- Add the ability to use the function argument as an immutable map function (This may be breaking for users who were relying on the return value of the function being ignored)
6+
7+
#### Chores
8+
9+
- Update deps
10+
- Switch from JSCS/JSHint to Prettier

index.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,54 @@ var Stream = require('stream');
44
var Path = require('path');
55

66
function gulpRename(obj, options) {
7-
87
options = options || {};
98

10-
var stream = new Stream.Transform({objectMode: true});
9+
var stream = new Stream.Transform({ objectMode: true });
1110

1211
function parsePath(path) {
13-
var extname = options.multiExt ? Path.basename(path).slice(Path.basename(path).indexOf('.')) : Path.extname(path);
12+
var extname = options.multiExt
13+
? Path.basename(path).slice(Path.basename(path).indexOf('.'))
14+
: Path.extname(path);
1415
return {
1516
dirname: Path.dirname(path),
1617
basename: Path.basename(path, extname),
1718
extname: extname
1819
};
1920
}
2021

21-
stream._transform = function (originalFile, unused, callback) {
22-
23-
24-
var file = originalFile.clone({contents: false});
22+
stream._transform = function(originalFile, unused, callback) {
23+
var file = originalFile.clone({ contents: false });
2524
var parsedPath = parsePath(file.relative);
2625
var path;
2726

2827
var type = typeof obj;
2928

3029
if (type === 'string' && obj !== '') {
31-
3230
path = obj;
33-
3431
} else if (type === 'function') {
35-
3632
let newParsedPath = obj(parsedPath, file);
3733
if (typeof newParsedPath === 'object' && newParsedPath !== null) {
3834
parsedPath = newParsedPath;
3935
}
40-
41-
path = Path.join(parsedPath.dirname, parsedPath.basename + parsedPath.extname);
4236

37+
path = Path.join(
38+
parsedPath.dirname,
39+
parsedPath.basename + parsedPath.extname
40+
);
4341
} else if (type === 'object' && obj !== undefined && obj !== null) {
44-
4542
var dirname = 'dirname' in obj ? obj.dirname : parsedPath.dirname,
4643
prefix = obj.prefix || '',
4744
suffix = obj.suffix || '',
4845
basename = 'basename' in obj ? obj.basename : parsedPath.basename,
4946
extname = 'extname' in obj ? obj.extname : parsedPath.extname;
5047

5148
path = Path.join(dirname, prefix + basename + suffix + extname);
52-
5349
} else {
54-
55-
callback(new Error('Unsupported renaming parameter type supplied'), undefined);
50+
callback(
51+
new Error('Unsupported renaming parameter type supplied'),
52+
undefined
53+
);
5654
return;
57-
5855
}
5956

6057
file.path = Path.join(file.base, path);

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gulp-rename",
3-
"version": "1.4.0",
3+
"version": "2.0.0",
44
"description": "Rename files",
55
"keywords": [
66
"gulpplugin"
@@ -21,17 +21,16 @@
2121
"url": "git://github.com/hparra/gulp-rename.git"
2222
},
2323
"scripts": {
24-
"pretest": "jscs index.js test/ && jshint index.js test/",
24+
"pretest": "prettier --single-quote --write index.js test/**/*.js",
2525
"test": "mocha"
2626
},
2727
"devDependencies": {
28-
"gulp": "^4.0.0",
29-
"gulp-sourcemaps": "^2.6.4",
30-
"jscs": "^3.0.0",
31-
"jshint": "^2.0.0",
28+
"gulp": "^4.0.2",
29+
"gulp-sourcemaps": "^2.6.5",
3230
"map-stream": "^0.0.7",
33-
"mocha": "^5.0.0",
34-
"should": "^13.0.0",
31+
"mocha": "^6.0.0",
32+
"prettier": "^1.19.1",
33+
"should": "^13.2.3",
3534
"vinyl": "^2.0.0"
3635
},
3736
"engines": {

test/.jshintrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/path-parsing.spec.js

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,129 +4,134 @@
44
require('./spec-helper');
55
var Path = require('path');
66

7-
describe('gulp-rename path parsing', function () {
8-
describe('dirname', function () {
9-
context('when src pattern contains no globs', function () {
10-
it('dirname is \'.\'', function (done) {
7+
describe('gulp-rename path parsing', function() {
8+
describe('dirname', function() {
9+
context('when src pattern contains no globs', function() {
10+
it("dirname is '.'", function(done) {
1111
var srcPattern = 'test/fixtures/hello.txt';
12-
var obj = function (path) {
12+
var obj = function(path) {
1313
path.dirname.should.equal('.');
1414
};
1515
helper(srcPattern, obj, null, done);
1616
});
1717
});
1818

19-
context('when src pattern contains filename glob', function () {
20-
it('dirname is \'.\'', function (done) {
19+
context('when src pattern contains filename glob', function() {
20+
it("dirname is '.'", function(done) {
2121
var srcPattern = 'test/fixtures/*.min.txt';
22-
var obj = function (path) {
22+
var obj = function(path) {
2323
path.dirname.should.equal('.');
2424
};
2525
helper(srcPattern, obj, null, done);
2626
});
2727
});
2828

29-
var dirnameHelper = function (srcPattern) {
30-
it('dirname is path from directory glob to file', function (done) {
31-
var obj = function (path) {
29+
var dirnameHelper = function(srcPattern) {
30+
it('dirname is path from directory glob to file', function(done) {
31+
var obj = function(path) {
3232
path.dirname.should.match(/^fixtures[0-9]?$/);
3333
};
3434
helper(srcPattern, obj, null, done);
3535
});
3636
};
3737

38-
context('when src pattern matches a directory with *', function () {
38+
context('when src pattern matches a directory with *', function() {
3939
dirnameHelper('test/*/*.min.txt');
4040
});
4141

42-
context('when src pattern matches a directory with **', function () {
42+
context('when src pattern matches a directory with **', function() {
4343
dirnameHelper('test/**/*.min.txt');
4444
});
4545

46-
context('when src pattern matches a directory with [...]', function () {
46+
context('when src pattern matches a directory with [...]', function() {
4747
dirnameHelper('test/fixt[a-z]res/*.min.txt');
4848
});
4949

50-
context('when src pattern matches a directory with {...,...}', function () {
50+
context('when src pattern matches a directory with {...,...}', function() {
5151
dirnameHelper('test/f{ri,ixtur}es/*.min.txt');
5252
});
5353

5454
/* SKIP: glob2base does not handle brace expansion as expected. See wearefractal/glob2base#1 */
55-
context.skip('when src pattern matches a directory with {#..#}', function () {
56-
dirnameHelper('test/fixtures{0..9}/*.min.txt');
57-
});
58-
59-
context('when src pattern matches a directory with an extglob', function () {
55+
context.skip(
56+
'when src pattern matches a directory with {#..#}',
57+
function() {
58+
dirnameHelper('test/fixtures{0..9}/*.min.txt');
59+
}
60+
);
61+
62+
context('when src pattern matches a directory with an extglob', function() {
6063
dirnameHelper('test/f+(ri|ixtur)es/*.min.txt');
6164
});
6265

63-
context('when src pattern includes `base` option', function () {
64-
it('dirname is path from given directory to file', function (done) {
66+
context('when src pattern includes `base` option', function() {
67+
it('dirname is path from given directory to file', function(done) {
6568
var srcPattern = 'test/**/*.min.txt';
66-
var srcOptions = {base: process.cwd()};
67-
var obj = function (path) {
69+
var srcOptions = { base: process.cwd() };
70+
var obj = function(path) {
6871
path.dirname.should.equal(Path.join('test', 'fixtures'));
6972
};
70-
helper({pattern: srcPattern, options: srcOptions}, obj, null, done);
73+
helper({ pattern: srcPattern, options: srcOptions }, obj, null, done);
7174
});
7275
});
7376
});
7477

75-
describe('basename', function () {
76-
it('strips extension like Path.basename(path, ext)', function (done) {
78+
describe('basename', function() {
79+
it('strips extension like Path.basename(path, ext)', function(done) {
7780
var srcPattern = 'test/fixtures/hello.min.txt';
78-
var obj = function (path) {
81+
var obj = function(path) {
7982
path.basename.should.equal('hello.min');
80-
path.basename.should.equal(Path.basename(srcPattern, Path.extname(srcPattern)));
83+
path.basename.should.equal(
84+
Path.basename(srcPattern, Path.extname(srcPattern))
85+
);
8186
};
8287
helper(srcPattern, obj, null, done);
8388
});
8489
});
8590

86-
describe('extname', function () {
87-
it('includes \'.\' like Path.extname', function (done) {
91+
describe('extname', function() {
92+
it("includes '.' like Path.extname", function(done) {
8893
var srcPattern = 'test/fixtures/hello.txt';
89-
var obj = function (path) {
94+
var obj = function(path) {
9095
path.extname.should.equal('.txt');
9196
path.extname.should.equal(Path.extname(srcPattern));
9297
};
9398
helper(srcPattern, obj, null, done);
9499
});
95100

96-
it('excludes multiple extensions like Path.extname', function (done) {
101+
it('excludes multiple extensions like Path.extname', function(done) {
97102
var srcPattern = 'test/fixtures/hello.min.txt';
98-
var obj = function (path) {
103+
var obj = function(path) {
99104
path.extname.should.equal('.txt');
100105
path.extname.should.equal(Path.extname(srcPattern));
101106
};
102107
helper(srcPattern, obj, null, done);
103108
});
104109
});
105110

106-
describe('multiExt option', function () {
107-
it('includes multiple extensions in extname', function (done) {
111+
describe('multiExt option', function() {
112+
it('includes multiple extensions in extname', function(done) {
108113
var srcPattern = 'test/fixtures/hello.min.txt';
109-
var obj = function (path) {
114+
var obj = function(path) {
110115
path.extname.should.equal('.min.txt');
111116
path.basename.should.equal('hello');
112117
};
113118
helper(srcPattern, obj, null, done, { multiExt: true });
114119
});
115120
});
116121

117-
describe('original file context', function () {
118-
it('passed to plugin as second argument', function (done) {
122+
describe('original file context', function() {
123+
it('passed to plugin as second argument', function(done) {
119124
var srcPattern = 'test/fixtures/hello.min.txt';
120-
var obj = function (path, file) {
125+
var obj = function(path, file) {
121126
file.should.be.instanceof(Object);
122127
file.should.be.ok();
123128
};
124129
helper(srcPattern, obj, null, done, { multiExt: true });
125130
});
126131

127-
it('has expected properties', function (done) {
132+
it('has expected properties', function(done) {
128133
var srcPattern = 'test/fixtures/hello.min.txt';
129-
var obj = function (path, file) {
134+
var obj = function(path, file) {
130135
file.path.should.equal(Path.resolve(srcPattern));
131136
file.base.should.equal(Path.dirname(Path.resolve(srcPattern)));
132137
file.basename.should.equal(Path.basename(srcPattern));

test/rename-sourcemap.spec.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,29 @@ var Vinyl = require('vinyl');
55
var sourceMaps = require('gulp-sourcemaps');
66
require('should');
77

8-
describe('gulp-rename', function () {
9-
10-
context('when file has source map', function () {
11-
12-
it ('updates source map file to match relative path of renamed file', function (done) {
13-
8+
describe('gulp-rename', function() {
9+
context('when file has source map', function() {
10+
it('updates source map file to match relative path of renamed file', function(done) {
1411
var init = sourceMaps.init();
1512
var stream = init
1613
.pipe(rename({ prefix: 'test-' }))
1714
.pipe(rename({ prefix: 'test-' }));
1815

19-
stream.on('data', function (file) {
16+
stream.on('data', function(file) {
2017
file.sourceMap.file.should.equal('test-test-fixture.css');
2118
file.sourceMap.file.should.equal(file.relative);
2219
done();
2320
});
2421

25-
init.write(new Vinyl({
26-
base: 'fixtures',
27-
path: 'fixtures/fixture.css',
28-
contents: new Buffer('')
29-
}));
22+
init.write(
23+
new Vinyl({
24+
base: 'fixtures',
25+
path: 'fixtures/fixture.css',
26+
contents: new Buffer('')
27+
})
28+
);
3029

3130
init.end();
32-
3331
});
34-
3532
});
36-
3733
});

0 commit comments

Comments
 (0)