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

@dobesv/clean-dest

v1.3.7

Published

A CLI to clean a destination directory given a source directory

Downloads

1,895

Readme

clean-dest

GitHub

A CLI to clean a destination directory given a source directory. This deletes files in the output folder that don't have a corresponding file in the source folder (any more). This helps deal with file renames and deletions when your build tool (e.g. babel or tsc) doesn't automatically delete output files whose input file was removed.

By default it keeps files in the output folder with the same name as files in the input folder, but you can configure this so that additional files are preserved by mapping a source file extension/suffix to output file extensions/suffixes.

Designed initially with typescript in mind, but can be used with any file types.

Install

$ npm install clean-dest

Usage

Folder structure

│
└───scripts
│   │   clean-dest.js
│
└───src
│   │   file1.ts
│   │   file2.ts
│
└───dist
│   │   file1.js
│   │   file1.js.map
│   │   file1.d.ts
│   │   file2.js
│   │   file2.js.map
│   │   file2.d.ts

Custom FileMap function

CLI command

clean-dest -s ./src -d ./dist --file-map ./scripts/clean-dest

CLI

src-root

Glob pattern(s) for source files.

dest-root

Destination root directory.

base-pattern

Glob pattern(s) to delete, default is "dest-root"/**/*. All files that match this pattern will be deleted unless they are matched to a source file or ignored using the ignore option.

file-map

This identifies files in dest-root that should be kept based on the files present in src-root based on a mapping from input file extensions to output file extensions.

The argument can either be a JS module to load for the mapping, or a mapping provided in a special format. If the argument matches the regular pattern /^.[a-z]/i it will be parsed as a mapping string, otherwise it is treated as a module to import.

using a string

It can be written as a series of file suffix mappings separated with semicolons. Each mapping has input file extensions and output file extensions around a colon (:). Multiple file extensions can be separated with commas. If a mapping has no colon then the input and output extensions are considered the same.

The output filename(s) are calculated by replacing a suffix found on the left by all the suffix(es) on the right.

Examples:

  • .js,.ts:.js,.js.map,.d.ts: For any .js or .ts file found in src-root, preserve matching files with suffixes .js, .js.map, .d.ts in dest-root
  • .js:.js,.js.map;.ts:.js,.js.map,.d.ts: For .js files in src-root, preserve .js and .js.map files in the dest-root. For .ts files, also preserve .d.ts files.
  • .js;.ts:.js,.js.map,.d.ts: For .js files in src-root, preserve .js files in the dest-root. For .ts files, preserve .js, .js.map, and .d.ts files.

using a js module

The argument can be a path to a js module that exports information about which files to keep in the output folder. The path will be loaded using require by default, so if it is a local module it should use a relative path.

If the module exports a string or array of strings they will be parsed and processed as if they were provided on the command line as a set of patterns.

If the module exports an object, the object's keys are considered a filename suffix to match. The object's values can be (1) strings or arrays of strings identifying replacement suffixes to use in the output folder, or (2) a function which takes a file path in the output folder but with the original file extension, and returns an array of potential output files.

For example:

// ./scripts/clean-dest.js
module.exports = exports = {
    // Rename the file extensions from the 'ts' from the src folder to what we expect in the dest folder
    '.ts': (destFilePath) => [
        destFilePath.replace(/.ts$/, '.d.ts'),
        destFilePath.replace(/.ts$/, '.js'),
        destFilePath.replace(/.ts$/, '.js.map'),
    ]
};

ignore

permanent

Optional permanent delete using del, otherwise uses trash.

dry-run

Optional test run to not actually delete matched files.

verbose

Optional output logging.

API

See the API docs.

Watch Mode

Use nodemon:

nodemon --watch ./src -e ts --exec clean-dest -s ./src -d ./dist