Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to remove just comments if the value being checked is false #11

Closed
JacobDB opened this issue Feb 20, 2017 · 2 comments
Closed

Comments

@JacobDB
Copy link

JacobDB commented Feb 20, 2017

I'm trying to use this module to set up an "init" task that will take some general source files and remove any modules that I don't need for a given project. So far I think I've got a good idea of how this can work, but I'm running in to a small issue.

When passing false as the value for the condition your checking, it'd be nice if there was an additional option removeCommentsIfFalse (or something like that) that would remove just the comments and leave the code within as-is.

I can probably work around this using additional modules and regular expressions, but I think this would a be great feature to bake-in.

@JacobDB
Copy link
Author

JacobDB commented Jun 8, 2017

I've accomplished this use a regular expression with gulp-replace. It's not ideal, but it'll do. Here's the task:

// remove any remaining comments
gulp.src(global.settings.paths.src + "/**/*")
    // check if a file is a binary
    .pipe(plugins.is_binary())
    // skip file if it's a binary
    .pipe(plugins.through.obj(function (file, enc, next) {
        if (file.isBinary()) {
            next();
            return;
        }

        // go to next file
        next(null, file);
    }))
    .pipe(plugins.replace(/((?:\/\*|<!--)(?:end)?[rR]emoveIf\([^)]+\)(?:\*\/|-->))/g, ""))
    .pipe(gulp.dest(global.settings.paths.src));

@crissdev
Copy link
Owner

Duplicate of #3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants