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

@carry0987/plugin-manager

v1.1.0

Published

This class provides utility functions for managing file operations, including cleaning directories, copying distribution folders, moving files, clearing unnecessary files, and removing empty directories in a file system.

Downloads

23

Readme

PluginManager-JS

NPM CI

The @carry0987/plugin-manager library provides a set of utility functions for managing file operations such as cleaning directories, copying distribution folders, moving files, clearing unnecessary files, and removing empty directories within a file system. This library is designed to streamline and simplify tasks commonly needed for managing plugins, assets, or similar sets of files.

Installation

You can install the library via npm:

npm i @carry0987/plugin-manager

Or via pnpm:

pnpm add @carry0987/plugin-manager

Usage

Here's an example of how you can use the @carry0987/plugin-manager library in your project:

import { PluginManager } from '@carry0987/plugin-manager';

const sourceDir = 'path/to/source';
const targetDir = 'path/to/target';

// Clean directories
PluginManager.cleanDir(sourceDir, targetDir);

// Copy distribution folders
PluginManager.copyDistFolders(sourceDir, targetDir);

// Move files
PluginManager.moveFiles(sourceDir, targetDir);

// Clear unnecessary files
PluginManager.clearUnnecessaryFiles(targetDir, ['*.js']);

// Clear empty directories
PluginManager.clearEmptyDirs(sourceDir);

// Remove directories
PluginManager.removeDirs([targetDir]);

API

cleanDir(sourceDir: string, targetDir?: string): void

Cleans directories within the given source directory. Identifies directory paths to be cleaned and removes them.

copyDistFolders(sourceDir: string, targetDir: string): void

Copies the contents of dist directories (often holding distribution-ready files) from the source directory to the target directory. Ensures that the necessary destination directories are created and recursively copies the files.

moveFiles(sourceDir: string, targetDir: string, pattern: string = '**/*', matchOption?: MicromatchOptions): void

Moves files matching a specific pattern from the source directory to the target directory. Supports advanced matching options and ensures that necessary destination directories are created.

clearUnnecessaryFiles(targetDir: string, patterns: string[]): void

Clears unnecessary files in the target directory by removing files that do not match the given patterns.

clearEmptyDirs(directory: string): boolean

Removes empty directories under the specified directory. Recursively checks each subdirectory, removing any that are empty. Returns true if the directory is empty, else false.

removeDirs(dirs: string[]): void

Removes specified directories, ensuring they exist before attempting the removal.

Private Utility Methods

These methods are intended for internal use within the PluginManager class.

removeDir(dirPath: string): void

Recursively removes the specified directory and its contents.

findDistDirs(dir: string, getRealPath?: boolean): string[]

Finds all dist directories within the specified directory.

findDestDirs(sourceDir: string, targetDir?: string): string[]

Identifies directories for cleaning based on the source and optional target directories.

copyRecursiveSync(src: string, dest: string): void

Recursively copies files from the source directory to the destination directory.

getAllFiles(dir: string, pattern: string, fileList: string[] = [], matchOption?: MicromatchOptions): string[]

Recursively collects all files matching the specified pattern from the directory.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.