Skip to content Skip to sidebar Skip to footer

How Can I Extract Filename From Gulp-contains Callback?

I am using gulp-contains to check for specific string and if that string is found I want to throw an error like 'String found in file abc'. the file param contains the whole object

Solution 1:

The file here is a file object in Node.js. You can get the path using file.path

.pipe(contains({
            search: 'myString',
            onFound: function (string, file, cb) {
                console.log(file);
                var sFile = require('path').parse(file.path).base;
                var error = 'Your file "' + sFile + '" contains "' + string + '", it should not.';
                cb(new gutil.PluginError('gulp-contains', error));
            }
        }))

Post a Comment for "How Can I Extract Filename From Gulp-contains Callback?"