gulp-revert-path
Advanced tools
+9
-4
| 'use strict'; | ||
| var through = require('through2'); | ||
| module.exports = function () { | ||
| module.exports = function (reversions) { | ||
| reversions = typeof reversions === 'number' ? reversions : 1; | ||
| return through.obj(function (file, enc, cb) { | ||
| var history = file.history; | ||
| var highestIndex = history.length - 1; | ||
| if (history.length > 1) { | ||
| history.pop(); | ||
| file.path = history[history.length - 1]; | ||
| if (reversions > highestIndex) { | ||
| reversions = highestIndex; | ||
| } | ||
| history.splice(-reversions, reversions); | ||
| file.path = history[history.length - 1]; | ||
| cb(null, file); | ||
| }); | ||
| }; |
+1
-1
| { | ||
| "name": "gulp-revert-path", | ||
| "version": "1.0.1", | ||
| "version": "1.1.0", | ||
| "description": "Revert the previous `file.path` change", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+27
-1
@@ -5,3 +5,3 @@ # gulp-revert-path [](https://travis-ci.org/sindresorhus/gulp-revert-path) | ||
| Many plugins change the `file.path` somehow. Most commenly the file extension. For example `gulp-babel` changes `.jsx` extensions to `.js` since it compiles JSX. Sometimes that's undesirable though. This plugin makes it easy to revert the path change. | ||
| Many plugins change the `file.path` somehow. Most commonly the file extension. For example `gulp-babel` changes `.jsx` extensions to `.js` since it compiles JSX. Sometimes that's undesirable though. This plugin makes it easy to revert the path change. | ||
@@ -22,2 +22,3 @@ | ||
| var revertPath = require('gulp-revert-path'); | ||
| var rename = require('gulp-rename'); | ||
@@ -30,7 +31,32 @@ gulp.task('default', function () { | ||
| }); | ||
| gulp.task('es2015', function () { | ||
| return gulp.src('src/app.txt') | ||
| .pipe(rename('src/app.jsx')) // file.path => src/app.jsx | ||
| .pipe(babel()) // file.path => src/app.js | ||
| .pipe(revertPath(2)) // file.path => src/app.txt | ||
| .pipe(gulp.dest('dist')); | ||
| }); | ||
| ``` | ||
| ## API | ||
| ### revertPath(reversions) | ||
| #### reversions | ||
| Type: `number` | ||
| Default: `1` | ||
| Number of times to revert the path. | ||
| ## Related | ||
| - [vinyl-paths](https://github.com/sindresorhus/vinyl-paths) - Get the file paths in a vinyl stream | ||
| ## License | ||
| MIT © [Sindre Sorhus](http://sindresorhus.com) |
3725
24.29%15
25%60
76.47%