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

sync-glob

v1.4.0

Published

Synchronize files and folders locally by glob patterns, watch option included.

Downloads

4,178

Readme

node-sync-glob

Build Status

Build status

Synchronize files and folders locally by glob patterns, watch option included.

Install

npm i sync-glob

Usage

Usage: bin/sync-glob.js <sources> <target>

Commands:
  sources  One or more globs, files or directories to be mirrored (glob
           exclusions are supported as well - ! prefix)
  target   Destination folder for mirrored files

Options:
  --version            Show version number                             [boolean]
  --help               Show help                                       [boolean]
  -d, --delete         Delete extraneous files from target
                                                       [boolean] [default: true]
  -w, --watch          Watch changes in sources and keep target in sync
                                                      [boolean] [default: false]
  -i, --depth          Maximum depth if you have performance issues (not
                       everywhere yet: only on existing mirrors and watch
                       scenario)                    [number] [default: Infinity]
  -t, --transform      A module name to transform each file. sync-glob lookups
                       the specified name via "require()".              [string]
  -e, --exit-on-error  Exit if an error occurred                 [default: true]
  -v, --verbose        Moar output                    [boolean] [default: false]
  -s, --silent         No output (except errors)                [default: false]

copyright 2016

In your package.json

You may have some build script in your package.json involving mirroring folders (let's say, static assets), that's a good use-case for sync-glob:

// Before
{
  "scripts": {
    "build": "cp -rf src/images dist/",
    "watch": "???"
  }
}

// After
{
  "devDependencies": {
    "sync-glob": "^1.0.0"
  },
  "scripts": {
    "build": "sync-glob 'src/images/*' dist/images",
    "watch": "sync-glob --watch 'src/images/*' dist/images"
  }
}

Important

Make sure that your globs are not being parsed by your shell by properly escaping them, e.g.: by quoting '**/*'.

Exclude stuff

To exclude stuff from source just use glob exclusion - ! prefix, like:

{
  "scripts": {
    "sync": "sync-glob 'src/images/*' '!src/images/excluded.jpg' dist/images"
  }
}

Windows

As node-glob and node-glob-all respectively only support unix style path separators /, don't use windows style \.

Please only use forward-slashes in glob expressions.

Though windows uses either / or \ as its path separator, only / characters are used by this glob implementation. You must use forward-slashes only in glob expressions. Back-slashes will always be interpreted as escape characters, not path separators.

Results from absolute patterns such as /foo/* are mounted onto the root setting using path.join. On windows, this will by default result in /foo/* matching C:\foo\bar.txt.

API

Check our API documentation

Credit/Inspiration

This package was mainly inspired by node-sync-files. I mainly kept the API as is, but enhanced the file matching by utilizing powerful globs. Additionally it is a complete rewrite in ES6 and it does not suffer from outdated dependencies. Some fancy features like --transform is inspired by cpx

Proudly brought to you by <scale-unlimited>