pax_global_header00006660000000000000000000000064135717607620014530gustar00rootroot0000000000000052 comment=056b298f9307f6fa8f58f469c79d463be3f9d919 gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/000077500000000000000000000000001357176076200206715ustar00rootroot00000000000000gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/.editorconfig000066400000000000000000000007571357176076200233570ustar00rootroot00000000000000# EditorConfig helps developers define and maintain consistent # coding styles between different editors and IDEs # editorconfig.org root = true [*] # Change these settings to your own preference indent_style = space indent_size = 2 # We recommend you to keep these unchanged end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false [test/fixtures/*] insert_final_newline = false trim_trailing_whitespace = false gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/.gitattributes000066400000000000000000000000131357176076200235560ustar00rootroot00000000000000* text=autogulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/.gitignore000066400000000000000000000000601357176076200226550ustar00rootroot00000000000000.DS_Store node_modules/ temp/ package-lock.json gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/.travis.yml000066400000000000000000000001261357176076200230010ustar00rootroot00000000000000language: node_js node_js: - '12' - '11' - '10' - '9' - '8' - '6' - '4' gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/CHANGELOG.md000066400000000000000000000004131357176076200225000ustar00rootroot00000000000000# v2.0.0 #### Breaking - 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) #### Chores - Update deps - Switch from JSCS/JSHint to Prettier gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/LICENSE000066400000000000000000000020561357176076200217010ustar00rootroot00000000000000Copyright 2013 Hector Guillermo Parra Alvarez Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/README.md000066400000000000000000000056401357176076200221550ustar00rootroot00000000000000# gulp-rename gulp-rename is a [gulp](https://github.com/wearefractal/gulp) plugin to rename files easily. [![NPM](https://nodei.co/npm/gulp-rename.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/gulp-rename/) [![build status](https://secure.travis-ci.org/hparra/gulp-rename.svg)](http://travis-ci.org/hparra/gulp-rename) [![devDependency Status](https://david-dm.org/hparra/gulp-rename/dev-status.svg)](https://david-dm.org/hparra/gulp-rename#info=devDependencies) ## Usage gulp-rename provides simple file renaming methods. ```javascript var rename = require("gulp-rename"); // rename to a fixed value gulp.src("./src/main/text/hello.txt") .pipe(rename("main/text/ciao/goodbye.md")) .pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/goodbye.md // rename via mutating function gulp.src("./src/**/hello.txt") .pipe(rename(function (path) { // Updates the object in-place path.dirname += "/ciao"; path.basename += "-goodbye"; path.extname = ".md"; })) .pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/hello-goodbye.md // rename via a map function gulp.src("./src/**/hello.txt") .pipe(rename(function (path) { // Returns a completely new object, make sure you return all keys needed! return { dirname: path.dirname + "/ciao", basename: path.basename + "-goodbye", extname: ".md" }; })) .pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/hello-goodbye.md // rename via a fixed object gulp.src("./src/main/text/hello.txt", { base: process.cwd() }) .pipe(rename({ dirname: "main/text/ciao", basename: "aloha", prefix: "bonjour-", suffix: "-hola", extname: ".md" })) .pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/bonjour-aloha-hola.md ``` **See test/rename.spec.js for more examples and test/path-parsing.spec.js for hairy details.** ## Notes * `dirname` is the relative path from the base directory set by `gulp.src` to the filename. * `gulp.src()` uses glob-stream which sets the base to the parent of the first directory glob (`*`, `**`, [], or extglob). `dirname` is the remaining directories or `./` if none. glob-stream versions >= 3.1.0 (used by gulp >= 3.2.2) accept a `base` option, which can be used to explicitly set the base. * `gulp.dest()` renames the directories between `process.cwd()` and `dirname` (i.e. the base relative to CWD). Use `dirname` to rename the directories matched by the glob or descendents of the base of option. * `basename` is the filename without the extension like path.basename(filename, path.extname(filename)). * `extname` is the file extension including the '.' like path.extname(filename). * when using a function, a second `file` argument is provided with the whole context and original file value * when using a function, if no `Object` is returned then the passed parameter object (along with any modifications) is re-used ## License [MIT License](http://en.wikipedia.org/wiki/MIT_License) gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/index.js000066400000000000000000000035431357176076200223430ustar00rootroot00000000000000'use strict'; var Stream = require('stream'); var Path = require('path'); function gulpRename(obj, options) { options = options || {}; var stream = new Stream.Transform({ objectMode: true }); function parsePath(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), extname: extname }; } stream._transform = function(originalFile, unused, callback) { var file = originalFile.clone({ contents: false }); var parsedPath = parsePath(file.relative); var path; var type = typeof obj; if (type === 'string' && obj !== '') { path = obj; } else if (type === 'function') { let newParsedPath = obj(parsedPath, file); if (typeof newParsedPath === 'object' && newParsedPath !== null) { parsedPath = newParsedPath; } path = Path.join( parsedPath.dirname, parsedPath.basename + parsedPath.extname ); } else if (type === 'object' && obj !== undefined && obj !== null) { var dirname = 'dirname' in obj ? obj.dirname : parsedPath.dirname, prefix = obj.prefix || '', suffix = obj.suffix || '', basename = 'basename' in obj ? obj.basename : parsedPath.basename, extname = 'extname' in obj ? obj.extname : parsedPath.extname; path = Path.join(dirname, prefix + basename + suffix + extname); } else { callback( new Error('Unsupported renaming parameter type supplied'), undefined ); return; } file.path = Path.join(file.base, path); // Rename sourcemap if present if (file.sourceMap) { file.sourceMap.file = file.relative; } callback(null, file); }; return stream; } module.exports = gulpRename; gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/package.json000066400000000000000000000016131357176076200231600ustar00rootroot00000000000000{ "name": "gulp-rename", "version": "2.0.0", "description": "Rename files", "keywords": [ "gulpplugin" ], "homepage": "https://github.com/hparra/gulp-rename", "bugs": "https://github.com/hparra/gulp-rename/issues", "author": { "name": "Hector Guillermo Parra Alvarez", "email": "hector@hectorparra.com", "url": "https://github.com/hparra" }, "main": "./index.js", "files": [ "index.js" ], "repository": { "type": "git", "url": "git://github.com/hparra/gulp-rename.git" }, "scripts": { "pretest": "prettier --single-quote --write index.js test/**/*.js", "test": "mocha" }, "devDependencies": { "gulp": "^4.0.2", "gulp-sourcemaps": "^2.6.5", "map-stream": "^0.0.7", "mocha": "^6.0.0", "prettier": "^1.19.1", "should": "^13.2.3", "vinyl": "^2.0.0" }, "engines": { "node": ">=4" }, "license": "MIT" } gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/test/000077500000000000000000000000001357176076200216505ustar00rootroot00000000000000gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/test/fixtures/000077500000000000000000000000001357176076200235215ustar00rootroot00000000000000gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/test/fixtures/hello.min.txt000066400000000000000000000000051357176076200261420ustar00rootroot00000000000000Hellogulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/test/fixtures/hello.txt000066400000000000000000000000051357176076200253600ustar00rootroot00000000000000Hellogulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/test/path-parsing.spec.js000066400000000000000000000113741357176076200255420ustar00rootroot00000000000000'use strict'; /* global helper */ require('./spec-helper'); var Path = require('path'); describe('gulp-rename path parsing', function() { describe('dirname', function() { context('when src pattern contains no globs', function() { it("dirname is '.'", function(done) { var srcPattern = 'test/fixtures/hello.txt'; var obj = function(path) { path.dirname.should.equal('.'); }; helper(srcPattern, obj, null, done); }); }); context('when src pattern contains filename glob', function() { it("dirname is '.'", function(done) { var srcPattern = 'test/fixtures/*.min.txt'; var obj = function(path) { path.dirname.should.equal('.'); }; helper(srcPattern, obj, null, done); }); }); var dirnameHelper = function(srcPattern) { it('dirname is path from directory glob to file', function(done) { var obj = function(path) { path.dirname.should.match(/^fixtures[0-9]?$/); }; helper(srcPattern, obj, null, done); }); }; context('when src pattern matches a directory with *', function() { dirnameHelper('test/*/*.min.txt'); }); context('when src pattern matches a directory with **', function() { dirnameHelper('test/**/*.min.txt'); }); context('when src pattern matches a directory with [...]', function() { dirnameHelper('test/fixt[a-z]res/*.min.txt'); }); context('when src pattern matches a directory with {...,...}', function() { dirnameHelper('test/f{ri,ixtur}es/*.min.txt'); }); /* SKIP: glob2base does not handle brace expansion as expected. See wearefractal/glob2base#1 */ context.skip( 'when src pattern matches a directory with {#..#}', function() { dirnameHelper('test/fixtures{0..9}/*.min.txt'); } ); context('when src pattern matches a directory with an extglob', function() { dirnameHelper('test/f+(ri|ixtur)es/*.min.txt'); }); context('when src pattern includes `base` option', function() { it('dirname is path from given directory to file', function(done) { var srcPattern = 'test/**/*.min.txt'; var srcOptions = { base: process.cwd() }; var obj = function(path) { path.dirname.should.equal(Path.join('test', 'fixtures')); }; helper({ pattern: srcPattern, options: srcOptions }, obj, null, done); }); }); }); describe('basename', function() { it('strips extension like Path.basename(path, ext)', function(done) { var srcPattern = 'test/fixtures/hello.min.txt'; var obj = function(path) { path.basename.should.equal('hello.min'); path.basename.should.equal( Path.basename(srcPattern, Path.extname(srcPattern)) ); }; helper(srcPattern, obj, null, done); }); }); describe('extname', function() { it("includes '.' like Path.extname", function(done) { var srcPattern = 'test/fixtures/hello.txt'; var obj = function(path) { path.extname.should.equal('.txt'); path.extname.should.equal(Path.extname(srcPattern)); }; helper(srcPattern, obj, null, done); }); it('excludes multiple extensions like Path.extname', function(done) { var srcPattern = 'test/fixtures/hello.min.txt'; var obj = function(path) { path.extname.should.equal('.txt'); path.extname.should.equal(Path.extname(srcPattern)); }; 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 }); }); }); describe('original file context', function() { it('passed to plugin as second argument', function(done) { var srcPattern = 'test/fixtures/hello.min.txt'; var obj = function(path, file) { file.should.be.instanceof(Object); file.should.be.ok(); }; helper(srcPattern, obj, null, done, { multiExt: true }); }); it('has expected properties', function(done) { var srcPattern = 'test/fixtures/hello.min.txt'; var obj = function(path, file) { file.path.should.equal(Path.resolve(srcPattern)); file.base.should.equal(Path.dirname(Path.resolve(srcPattern))); file.basename.should.equal(Path.basename(srcPattern)); file.relative.should.equal(Path.basename(srcPattern)); file.extname.should.equal(Path.extname(srcPattern)); }; helper(srcPattern, obj, null, done, { multiExt: true }); }); }); }); gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/test/rename-sourcemap.spec.js000066400000000000000000000015341357176076200264050ustar00rootroot00000000000000'use strict'; var rename = require('../index'); var Vinyl = require('vinyl'); var sourceMaps = require('gulp-sourcemaps'); require('should'); describe('gulp-rename', function() { context('when file has source map', function() { it('updates source map file to match relative path of renamed file', function(done) { var init = sourceMaps.init(); var stream = init .pipe(rename({ prefix: 'test-' })) .pipe(rename({ prefix: 'test-' })); stream.on('data', function(file) { file.sourceMap.file.should.equal('test-test-fixture.css'); file.sourceMap.file.should.equal(file.relative); done(); }); init.write( new Vinyl({ base: 'fixtures', path: 'fixtures/fixture.css', contents: new Buffer('') }) ); init.end(); }); }); }); gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/test/rename.spec.js000066400000000000000000000173061357176076200244150ustar00rootroot00000000000000'use strict'; /* global helper, helperError */ require('./spec-helper'); var rename = require('../'); var gulp = require('gulp'); var Path = require('path'); describe('gulp-rename', function() { context('with string parameter', function() { context('when src pattern does not contain directory glob', function() { it('sets filename to value', function(done) { var srcPattern = 'test/fixtures/hello.txt'; var obj = 'hola.md'; var expectedPath = 'test/fixtures/hola.md'; helper(srcPattern, obj, expectedPath, done); }); }); context('when src pattern contains directory glob', function() { it('sets relative path to value', function(done) { var srcPattern = 'test/**/hello.txt'; var obj = 'fixtures/hola.md'; var expectedPath = 'test/fixtures/hola.md'; helper(srcPattern, obj, expectedPath, done); }); }); }); context('with object parameter', function() { var srcPattern; beforeEach(function() { srcPattern = 'test/**/hello.txt'; }); context('with empty object', function() { it('has no effect', function(done) { var obj = {}; var expectedPath = 'test/fixtures/hello.txt'; helper(srcPattern, obj, expectedPath, done); }); }); context('with dirname value', function() { it('replaces dirname with value', function(done) { var obj = { dirname: 'elsewhere' }; var expectedPath = 'test/elsewhere/hello.txt'; helper(srcPattern, obj, expectedPath, done); }); it("removes dirname with './'", function(done) { var obj = { dirname: './' }; var expectedPath = 'test/hello.txt'; helper(srcPattern, obj, expectedPath, done); }); it('removes dirname with empty string', function(done) { var obj = { dirname: '' }; var expectedPath = 'test/hello.txt'; helper(srcPattern, obj, expectedPath, done); }); }); context('with prefix value', function() { it('prepends value to basename', function(done) { var obj = { prefix: 'bonjour-' }; var expectedPath = 'test/fixtures/bonjour-hello.txt'; helper(srcPattern, obj, expectedPath, done); }); }); context('with basename value', function() { it('replaces basename with value', function(done) { var obj = { basename: 'aloha' }; var expectedPath = 'test/fixtures/aloha.txt'; helper(srcPattern, obj, expectedPath, done); }); it('removes basename with empty string (for consistency)', function(done) { var obj = { prefix: 'aloha', basename: '' }; var expectedPath = 'test/fixtures/aloha.txt'; helper(srcPattern, obj, expectedPath, done); }); }); context('with suffix value', function() { it('appends value to basename', function(done) { var obj = { suffix: '-hola' }; var expectedPath = 'test/fixtures/hello-hola.txt'; helper(srcPattern, obj, expectedPath, done); }); }); context('with extname value', function() { it('replaces extname with value', function(done) { var obj = { extname: '.md' }; var expectedPath = 'test/fixtures/hello.md'; helper(srcPattern, obj, expectedPath, done); }); it('removes extname with empty string', function(done) { var obj = { extname: '' }; var expectedPath = 'test/fixtures/hello'; helper(srcPattern, obj, expectedPath, done); }); }); }); context('with function parameter', function() { var srcPattern; beforeEach(function() { srcPattern = 'test/**/hello.txt'; }); it('receives object with dirname', function(done) { var obj = function(path) { path.dirname.should.equal('fixtures'); path.dirname = 'elsewhere'; }; var expectedPath = 'test/elsewhere/hello.txt'; helper(srcPattern, obj, expectedPath, done); }); it('receives object with basename', function(done) { var obj = function(path) { path.basename.should.equal('hello'); path.basename = 'aloha'; }; var expectedPath = 'test/fixtures/aloha.txt'; helper(srcPattern, obj, expectedPath, done); }); it('receives object with extname', function(done) { var obj = function(path) { path.extname.should.equal('.txt'); path.extname = '.md'; }; var expectedPath = 'test/fixtures/hello.md'; helper(srcPattern, obj, expectedPath, done); }); it('receives object from return value', function(done) { var obj = function(path) { return { dirname: path.dirname, basename: path.basename, extname: '.md' }; }; var expectedPath = 'test/fixtures/hello.md'; helper(srcPattern, obj, expectedPath, done); }); it('ignores null return value but uses passed object', function(done) { var obj = function(path) { path.extname.should.equal('.txt'); path.extname = '.md'; return null; }; var expectedPath = 'test/fixtures/hello.md'; helper(srcPattern, obj, expectedPath, done); }); it('receives object with extname even if a different value is returned', function(done) { var obj = function(path) { path.extname.should.equal('.txt'); path.extname = '.md'; }; var expectedPath = 'test/fixtures/hello.md'; helper(srcPattern, obj, expectedPath, done); }); }); context('in parallel streams', function() { it('only changes the file in the current stream', function(done) { var files = gulp.src('test/fixtures/hello.txt'); var pipe1 = files.pipe(rename({ suffix: '-1' })); var pipe2 = files.pipe(rename({ suffix: '-2' })); var end1 = false; var end2 = false; var file1; var file2; function check() { file1.path.should.equal(Path.resolve('test/fixtures/hello-1.txt')); file2.path.should.equal(Path.resolve('test/fixtures/hello-2.txt')); return done(); } pipe1 .on('data', function(file) { file1 = file; }) .on('end', function() { end1 = true; if (end2) { return check(); } }); pipe2 .on('data', function(file) { file2 = file; }) .on('end', function() { end2 = true; if (end1) { return check(); } }); }); }); context('throws unsupported parameter type', function() { var srcPattern; beforeEach(function() { srcPattern = 'test/**/hello.txt'; }); var UNSUPPORTED_PARAMATER = 'Unsupported renaming parameter type supplied'; it('with undefined object', function(done) { var obj; var expectedError = UNSUPPORTED_PARAMATER; helperError(srcPattern, obj, expectedError, done); }); it('with null object', function(done) { var obj = null; var expectedError = UNSUPPORTED_PARAMATER; helperError(srcPattern, obj, expectedError, done); }); it('with empty string', function(done) { var obj = ''; var expectedError = UNSUPPORTED_PARAMATER; helperError(srcPattern, obj, expectedError, done); }); it('with boolean value', function(done) { var obj = true; var expectedError = UNSUPPORTED_PARAMATER; helperError(srcPattern, obj, expectedError, done); }); it('with numeric value', function(done) { var obj = 1; var expectedError = UNSUPPORTED_PARAMATER; helperError(srcPattern, obj, expectedError, done); }); }); }); gulp-rename-056b298f9307f6fa8f58f469c79d463be3f9d919/test/spec-helper.js000066400000000000000000000021531357176076200244160ustar00rootroot00000000000000'use strict'; require('should'); require('mocha'); var Path = require('path'), gulp = require('gulp'), rename = require('../'); 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, options)); var count = 0; stream.on('error', done); stream.on('data', function() { count++; }); if (expectedPath) { stream.on('data', function(file) { var resolvedExpectedPath = Path.resolve(expectedPath); var resolvedActualPath = Path.join(file.base, file.relative); resolvedActualPath.should.equal(resolvedExpectedPath); }); } stream.on('end', function() { count.should.be.greaterThan(0); done.apply(this, arguments); }); }; global.helperError = function(srcPattern, obj, expectedError, done) { var stream = gulp.src(srcPattern).pipe(rename(obj)); stream.on('error', function(err) { err.message.should.equal(expectedError); done(); }); stream.on('data', function() {}); stream.on('end', done); };