tjeastmond / gulp-ext-replace Goto Github PK
View Code? Open in Web Editor NEWSmall gulp plugin to change a file's extension
Small gulp plugin to change a file's extension
source path "bower_components\video.js\dist\video.js"
.pipe(extReplace('.min.js'))
result path "bower_components*video.min.js*\dist\video.js"
replaced in the wrong place
The following code is copying .css
files as .css.hidden
(not renaming)
gulp.task('hide-material-css-files', function () {
var ext_replace = require('gulp-ext-replace');
console.log(ext_replace);
return gulp.src(material + '/**/*.css')
.pipe(ext_replace('.css.hidden'))
.pipe(gulp.dest(material));
});
is there a way to get the function to rename instead of copying?
Hello
I'm using rails style file format. So, it's look like index.haml.html
Would be a nice to have option for working with files which have multiple types.
Example:
Origin file index.haml.html
or index.html
or index.haml.something.html
โ index.html
Can i send a pull request for this missing feature?
I have this use pattern:
- templates
- t1.js.jst
- t2.html.jst
- t3.stuf.zbuf.jst
Then gulp:
gulp.src('templates/**/*.jst')
.pipe(extReplace(''))
.pipe(gulp.dest('output'));
And it does not produce the expected result:
- templates
- t1.js
- t2.html
- t3.stuf.zbuf
The extension still remain, using 0.2.0
If there's a dot in a source folder name, the plugin creates a folder instead of a file.
Here is my version of index.js
'use strict';
// dependencies
var through = require('through2');
var path = require('path');
module.exports = function(ext, replaceExt) {
var extension_replace = function(file, encoding, callback) {
replaceExt = replaceExt || false;
var expr;
if (typeof ext === 'string' && ext.length > 0) {
ext = ext.indexOf('.') === 0 ? ext : '.' + ext;
expr = new RegExp('\\' + path.extname(file.path) + '$', 'g');
file.path = file.path.replace(replaceExt ? replaceExt : expr, ext);
}
callback(null, file);
};
return through.obj(extension_replace);
};
Check the expr = new RegExp('\\' + path.extname(file.path) + '$', 'g');
line
I am using gulp-save to save and restore the content and write to different files. My approach is to have source.js create three different files: [source.nl.js, source.de.js, source.en.js]. But calling ext_replace multiple times creates [source.nl.js, source.de.js, source.de.en.js] and that is not what I want. So I've created this version (no replace anymore!:)
module.exports = function(ext, replaceExt) {
var extension_replace = function(file, encoding, callback) {
replaceExt = replaceExt || false;
if (typeof ext === 'string' && ext.length > 0) {
ext = ext.indexOf('.') === 0 ? ext : '.' + ext;
var firstextensiondot = file.path.lastIndexOf('\\');
var fullnamewithoutextension = file.path.substring(0, file.path.substring(firstextensiondot).indexOf('.') + firstextensiondot)
file.path = fullnamewithoutextension + ext;
}
callback(null, file);
};
return through.obj(extension_replace);
};
The current regex (/\.[a-z]+$/g
) doesn't handle extensions with numbers, like .mp4
.
In your readme:
If you have a slightly more involved extension you'd like to replace like .min.css, you can tell the plugin to replace that instead of the default behavior by passing in a second variable to ext_replace in the following example:
That's probably clear as day to you, but not to a mere mortal ๐
I have no idea what the second argument is supposed to do. How does it replace by two different extensions? Or rather, what does it replace by what?
I would suggest adding a bit more explanation to it, and preferably also an example before / after view for this "more involved" scenario. Whatever that means ๐ค
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.