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

mirror-directories

v4.0.4

Published

mirror multiple source directories to multiple target destinations

Downloads

21

Readme

mirror-directories

build status Known Vulnerabilities Renovate

Usage

Example 1

Recursively copy all the directories matching the glob src/* to out1 and out2:

% mirror-directories -s 'src/*' -d out1 -d out2

If src/project1 and src/project2 exist then they will be copied to out1/project1, out1/project2, out2/project1 and out2/project2.

Existing contents of the destination directories will be erased before the copying occurs such that the destination directories will mirror the source directories exactly.

Example 2

Recursively copy src1 and src2 to all the directories matching destinations/*:

% mirror-directories -s src1 -s src2 -d 'destinations/*'

If destinations/birthday and destinations/fear exist then at the end destinations/{birthday,fear}/{src1,src2} will be exact copies of their respective source directories.

Example 3

A trailing slash can be used to copy the contents of the source directory into the destination directory.

% mirror-directories -s 'src/' -d out

Creates out as a mirror of src instead of creating out/src as a mirror of src. This corresponds to the rename option of the API.

Example 4

The -m argument can be used to specify independent source/dest pairs.

% mirror-directories -m src:out -m friends/:enemies

This will mirror src to out/src and the contents of the friends directory to the enemies directory.

Example 5

The -m argument can be used to specify multiple source directories for a single dest directory. Either all of none of the source directories must have a trailing slash. When all source directories have a trailing slash, meaning all of them relate to rename watches, files in latter source directories will take precedence over those specified earlier.

% mirror-directories -m src1/:src2/:out

In this circumstance if both src1/file and src2/file exist then out/file will always mirror src2/file. If -w were used then any changes to src1/file would be ignored. Removing src2/file would lead to out/file being a mirror of src1/file until src2/file is recreated.

Example 6

The -e argument can be used to exclude directories

% mirror-directories -e blah -e hero/cat -m src:out -m friends/:enemies

This will mirror src to out/src and the contents of the friends directory to the enemies directory but will not mirror src/blah or src/hero/cat. If src/blah and/or src/hero/cat are directories then their contents would also be ignored.

Example 7

The -P argument can be used to exclude paths matching a pattern (using micromatch patterns internally with th matchBase option set). It applies to each component in the entire source path (relative to the source directory), so ex* would exclude all files and directories within the dir/exclude directory and the file dir/include/exclude.

% mirror-directories -P '*d' -m src:out

This will mirror src to out/src and will not copy any paths ending in the letter d.

API

This library also exports an API:

import { mirrorDirectories, watchDirectoriesForChangesAndMirror } from 'mirror-directories'

// the default options are { keep: false, rename: false }
mirrorDirectories([
  { srcDirs: ['src1'], destDirs: ['dest1', 'dest2'] },
  { srcDirs: ['src2', 'src3'], destDirs: ['dest2', 'dest3'] },
])

const stopWatching = await watchDirectoriesForChangesAndMirror(
  [{ srcDirs: ['src4'], destDirs: ['dest4', 'dest5'] }],
  {
    // keep existing contents in destination directories
    keep: true,
    // use watchman's "watch-project" command rather than "watch"
    watchProject: true,
    // mirrors `src4` to `dest4` and `dest5` instead of
    // `dest4/src4` and `dest5/src4`
    rename: true,
  },
)
process.on('exit', stopWatching())