gulp-rename
Advanced tools
Comparing version 1.2.0 to 1.2.2
81
index.js
@@ -1,58 +0,65 @@ | ||
var Stream = require("stream"), | ||
Path = require("path"); | ||
'use strict'; | ||
var Stream = require('stream'); | ||
var Path = require('path'); | ||
function gulpRename(obj) { | ||
"use strict"; | ||
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 | ||
}; | ||
} | ||
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) { | ||
stream._transform = function(file, unused, callback) { | ||
var parsedPath = parsePath(file.relative); | ||
var path; | ||
var parsedPath = parsePath(file.relative); | ||
var path; | ||
var type = typeof obj; | ||
var type = typeof obj; | ||
if (type === "string" && obj !== "") { | ||
if (type === 'string' && obj !== '') { | ||
path = obj; | ||
path = obj; | ||
} else if (type === "function") { | ||
} else if (type === 'function') { | ||
var result = obj(parsedPath) || parsedPath; | ||
path = Path.join(result.dirname, result.basename + result.extname); | ||
obj(parsedPath); | ||
path = Path.join(parsedPath.dirname, parsedPath.basename + parsedPath.extname); | ||
} else if (type === "object" && obj !== undefined && obj !== null) { | ||
} 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; | ||
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); | ||
path = Path.join(dirname, prefix + basename + suffix + extname); | ||
} else { | ||
callback(new Error("Unsupported renaming parameter type supplied"), undefined); | ||
return; | ||
} | ||
} else { | ||
file.path = Path.join(file.base, path); | ||
callback(new Error('Unsupported renaming parameter type supplied'), undefined); | ||
return; | ||
callback(null, file); | ||
} | ||
} | ||
return stream; | ||
}; | ||
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; | ||
{ | ||
"name": "gulp-rename", | ||
"version": "1.2.0", | ||
"version": "1.2.2", | ||
"description": "Rename files", | ||
@@ -16,2 +16,5 @@ "keywords": [ | ||
"main": "./index.js", | ||
"files": [ | ||
"index.js" | ||
], | ||
"repository": { | ||
@@ -22,10 +25,13 @@ "type": "git", | ||
"scripts": { | ||
"test": "mocha test/*.spec.js" | ||
"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", | ||
"gulp": ">=3.0.0", | ||
"gulp-jshint": ">=1.1.0" | ||
"should": ">=2.1.0" | ||
}, | ||
@@ -32,0 +38,0 @@ "engines": { |
@@ -5,2 +5,7 @@ # gulp-rename | ||
[![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 | ||
@@ -15,24 +20,24 @@ | ||
gulp.src("./src/main/text/hello.txt") | ||
.pipe(rename("main/text/ciao/goodbye.md")) | ||
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/goodbye.md | ||
.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 | ||
.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 | ||
.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 | ||
``` | ||
@@ -47,3 +52,2 @@ | ||
* `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. | ||
* KNOWN ISSUE: The base set when using brace expansion may not be what you expect (See wearefractal/glob2base#1). Use the `base` option described above. | ||
* `basename` is the filename without the extension like path.basename(filename, path.extname(filename)). | ||
@@ -50,0 +54,0 @@ * `extname` is the file extension including the '.' like path.extname(filename). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
56
0
4759
7
3
43
2