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.
You can install the library via npm:
npm i @carry0987/plugin-manager
Or via pnpm:
pnpm add @carry0987/plugin-manager
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]);
Cleans directories within the given source directory. Identifies directory paths to be cleaned and removes them.
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.
Clears unnecessary files in the target directory by removing files that do not match the given patterns.
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
.
Removes specified directories, ensuring they exist before attempting the removal.
These methods are intended for internal use within the PluginManager
class.
Recursively removes the specified directory and its contents.
Finds all dist
directories within the specified directory.
Identifies directories for cleaning based on the source and optional target directories.
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.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License. See the LICENSE file for details.