gulp-remove-code
gulp-remove-code copied to clipboard
Add support for multiple comment formats
Took me a while to figure out why this wasn't working with my PHP files, but I realized it's because PHP wasn't being recognized as using "HTML-style" comments. I rectified it by using the commentStart
and commentEnd
parameters, but then I got thinking.
What if I needed to remove blocks of HTML code in one part of a PHP file, and PHP code in another part? I suppose I could wrap the HTML parts in <?php /*removeIf(condition)*/ ?> ... <?php /*endRemoveIf(condition)*/ ?>
, but then I'd be stuck with an empty <?php ?>
, which isn't ideal.
Additionally, what if I want to search multiple file types for the same condition? For example, remove all PHP, HTML, JS, and CSS for a module. I'd have to duplicate a lot of code in my task, saying "check this format, and then this format, and then this one," which again, isn't ideal.
I'd really like to see an option to set commentStart
and commentEnd
as arrays, something like the following:
gulp.task("init", function () {
return gulp.src(src + "/**/*")
// remove login HTML code if --remove --login is passed
.pipe(gulpif(argv.remove && argv.login, removeCode({no_login: true, commentStart: ["<!--", "/*", "//"], commentEnd: ["-->", "*/", ""]})))
// return to the source directory
.pipe(gulp.dest(src));
});
That way you could parse multiple file types at once.
@crissdev any chance you could implement this? I've found a workaround, but I have to add multiple calls to the module with differing names, which seems very inefficient.
.pipe(plugins.remove_code({login_html: plugins.argv.remove && plugins.argv.remove.includes("login") ? true : false, commentStart: "<!--", commentEnd: "-->"}))
.pipe(plugins.remove_code({login_php: plugins.argv.remove && plugins.argv.remove.includes("login") ? true : false, commentStart: "/*", commentEnd: "*/"}))
.pipe(plugins.remove_code({login_css: plugins.argv.remove && plugins.argv.remove.includes("login") ? true : false, commentStart: "/*", commentEnd: "*/"}))