npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-rev-dist-clean

v3.2.3

Published

Clean temporary files created by gulp-rev

Downloads

1,483

Readme

npm version   npm downloads   CI status   codecov   license

gulp-rev-dist-clean

gulp-rev-dist-clean is a gulp package to ease clean-up of temporary and legacy files created by the gulp-rev plugin.

NPM

How It Works

The plugin parses the rev-manifest.json file created by gulp-rev and compares it to your directory tree, deleting tempory files that you do not wish to keep.

For instance, according to the following rev-manifest.json file:

{
    "css/libs.css": "css/libs-beaeb26c53.css",
    "css/main.css": "css/main-3b7de4f4f1.css",
    "js/libs.js": "js/libs-a90857797b.js",
    "js/main.js": "js/main-beaeb26c53.js"
}

and the following directory tree:

build/assets
├─── css
│    ├─── libs.css
│    ├─── libs-beaeb26c53.css
│    ├─── main.css
│    ├─── main-3b7de4f4f1.css
│    ├─── old-file.css
│    └─── old-file-55900dd045.css
├─── js
│    ├─── libs.js
│    ├─── libs-a90857797b.js
│    ├─── main.js
│    └─── main-beaeb26c53.js
└─── rev-manifest.json

the plugin will always delete the following files, because they are not listed in the manifest:

  • build/assets/css/old-file.css
  • build/assets/css/old-file-55900dd045.css

It can optionally remove either the revised files (via the keepRenamedFiles option):

  • build/assets/css/libs-beaeb26c53.css
  • build/assets/css/main-3b7de4f4f1.css
  • build/assets/js/libs-a90857797b.js
  • build/assets/js/main-beaeb26c53.js

and/or the original files (via the keepOriginalFiles option):

  • build/assets/css/libs.css
  • build/assets/css/main.css
  • build/assets/js/libs.js
  • build/assets/js/main.js

and/or the manifest file itself (via the keepManifestFile option):

  • build/assets/rev-manifest.json

Prerequisites

You already have a task creating a manifest file via the gulp-rev plugin:

const gulp = require("gulp");
const rev = require("gulp-rev");

gulp.task("default", () =>
    gulp
        .src(["assets/css/*.css", "assets/js/*.js"], { base: "assets" })
        .pipe(gulp.dest("build/assets"))
        .pipe(rev())
        .pipe(gulp.dest("build/assets"))
        .pipe(rev.manifest())
        .pipe(gulp.dest("build/assets"))
);

Installation

First, install the plugin via npm:

npm install --save-dev gulp-rev-dist-clean

Usage

Add the plugin to the imported node modules and create a new task as following. The plugin will clean all the matching directories according to the specified manifest file.

const gulp = require("gulp");
const rev = require("gulp-rev");
const revDistClean = require("gulp-rev-dist-clean");

gulp.task("default", () =>
    gulp
        .src(["assets/css/*.css", "assets/js/*.js"], { base: "assets" })
        .pipe(gulp.dest("build/assets"))
        .pipe(rev())
        .pipe(gulp.dest("build/assets"))
        .pipe(rev.manifest())
        .pipe(gulp.dest("build/assets"))
);

gulp.task("rev-dist-clean", () =>
    gulp
        .src(["build/assets/**/*"], { read: false })
        .pipe(revDistClean("build/assets/rev-manifest.json"))
);

Notes

  • the plugin doesn't need to access the content of your files, hence you can add the read: false optimization in gulp.src()
  • the plugin only deletes files (sub-directories are emptied but wont be deleted)

Options

Options can be passed as the second parameter:

gulp.src(["build/assets/**/*"], { read: false }).pipe(
    revDistClean("build/assets/rev-manifest.json", { keepRenamedFiles: false })
);

keepOriginalFiles

Type: boolean

Default: true

Keep the original files? [yes/no] (cf. How It Works for an example)

keepRenamedFiles

Type: boolean

Default: true

Keep the revised files generated by gulp-rev's rev() method? [yes/no] (see How It Works for an example)

keepSourceMapFiles

Type: boolean

Default: false

Keep the source map files generated by gulp-sourcemaps? [yes/no]

keepManifestFile

Type: boolean

Default: true

Keep the manifest file generated by gulp-rev's rev.manifest() method? [yes/no] (see How It Works for an example)

emitChunks

Type: boolean

Default: false

Set to true if you need to pipe() the files to another gulp plugin. When set to false nothing will get emitted to the stream.

delOptions

Type: object

Default: {}

Options to pass down to the del module whilst deleting files. See del module documentation for a list of available options.

License

This project is licensed under the MIT License.