gulp-rename2
v0.1.5
Published
A gulp plugin for transforming file paths in the stream
Downloads
9
Maintainers
Readme
gulp-rename2
A simple, yet powerful gulp plugin for transforming file paths in the stream.
Usage
Here is a contrived example of transforming app/modules/viewer/index.coffee
to .build/modules/viewer/index.js
.
Obviously, you may do anything you want inside pathObj.join()
as long as it returns syntactically valid file path
(i.e. no checks are made against the files system whether this path is valid or not).
var rename = require("gulp-rename2");
gulp.src("app/modules/viewer/index.coffee")
.pipe(rename(function (pathObj, filePath) {
return pathObj.join(
// remove leading 'app/' directory from the file path
pathObj.dirname(filePath).replace(/^app\/?/,''),
// replace '.coffee' file extension with '.js'
pathObj.basename(filePath, '.coffee') + '.js'
);
}))
// output to '.build' directory
.pipe(gulp.dest('.build')); // .build/modules/viewer/index.js
API
rename(transformFunction [, options])
transformFunction
The transformFunction
must have the following signature function (pathObj, filePath) {}
.
The pathObj
is an instance of the core Node.js Path
module and the filePath
is the relative file path of the file piped through the stream.
Basically, use pathObj
instance to perform transformations on the filePath
leveraging
methods provided by the Node's Path
core module.
This function must return the final path string.
[options]
{ verbose: true }
Use verbose option to output the original and the transformed file paths to the log.
The default is false
.
var rename = require("gulp-rename2");
gulp.src("app/**/*.coffee")
.pipe(rename(function (pathObj, filePath) {
return pathObj.join(
// file path transformations
... ... ...
);
}, { verbose: true }))
.pipe(gulp.dest('.build'));