Skip to content

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

Closed

Description

@JacobDB

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.

Activity

  1. JacobDB commented on Jun 8, 2017

    @JacobDB
    Author

    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));
    
  2. crissdev commented on Jun 11, 2017

    @crissdev
    Owner

    Duplicate of #3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions