pax_global_header00006660000000000000000000000064125071042750014515gustar00rootroot0000000000000052 comment=e1fb4e41dd107b38e96f1156fcbee70ebcf16fb6 gulp-rename-1.2.2/000077500000000000000000000000001250710427500137335ustar00rootroot00000000000000gulp-rename-1.2.2/.editorconfig000066400000000000000000000007571250710427500164210ustar00rootroot00000000000000# 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-1.2.2/.gitattributes000066400000000000000000000000131250710427500166200ustar00rootroot00000000000000* text=autogulp-rename-1.2.2/.gitignore000066400000000000000000000000361250710427500157220ustar00rootroot00000000000000.DS_Store node_modules/ temp/ gulp-rename-1.2.2/.jshintrc000066400000000000000000000006051250710427500155610ustar00rootroot00000000000000{ "node": true, "esnext": true, "bitwise": true, "camelcase": true, "curly": true, "eqeqeq": true, "immed": true, "indent": 2, "latedef": true, "newcap": true, "noarg": true, "quotmark": "single", "regexp": true, "undef": true, "unused": true, "strict": true, "trailing": true, "smarttabs": true, "white": true } gulp-rename-1.2.2/.travis.yml000066400000000000000000000000771250710427500160500ustar00rootroot00000000000000language: node_js node_js: - 0.10 - 0.11 - 0.12 - iojs gulp-rename-1.2.2/LICENSE000066400000000000000000000020561250710427500147430ustar00rootroot00000000000000Copyright 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-1.2.2/README.md000066400000000000000000000044011250710427500152110ustar00rootroot00000000000000# 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 via string 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 function gulp.src("./src/**/hello.txt") .pipe(rename(function (path) { path.dirname += "/ciao"; path.basename += "-goodbye"; path.extname = ".md" })) .pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/hello-goodbye.md // rename via hash 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). ## License [MIT License](http://en.wikipedia.org/wiki/MIT_License) gulp-rename-1.2.2/index.js000066400000000000000000000027511250710427500154050ustar00rootroot00000000000000'use strict'; var Stream = require('stream'); var Path = require('path'); function gulpRename(obj) { var stream = new Stream.Transform({objectMode: true}); function parsePath(path) { var extname = Path.extname(path); return { dirname: Path.dirname(path), basename: Path.basename(path, extname), extname: extname }; } stream._transform = function(file, unused, callback) { var parsedPath = parsePath(file.relative); var path; var type = typeof obj; if (type === 'string' && obj !== '') { path = obj; } else if (type === 'function') { obj(parsedPath); 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-1.2.2/package.json000066400000000000000000000016551250710427500162300ustar00rootroot00000000000000{ "name": "gulp-rename", "version": "1.2.2", "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": "jshint index.js test/", "test": "mocha" }, "devDependencies": { "gulp": ">=3.0.0", "gulp-sourcemaps": "^1.5.0", "gulp-util": "^3.0.4", "jshint": "^2.6.3", "map-stream": ">=0.0.4", "mocha": ">=1.15.0", "should": ">=2.1.0" }, "engines": { "node": ">=0.10.0", "npm": ">=1.2.10" }, "licenses": [ { "type": "MIT" } ] } gulp-rename-1.2.2/test/000077500000000000000000000000001250710427500147125ustar00rootroot00000000000000gulp-rename-1.2.2/test/.jshintrc000066400000000000000000000000611250710427500165340ustar00rootroot00000000000000{ "extends": "../.jshintrc", "mocha": true } gulp-rename-1.2.2/test/fixtures/000077500000000000000000000000001250710427500165635ustar00rootroot00000000000000gulp-rename-1.2.2/test/fixtures/hello.min.txt000066400000000000000000000000051250710427500212040ustar00rootroot00000000000000Hellogulp-rename-1.2.2/test/fixtures/hello.txt000066400000000000000000000000051250710427500204220ustar00rootroot00000000000000Hellogulp-rename-1.2.2/test/path-parsing.spec.js000066400000000000000000000071661250710427500206100ustar00rootroot00000000000000'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'); }); /* 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/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'); }); /* requires glob-stream >= 3.1.0 */ context.skip('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('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); }); }); }); gulp-rename-1.2.2/test/rename-sourcemap.spec.js000066400000000000000000000015301250710427500214430ustar00rootroot00000000000000'use strict'; var rename = require('../index'); var gutil = require('gulp-util'); 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 gutil.File({ base: 'fixtures', path: 'fixtures/fixture.css', contents: new Buffer('') })); init.end(); }); }); }); gulp-rename-1.2.2/test/rename.spec.js000066400000000000000000000145331250710427500174560ustar00rootroot00000000000000'use strict'; /* global helper, helperError */ require('./spec-helper'); 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('ignores the return value', function (done) { var obj = function (/*path*/) { return { dirname: 'elsewhere', basename: 'aloha', extname: '.md' }; }; var expectedPath = 'test/fixtures/hello.txt'; 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('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-1.2.2/test/spec-helper.js000066400000000000000000000021401250710427500174540ustar00rootroot00000000000000'use strict'; require('should'); require('mocha'); var Path = require('path'), gulp = require('gulp'), rename = require('../'); global.helper = function (srcArgs, obj, expectedPath, done) { var srcPattern = srcArgs.pattern || srcArgs; var srcOptions = srcArgs.options || {}; var stream = gulp.src(srcPattern, srcOptions).pipe(rename(obj)); 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); };